delete.py 1.12 KB
Newer Older
1
from cgi import parse_qs, escape
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import site

site.addsitedir('/srv/http/go/wsgi')
import library
import goconfig

def application(environ, start_response):

  if( not library.user_logged_in( environ ) ):
    status = '303 See other'
    response_headers = [('Location', '/login')]
    start_response(status, response_headers)
    return ['Redirecting to login . . .']

  if not (environ["REQUEST_METHOD"] == "GET"):
    status = '303 See other'
    response_headers = [('Location', '/')]
    start_response(status, response_headers)
    return ['Redirecting to index . . .']

  body = []

24
25
26
27
  # Grab user data.
  data = parse_qs(environ['QUERY_STRING'])
  short_url = data.get("u", [''])[0]
  short_url = escape(short_url)
28

29
30
  username = library.get_username( environ )
  links = library.get_links( username )
31

32
33
34
35
36
  if links is not None:
    for link in links:
      (link_id, _, link_short_url, _, _, _) = link
      if short_url == link_short_url:
        library.delete_url( link_id )
37
38
39
40

  status = '303 See other'
  response_headers = [('Location', '/mylinks')]
  start_response(status, response_headers)
41
  return ['Redirecting to mylinks . . .']