]> git.openstreetmap.org Git - osqa.git/commitdiff
Fix error reported at http://meta.osqa.net/question/1673/default-values-on-badges...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 7 May 2010 22:18:04 +0000 (22:18 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 7 May 2010 22:18:04 +0000 (22:18 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@165 0cfe37f9-358a-4d5e-be75-b63607b5c754

18 files changed:
forum/actions/node.py
forum/badges/__init__.py
forum/models/action.py
forum/models/meta.py
forum/models/node.py
forum/models/user.py
forum/skins/default/templates/node/contributors_info.html [new file with mode: 0644]
forum/skins/default/templates/node/reviser_info.html [new file with mode: 0644]
forum/skins/default/templates/post_contributor_info.html [deleted file]
forum/skins/default/templates/question.html
forum/skins/default/templates/revisions.html [moved from forum/skins/default/templates/revisions_question.html with 97% similarity]
forum/skins/default/templates/revisions_answer.html [deleted file]
forum/skins/default/templates/users/edit.html
forum/templatetags/extra_tags.py
forum/templatetags/node_tags.py
forum/templatetags/user_tags.py
forum/urls.py
forum/views/readers.py

index be386facd8d640aaba0eba19437450496c138f5b..931b6e1ce4572788519bba7c2a639de5c59d557e 100644 (file)
@@ -67,9 +67,13 @@ class ReviseAction(NodeEditAction):
 \r
     def process_data(self, **data):\r
         revision_data = self.create_revision_data(**data)\r
-        revision = self.node.create_revision(self.user, action=self, **revision_data)\r
+        revision = self.node.create_revision(self.user, **revision_data)\r
         self.extra = revision.revision\r
 \r
+    def process_action(self):\r
+        self.node.last_edited = self\r
+        self.node.save()\r
+\r
     def describe(self, viewer=None):\r
         return _("%(user)s edited %(post_desc)s") % {\r
             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
@@ -85,7 +89,12 @@ class RetagAction(ActionProxy):
     def process_data(self, tagnames=''):\r
         active = self.node.active_revision\r
         revision_data = dict(summary=_('Retag'), title=active.title, tagnames=strip_tags(tagnames.strip()), body=active.body)\r
-        self.node.create_revision(self.user, action=self, **revision_data)\r
+        revision = self.node.create_revision(self.user, **revision_data)\r
+        self.extra = revision.revision\r
+\r
+    def process_action(self):\r
+        self.node.last_edited = self\r
+        self.node.save()\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s retagged %(post_desc)s") % {\r
@@ -101,9 +110,13 @@ class RollbackAction(ActionProxy):
 \r
     def process_data(self, activate=None):\r
         previous = self.node.active_revision\r
-        self.node.activate_revision(self.user, activate, self)\r
+        self.node.activate_revision(self.user, activate)\r
         self.extra = "%d:%d" % (previous.revision, activate.revision)\r
 \r
+    def process_action(self):\r
+        self.node.last_edited = self\r
+        self.node.save()\r
+\r
     def describe(self, viewer=None):\r
         revisions = [NodeRevision.objects.get(node=self.node, revision=int(n)) for n in self.extra.split(':')]\r
 \r
@@ -123,12 +136,12 @@ class CloseAction(ActionProxy):
     def process_action(self):\r
         self.node.extra_action = self\r
         self.node.marked = True\r
-        self.node.save()\r
+        self.node.update_last_activity(self.user, save=True)\r
 \r
     def cancel_action(self):\r
         self.node.extra_action = None\r
         self.node.marked = False\r
-        self.node.save()\r
+        self.node.update_last_activity(self.user, save=True)\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s closed %(post_desc)s: %(reason)s") % {\r
index 935effdbe2ff382d1009aac9bc182c9633bf228f..c413e82dbff0712f4ce61566f78746f3207c7a8a 100644 (file)
@@ -1,3 +1,6 @@
 from forum.modules import get_modules_script
 
 get_modules_script('badges')
+
+from base import BadgesMeta
+
index 583b27c078fcf46c55eb6c3017082caaabf1effe..790997491c9dc986eb17a93bcc66d386ed3a59de 100644 (file)
@@ -65,9 +65,19 @@ class Action(models.Model):
     def cancel_action(self):\r
         pass\r
 \r
+    @property\r
+    def verb(self):\r
+        return ""\r
+\r
     def describe(self, viewer=None):\r
         return ""\r
 \r
+    def get_absolute_url(self):\r
+        if self.node:\r
+            return self.node.get_absolute_url()\r
+        else:\r
+            return self.user.get_profile_url()\r
+\r
     def repute(self, user, value):\r
         repute = ActionRepute(action=self, user=user, value=value)\r
         repute.save()\r
index 6465105d3d1f4d272b30583fc9c9cc7e0590c50c..53d4c493049697efd25192185b25ef8611f2a751 100644 (file)
@@ -64,7 +64,15 @@ class Badge(models.Model):
 \r
     @models.permalink\r
     def get_absolute_url(self):\r
-        return ('badge', [], {'id': self.id, 'slug': slugify(self.name)})        \r
+        return ('badge', [], {'id': self.id, 'slug': slugify(self.name)})\r
+\r
+    def save(self, *args, **kwargs):\r
+        if isinstance(self.awarded_count, models.expressions.ExpressionNode):\r
+            super(Badge, self).save(*args, **kwargs)\r
+            self.awarded_count = self.__class__.objects.filter(id=self.id).values_list('awarded_count', flat=True)[0]\r
+        else:\r
+            super(Badge, self).save(*args, **kwargs)\r
+\r
 \r
     class Meta:\r
         app_label = 'forum'\r
index 3150e992e0d915e7836a3c90707ad87998573394..7c09189b7f1228858d5a232f646a26cfaa2b2dcd 100644 (file)
@@ -166,6 +166,10 @@ class Node(BaseModel, NodeContent):
     def summary(self):\r
         return strip_tags(self.html)[:300]\r
 \r
+    @models.permalink\r
+    def get_revisions_url(self):\r
+        return ('revisions', (), {'id': self.id})\r
+\r
     def update_last_activity(self, user, save=False):\r
         self.last_activity_by = user\r
         self.last_activity_at = datetime.datetime.now()\r
@@ -181,13 +185,13 @@ class Node(BaseModel, NodeContent):
         revision.save()\r
         return revision\r
 \r
-    def create_revision(self, user, action=None, **kwargs):\r
+    def create_revision(self, user, **kwargs):\r
         number = self.revisions.aggregate(last=models.Max('revision'))['last'] + 1\r
         revision = self._create_revision(user, number, **kwargs)\r
-        self.activate_revision(user, revision, action)\r
+        self.activate_revision(user, revision)\r
         return revision\r
 \r
-    def activate_revision(self, user, revision, action=None):\r
+    def activate_revision(self, user, revision):\r
         self.title = revision.title\r
         self.tagnames = revision.tagnames\r
         self.body = revision.body\r
@@ -195,9 +199,6 @@ class Node(BaseModel, NodeContent):
         self.active_revision = revision\r
         self.update_last_activity(user)\r
 \r
-        if action:\r
-            self.last_edited = action\r
-\r
         self.save()\r
 \r
     def get_tag_list_if_changed(self):\r
index 53b5ee223a10b3ae1bc1ac7f8574a6bbb8facb05..ff7bef1d2f011ede2e96f9b233598904e2b3f529 100644 (file)
@@ -133,8 +133,9 @@ class User(BaseModel, DjangoUser):
     def delete_messages(self):\r
         self.message_set.all().delete()\r
 \r
+    @models.permalink\r
     def get_profile_url(self):\r
-        return "/%s%d/%s" % (_('users/'), self.id, slugify(self.username))\r
+        return ('user_profile', (), {'id': self.id, 'slug': slugify(self.username)})\r
 \r
     def get_profile_link(self):\r
         profile_link = u'<a href="%s">%s</a>' % (self.get_profile_url(),self.username)\r
diff --git a/forum/skins/default/templates/node/contributors_info.html b/forum/skins/default/templates/node/contributors_info.html
new file mode 100644 (file)
index 0000000..54e0bbe
--- /dev/null
@@ -0,0 +1,25 @@
+{% load extra_tags %}
+<div class='post-update-info'>
+    <p style="line-height:12px;">
+        {{ node_verb }}
+        <strong>{% diff_date node.added_at %}</strong>
+    </p>
+    {% gravatar node.author 32 %}
+    <p><a href="{{ node.author.get_profile_url }}">{{ node.author.username }}</a><br/>
+    {% get_score_badge node.author %}</p>
+</div>
+{% if node.last_edited %}
+    <div class='post-update-info'>
+        <p style="line-height:12px;">
+            <a href="{{ node.get_revisions_url }}">
+                {{ node.last_edited.verb }}
+                <strong>{% diff_date node.last_edited.at %}</strong>
+            </a>
+        </p>
+        {% ifnotequal node.author node.last_edited.by %}
+            {% gravatar node.last_edited.by 32 %}
+            <p><a href="{{ node.last_edited.by.get_profile_url }}">{{ node.last_edited.by.username }}</a><br/>
+            {% get_score_badge node.last_edited.by %}</p>
+        {% endifnotequal %}
+    </div>
+{% endif %}
diff --git a/forum/skins/default/templates/node/reviser_info.html b/forum/skins/default/templates/node/reviser_info.html
new file mode 100644 (file)
index 0000000..8b46047
--- /dev/null
@@ -0,0 +1,9 @@
+{% load extra_tags %}\r
+<div class='post-update-info'>\r
+    <p style="line-height:12px;">\r
+        <strong>{% diff_date revision.revised_at %}</strong>\r
+    </p>\r
+    {% gravatar revision.author 32 %}\r
+    <p><a href="{{ revised_at.author.get_profile_url }}">{{ revision.author.username }}</a><br/>\r
+    {% get_score_badge revision.author %}</p>\r
+</div>
\ No newline at end of file
diff --git a/forum/skins/default/templates/post_contributor_info.html b/forum/skins/default/templates/post_contributor_info.html
deleted file mode 100644 (file)
index 2770644..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-{% load i18n %}
-{% load smart_if %}
-{% load extra_tags %}
-<div class='post-update-info'>
-{% ifequal contributor_type "original_author" %}
-    {% if wiki %}
-        <p>{% trans "community wiki" %}</p>
-        <p>
-            {% blocktrans count post.revisions.all|length as rev_count %}
-                one revision
-            {% plural %}
-                {{rev_count}} revisions
-            {% endblocktrans %}
-        </p>
-        <p>{{post.author.get_profile_link}}</p>
-    {% else %}
-        <p style="line-height:12px;">
-            {% ifequal post_type "question" %}
-                {% trans "asked" %}
-            {% else %}
-                {% ifequal post_type "answer" %}
-                    {% trans "answered" %}
-                {% else %}
-                    {% trans "posted" %}
-                {% endifequal %}
-            {% endifequal %}
-            {% ifequal post_type "revision" %}
-                <strong>{% diff_date post.revised_at %}</strong>
-            {% else %}
-                <strong>{% diff_date post.added_at %}</strong>
-            {% endifequal %}
-        </p>
-        {% gravatar post.author 32 %}
-        <p>{{post.author.get_profile_link}}<br/>
-        {% get_score_badge post.author %}</p>
-    {% endif %}
-{% else %}
-    {% if post.last_edited %}
-        <p style="line-height:12px;">
-        {% ifequal post_type 'question' %}
-        <a href="{% url question_revisions post.id %}">
-        {% else %}
-        <a href="{% url answer_revisions post.id %}">
-        {% endifequal %}
-        {% trans "updated" %} <strong>{% diff_date post.last_edited.at %}</strong>
-        </a>
-        </p>
-        {% if post.author != post.last_edited.by or wiki %}
-            {% gravatar post.last_edited.by 32 %}
-            <p style="float:left">{{post.last_edited.by.get_profile_link}}<br/>
-            {% get_score_badge post.last_edited.by %}</p>
-        {% endif %}
-    {% endif %}
-{% endifequal %}
-</div>
index b6300d596ab13fda148935e97c4f74946607728b..0a75abae5fc4cd4a9baa6e0cfdc7c46762866322 100644 (file)
@@ -71,8 +71,7 @@
                                 {% post_controls question request.user %}\r
                             </div>\r
                             <div class="post-update-info-container">\r
-                                    {% post_contributor_info question "original_author" %}\r
-                                    {% post_contributor_info question "last_updater" %}\r
+                                    {% contributors_info question %}\r
                             </div>\r
                             {% comments question request.user %}\r
                         </div>\r
                                             {% post_controls answer request.user %}\r
                                         </div>\r
                                         <div class="post-update-info-container">\r
-                                                {% post_contributor_info answer "original_author" %}\r
-                                                {% post_contributor_info answer "last_updater" %}\r
+                                            {% contributors_info answer %}\r
                                         </div>\r
                                         {% comments answer request.user %}\r
                                     </div>\r
similarity index 97%
rename from forum/skins/default/templates/revisions_question.html
rename to forum/skins/default/templates/revisions.html
index 3d0747874fdae32e31c1764dfdfc76172faee264..4c57e61b609c99bd9b43a931bbd09c3014a288b7 100644 (file)
@@ -1,5 +1,5 @@
 {% extends "base_content.html" %}
-
+{% load node_tags %}
 {% load extra_tags %}
 {% load i18n %}
 {% load extra_filters %}
@@ -52,7 +52,7 @@
                     </td>
                     <td align="right">
                         <div class="revision-mark" >
-                            {% post_contributor_info revision.inst %}
+                            {% reviser_info revision.inst %}
                         </div>
                     </td>
                 </tr>
diff --git a/forum/skins/default/templates/revisions_answer.html b/forum/skins/default/templates/revisions_answer.html
deleted file mode 100644 (file)
index 6df996c..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-{% extends "base_content.html" %}
-<!-- revisions_answer.html -->
-{% load i18n %}
-{% load extra_tags %}
-{% load extra_filters %}
-{% load humanize %}
-{% block title %}{% spaceless %}{% trans "Revision history" %}{% endspaceless %}{% endblock %}
-{% block forejs %}
-        <script type="text/javascript">
-        //todo - take this out into .js file 
-        $().ready(function(){
-            $("#nav_questions").attr('className',"on");
-            $('div.revision div[id^=rev-header-]').bind('click', function(){
-                var revId = this.id.substr(11);
-                toggleRev(revId); 
-            
-            });
-            lanai.highlightSyntax();
-        });
-        
-        function toggleRev(id) {
-            var arrow = $("#rev-arrow-" + id);
-            var visible = arrow.attr("src").indexOf("hide") > -1;
-
-            var path = $.i18n._('/') + "media/images/expander-arrow-" + 
-                        (visible ? "show" : "hide") + ".gif" + "?v={{settings.RESOURCE_REVISION}}";
-            arrow.attr("src", path);
-            $("#rev-body-" + id).slideToggle("fast");
-        }
-        
-        </script>
-{% endblock %}
-        
-{% block content %}
-<div id="main-bar" class="headNormal">
-    {% trans "Revision history" %} [<a href="{{ post.get_absolute_url }}">{% trans "back" %}</a>]
-</div>
-<div id="main-body" class="">
-    <div id="revisions">
-    {% for revision in revisions %}
-      <div class="revision">
-        <div id="rev-header-{{ revision.revision }}" class="header {% ifequal post.author_id revision.author_id %}author{% endifequal %}">
-          <div class="header-controls">
-            <table width="100%">
-                <tr>
-                    <td width="20" style="vertical-align:middle"><img id="rev-arrow-{{ revision.revision }}" 
-                                                                    src="{% media  "/media/images/expander-arrow-show.gif" %}"
-                                                                    alt="{% trans "click to hide/show revision" %}"/>
-                    </td>
-                    <td width="30px" style="vertical-align:middle"><span class="revision-number" title="{% trans "revision" %} {{ revision.revision }}">{{ revision.revision }}</span></td>
-                    <td width="200px" style="vertical-align:middle">
-                        {% if revision.summary %}
-                        <div class="summary"><span>{{ revision.summary }}</span></div>
-                        {% endif %}
-                        {% if request.user|can_edit_post:post %}
-                        <a href="{% url edit_answer post.id %}?revision={{ revision.revision }}">{% trans "edit" %}</a>
-                        {% endif %}
-  
-                    </td>
-                    <td align="right">
-                        <div class="revision-mark" >
-                            {% post_contributor_info revision %}
-                        </div>
-                    </td>
-                </tr>
-                   
-            </table>
-          </div>
-        </div>
-        <div id="rev-body-{{ revision.revision }}" class="answerbody">
-            {{ revision.diff|safe }}
-        </div>
-      </div>
-    {% endfor %}
-    </div>
-</div>
-{% endblock %}
-
-{% block endjs %}
-{% endblock %}
-<!-- end revisions_answer.html -->
index b86c59db24cfb3247257bb6603d144b1bffa81b6..b3a7e74b68d14bb45710dfa6ccd17c58c9516de3 100644 (file)
@@ -5,14 +5,10 @@
 {% load i18n %}\r
 {% block title %}{% spaceless %}{% trans "Edit user profile" %}{% endspaceless %}{% endblock %}\r
 {% block forejs %}\r
-        <script type="text/javascript">google.load("jquery", "1.4.2");</script>\r
+        <script type="text/javascript">google.load("jquery", "1.4.2");google.load("jqueryui", "1.8.1");</script>\r
 \r
         <link rel="stylesheet" href="http://jquery-ui.googlecode.com/svn/tags/latest/themes/base/jquery-ui.css" type="text/css" media="all" />\r
         <link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />\r
-        \r
-        <script src="{% media  "/media/js/effects.core.min.js" %}" type="text/javascript"></script>\r
-        <script src="{% media  "/media/js/ui.core.js" %}" type="text/javascript"></script>\r
-        <script src="{% media  "/media/js/ui.datepicker.js" %}" type="text/javascript"></script>\r
 \r
         <script type="text/javascript">\r
             $().ready(function(){\r
index 822fdc1b94636c6f28c4620d08dd036b78f5b779..a6c9047dbcccd9c8d263b4092be29a1ba0367b1c 100644 (file)
@@ -123,23 +123,7 @@ def cnprog_pagesize(context):
             "is_paginated": context["is_paginated"]
         }
 
-@register.inclusion_tag("post_contributor_info.html")
-def post_contributor_info(post,contributor_type='original_author'):
-    """contributor_type: original_author|last_updater
-    """
-    if isinstance(post,Question):
-        post_type = 'question'
-    elif isinstance(post,Answer):
-        post_type = 'answer'
-    elif isinstance(post,(AnswerRevision, QuestionRevision, NodeRevision)):
-        post_type = 'revision'
-    return {
-        'post':post,
-        'post_type':post_type,
-        'wiki_on':settings.WIKI_ON,
-        'contributor_type':contributor_type
-    }
-        
+   
 @register.simple_tag
 def get_score_badge(user):
     BADGE_TEMPLATE = '<span class="score" title="%(reputation)s %(reputationword)s">%(reputation)s</span>'
index a744d36cec83da77178458a6d0021a6fd2cab1e3..72bfaf2a25939382ca634532e7e787fea030dd8d 100644 (file)
@@ -121,3 +121,18 @@ def comments(post, user):
         'total': len(all_comments),\r
         'user': user,\r
     }\r
+\r
+\r
+@register.inclusion_tag("node/contributors_info.html")\r
+def contributors_info(node):\r
+    return {\r
+        'node_verb': (node.node_type == "question") and _("asked") or (\r
+                    (node.node_type == "answer") and _("answered") or _("posted")),\r
+        'node': node,\r
+    }\r
+\r
+\r
+@register.inclusion_tag("node/reviser_info.html")\r
+def reviser_info(revision):\r
+    return {'revision': revision}\r
+\r
index 8ab1bb2b4eb30d264ac6c83282a1ead667c90cde..3ca19ac4b7aad12bf06ad4e5212bae5aff54df48 100644 (file)
@@ -56,7 +56,7 @@ def activity_item(parser, token):
     return ActivityNode(activity, viewer)\r
 \r
 \r
-@register.inclusion_tag('users/moderation.html')\r
+@register.inclusion_tag('users/action_info.html')\r
 def user_moderation(moderator, user):\r
-    \r
     return dict(user=user)\r
+\r
index 7975644e9f6207d83d40f6005cc05e62203f75a4..28555e56e0417d37ea59b8c1b8c8e4f28a22b326 100644 (file)
@@ -51,7 +51,7 @@ urlpatterns += patterns('',
     url(r'^%s$' % _('privacy/'), app.meta.privacy, name='privacy'),
     url(r'^%s$' % _('logout/'), app.meta.logout, name='logout'),
     url(r'^%s(?P<id>\d+)/%s$' % (_('answers/'), _('edit/')), app.writers.edit_answer, name='edit_answer'),
-    url(r'^%s(?P<id>\d+)/%s$' % (_('answers/'), _('revisions/')), app.readers.revisions, name='answer_revisions'),
+    url(r'^%s(?P<id>\d+)/$' % _('revisions/'), app.readers.revisions, name='revisions'),
     url(r'^%s$' % _('questions/'), app.readers.questions, name='questions'),
     url(r'^%s%s$' % (_('questions/'), _('ask/')), app.writers.ask, name='ask'),
     url(r'^%s%s$' % (_('questions/'), _('unanswered/')), app.readers.unanswered, name='unanswered'),
@@ -72,8 +72,6 @@ urlpatterns += patterns('',
     url(r'^%s' % _('matching_tags/'), app.commands.matching_tags, name='matching_tags'),
     url(r'^%s(?P<id>\d+)/' % _('node_markdown/'), app.commands.node_markdown, name='node_markdown'),
 
-    url(r'^%s(?P<id>\d+)/%s$' % (_('questions/'), _('revisions/')), app.readers.revisions, name='question_revisions'),
-
     #place general question item in the end of other operations
     url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]*)$' % _('question/'), app.readers.question, name='question'),
     url(r'^%s$' % _('tags/'), app.readers.tags, name='tags'),
index 1714a5117f24dc233cfccf6a79f85ed2e66d1327..c19282042d6bca2eee471e093cc163dfcc663f45 100644 (file)
@@ -276,7 +276,7 @@ def revisions(request, id):
         else:
             rev_ctx[i]['summary'] = revision.summary
             
-    return render_to_response('revisions_question.html', {
+    return render_to_response('revisions.html', {
                               'post': post,
                               'revisions': rev_ctx,
                               }, context_instance=RequestContext(request))