35 act_view = { |
35 act_view = { |
36 'view_texts' : get_int(request.GET, 'view_texts', 1), |
36 'view_texts' : get_int(request.GET, 'view_texts', 1), |
37 'view_comments' : get_int(request.GET, 'view_comments', 1), |
37 'view_comments' : get_int(request.GET, 'view_comments', 1), |
38 'view_users' : get_int(request.GET, 'view_users', 1), |
38 'view_users' : get_int(request.GET, 'view_users', 1), |
39 } |
39 } |
40 |
40 |
41 paginate_by = get_int(request.GET, 'paginate', ACTIVITY_PAGINATION) |
41 paginate_by = get_int(request.GET, 'paginate', ACTIVITY_PAGINATION) |
42 |
42 |
43 # texts with can_view_unapproved_comment perms |
43 # texts with can_view_unapproved_comment perms |
44 moderator_texts = get_texts_with_perm(request, 'can_view_unapproved_comment') |
44 moderator_texts = get_texts_with_perm(request, 'can_view_unapproved_comment') |
45 viewer_texts = get_texts_with_perm(request, 'can_view_approved_comment') |
45 viewer_texts = get_texts_with_perm(request, 'can_view_approved_comment') |
46 all_texts_ids = [t.id for t in moderator_texts] + [t.id for t in viewer_texts] |
46 all_texts_ids = [t.id for t in moderator_texts] + [t.id for t in viewer_texts] |
47 |
47 |
48 span = get_among(request.GET, 'span', ('day', 'month', 'week',), 'week') |
48 span = get_among(request.GET, 'span', ('day', 'month', 'week',), 'week') |
49 template_dict = { |
49 template_dict = { |
50 'span' : span, |
50 'span' : span, |
51 'last_texts' : get_texts_with_perm(request, 'can_view_text').order_by('-modified')[:RECENT_TEXT_NB], |
51 'last_texts' : get_texts_with_perm(request, 'can_view_text').order_by('-modified')[:RECENT_TEXT_NB], |
52 'last_comments' : Comment.objects.filter(text_version__text__in=all_texts_ids).order_by('-created')[:RECENT_COMMENT_NB], # TODO: useful? |
52 'last_comments' : Comment.objects.filter(text_version__text__in=all_texts_ids).order_by('-created')[:RECENT_COMMENT_NB], # TODO: useful? |
53 #'last_users' : User.objects.all().order_by('-date_joined')[:5], |
53 #'last_users' : User.objects.all().order_by('-date_joined')[:5], |
54 } |
54 } |
55 template_dict.update(act_view) |
55 template_dict.update(act_view) |
56 |
56 |
57 #selected_activities = [] |
57 #selected_activities = [] |
58 #[selected_activities.extend(Activity.VIEWABLE_ACTIVITIES[k]) for k in act_view.keys() if act_view[k]] |
58 #[selected_activities.extend(Activity.VIEWABLE_ACTIVITIES[k]) for k in act_view.keys() if act_view[k]] |
59 activities = get_viewable_activities(request, act_view) |
59 activities = get_viewable_activities(request, act_view) |
60 |
60 |
61 if not has_perm(request, 'can_manage_workspace'): |
61 if not has_perm(request, 'can_manage_workspace'): |
62 template_dict['to_mod_profiles'] = [] |
62 template_dict['to_mod_profiles'] = [] |
63 else: |
63 else: |
64 template_dict['to_mod_profiles'] = UserProfile.objects.filter(user__is_active=False).filter(is_suspended=True).order_by('-user__date_joined')[:MODERATE_NB] |
64 template_dict['to_mod_profiles'] = UserProfile.objects.filter(user__is_active=False).filter(is_suspended=True).order_by('-user__date_joined')[:MODERATE_NB] |
65 |
65 |
66 template_dict['to_mod_comments'] = Comment.objects.filter(state='pending').filter(text_version__text__in=moderator_texts).order_by('-modified')[:MODERATE_NB - len(template_dict['to_mod_profiles'])] |
66 template_dict['to_mod_comments'] = Comment.objects.filter(state='pending').filter(text_version__text__in=moderator_texts).order_by('-modified')[:MODERATE_NB - len(template_dict['to_mod_profiles'])] |
67 |
67 |
68 activities = activities.order_by('-created') |
68 activities = activities.order_by('-created') |
69 return object_list(request, activities, |
69 return object_list(request, activities, |
70 template_name='site/dashboard.html', |
70 template_name='site/dashboard.html', |
71 paginate_by=paginate_by, |
71 paginate_by=paginate_by, |
72 extra_context=template_dict, |
72 extra_context=template_dict, |
73 ) |
73 ) |
74 |
74 |
75 else: |
75 else: |
76 if request.method == 'POST': |
76 if request.method == 'POST': |
77 form = AuthenticationForm(request, request.POST) |
77 form = AuthenticationForm(request, request.POST) |
78 if form.is_valid(): |
78 if form.is_valid(): |
79 user = form.get_user() |
79 user = form.get_user() |
80 user.backend = 'django.contrib.auth.backends.ModelBackend' |
80 user.backend = 'django.contrib.auth.backends.ModelBackend' |
81 cm_login(request, user) |
81 cm_login(request, user) |
82 display_message(request, _(u"You're logged in!")) |
82 display_message(request, _(u"You're logged in!")) |
83 return HttpResponseRedirect(reverse('index')) |
83 return HttpResponseRedirect(reverse('index')) |
84 else: |
84 else: |
85 form = AuthenticationForm() |
85 form = AuthenticationForm() |
86 |
86 |
87 |
87 |
88 public_texts = get_texts_with_perm(request, 'can_view_text').order_by('-modified') |
88 public_texts = get_texts_with_perm(request, 'can_view_text').order_by('-modified') |
89 |
89 |
90 template_dict = { |
90 template_dict = { |
91 'form' : form, |
91 'form' : form, |
92 'public_texts' : public_texts, |
92 'public_texts' : public_texts, |
93 } |
93 } |
94 return render_to_response('site/non_authenticated_index.html', template_dict, context_instance=RequestContext(request)) |
94 return render_to_response('site/non_authenticated_index.html', template_dict, context_instance=RequestContext(request)) |
95 |
95 |
96 |
96 |
97 class HeaderContactForm(forms.Form): |
97 class HeaderContactForm(forms.Form): |
98 name = forms.CharField( |
98 name = forms.CharField( |
99 max_length=100, |
99 max_length=100, |
100 label=ugettext_lazy(u"Your name"), |
100 label=ugettext_lazy(u"Your name"), |
101 ) |
101 ) |
102 email = forms.EmailField(label=ugettext_lazy(u"Your email address"),) |
102 email = forms.EmailField(label=ugettext_lazy(u"Your email address"),) |
104 class BodyContactForm(forms.Form): |
104 class BodyContactForm(forms.Form): |
105 title = forms.CharField(label=ugettext_lazy(u"Subject of the message"), max_length=100) |
105 title = forms.CharField(label=ugettext_lazy(u"Subject of the message"), max_length=100) |
106 body = forms.CharField(label=ugettext_lazy(u"Body of the message"), widget=forms.Textarea) |
106 body = forms.CharField(label=ugettext_lazy(u"Body of the message"), widget=forms.Textarea) |
107 copy = forms.BooleanField( |
107 copy = forms.BooleanField( |
108 label=ugettext_lazy(u"Send me a copy of the email"), |
108 label=ugettext_lazy(u"Send me a copy of the email"), |
109 #help_text=ugettext_lazy(u"also send me a copy of the email"), |
109 #help_text=ugettext_lazy(u"also send me a copy of the email"), |
110 required=False) |
110 required=False) |
111 |
111 |
112 class ContactForm(HeaderContactForm, BodyContactForm): |
112 class ContactForm(HeaderContactForm, BodyContactForm): |
113 pass |
113 pass |
114 |
114 |
115 def contact(request): |
115 def contact(request): |
116 if request.method == 'POST': |
116 if request.method == 'POST': |
117 form = BodyContactForm(request.POST) if request.user.is_authenticated() else ContactForm(request.POST) |
117 form = BodyContactForm(request.POST) if request.user.is_authenticated() else ContactForm(request.POST) |
118 if form.is_valid(): |
118 if form.is_valid(): |
119 name = form.cleaned_data.get('name', None) or request.user.username |
119 name = form.cleaned_data.get('name', None) or request.user.username |
120 email = form.cleaned_data.get('email', None) or request.user.email |
120 email = form.cleaned_data.get('email', None) or request.user.email |
121 message = render_to_string('email/site_contact_email.txt', |
121 message = render_to_string('email/site_contact_email.txt', |
122 { |
122 { |
131 dest = settings.CONTACT_DEST |
131 dest = settings.CONTACT_DEST |
132 send_mail(subject, message, email, [dest]) |
132 send_mail(subject, message, email, [dest]) |
133 if form.cleaned_data['copy']: |
133 if form.cleaned_data['copy']: |
134 my_subject = _(u"Copy of message:") + u" " + subject |
134 my_subject = _(u"Copy of message:") + u" " + subject |
135 send_mail(my_subject, message, email, [email]) |
135 send_mail(my_subject, message, email, [email]) |
136 display_message(request, _(u"Email sent. We will get back to you as quickly as possible.")) |
136 display_message(request, _(u"Email sent. We will get back to you as quickly as possible.")) |
137 redirect_url = reverse('index') |
137 redirect_url = reverse('index') |
138 return HttpResponseRedirect(redirect_url) |
138 return HttpResponseRedirect(redirect_url) |
139 else: |
139 else: |
140 form = BodyContactForm() if request.user.is_authenticated() else ContactForm() |
140 form = BodyContactForm() if request.user.is_authenticated() else ContactForm() |
141 return render_to_response('site/contact.html', {'form': form}, context_instance=RequestContext(request)) |
141 return render_to_response('site/contact.html', {'form': form}, context_instance=RequestContext(request)) |
142 |
142 |
143 def global_feed(request): |
143 def global_feed(request): |
144 pass |
144 pass |
150 def __init__(self, data=None, initial=None): |
150 def __init__(self, data=None, initial=None): |
151 forms.Form.__init__(self, data=data, initial=initial) |
151 forms.Form.__init__(self, data=data, initial=initial) |
152 for field in self.fields: |
152 for field in self.fields: |
153 if field in self.conf_fields: |
153 if field in self.conf_fields: |
154 self.fields[field].initial = Configuration.objects.get_key(field) |
154 self.fields[field].initial = Configuration.objects.get_key(field) |
155 |
155 |
156 self.fields[field].initial = Configuration.objects.get_key(field) |
156 self.fields[field].initial = Configuration.objects.get_key(field) |
157 |
157 |
158 def save(self): |
158 def save(self): |
159 for field in self.fields: |
159 for field in self.fields: |
160 if field in self.conf_fields: |
160 if field in self.conf_fields: |
161 val = self.cleaned_data[field] |
161 val = self.cleaned_data[field] |
162 Configuration.objects.set_key(field, val) |
162 Configuration.objects.set_key(field, val) |
163 |
163 |
164 class SettingsForm(BaseSettingsForm): |
164 class SettingsForm(BaseSettingsForm): |
165 workspace_name = forms.CharField(label=ugettext_lazy("Workspace name"), |
165 workspace_name = forms.CharField(label=ugettext_lazy("Workspace name"), |
166 widget=forms.TextInput, |
166 widget=forms.TextInput, |
167 required=False, |
167 required=False, |
168 ) |
168 ) |
169 |
169 |
170 workspace_tagline = forms.CharField(label=ugettext_lazy("Workspace tagline"), |
170 workspace_tagline = forms.CharField(label=ugettext_lazy("Workspace tagline"), |
171 widget=forms.TextInput, |
171 widget=forms.TextInput, |
172 required=False, |
172 required=False, |
173 ) |
173 ) |
174 |
174 |
185 workspace_role_model = forms.ChoiceField(label=ugettext_lazy("Role model"), |
185 workspace_role_model = forms.ChoiceField(label=ugettext_lazy("Role model"), |
186 help_text=(ugettext_lazy("Change the roles available in the workspace")), |
186 help_text=(ugettext_lazy("Change the roles available in the workspace")), |
187 choices=role_models_choices, |
187 choices=role_models_choices, |
188 required=False, |
188 required=False, |
189 ) |
189 ) |
190 |
190 |
191 |
191 |
192 # fields to save in the Configuration objects |
192 # fields to save in the Configuration objects |
193 conf_fields = ['workspace_name', 'workspace_tagline', 'workspace_registration', 'workspace_registration_moderation', 'workspace_role_model'] |
193 conf_fields = ['workspace_name', 'workspace_tagline', 'workspace_registration', 'workspace_registration_moderation', 'workspace_role_model'] |
194 |
194 |
195 |
195 |
196 @has_global_perm('can_manage_workspace') |
196 @has_global_perm('can_manage_workspace') |
197 def settingss(request): |
197 def settingss(request): |
198 if request.method == 'POST': |
198 if request.method == 'POST': |
199 if 'delete_logo' in request.POST: |
199 if 'delete_logo' in request.POST: |
200 Configuration.objects.del_key('workspace_logo_file_key') |
200 Configuration.objects.del_key('workspace_logo_file_key') |
201 display_message(request, _(u'Settings saved')) |
201 display_message(request, _(u'Settings saved')) |
202 return HttpResponseRedirect(reverse('index')) |
202 return HttpResponseRedirect(reverse('settings')) |
203 else: |
203 else: |
204 form = SettingsForm(data=request.POST) |
204 form = SettingsForm(data=request.POST) |
205 if form.is_valid() : |
205 if form.is_valid() : |
206 form.save() |
206 form.save() |
207 display_message(request, _(u'Settings saved')) |
207 display_message(request, _(u'Settings saved')) |
208 return HttpResponseRedirect(reverse('index')) |
208 return HttpResponseRedirect(reverse('settings')) |
209 else: |
209 else: |
210 form = SettingsForm() |
210 form = SettingsForm() |
211 |
211 |
212 return render_to_response('site/settings.html', {'form' : form, 'help_links' : {'workspace_role_model':'role_model'}}, context_instance=RequestContext(request)) |
212 return render_to_response('site/settings.html', {'form' : form, 'help_links' : {'workspace_role_model':'role_model'}}, context_instance=RequestContext(request)) |
213 |
213 |
214 class SettingsDesignForm(BaseSettingsForm): |
214 class SettingsDesignForm(BaseSettingsForm): |
215 workspace_logo_file = forms.FileField(label=ugettext_lazy("Workspace logo"),required=False) |
215 workspace_logo_file = forms.FileField(label=ugettext_lazy("Workspace logo"),required=False) |
216 |
216 |
217 workspace_code = forms.CharField(label=ugettext_lazy("Workspace html code"), |
217 custom_css = forms.CharField(label=ugettext_lazy("Custom CSS rules"), |
218 help_text=(ugettext_lazy("Add stylesheets etc. Warning: this code will be added to the workspace code, make sure you know what you're doing before adding something here.")), |
218 help_text=mark_safe(ugettext_lazy("Add stylesheet rules in CSS format (do not include <code><style></code> HTML tags). Warning: this code will be added to all content, make sure you know what you're doing before adding something here.")), |
219 widget=forms.Textarea, |
219 widget=forms.Textarea, |
220 required=False, |
220 required=False, |
221 ) |
221 ) |
222 |
222 |
223 conf_fields = ['workspace_code'] |
223 custom_font = forms.CharField(label=ugettext_lazy("Custom font"), |
224 |
224 widget=forms.TextInput, |
|
225 help_text=mark_safe(ugettext_lazy("Custom alternative font family to 'modern', 'classic' and 'code' that visitors can chose for the body of co-ment texts. Enter a coma separated list of font families. Font family names including space characters should be enclosed in double quotes. Eg. ") + '<code>"Times New Roman", Times, serif</code>.'), |
|
226 required=False, |
|
227 ) |
|
228 |
|
229 custom_titles_font = forms.CharField(label=ugettext_lazy("Custom font for titles"), |
|
230 widget=forms.TextInput, |
|
231 help_text=mark_safe(ugettext_lazy("Custom alternative font family to 'modern', 'classic' and 'code' that visitors can chose for titles (h1 to h6) of co-ment texts. Enter a coma separated list of font families. Font family names including space characters should be enclosed in double quotes. Eg. ") + '<code>"Gill Sans", Helvetica, sans-serif</code>.'), |
|
232 required=False, |
|
233 ) |
|
234 conf_fields = ['custom_css', 'custom_font', 'custom_titles_font'] |
|
235 |
225 def save_file(self, logo_file): |
236 def save_file(self, logo_file): |
226 attach = Attachment.objects.create_attachment(filename='wp_logo', data=logo_file.read(), text_version=None) |
237 attach = Attachment.objects.create_attachment(filename='wp_logo', data=logo_file.read(), text_version=None) |
227 Configuration.objects.set_key('workspace_logo_file_key', attach.key) |
238 Configuration.objects.set_key('workspace_logo_file_key', attach.key) |
228 |
239 |
229 |
240 |
230 @has_global_perm('can_manage_workspace') |
241 @has_global_perm('can_manage_workspace') |
231 def settings_design(request): |
242 def settings_design(request): |
232 if request.method == 'POST': |
243 if request.method == 'POST': |
233 if 'delete_logo' in request.POST: |
244 if 'delete_logo' in request.POST: |
234 Configuration.objects.del_key('workspace_logo_file_key') |
245 Configuration.objects.del_key('workspace_logo_file_key') |
235 display_message(request, _(u'Settings saved')) |
246 display_message(request, _(u'Settings saved')) |
236 return HttpResponseRedirect(reverse('index')) |
247 return HttpResponseRedirect(reverse('settings-design')) |
237 else: |
248 else: |
238 form = SettingsDesignForm(data=request.POST) |
249 form = SettingsDesignForm(data=request.POST) |
239 if form.is_valid() : |
250 if form.is_valid() : |
240 form.save() |
251 form.save() |
241 logo_file = request.FILES.get('workspace_logo_file',None) |
252 logo_file = request.FILES.get('workspace_logo_file',None) |
242 if logo_file: |
253 if logo_file: |
243 form.save_file(logo_file) |
254 form.save_file(logo_file) |
244 display_message(request, _(u'Settings saved')) |
255 display_message(request, _(u'Settings saved')) |
245 return HttpResponseRedirect(reverse('index')) |
256 return HttpResponseRedirect(reverse('settings-design')) |
246 else: |
257 else: |
247 form = SettingsDesignForm() |
258 from cm.models import ApplicationConfiguration |
248 |
259 custom_css = ApplicationConfiguration.get_key('custom_css') |
|
260 if custom_css: |
|
261 default_css = custom_css |
|
262 else: |
|
263 default_css = ''' |
|
264 .voted { |
|
265 color: #008000; |
|
266 } |
|
267 |
|
268 .rejected, .fallen, .withdrawn { |
|
269 color: #ff0000; |
|
270 } |
|
271 |
|
272 div.frame { |
|
273 border: 1px solid #000; |
|
274 padding: 5px; |
|
275 } |
|
276 |
|
277 div.frame .title { |
|
278 font-weight: bold; |
|
279 text-align: center; |
|
280 }''' |
|
281 form = SettingsDesignForm(initial={'custom_css': default_css}) |
|
282 |
249 return render_to_response('site/settings_design.html', {'form' : form}, context_instance=RequestContext(request)) |
283 return render_to_response('site/settings_design.html', {'form' : form}, context_instance=RequestContext(request)) |
250 |
284 |
251 |
285 |
252 def password_reset_done(request): |
286 def password_reset_done(request): |
253 display_message(request, _(u'A link to reset your password has been sent to the profile email. Please check your email.')) |
287 display_message(request, _(u'A link to reset your password has been sent to the profile email. Please check your email.')) |