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,11 +15,15 @@ from django.utils.translation import ugettext_lazy as _ | ||
15 | 15 | ||
16 | from conversejs.models import XMPPAccount | 16 | from conversejs.models import XMPPAccount |
17 | 17 | ||
18 | +from django.conf import settings | ||
19 | + | ||
18 | from .utils.validators import validate_social_account | 20 | from .utils.validators import validate_social_account |
19 | from .utils import mailman | 21 | from .utils import mailman |
20 | 22 | ||
21 | User = get_user_model() | 23 | User = get_user_model() |
22 | 24 | ||
25 | +SOCIAL_NETWORK_ENABLED = getattr(settings, 'SOCIAL_NETWORK_ENABLED') | ||
26 | + | ||
23 | 27 | ||
24 | class SocialAccountField(forms.Field): | 28 | class SocialAccountField(forms.Field): |
25 | def __init__(self, *args, **kwargs): | 29 | def __init__(self, *args, **kwargs): |
@@ -107,6 +111,7 @@ class UserForm(forms.ModelForm): | @@ -107,6 +111,7 @@ class UserForm(forms.ModelForm): | ||
107 | 111 | ||
108 | 112 | ||
109 | class UserUpdateForm(UserForm): | 113 | class UserUpdateForm(UserForm): |
114 | + | ||
110 | bio = forms.CharField( | 115 | bio = forms.CharField( |
111 | widget=forms.Textarea(attrs={'rows': '6', 'maxlength': '200'}), | 116 | widget=forms.Textarea(attrs={'rows': '6', 'maxlength': '200'}), |
112 | max_length=200, | 117 | max_length=200, |
@@ -122,12 +127,16 @@ class UserUpdateForm(UserForm): | @@ -122,12 +127,16 @@ class UserUpdateForm(UserForm): | ||
122 | class Meta: | 127 | class Meta: |
123 | model = User | 128 | model = User |
124 | fields = ('first_name', 'last_name', | 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 | class ListsForm(forms.Form): | 142 | class ListsForm(forms.Form): |
colab/accounts/templates/accounts/user_detail.html
@@ -60,25 +60,27 @@ | @@ -60,25 +60,27 @@ | ||
60 | </li> | 60 | </li> |
61 | {% endif %} | 61 | {% endif %} |
62 | {% if request.user.is_active %} | 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 | {% endif %} | 84 | {% endif %} |
83 | {% endif %} | 85 | {% endif %} |
84 | </ul> | 86 | </ul> |
colab/management/initconfig.py
@@ -45,6 +45,9 @@ ALLOWED_HOSTS: | @@ -45,6 +45,9 @@ ALLOWED_HOSTS: | ||
45 | ### Uncomment to enable Broswer ID protocol for authentication | 45 | ### Uncomment to enable Broswer ID protocol for authentication |
46 | # BROWSERID_ENABLED: True | 46 | # BROWSERID_ENABLED: True |
47 | 47 | ||
48 | +### Uncomment to enable social networks fields profile | ||
49 | +# SOCIAL_NETWORK_ENABLED: True | ||
50 | + | ||
48 | ### Uncomment to enable Converse.js | 51 | ### Uncomment to enable Converse.js |
49 | # CONVERSEJS_ENABLED: True | 52 | # CONVERSEJS_ENABLED: True |
50 | 53 |
colab/settings.py
@@ -322,6 +322,7 @@ if FEEDZILLA_ENABLED: | @@ -322,6 +322,7 @@ if FEEDZILLA_ENABLED: | ||
322 | ) | 322 | ) |
323 | 323 | ||
324 | BROWSERID_ENABLED = locals().get('BROWSERID_ENABLED') or False | 324 | BROWSERID_ENABLED = locals().get('BROWSERID_ENABLED') or False |
325 | +SOCIAL_NETWORK_ENABLED = locals().get('SOCIAL_NETWORK_ENABLED') or False | ||
325 | 326 | ||
326 | PROXIED_APPS = locals().get('PROXIED_APPS') or {} | 327 | PROXIED_APPS = locals().get('PROXIED_APPS') or {} |
327 | 328 |
colab/super_archives/models.py
@@ -134,6 +134,10 @@ class Thread(models.Model, HitCounterModelMixin): | @@ -134,6 +134,10 @@ class Thread(models.Model, HitCounterModelMixin): | ||
134 | objects = NotSpamManager() | 134 | objects = NotSpamManager() |
135 | tags = TaggableManager() | 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 | class Meta: | 141 | class Meta: |
138 | verbose_name = _(u"Thread") | 142 | verbose_name = _(u"Thread") |
139 | verbose_name_plural = _(u"Threads") | 143 | verbose_name_plural = _(u"Threads") |
@@ -182,6 +186,12 @@ class Thread(models.Model, HitCounterModelMixin): | @@ -182,6 +186,12 @@ class Thread(models.Model, HitCounterModelMixin): | ||
182 | self.subject_token, | 186 | self.subject_token, |
183 | self.message_set.count()) | 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 | def update_score(self): | 195 | def update_score(self): |
186 | """Update the relevance score for this thread. | 196 | """Update the relevance score for this thread. |
187 | 197 | ||
@@ -205,22 +215,15 @@ class Thread(models.Model, HitCounterModelMixin): | @@ -205,22 +215,15 @@ class Thread(models.Model, HitCounterModelMixin): | ||
205 | if not self.subject_token: | 215 | if not self.subject_token: |
206 | return | 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 | vote_score = 0 | 218 | vote_score = 0 |
216 | replies_score = 0 | 219 | replies_score = 0 |
217 | for msg in self.message_set.all(): | 220 | for msg in self.message_set.all(): |
218 | # Calculate replies_score | 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 | # Calculate vote_score | 224 | # Calculate vote_score |
222 | for vote in msg.vote_set.all(): | 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 | # Calculate page_view_score | 228 | # Calculate page_view_score |
226 | page_view_score = self.hits * 10 | 229 | page_view_score = self.hits * 10 |
docs/source/user.rst
@@ -35,6 +35,15 @@ SVN | @@ -35,6 +35,15 @@ SVN | ||
35 | +++ | 35 | +++ |
36 | .. TODO | 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 | Auth | 47 | Auth |
39 | ++++ | 48 | ++++ |
40 | .. attribute:: BROWSERID_ENABLED | 49 | .. attribute:: BROWSERID_ENABLED |
tests/settings.py
1 | from colab.settings import * # noqa | 1 | from colab.settings import * # noqa |
2 | 2 | ||
3 | - | 3 | +SOCIAL_NETWORK_ENABLED = True |
4 | STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' | 4 | STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' |
5 | 5 | ||
6 | LOGGING = { | 6 | LOGGING = { |