Commit 0f0d7015d4eea5667409b033859ddb2baf3120d8
Exists in
master
and in
39 other branches
Merge branch 'disable_social_networks' into 'master'
Disable social networks
Showing
8 changed files
with
66 additions
and
32 deletions
Show diff stats
colab/accounts/forms.py
... | ... | @@ -15,11 +15,15 @@ from django.utils.translation import ugettext_lazy as _ |
15 | 15 | |
16 | 16 | from conversejs.models import XMPPAccount |
17 | 17 | |
18 | +from django.conf import settings | |
19 | + | |
18 | 20 | from .utils.validators import validate_social_account |
19 | 21 | from .utils import mailman |
20 | 22 | |
21 | 23 | User = get_user_model() |
22 | 24 | |
25 | +SOCIAL_NETWORK_ENABLED = getattr(settings, 'SOCIAL_NETWORK_ENABLED') | |
26 | + | |
23 | 27 | |
24 | 28 | class SocialAccountField(forms.Field): |
25 | 29 | def __init__(self, *args, **kwargs): |
... | ... | @@ -107,6 +111,7 @@ class UserForm(forms.ModelForm): |
107 | 111 | |
108 | 112 | |
109 | 113 | class UserUpdateForm(UserForm): |
114 | + | |
110 | 115 | bio = forms.CharField( |
111 | 116 | widget=forms.Textarea(attrs={'rows': '6', 'maxlength': '200'}), |
112 | 117 | max_length=200, |
... | ... | @@ -122,12 +127,16 @@ class UserUpdateForm(UserForm): |
122 | 127 | class Meta: |
123 | 128 | model = User |
124 | 129 | fields = ('first_name', 'last_name', |
125 | - 'institution', 'role', 'twitter', 'facebook', | |
126 | - 'google_talk', 'github', 'webpage', 'bio') | |
127 | - | |
128 | - twitter = SocialAccountField(url='https://twitter.com/', required=False) | |
129 | - facebook = SocialAccountField(url='https://graph.facebook.com/', | |
130 | - required=False) | |
130 | + 'institution', 'role') | |
131 | + if SOCIAL_NETWORK_ENABLED: | |
132 | + fields += ('twitter', 'facebook', 'google_talk', 'github') | |
133 | + fields += ('webpage', 'bio') | |
134 | + | |
135 | + if SOCIAL_NETWORK_ENABLED: | |
136 | + twitter = SocialAccountField(url='https://twitter.com/', | |
137 | + required=False) | |
138 | + facebook = SocialAccountField(url='https://graph.facebook.com/', | |
139 | + required=False) | |
131 | 140 | |
132 | 141 | |
133 | 142 | class ListsForm(forms.Form): | ... | ... |
colab/accounts/templates/accounts/user_detail.html
... | ... | @@ -60,25 +60,27 @@ |
60 | 60 | </li> |
61 | 61 | {% endif %} |
62 | 62 | {% if request.user.is_active %} |
63 | - <li> | |
64 | - {% if user_.twitter %} | |
65 | - <span class="icon-twitter icon-fixed-width" title="{% trans 'Twitter account' %}"></span> <a target="_blank" href="{{ user_.twitter_link }}" title="{% trans 'Twitter account' %}">{{ user_.twitter }}</a> | |
66 | - {% endif %} | |
67 | - {% if user_.facebook %} | |
68 | - <span class="icon-facebook icon-fixed-width" title="{% trans 'Facebook account' %}"></span> <a target="_blank" href="{{ user_.facebook_link }}" title="{% trans 'Facebook account' %}">{{ user_.facebook }}</a> | |
69 | - {% endif %} | |
70 | - </li> | |
63 | + {% if SOCIAL_NETWORK_ENABLED %} | |
64 | + <li> | |
65 | + {% if user_.twitter %} | |
66 | + <span class="icon-twitter icon-fixed-width" title="{% trans 'Twitter account' %}"></span> <a target="_blank" href="{{ user_.twitter_link }}" title="{% trans 'Twitter account' %}">{{ user_.twitter }}</a> | |
67 | + {% endif %} | |
68 | + {% if user_.facebook %} | |
69 | + <span class="icon-facebook icon-fixed-width" title="{% trans 'Facebook account' %}"></span> <a target="_blank" href="{{ user_.facebook_link }}" title="{% trans 'Facebook account' %}">{{ user_.facebook }}</a> | |
70 | + {% endif %} | |
71 | + </li> | |
71 | 72 | |
72 | - {% if user_.google_talk %} | |
73 | - <li><span class="icon-google-plus icon-fixed-width" title="{% trans 'Google talk account' %}"></span> {{ user_.google_talk }}</li> | |
74 | - {% endif %} | |
73 | + {% if user_.google_talk %} | |
74 | + <li><span class="icon-google-plus icon-fixed-width" title="{% trans 'Google talk account' %}"></span> {{ user_.google_talk }}</li> | |
75 | + {% endif %} | |
75 | 76 | |
76 | - {% if user_.github %} | |
77 | - <li><span class="icon-github icon-fixed-width" title="{% trans 'Github account' %}"></span> <a target="_blank" href="https://github.com/{{ user_.github }}">{{ user_.github }}</a></li> | |
78 | - {% endif %} | |
77 | + {% if user_.github %} | |
78 | + <li><span class="icon-github icon-fixed-width" title="{% trans 'Github account' %}"></span> <a target="_blank" href="https://github.com/{{ user_.github }}">{{ user_.github }}</a></li> | |
79 | + {% endif %} | |
79 | 80 | |
80 | - {% if user_.webpage %} | |
81 | - <li><span class="icon-link icon-fixed-width" title="{% trans 'Personal webpage' %}"></span> <a target="_blank" href="{{ user_.webpage }}" title="{% trans 'Personal webpage' %}">{{ user_.webpage }}</a></li> | |
81 | + {% if user_.webpage %} | |
82 | + <li><span class="icon-link icon-fixed-width" title="{% trans 'Personal webpage' %}"></span> <a target="_blank" href="{{ user_.webpage }}" title="{% trans 'Personal webpage' %}">{{ user_.webpage }}</a></li> | |
83 | + {% endif %} | |
82 | 84 | {% endif %} |
83 | 85 | {% endif %} |
84 | 86 | </ul> | ... | ... |
colab/management/initconfig.py
... | ... | @@ -45,6 +45,9 @@ ALLOWED_HOSTS: |
45 | 45 | ### Uncomment to enable Broswer ID protocol for authentication |
46 | 46 | # BROWSERID_ENABLED: True |
47 | 47 | |
48 | +### Uncomment to enable social networks fields profile | |
49 | +# SOCIAL_NETWORK_ENABLED: True | |
50 | + | |
48 | 51 | ### Uncomment to enable Converse.js |
49 | 52 | # CONVERSEJS_ENABLED: True |
50 | 53 | ... | ... |
colab/settings.py
colab/super_archives/models.py
... | ... | @@ -134,6 +134,10 @@ class Thread(models.Model, HitCounterModelMixin): |
134 | 134 | objects = NotSpamManager() |
135 | 135 | tags = TaggableManager() |
136 | 136 | |
137 | + # Save this pseudo now to avoid calling the | |
138 | + # function N times in the loops below | |
139 | + now = timezone.now() | |
140 | + | |
137 | 141 | class Meta: |
138 | 142 | verbose_name = _(u"Thread") |
139 | 143 | verbose_name_plural = _(u"Threads") |
... | ... | @@ -182,6 +186,12 @@ class Thread(models.Model, HitCounterModelMixin): |
182 | 186 | self.subject_token, |
183 | 187 | self.message_set.count()) |
184 | 188 | |
189 | + def _days_ago(self, date): | |
190 | + return (self.now - date).days | |
191 | + | |
192 | + def _get_score(self, weight, created): | |
193 | + return max(weight - (self.days_ago(created) // 3), 5) | |
194 | + | |
185 | 195 | def update_score(self): |
186 | 196 | """Update the relevance score for this thread. |
187 | 197 | |
... | ... | @@ -205,22 +215,15 @@ class Thread(models.Model, HitCounterModelMixin): |
205 | 215 | if not self.subject_token: |
206 | 216 | return |
207 | 217 | |
208 | - # Save this pseudo now to avoid calling the | |
209 | - # function N times in the loops below | |
210 | - now = timezone.now() | |
211 | - days_ago = lambda date: (now - date).days | |
212 | - get_score = lambda weight, created: max(weight - (days_ago(created) | |
213 | - // 3), 5) | |
214 | - | |
215 | 218 | vote_score = 0 |
216 | 219 | replies_score = 0 |
217 | 220 | for msg in self.message_set.all(): |
218 | 221 | # Calculate replies_score |
219 | - replies_score += get_score(300, msg.received_time) | |
222 | + replies_score += self._get_score(300, msg.received_time) | |
220 | 223 | |
221 | 224 | # Calculate vote_score |
222 | 225 | for vote in msg.vote_set.all(): |
223 | - vote_score += get_score(100, vote.created) | |
226 | + vote_score += self._get_score(100, vote.created) | |
224 | 227 | |
225 | 228 | # Calculate page_view_score |
226 | 229 | page_view_score = self.hits * 10 | ... | ... |
docs/source/user.rst
... | ... | @@ -35,6 +35,15 @@ SVN |
35 | 35 | +++ |
36 | 36 | .. TODO |
37 | 37 | |
38 | +Social Networks | |
39 | +++++ | |
40 | +.. attribute:: SOCIAL_NETWORK_ENABLED | |
41 | + | |
42 | + :default: False | |
43 | + | |
44 | + When this variable is True, the social networks fields, like Facebook and | |
45 | + Twitter, are added in user profile. By default, this fields are disabled. | |
46 | + | |
38 | 47 | Auth |
39 | 48 | ++++ |
40 | 49 | .. attribute:: BROWSERID_ENABLED | ... | ... |