From: Michael Tremer Date: Wed, 12 Dec 2012 13:38:17 +0000 (+0100) Subject: Add pages to show recent comments. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62c7e7cd7bc218772a590f2bf8e61ae57e4bf68d;p=pbs.git Add pages to show recent comments. --- diff --git a/backend/builds.py b/backend/builds.py index 81f77dac..d2046993 100644 --- a/backend/builds.py +++ b/backend/builds.py @@ -269,6 +269,39 @@ class Builds(base.Object): return builds + def get_comments(self, limit=10, offset=None, user=None): + query = "SELECT * FROM builds_comments \ + JOIN users ON builds_comments.user_id = users.id" + args = [] + + wheres = [] + if user: + wheres.append("users.id = %s") + args.append(user.id) + + if wheres: + query += " WHERE %s" % " AND ".join(wheres) + + # Sort everything. + query += " ORDER BY time_created DESC" + + # Limits. + if limit: + if offset: + query += " LIMIT %s,%s" + args.append(offset) + else: + query += " LIMIT %s" + + args.append(limit) + + comments = [] + for comment in self.db.query(query, *args): + comment = logs.CommentLogEntry(self.pakfire, comment) + comments.append(comment) + + return comments + class Build(base.Object): def __init__(self, pakfire, id, data=None): diff --git a/backend/logs.py b/backend/logs.py index 20c54c67..af2e83dd 100644 --- a/backend/logs.py +++ b/backend/logs.py @@ -79,6 +79,14 @@ class CommentLogEntry(LogEntry): def credit(self): return self.data.credit + @property + def build_id(self): + return self.data.build_id + + @property + def build(self): + return self.pakfire.builds.get_by_id(self.build_id) + @property def vote(self): if self.credit > 0: diff --git a/backend/users.py b/backend/users.py index 8a32f11c..255e1b3d 100644 --- a/backend/users.py +++ b/backend/users.py @@ -473,19 +473,6 @@ class User(base.Object): self.pakfire.messages.add("%s <%s>" % (self.realname, self.email), subject, message) - def get_comments(self, limit=5): - comments = self.db.query("""SELECT * FROM builds_comments - WHERE user_id = %s ORDER BY time_created DESC LIMIT %s""", self.id, limit) - - return comments - - @property - def log(self): - return self.get_history(limit=15) - - def get_history(self, limit=None): - return [] # XXX TODO - # Some testing code. if __name__ == "__main__": diff --git a/data/templates/build-index.html b/data/templates/build-index.html index c549fea2..bc9f303d 100644 --- a/data/templates/build-index.html +++ b/data/templates/build-index.html @@ -3,6 +3,25 @@ {% block title %}{{ _("Builds") }}{% end block %} {% block body %} + + + + diff --git a/data/templates/builds/comments.html b/data/templates/builds/comments.html new file mode 100644 index 00000000..fc9e72fc --- /dev/null +++ b/data/templates/builds/comments.html @@ -0,0 +1,84 @@ +{% extends "../base.html" %} + +{% block title %}{{ _("Build comments") }}{% end block %} + +{% block body %} + + + {% if user %} + + {% end %} + + + + {% if comments %} +

+ {% if user %} + {{ _("This page shows %s's latest comments.") % user.firstname }} + {% else %} + {{ _("This page shows the latest comments on builds.") }} + {% end %} + {{ _("The Pakfire Build Service is all about social development and so, communicating with eath others is important. Please join.") }} +

+ + {% module Log(comments, show_build=True) %} + + + {% elif not comments and user %} +

+ {{ _("%s did not comment on anything, yet.") % user.firstname }} +

+ {% end %} +{% end block %} diff --git a/data/templates/modules/log-entry-comment.html b/data/templates/modules/log-entry-comment.html index 595418dc..126738de 100644 --- a/data/templates/modules/log-entry-comment.html +++ b/data/templates/modules/log-entry-comment.html @@ -18,8 +18,8 @@ {% if entry.get_message(current_user) %} {% module Text(entry.get_message(current_user), remove_linebreaks=False) %} {% else %} -

- {{ _("No comment given.") }} +

+ {{ _("No comment given.") }}

{% end %} {% end %} diff --git a/data/templates/modules/log-entry.html b/data/templates/modules/log-entry.html index c73fa920..53edce8f 100644 --- a/data/templates/modules/log-entry.html +++ b/data/templates/modules/log-entry.html @@ -22,6 +22,12 @@ {% else %} {{ entry.user.realname }} {% end %} + + {% if show_build %} + - + {{ entry.build.name }} + + {% end %} {% end %} {% end block %} diff --git a/data/templates/user-profile.html b/data/templates/user-profile.html index 2d0537d7..5dc7efdd 100644 --- a/data/templates/user-profile.html +++ b/data/templates/user-profile.html @@ -17,8 +17,16 @@ + +
@@ -110,7 +118,7 @@ {% if current_user == user or current_user.is_admin() %}
-

{{ _("Permissions") }}

+

{{ _("Permissions") }}

{% if user.is_admin() %}

@@ -136,20 +144,4 @@

{% end %} - - - - - - {% end block %} diff --git a/web/__init__.py b/web/__init__.py index c5f3b3e4..58eadc29 100644 --- a/web/__init__.py +++ b/web/__init__.py @@ -110,7 +110,6 @@ class Application(tornado.web.Application): # User profiles (r"/users", UsersHandler), - (r"/users/comments", UsersCommentsHandler), (r"/user/impersonate", UserImpersonateHandler), (r"/user/(\w+)/passwd", UserPasswdHandler), (r"/user/(\w+)/delete", UserDeleteHandler), @@ -136,6 +135,8 @@ class Application(tornado.web.Application): (r"/builds", BuildsHandler), (r"/builds/filter", BuildFilterHandler), (r"/builds/queue", BuildQueueHandler), + (r"/builds/comments", BuildsCommentsHandler), + (r"/builds/comments/(\w+)", BuildsCommentsHandler), (r"/build/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", BuildDetailHandler), (r"/build/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/bugs", BuildBugsHandler), (r"/build/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/manage", BuildManageHandler), diff --git a/web/handlers_builds.py b/web/handlers_builds.py index f113c087..266874cd 100644 --- a/web/handlers_builds.py +++ b/web/handlers_builds.py @@ -126,6 +126,37 @@ class BuildBugsHandler(BaseHandler): self.redirect("/build/%s/bugs" % build.uuid) +class BuildsCommentsHandler(BaseHandler): + def get(self, user_name=None): + user = None + if user_name: + user = self.pakfire.users.get_by_name(user_name) + + limit = self.get_argument("limit", 10) + offset = self.get_argument("offset", 0) + + try: + limit = int(limit) + offset = int(offset) + except: + raise tornado.web.HTTPError(400) + + # Try to get one more comment than requested and check if there + # is a next page that it to be shown. + comments = self.pakfire.builds.get_comments(limit=limit + 1, + offset=offset, user=user) + + # Set markers for next and prev pages. + have_next = len(comments) > limit + have_prev = offset > limit + + # Remove the extra element from the list. + comments = comments[:limit] + + self.render("builds/comments.html", comments=comments, limit=limit, + offset=offset + limit, user=user, have_prev=have_prev, have_next=have_next) + + class BuildStateHandler(BaseHandler): def get(self, uuid): build = self.pakfire.builds.get_by_uuid(uuid) diff --git a/web/handlers_users.py b/web/handlers_users.py index ced715a9..06bd49e2 100644 --- a/web/handlers_users.py +++ b/web/handlers_users.py @@ -17,10 +17,7 @@ class UserHandler(BaseHandler): if not user: raise tornado.web.HTTPError(404, "User does not exist: %s" % name) - log = user.get_history(limit=10) - comments = user.get_comments(limit=5) - - self.render("user-profile.html", user=user, log=log, comments=comments) + self.render("user-profile.html", user=user) class UserImpersonateHandler(BaseHandler): @@ -218,14 +215,6 @@ class UsersHandler(BaseHandler): self.render("user-list.html", users=users) -class UsersCommentsHandler(BaseHandler): - @tornado.web.authenticated - def get(self): - comments = self.pakfire.packages.get_comments(limit=20) - - self.render("user-comments.html", comments=comments) - - class UsersBuildsHandler(BaseHandler): def get(self, name=None): if name is None: diff --git a/web/ui_modules.py b/web/ui_modules.py index 8285abed..51dc858e 100644 --- a/web/ui_modules.py +++ b/web/ui_modules.py @@ -407,13 +407,14 @@ class LogEntryModule(UIModule): else: template = "modules/log-entry.html" - return self.render_string(template, entry=entry, u=entry.user, **args) + return self.render_string(template, entry=entry, u=entry.user, + show_build=False, **args) class LogEntryCommentModule(LogEntryModule): - def render(self, entry, **args): + def render(self, entry, show_build=False, **args): return self.render_string("modules/log-entry-comment.html", - entry=entry, u=entry.user, **args) + entry=entry, u=entry.user, show_build=show_build, **args) class MaintainerModule(UIModule):