diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-03-08 20:17:12 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-03-08 20:17:12 -0500 |
commit | 2f02980a8faf24ba091a52cd00c52a332075c205 (patch) | |
tree | 5ac0b1540b2ec8026718440c3c0df97e4e4ab2c4 /forum | |
parent | 5e3078ef2f2b430a8b4420752079f62508443200 (diff) | |
download | askbot-2f02980a8faf24ba091a52cd00c52a332075c205.tar.gz askbot-2f02980a8faf24ba091a52cd00c52a332075c205.tar.bz2 askbot-2f02980a8faf24ba091a52cd00c52a332075c205.zip |
loaded comments and badges
Diffstat (limited to 'forum')
-rwxr-xr-x | forum/management/commands/once_award_badges.py | 2 | ||||
-rwxr-xr-x | forum/models/__init__.py | 8 | ||||
-rwxr-xr-x | forum/models/base.py | 16 | ||||
-rwxr-xr-x | forum/views/writers.py | 9 |
4 files changed, 20 insertions, 15 deletions
diff --git a/forum/management/commands/once_award_badges.py b/forum/management/commands/once_award_badges.py index 8c913348..372eb3aa 100755 --- a/forum/management/commands/once_award_badges.py +++ b/forum/management/commands/once_award_badges.py @@ -337,7 +337,7 @@ class Command(BaseCommand): if user_id not in awarded_users: user = get_object_or_404(User, id=user_id) - award = Award(user=user, badge=badge) + award = Award(user=user, badge=badge)#todo: will this work with content_object null? award.save() awarded_users.append(user_id) finally: diff --git a/forum/models/__init__.py b/forum/models/__init__.py index db66a227..c9a351bb 100755 --- a/forum/models/__init__.py +++ b/forum/models/__init__.py @@ -118,9 +118,7 @@ def record_answer_event(instance, created, **kwargs): if created: q_author = instance.question.author found_match = False - print 'going through %d messages' % q_author.message_set.all().count() for m in q_author.message_set.all(): - print m.message match = record_answer_event_re.search(m.message) if match: found_match = True @@ -130,15 +128,11 @@ def record_answer_event(instance, created, **kwargs): cnt = 1 m.message = u"You have received %d <a href=\"%s?sort=responses\">new responses</a>."\ % (cnt+1, q_author.get_profile_url()) - print 'updated message' - print m.message m.save() break if not found_match: msg = u"You have received a <a href=\"%s?sort=responses\">new response</a>."\ % q_author.get_profile_url() - print 'new message' - print msg q_author.message_set.create(message=msg) activity = Activity(user=instance.author, \ @@ -201,7 +195,7 @@ def notify_award_message(instance, created, **kwargs): + u"Check out <a href=\"%s\">your profile</a>.") \ % (instance.badge.name, user.get_profile_url()) - user.message_set.create(message=message) + user.message_set.create(message=msg) def record_answer_accepted(instance, created, **kwargs): """ diff --git a/forum/models/base.py b/forum/models/base.py index 44fa6e66..56cb95be 100755 --- a/forum/models/base.py +++ b/forum/models/base.py @@ -120,10 +120,22 @@ class Content(models.Model): except Exception: logging.debug('problem pinging google did you register you sitemap with google?') - def get_object_comments(self): + def get_comments(self): comments = self.comments.all().order_by('id') return comments + def add_comment(self, comment=None, user=None, added_at=None): + if added_at is None: + added_at = datetime.datetime.now() + if None in (comment ,user): + raise Exception('arguments comment and user are required') + + Comment = models.get_model('forum','Comment')#todo: forum hardcoded + comment = Comment(content_object=self, comment=comment, user=user, added_at=added_at) + comment.save() + self.comment_count = self.comment_count + 1 + self.save() + def post_get_last_update_info(self): when = self.added_at who = self.author @@ -136,4 +148,4 @@ class Content(models.Model): if c.added_at > when: when = c.added_at who = c.user - return when, who
\ No newline at end of file + return when, who diff --git a/forum/views/writers.py b/forum/views/writers.py index 52d910b5..a9406fdc 100755 --- a/forum/views/writers.py +++ b/forum/views/writers.py @@ -337,11 +337,10 @@ def __comments(request, obj, type):#non-view generic ajax handler to load commen response = __generate_comments_json(obj, type, user) elif request.method == "POST": if auth.can_add_comments(user,obj): - comment_data = request.POST.get('comment') - comment = Comment(content_object=obj, comment=comment_data, user=request.user) - comment.save() - obj.comment_count = obj.comment_count + 1 - obj.save() + obj.add_comment( + comment = request.POST.get('comment'), + user = request.user, + ) response = __generate_comments_json(obj, type, user) else: response = HttpResponseForbidden(mimetype="application/json") |