From: hernani Date: Fri, 7 May 2010 22:18:04 +0000 (+0000) Subject: Fix error reported at http://meta.osqa.net/question/1673/default-values-on-badges... X-Git-Tag: live~964 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/b8f3a2323d03384198863e35d6467a8624a2e31a?hp=dbfc77cdf18bf52c3d35da5b8170d16753fe3a3a Fix error reported at http://meta.osqa.net/question/1673/default-values-on-badges-page, also fix error where the last edited flag was not updating correctly and moved revisions to theyr own url. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@165 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/actions/node.py b/forum/actions/node.py index be386fa..931b6e1 100644 --- a/forum/actions/node.py +++ b/forum/actions/node.py @@ -67,9 +67,13 @@ class ReviseAction(NodeEditAction): def process_data(self, **data): revision_data = self.create_revision_data(**data) - revision = self.node.create_revision(self.user, action=self, **revision_data) + revision = self.node.create_revision(self.user, **revision_data) self.extra = revision.revision + def process_action(self): + self.node.last_edited = self + self.node.save() + def describe(self, viewer=None): return _("%(user)s edited %(post_desc)s") % { 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), @@ -85,7 +89,12 @@ class RetagAction(ActionProxy): def process_data(self, tagnames=''): active = self.node.active_revision revision_data = dict(summary=_('Retag'), title=active.title, tagnames=strip_tags(tagnames.strip()), body=active.body) - self.node.create_revision(self.user, action=self, **revision_data) + revision = self.node.create_revision(self.user, **revision_data) + self.extra = revision.revision + + def process_action(self): + self.node.last_edited = self + self.node.save() def describe(self, viewer=None): return _("%(user)s retagged %(post_desc)s") % { @@ -101,9 +110,13 @@ class RollbackAction(ActionProxy): def process_data(self, activate=None): previous = self.node.active_revision - self.node.activate_revision(self.user, activate, self) + self.node.activate_revision(self.user, activate) self.extra = "%d:%d" % (previous.revision, activate.revision) + def process_action(self): + self.node.last_edited = self + self.node.save() + def describe(self, viewer=None): revisions = [NodeRevision.objects.get(node=self.node, revision=int(n)) for n in self.extra.split(':')] @@ -123,12 +136,12 @@ class CloseAction(ActionProxy): def process_action(self): self.node.extra_action = self self.node.marked = True - self.node.save() + self.node.update_last_activity(self.user, save=True) def cancel_action(self): self.node.extra_action = None self.node.marked = False - self.node.save() + self.node.update_last_activity(self.user, save=True) def describe(self, viewer=None): return _("%(user)s closed %(post_desc)s: %(reason)s") % { diff --git a/forum/badges/__init__.py b/forum/badges/__init__.py index 935effd..c413e82 100644 --- a/forum/badges/__init__.py +++ b/forum/badges/__init__.py @@ -1,3 +1,6 @@ from forum.modules import get_modules_script get_modules_script('badges') + +from base import BadgesMeta + diff --git a/forum/models/action.py b/forum/models/action.py index 583b27c..7909974 100644 --- a/forum/models/action.py +++ b/forum/models/action.py @@ -65,9 +65,19 @@ class Action(models.Model): def cancel_action(self): pass + @property + def verb(self): + return "" + def describe(self, viewer=None): return "" + def get_absolute_url(self): + if self.node: + return self.node.get_absolute_url() + else: + return self.user.get_profile_url() + def repute(self, user, value): repute = ActionRepute(action=self, user=user, value=value) repute.save() diff --git a/forum/models/meta.py b/forum/models/meta.py index 6465105..53d4c49 100644 --- a/forum/models/meta.py +++ b/forum/models/meta.py @@ -64,7 +64,15 @@ class Badge(models.Model): @models.permalink def get_absolute_url(self): - return ('badge', [], {'id': self.id, 'slug': slugify(self.name)}) + return ('badge', [], {'id': self.id, 'slug': slugify(self.name)}) + + def save(self, *args, **kwargs): + if isinstance(self.awarded_count, models.expressions.ExpressionNode): + super(Badge, self).save(*args, **kwargs) + self.awarded_count = self.__class__.objects.filter(id=self.id).values_list('awarded_count', flat=True)[0] + else: + super(Badge, self).save(*args, **kwargs) + class Meta: app_label = 'forum' diff --git a/forum/models/node.py b/forum/models/node.py index 3150e99..7c09189 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -166,6 +166,10 @@ class Node(BaseModel, NodeContent): def summary(self): return strip_tags(self.html)[:300] + @models.permalink + def get_revisions_url(self): + return ('revisions', (), {'id': self.id}) + def update_last_activity(self, user, save=False): self.last_activity_by = user self.last_activity_at = datetime.datetime.now() @@ -181,13 +185,13 @@ class Node(BaseModel, NodeContent): revision.save() return revision - def create_revision(self, user, action=None, **kwargs): + def create_revision(self, user, **kwargs): number = self.revisions.aggregate(last=models.Max('revision'))['last'] + 1 revision = self._create_revision(user, number, **kwargs) - self.activate_revision(user, revision, action) + self.activate_revision(user, revision) return revision - def activate_revision(self, user, revision, action=None): + def activate_revision(self, user, revision): self.title = revision.title self.tagnames = revision.tagnames self.body = revision.body @@ -195,9 +199,6 @@ class Node(BaseModel, NodeContent): self.active_revision = revision self.update_last_activity(user) - if action: - self.last_edited = action - self.save() def get_tag_list_if_changed(self): diff --git a/forum/models/user.py b/forum/models/user.py index 53b5ee2..ff7bef1 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -133,8 +133,9 @@ class User(BaseModel, DjangoUser): def delete_messages(self): self.message_set.all().delete() + @models.permalink def get_profile_url(self): - return "/%s%d/%s" % (_('users/'), self.id, slugify(self.username)) + return ('user_profile', (), {'id': self.id, 'slug': slugify(self.username)}) def get_profile_link(self): profile_link = u'%s' % (self.get_profile_url(),self.username) diff --git a/forum/skins/default/templates/node/contributors_info.html b/forum/skins/default/templates/node/contributors_info.html new file mode 100644 index 0000000..54e0bbe --- /dev/null +++ b/forum/skins/default/templates/node/contributors_info.html @@ -0,0 +1,25 @@ +{% load extra_tags %} +
+

+ {{ node_verb }} + {% diff_date node.added_at %} +

+ {% gravatar node.author 32 %} +

{{ node.author.username }}
+ {% get_score_badge node.author %}

+
+{% if node.last_edited %} +
+

+ + {{ node.last_edited.verb }} + {% diff_date node.last_edited.at %} + +

+ {% ifnotequal node.author node.last_edited.by %} + {% gravatar node.last_edited.by 32 %} +

{{ node.last_edited.by.username }}
+ {% get_score_badge node.last_edited.by %}

+ {% endifnotequal %} +
+{% 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 index 0000000..8b46047 --- /dev/null +++ b/forum/skins/default/templates/node/reviser_info.html @@ -0,0 +1,9 @@ +{% load extra_tags %} +
+

+ {% diff_date revision.revised_at %} +

+ {% gravatar revision.author 32 %} +

{{ revision.author.username }}
+ {% get_score_badge revision.author %}

+
\ 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 index 2770644..0000000 --- a/forum/skins/default/templates/post_contributor_info.html +++ /dev/null @@ -1,55 +0,0 @@ -{% load i18n %} -{% load smart_if %} -{% load extra_tags %} -
-{% ifequal contributor_type "original_author" %} - {% if wiki %} -

{% trans "community wiki" %}

-

- {% blocktrans count post.revisions.all|length as rev_count %} - one revision - {% plural %} - {{rev_count}} revisions - {% endblocktrans %} -

-

{{post.author.get_profile_link}}

- {% else %} -

- {% ifequal post_type "question" %} - {% trans "asked" %} - {% else %} - {% ifequal post_type "answer" %} - {% trans "answered" %} - {% else %} - {% trans "posted" %} - {% endifequal %} - {% endifequal %} - {% ifequal post_type "revision" %} - {% diff_date post.revised_at %} - {% else %} - {% diff_date post.added_at %} - {% endifequal %} -

- {% gravatar post.author 32 %} -

{{post.author.get_profile_link}}
- {% get_score_badge post.author %}

- {% endif %} -{% else %} - {% if post.last_edited %} -

- {% ifequal post_type 'question' %} - - {% else %} - - {% endifequal %} - {% trans "updated" %} {% diff_date post.last_edited.at %} - -

- {% if post.author != post.last_edited.by or wiki %} - {% gravatar post.last_edited.by 32 %} -

{{post.last_edited.by.get_profile_link}}
- {% get_score_badge post.last_edited.by %}

- {% endif %} - {% endif %} -{% endifequal %} -
diff --git a/forum/skins/default/templates/question.html b/forum/skins/default/templates/question.html index b6300d5..0a75aba 100644 --- a/forum/skins/default/templates/question.html +++ b/forum/skins/default/templates/question.html @@ -71,8 +71,7 @@ {% post_controls question request.user %}
- {% post_contributor_info question "original_author" %} - {% post_contributor_info question "last_updater" %} + {% contributors_info question %}
{% comments question request.user %} @@ -133,8 +132,7 @@ {% post_controls answer request.user %}
- {% post_contributor_info answer "original_author" %} - {% post_contributor_info answer "last_updater" %} + {% contributors_info answer %}
{% comments answer request.user %} diff --git a/forum/skins/default/templates/revisions_question.html b/forum/skins/default/templates/revisions.html similarity index 97% rename from forum/skins/default/templates/revisions_question.html rename to forum/skins/default/templates/revisions.html index 3d07478..4c57e61 100644 --- a/forum/skins/default/templates/revisions_question.html +++ b/forum/skins/default/templates/revisions.html @@ -1,5 +1,5 @@ {% extends "base_content.html" %} - +{% load node_tags %} {% load extra_tags %} {% load i18n %} {% load extra_filters %} @@ -52,7 +52,7 @@
- {% post_contributor_info revision.inst %} + {% reviser_info revision.inst %}
diff --git a/forum/skins/default/templates/revisions_answer.html b/forum/skins/default/templates/revisions_answer.html deleted file mode 100644 index 6df996c..0000000 --- a/forum/skins/default/templates/revisions_answer.html +++ /dev/null @@ -1,81 +0,0 @@ -{% extends "base_content.html" %} - -{% load i18n %} -{% load extra_tags %} -{% load extra_filters %} -{% load humanize %} -{% block title %}{% spaceless %}{% trans "Revision history" %}{% endspaceless %}{% endblock %} -{% block forejs %} - -{% endblock %} - -{% block content %} -
- {% trans "Revision history" %} [{% trans "back" %}] -
-
-
- {% for revision in revisions %} -
-
-
- - - - - - - - -
{% trans - {{ revision.revision }} - {% if revision.summary %} -
{{ revision.summary }}
- {% endif %} - {% if request.user|can_edit_post:post %} - {% trans "edit" %} - {% endif %} - -
-
- {% post_contributor_info revision %} -
-
-
-
-
- {{ revision.diff|safe }} -
-
- {% endfor %} -
-
-{% endblock %} - -{% block endjs %} -{% endblock %} - diff --git a/forum/skins/default/templates/users/edit.html b/forum/skins/default/templates/users/edit.html index b86c59d..b3a7e74 100644 --- a/forum/skins/default/templates/users/edit.html +++ b/forum/skins/default/templates/users/edit.html @@ -5,14 +5,10 @@ {% load i18n %} {% block title %}{% spaceless %}{% trans "Edit user profile" %}{% endspaceless %}{% endblock %} {% block forejs %} - + - - - -