Commit 02d42cadddeabe53551bdd501add6697a82b1095

Authored by Carlos Coêlho
1 parent f17ef3ef

Verifying if social networks are enabled

Verified in forms and user detail template if social networks are enabled, if so display these infos

Signed-off-by: Carlos Oliveira <carlospecter@gmail.com>
Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com>
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 colab 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>