Merge lp:~benste/mailmanweb/main_dev into lp:mailmanweb

Proposed by benste
Status: Needs review
Proposed branch: lp:~benste/mailmanweb/main_dev
Merge into: lp:mailmanweb
Diff against target: 437 lines (+85/-56) (has conflicts)
3 files modified
dev_setup/settings.py (+2/-0)
src/mailmanweb/templates/mailmanweb/base.html (+7/-0)
src/mailmanweb/views.py (+76/-56)
Text conflict in src/mailmanweb/views.py
To merge this branch: bzr merge lp:~benste/mailmanweb/main_dev
Reviewer Review Type Date Requested Status
Florian Fuchs Approve
Review via email: mp+97469@code.launchpad.net

Commit message

Merge - added Django Messaging Framework - fixes lp920084 - by benste

Description of the change

Dear Terri and Flo,
the long promissed change which got delayed due to my old revisions ...

No CSS for new class mm_message included
+ For some strange reason the message Tag / Type seems not to be stored hence we don't get a special class e.g. for a warningn

To post a comment you must log in.
lp:~benste/mailmanweb/main_dev updated
35. By benste

changed all render error, error and message vars in views.py to new messaging frame

Revision history for this message
Florian Fuchs (flo-fuchs) wrote :

Thank you! I had to add the request param to the messages.success call in line 134. Other than that everything's fine. Added to the trunk...

review: Approve

Unmerged revisions

35. By benste

changed all render error, error and message vars in views.py to new messaging frame

33. By Terri

Made it so that the settings menu doesn't disappear when you change settings.

32. By Terri

Assorted fixes to make sure the settings forms will submit correctly. This
should fix the enums and booleans, but does not fix acceptable_aliases (which
needs to submit a set of unicode strings)

31. By Terri

Fixes to the settings page, mostly making sure we use the right enums for
things.

30. By Terri

Removing settings templates that we've decided not to use

29. By Terri

Merged

28. By Terri

Regrouping of the list settings pages.

27. By Terri

Rearranging settings in a way that hopefully makes sense.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dev_setup/settings.py'
2--- dev_setup/settings.py 2012-03-13 03:58:06 +0000
3+++ dev_setup/settings.py 2012-03-14 19:51:23 +0000
4@@ -102,6 +102,7 @@
5
6 TEMPLATE_CONTEXT_PROCESSORS = (
7 "django.contrib.auth.context_processors.auth",
8+ "django.contrib.messages.context_processors.messages",
9 "django.core.context_processors.debug",
10 "django.core.context_processors.i18n",
11 "django.core.context_processors.media",
12@@ -138,6 +139,7 @@
13
14 INSTALLED_APPS = (
15 'django.contrib.auth',
16+ 'django.contrib.messages',
17 'django.contrib.contenttypes',
18 'django.contrib.sessions',
19 'django.contrib.sites',
20
21=== modified file 'src/mailmanweb/templates/mailmanweb/base.html'
22--- src/mailmanweb/templates/mailmanweb/base.html 2012-03-14 17:43:32 +0000
23+++ src/mailmanweb/templates/mailmanweb/base.html 2012-03-14 19:51:23 +0000
24@@ -50,6 +50,13 @@
25 </header>
26
27 <div class="mm_main mm_canvas">
28+ {% if messages %}
29+ <ul class="mm_messages">
30+ {% for message in messages %}
31+ <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
32+ {% endfor %}
33+ </ul>
34+ {% endif %}
35 {% block main %}{% endblock main %}
36 </div>
37 <div id="mm_footer">
38
39=== modified file 'src/mailmanweb/views.py'
40--- src/mailmanweb/views.py 2012-03-14 17:45:34 +0000
41+++ src/mailmanweb/views.py 2012-03-14 19:51:23 +0000
42@@ -23,6 +23,7 @@
43
44
45 from django.conf import settings
46+from django.contrib import messages
47 from django.contrib.auth import logout, authenticate, login
48 from django.contrib.auth.decorators import login_required, permission_required
49 from django.contrib.auth.forms import AuthenticationForm
50@@ -53,15 +54,26 @@
51 try:
52 existing_domains = Domain.objects.all()
53 logger.debug(Domain.objects)
54+<<<<<<< TREE
55 except MailmanApiError:
56 return utils.render_api_error(request)
57 return render_to_response('mailmanweb/domain_index.html', {'domains':existing_domains,},
58+=======
59+ except MailmanApiError, e:
60+ messages.error(request,e)
61+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
62+ return render_to_response(template, {'domains':existing_domains,},
63+>>>>>>> MERGE-SOURCE
64 context_instance=RequestContext(request))
65
66 @login_required
67 @permission_required('server_admin')
68+<<<<<<< TREE
69 def domain_new(request):
70 message = None
71+=======
72+def domain_new(request, template = 'mailmanweb/domain_new.html'):
73+>>>>>>> MERGE-SOURCE
74 if request.method == 'POST':
75 form = DomainNew(request.POST)
76 if form.is_valid():
77@@ -70,15 +82,23 @@
78 description=form.cleaned_data['description'])
79 try:
80 domain.save()
81- except MailmanApiError:
82- return utils.render_api_error(request)
83+ except MailmanApiError, e:
84+ messages.error(request,e)
85+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
86 except HTTPError, e:
87- message=e
88+ messages.error(request,e)
89+ else:
90+ messages.success(request,_("New Domain registered"))
91 return redirect("domain_index")
92 else:
93 form = DomainNew()
94+<<<<<<< TREE
95 return render_to_response('mailmanweb/domain_new.html',
96 {'form': form,'message': message},
97+=======
98+ return render_to_response(template,
99+ {'form': form},
100+>>>>>>> MERGE-SOURCE
101 context_instance=RequestContext(request))
102
103 @login_required
104@@ -92,14 +112,13 @@
105 filled in before the last POST request is returned. The user must
106 be logged in to create a new list.
107 """
108- error = None
109- message = None
110 mailing_list = None
111 if request.method == 'POST':
112 try:
113 domains = Domain.objects.all()
114- except MailmanApiError:
115- return utils.render_api_error(request)
116+ except MailmanApiError, e:
117+ messages.error(request,e)
118+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
119 choosable_domains = [("",_("Choose a Domain"))]
120 for domain in domains:
121 choosable_domains.append((domain.mail_host,
122@@ -118,29 +137,31 @@
123 #settings["???"] = form.cleaned_data['languages'] #TODO not found in REST:
124 list_settings["advertised"] = form.cleaned_data['advertised']
125 list_settings.save()
126+ messages.success(_("List created"))
127 return redirect("list_summary",fqdn_listname=mailing_list.fqdn_listname)
128 #TODO catch correct Error class:
129 except HTTPError, e:
130- return render_to_response('mailmanweb/errors/generic.html',
131- {'error':e},
132- context_instance=RequestContext(request))
133+ messages.error(request,e)
134+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
135+ else:
136+ messages.success(_("New List created"))
137 else:
138 try:
139 domains = Domain.objects.all()
140- except MailmanApiError:
141- return utils.render_api_error(request)
142+ except MailmanApiError, e:
143+ messages.error(request,e)
144+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
145 choosable_domains = [("",_("Choose a Domain"))]
146 for domain in domains:
147 choosable_domains.append((domain.mail_host,domain.mail_host))
148 form = ListNew(choosable_domains,initial={'list_owner': request.user.username})
149- return render_to_response(template, {'form': form, error:None},
150+ return render_to_response(template, {'form': form},
151 context_instance=RequestContext(request))
152
153 def list_index(request, template = 'mailmanweb/lists/index.html'):
154 """Show a table of all public mailing lists.
155 """
156 lists = []
157- error = None
158 domain = None
159 only_public = True
160 if request.user.is_authenticated():
161@@ -148,13 +169,13 @@
162 try:
163 lists = List.objects.all(only_public=only_public)
164 except MailmanApiError:
165- return utils.render_api_error(request)
166+ messages.error(request,e)
167+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
168 if request.method == 'POST':
169 return redirect("list_summary", fqdn_listname=request.POST["list"])
170 else:
171 return render_to_response(template,
172- {'error': error,
173- 'lists': lists,},
174+ {'lists': lists,},
175 context_instance=RequestContext(request))
176
177 def list_metrics(request,fqdn_listname=None,option=None,template='mailmanweb/lists/metrics.html'):
178@@ -164,7 +185,6 @@
179 information about the list such as the date of the last post and the
180 time the last digest is sent.
181 """
182- error=None
183 user_is_subscribed = False
184 if request.method == 'POST':
185 return redirect("list_summary", fqdn_listname=request.POST["list"])
186@@ -177,7 +197,8 @@
187 except:
188 pass #init
189 except MailmanApiError:
190- return render_api_error(request)
191+ messages.error(request,e)
192+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
193 return render_to_response(template,
194 {'list':the_list,
195 'message': None,
196@@ -193,7 +214,8 @@
197 try:
198 the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
199 except MailmanApiError:
200- return utils.render_api_error(request)
201+ messages.error(request,e)
202+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
203 return render_to_response(template,
204 {'list': the_list,
205 'subscribe_form': ListSubscribe(),
206@@ -206,7 +228,8 @@
207 try:
208 the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
209 except MailmanApiError:
210- return utils.render_api_error(request)
211+ messages.error(request,e)
212+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
213 if request.method == 'POST':
214 form = ListSubscribe(request.POST)
215 else:
216@@ -224,8 +247,6 @@
217 user to fill in which are evaluated in this function.
218 """
219 #create Values for Template usage
220- message = None
221- error = None
222 form_subscribe = None
223 form_unsubscribe = None
224 if request.POST.get('fqdn_listname', ''):
225@@ -233,9 +254,9 @@
226 # connect REST and catch issues getting the list
227 try:
228 the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
229- except AttributeError, e:
230+ except MailmanApiError, e:
231+ messages.error(request,"REST API not found / Offline")
232 return render_to_response('mailmanweb/errors/generic.html',
233- {'error': "REST API not found / Offline"},
234 context_instance=RequestContext(request))
235 #process submitted form
236 if request.method == 'POST':
237@@ -254,8 +275,8 @@
238 'option':option,
239 'message':_("Subscribed ")+ email },context_instance=RequestContext(request))
240 except HTTPError, e:
241- return render_to_response('mailmanweb/errors/generic.html',
242- {'error':e}, context_instance=RequestContext(request))
243+ messages.error(request,e)
244+ return render_to_response('mailmanweb/errors/generic.html', context_instance=RequestContext(request))
245 else: #invalid subscribe form
246 form_subscribe = form
247 form_unsubscribe = ListUnsubscribe(initial = {'fqdn_listname': fqdn_listname, 'name' : 'unsubscribe'})
248@@ -269,8 +290,8 @@
249 return render_to_response('mailmanweb/lists/summary.html',
250 {'list': the_list, 'message':_("Unsubscribed ")+ email },context_instance=RequestContext(request))
251 except ValueError, e:
252- return render_to_response('mailmanweb/errors/generic.html',
253- {'error':e}, context_instance=RequestContext(request))
254+ messages.error(request,e)
255+ return render_to_response('mailmanweb/errors/generic.html', context_instance=RequestContext(request))
256 else:#invalid unsubscribe form
257 form_subscribe = ListSubscribe(initial = {'fqdn_listname': fqdn_listname,
258 'option':option,
259@@ -288,8 +309,6 @@
260 the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)#TODO
261 return render_to_response(template, {'form_subscribe': form_subscribe,
262 'form_unsubscribe': form_unsubscribe,
263- 'message':message,
264- 'error':error,
265 'list': the_list,
266 }
267 ,context_instance=RequestContext(request))
268@@ -301,7 +320,8 @@
269 try:
270 the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
271 except MailmanApiError:
272- return utils.render_api_error(request)
273+ messages.error(request,e)
274+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
275 if request.method == 'POST':
276 the_list.delete()
277 # let the user return to the list index page
278@@ -328,7 +348,6 @@
279 to show only parts of the settings
280 <param> is optional / is used to differ in between section and option might result in using //option
281 """
282- message = ""
283 logger.debug(visible_section)
284 if visible_section == None:
285 visible_section = 'List Identity'
286@@ -336,14 +355,15 @@
287 try:
288 the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
289 except MailmanApiError:
290- return utils.render_api_error(request)
291+ messages.error(request,e)
292+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
293 #collect all Form sections for the links:
294 temp = ListSettings('','')
295 for section in temp.layout:
296 try:
297 form_sections.append((section[0],temp.section_descriptions[section[0]]))
298 except KeyError, e:
299- error=e
300+ messages.error(e)
301 del temp
302 #Save a Form Processed by POST
303 if request.method == 'POST':
304@@ -354,9 +374,9 @@
305 for key in form.fields.keys():
306 list_settings[key] = form.cleaned_data[key]
307 list_settings.save()
308- message = _("The list has been updated.")
309+ messages.success(_("The list has been updated."))
310 else:
311- message = _("Validation Error - The list has not been updated.")
312+ messages.success(_("Validation Error - The list has not been updated."))
313
314 else:
315 #Provide a form with existing values
316@@ -372,7 +392,6 @@
317 form.truncate()
318 return render_to_response(template, {'form': form,
319 'form_sections': form_sections,
320- 'message': message,
321 'list': the_list,
322 'visible_option':visible_option,
323 'visible_section':visible_section,
324@@ -387,11 +406,11 @@
325 This functions is part of the settings for a list and requires the
326 user to be logged in to perform the action.
327 """
328- message = ""
329 try:
330 the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
331 except MailmanApiError:
332- return utils.render_api_error(request)
333+ messages.error(request,e)
334+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
335 if request.method == 'POST':
336 form = ListMassSubscription(request.POST)
337 if form.is_valid():
338@@ -405,16 +424,15 @@
339 if len(parts) == 2 and '.' in parts[1]: #TODO - move check to clean method of the form - see example in django docs
340 try:
341 the_list.subscribe(address=email, real_name="")
342- message = "The mass subscription was successful."
343+ messages.success(_("The mass subscription was successful."))
344 except Exception, e: #TODO find right exception and catch only this one
345- return render_to_response('mailmanweb/errors/generic.html',
346- {'error': str(e)})
347-
348+ messages.error(request,str(e))
349+ return render_to_response('mailmanweb/errors/generic.html', )
350 else:
351 # At least one email address wasn't valid so
352 # overwrite the success message and ask them to
353 # try again.
354- message = "Please enter valid email addresses."
355+ messages.error(_("Please enter valid email addresses."))
356 except Exception, e:
357 return HttpResponse(e)
358 else:
359@@ -422,7 +440,6 @@
360 # mass subscribe users.
361 form = ListMassSubscription()
362 return render_to_response(template, {'form': form,
363- 'message': message,
364 'list': the_list}
365 ,context_instance=RequestContext(request))
366
367@@ -438,7 +455,6 @@
368 change to the correct calls here
369 """
370 member = request.user.username
371- message = ''
372 form = None
373 the_list=None
374 membership_lists = []
375@@ -450,8 +466,14 @@
376 the_list = List.objects.get(fqdn_listname=fqdn_listname)
377 user_object = the_list.get_member(member)
378 else:
379+<<<<<<< TREE
380 message = ("Using a workaround to replace missing Client functionality → LP:820827")
381 for mlist in List.objects.all():
382+=======
383+ messages.debug("Using a workaround to replace missing Client functionality → LP:820827") #Todo - no translation neededf
384+ #### BEGIN workaround
385+ for mlist in Lists.objects.all():
386+>>>>>>> MERGE-SOURCE
387 try:
388 mlist.get_member(member)
389 membership_lists.append(mlist)
390@@ -462,17 +484,16 @@
391 # tuples of length 2
392 raise Exception("WORK in PROGRRESS needs REST Auth Middleware! - TODO")
393 address_choices = [[addr, addr] for addr in user_object.address]
394- except AttributeError, e:
395- return render_to_response('mailmanweb/errors/generic.html',
396- {'error': str(e)+"REST API not found / Offline"},
397- context_instance=RequestContext(request))
398+ except MailmanApiError, e:
399+ messages.error(request,str(e)+"REST API not found / Offline")
400+ return render_to_response('mailmanweb/errors/generic.html',context_instance=RequestContext(request))
401 except ValueError, e:
402+ messages.error(request,e)
403 return render_to_response('mailmanweb/errors/generic.html',
404- {'error': e},
405 context_instance=RequestContext(request))
406 except HTTPError,e :
407+ messages.error(request,_("List ")+fqdn_listname+_(" does not exist"))
408 return render_to_response('mailmanweb/errors/generic.html',
409- {'error': _("List ")+fqdn_listname+_(" does not exist")},
410 context_instance=RequestContext(request))
411 #-----------------------------------------------------------------
412 if request.method == 'POST':
413@@ -484,7 +505,7 @@
414 if form.is_valid():
415 member_object = c.get_member(member, request.GET["list"])
416 member_object.update(request.POST)
417- message = "The membership settings have been updated."
418+ messages.success(_("The membership settings have been updated."))
419 else:
420 # the post request came from the user tab
421 # the 'address' field need choices as a tuple of length 2
422@@ -498,7 +519,7 @@
423 # not just the address_choices (add mock data to _User
424 # class and make the call with 'user_object.info')
425 form = UserSettings(address_choices)
426- message = "The user settings have been updated."
427+ messages.success(_("The user settings have been updated."))
428
429 else:
430 if tab == "membership" and fqdn_listname :
431@@ -533,7 +554,6 @@
432 'tab': tab,
433 'list': the_list,
434 'membership_lists': membership_lists,
435- 'message': message,
436 'member': member}
437 ,context_instance=RequestContext(request))
438

Subscribers

People subscribed via source and target branches