# HG changeset patch # User Brian Neal # Date 1300667992 0 # Node ID e0523e17ea431e1dc9cdce20addc56f8d15f4dcc # Parent 3fa61786abf191433620d1fee2d62879bef308d2 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. diff -r 3fa61786abf1 -r e0523e17ea43 gpp/bio/forms.py --- 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 = { diff -r 3fa61786abf1 -r e0523e17ea43 gpp/bio/models.py --- 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 diff -r 3fa61786abf1 -r e0523e17ea43 gpp/forums/signals.py --- 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'] diff -r 3fa61786abf1 -r e0523e17ea43 gpp/forums/tools.py --- 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) diff -r 3fa61786abf1 -r e0523e17ea43 gpp/templates/bio/view_profile.html --- 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 %} Email{{ subject.email }} {% endif %} - {% if profile.icq %} - ICQ{{ profile.icq }} - {% endif %} {% if profile.profile_html %} Profile{{ profile.profile_html|safe }} {% endif %}