Commits

danjac  committed 3f62c38

fixed timesince

  • Participants
  • Parent commits 43c4760
  • Branches flatland

Comments (0)

Files changed (5)

 
 manager = Manager(create_app)
 
+@manager.command
+def rungevent(port=5000, name=''):
+    from gevent.wsgi import WSGIServer
+    server = WSGIServer((name, port), 
+                        current_app._get_current_object())
+    server.serve_forever()
+
+
 @manager.option("-u", "--url", dest="url", help="Feed URL")
 @manager.option("-n", "--username", dest="username", help="Save to user")
 def importfeed(url, username):

File newsmeme/config.py

 
     DEFAULT_MAIL_SENDER = "support@thenewsmeme.com"
 
-    ACCEPT_LANGUAGES = ['en', 'fi']
+    ACCEPT_LANGUAGES = ['en_gb', 'fi']
 
     DEBUG_LOG = 'logs/debug.log'
     ERROR_LOG = 'logs/error.log'

File newsmeme/helpers.py

     """
     Returns string representing "time since" e.g.
     3 days ago, 5 hours ago etc.
+    NB: when/if Babel 1.0 releaseduse format_timedelta/timedeltaformat instead
     """
     
     if default is None:
     now = datetime.utcnow()
     diff = now - dt
     
+    years = diff.days / 365
+    months = diff.days / 30
+    weeks = diff.days / 7
+    days = diff.days
+    hours = diff.seconds / 3600
+    minutes = diff.seconds / 60
+    seconds = diff.seconds 
+
     periods = (
-        (diff.days / 365, "year", "years"),
-        (diff.days / 30, "month", "months"),
-        (diff.days / 7, "week", "weeks"),
-        (diff.days, "day", "days"),
-        (diff.seconds / 3600, "hour", "hours"),
-        (diff.seconds / 60, "minute", "minutes"),
-        (diff.seconds, "second", "seconds"),
+        (years, ngettext("%(num)s year", "%(num)s years", num=years)),
+        (months, ngettext("%(num)s month", "%(num)s months", num=months)),
+        (weeks, ngettext("%(num)s week", "%(num)s weeks", num=weeks)),
+        (days, ngettext("%(num)s day", "%(num)s days", num=days)),
+        (hours, ngettext("%(num)s hour", "%(num)s hours", num=hours)),
+        (minutes, ngettext("%(num)s minute", "%(num)s minutes", num=minutes)),
+        (seconds, ngettext("%(num)s second", "%(num)s seconds", num=seconds)),
     )
 
-    for period, singular, plural in periods:
-        
-        if not period:
-            continue
-
-        singular = u"%%(num)d %s ago" % singular
-        plural = u"%%(num)d %s ago" % plural
-
-        return ngettext(singular, plural, num=period)
+    for period, trans in periods:
+        if period:
+            return gettext("%(period)s ago", period=trans)
 
     return default
 

File newsmeme/static/js/newsmeme.js

         newsmeme.ajax_post(url, null, callback);
     }
 
+    filter_tag : function(url){
+        var callback = function(response){
+            $('#filter-tag').hide();
+            $('#filter-tag-confirm').show();
+        }
+
+        newsmeme.ajax_post(url, null, callback);
+    }
 }

File newsmeme/views/frontend.py

 
 frontend = Module(__name__)
 
+
 @frontend.route("/")
 @frontend.route("/<int:page>/")
 @cached()
                            page_url=page_url,
                            page_obj=page_obj)
     
+@frontend.route("/tags/filter/<int:tag_id>/", methods=("POST",))
+@auth.require(401)
+def filter_tag(tag_id):
+
+    tag = Tag.query.get_or_404(tag_id)
+    g.user.filters.add(tag.id)
+    db.session.commit()
+
+    return jsonify(success=True)
 
 @frontend.route("/help/")
 @keep_login_url