From 9a9b5c19d8c07026b104ed81838145454bfa9fc9 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 12 Apr 2015 17:03:20 +0200 Subject: It is now possible to add a new feed from any page via a dropdown menu. --- pyaggr3g470r/forms.py | 9 +++++-- pyaggr3g470r/static/css/customized-bootstrap.css | 1 - pyaggr3g470r/templates/layout.html | 32 +++++++++++++++++++++--- pyaggr3g470r/views/feed.py | 5 +++- pyaggr3g470r/views/views.py | 10 ++++++++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py index e385c4e2..fb4a829c 100644 --- a/pyaggr3g470r/forms.py +++ b/pyaggr3g470r/forms.py @@ -87,11 +87,16 @@ class SigninForm(Form): class AddFeedForm(Form): title = TextField(lazy_gettext("Title"), [validators.Optional()]) - link = TextField(lazy_gettext("Feed link"), [validators.Optional()]) - site_link = TextField(lazy_gettext("Site link")) + link = TextField(lazy_gettext("Feed link")) + site_link = TextField(lazy_gettext("Site link"), [validators.Optional()]) enabled = BooleanField(lazy_gettext("Check for updates"), default=True) submit = SubmitField(lazy_gettext("Save")) + def validate(self): + if not super(AddFeedForm, self).validate(): + return False + return True + class ProfileForm(Form): nickname = TextField(lazy_gettext("Nickname"), diff --git a/pyaggr3g470r/static/css/customized-bootstrap.css b/pyaggr3g470r/static/css/customized-bootstrap.css index 58a9d182..1b3c197d 100644 --- a/pyaggr3g470r/static/css/customized-bootstrap.css +++ b/pyaggr3g470r/static/css/customized-bootstrap.css @@ -11,7 +11,6 @@ div.top { .navbar-custom { background-color: #205081; border: #205081; - color: #FFFFFF; border-radius: 0; } diff --git a/pyaggr3g470r/templates/layout.html b/pyaggr3g470r/templates/layout.html index e673a128..d183f79b 100644 --- a/pyaggr3g470r/templates/layout.html +++ b/pyaggr3g470r/templates/layout.html @@ -1,4 +1,4 @@ - + {% block head %} @@ -33,7 +33,33 @@ diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index e4c0dc9a..af43d6f0 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -134,6 +134,8 @@ def form(feed_id=None): if request.method == 'POST': if not form.validate(): + print(dir(form)) + print("oups") return render_template('edit_feed.html', form=form) existing_feeds = list(feed_contr.read(link=form.link.data)) if existing_feeds and feed_id is None: @@ -141,8 +143,8 @@ def form(feed_id=None): "warning") return redirect(url_for('feed.form', feed_id=existing_feeds[0].id)) - # Edit an existing feed + print("new...") if feed_id is not None: feed_contr.update({'id': feed_id}, {'title': form.title.data, @@ -154,6 +156,7 @@ def form(feed_id=None): return redirect(url_for('feed.form', feed_id=feed_id)) # Create a new feed + print("new feed") new_feed = FeedController(g.user.id).create( title=form.title.data, description="", diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index e06e1a9d..06b234cd 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -138,6 +138,16 @@ def get_timezone(): except: return conf.TIME_ZONE["en"] +@app.context_processor +def inject_feed_form(): + """ + Injects the 'AddFeedForm' objects in all templates. + + Context processors run before the template is rendered and have the + ability to inject new values into the template context. + """ + return dict(create_feed_form=AddFeedForm()) + # # Views. # -- cgit