Mercurial > public > sg101
changeset 390:e0523e17ea43
Fixing #175; add an auto-subscribe and auto-favorite forum topic feature. Added 2 flags to the user profile. Added 2 functions that are called on the post post-save signal that auto-favorite and auto-subscribe the post creator if they have requested this service.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 21 Mar 2011 00:39:52 +0000 |
parents | 3fa61786abf1 |
children | 0398aae48807 |
files | gpp/bio/forms.py gpp/bio/models.py gpp/forums/signals.py gpp/forums/tools.py gpp/templates/bio/view_profile.html |
diffstat | 5 files changed, 36 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/bio/forms.py Sun Mar 20 20:23:29 2011 +0000 +++ b/gpp/bio/forms.py Mon Mar 21 00:39:52 2011 +0000 @@ -32,15 +32,19 @@ time_zone = forms.CharField(required=False, widget=forms.HiddenInput()) use_24_time = forms.BooleanField(label='Show times in 24-hour mode', required=False) profile_text = forms.CharField(required=False, - widget=forms.Textarea(attrs={'class': 'markItUp'})) + widget=forms.Textarea(attrs={'class': 'markItUp'})) signature = forms.CharField(required=False, - widget=forms.Textarea(attrs={'class': 'markItUp'})) + widget=forms.Textarea(attrs={'class': 'markItUp'})) + auto_favorite = forms.BooleanField( + label='Automatically favorite every forum topic I create or reply to', required=False) + auto_subscribe = forms.BooleanField( + label='Automatically subscribe to every forum topic I create or reply to', required=False) class Meta: model = UserProfile fields = ('location', 'birthday', 'occupation', 'interests', 'profile_text', 'hide_email', 'signature', 'time_zone', - 'use_24_time', ) + 'use_24_time', 'auto_favorite', 'auto_subscribe') class Media: css = {
--- a/gpp/bio/models.py Sun Mar 20 20:23:29 2011 +0000 +++ b/gpp/bio/models.py Mon Mar 21 00:39:52 2011 +0000 @@ -92,6 +92,8 @@ status_date = models.DateTimeField(auto_now_add=True) badges = models.ManyToManyField(Badge, through="BadgeOwnership") update_date = models.DateTimeField(db_index=True, blank=True) + auto_favorite = models.BooleanField(default=False) + auto_subscribe = models.BooleanField(default=False) def __unicode__(self): return self.user.username
--- a/gpp/forums/signals.py Sun Mar 20 20:23:29 2011 +0000 +++ b/gpp/forums/signals.py Mon Mar 21 00:39:52 2011 +0000 @@ -6,6 +6,7 @@ from forums.models import Forum, Topic, Post from forums.views.subscriptions import notify_topic_subscribers +from forums.tools import auto_favorite, auto_subscribe def on_topic_save(sender, **kwargs): @@ -36,6 +37,10 @@ # send out any email notifications notify_topic_subscribers(post) + # perform any auto-favorite and auto-subscribe actions for the new post + auto_favorite(post) + auto_subscribe(post) + def on_post_delete(sender, **kwargs): post = kwargs['instance']
--- a/gpp/forums/tools.py Sun Mar 20 20:23:29 2011 +0000 +++ b/gpp/forums/tools.py Mon Mar 21 00:39:52 2011 +0000 @@ -106,3 +106,25 @@ body=post_body, user_ip=ip) post.save() + + +def auto_favorite(post): + """ + Given a newly created post, perform an auto-favorite action if the post + creator has that option set in their profile. + + """ + profile = post.user.get_profile() + if profile.auto_favorite: + post.topic.bookmarkers.add(post.user) + + +def auto_subscribe(post): + """ + Given a newly created post, perform an auto-subscribe action if the post + creator has that option set in their profile. + + """ + profile = post.user.get_profile() + if profile.auto_subscribe: + post.topic.subscribers.add(post.user)
--- a/gpp/templates/bio/view_profile.html Sun Mar 20 20:23:29 2011 +0000 +++ b/gpp/templates/bio/view_profile.html Mon Mar 21 00:39:52 2011 +0000 @@ -54,9 +54,6 @@ {% if not profile.hide_email %} <tr><th>Email</th><td>{{ subject.email }}</td></tr> {% endif %} - {% if profile.icq %} - <tr><th>ICQ</th><td>{{ profile.icq }}</td></tr> - {% endif %} {% if profile.profile_html %} <tr><th>Profile</th><td>{{ profile.profile_html|safe }}</td></tr> {% endif %}