-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_handler.py
46 lines (43 loc) · 1.65 KB
/
add_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import webapp2, logging
from database import get_feed_source_by_name, store_feed_source, \
get_feed_source_by_url, change_feed_source_url
class AddHandler(webapp2.RequestHandler):
def post(self):
from database import FeedSource
name = self.request.get('name')
url = self.request.get('url')
frequency_ms = self.request.get('frequency_ms')
should_update = self.request.get('should_update')
should_be_added = True
existing_source = get_feed_source_by_url(url)
if existing_source:
should_be_added = False
self.response.write( \
'The URL (' + url + ') already exists (name - ' + \
existing_source.name + ').<br/>')
self.response.write('Forgot you added it already? :O')
else:
existing_source = get_feed_source_by_name(name)
if existing_source:
if should_update:
should_be_added = False
change_feed_source_url(existing_source, url)
self.response.write('Updated.')
else:
should_be_added = False
self.response.write('The name (' + name + ') already exists.<br/>')
self.response.write( \
'Go back and choose a different name, or tick "Update?".<br/>')
if should_be_added and store_feed_source(name, url, int(frequency_ms)):
self.response.write('Added.');
def get(self):
from database import FeedSource
self.response.write("""<!doctype html><title>Add Feed</title>
<form method="post">
Name - <input name="name"/><br/>
URL - <input name="url"/><br/>
Frequency (milliseconds) -
<input type="number" value="1000" name="frequency_ms"/><br/>
<label>Update?<input type="checkbox" name="should_update" value="1"/></label>
<input type="submit"/>
</form>""")