added fqdn_listname + workaround to user_settings
1 parent 97ab694 commit 1851bddd71d16084574efb917e253d504e972726
@benste benste authored on 4 Aug 2011
Showing 2 changed files
View
2
■■■
urls.py
url(r'^subscriptions/(?P<fqdn_listname>[^/]+)/(?:(?P<option>subscribe|unsubscribe)?)(/(?P<user_email>.+))?$', 'list_subscriptions', name = 'list_subscriptions'),#public
url(r'^subscriptions/(?P<fqdn_listname>[^/]+)/mass_subscribe/$', 'mass_subscribe', name = 'mass_subscribe'),#admin
url(r'^delete_list/(?P<fqdn_listname>[^/]+)/$', 'list_delete', name = 'list_delete'),
url(r'^user_settings/$', 'user_settings', kwargs={"tab": "user"}, name = 'user_settings'),
url(r'^membership_settings/$', 'user_settings', kwargs={"tab": "membership"}, name = 'membership_settings'), #todo improve regexp of above 2 urls
url(r'^membership_settings(/(?P<fqdn_listname>[^/]+))?/$', 'user_settings', kwargs={"tab": "membership"}, name = 'membership_settings'), #todo improve regexp of above 2 urls
#url(r'^settings/(?P<fqdn_listname>[^/]+)/(?P<visible_section>[^/]+)?/(?P<visible_option>.+)?$', 'list_settings', name = 'list_settings'),
url(r'^settings/(?P<fqdn_listname>[^/]+)/(?P<visible_section>[^/]+)?(?:/(?P<visible_option>.*))?$', 'list_settings', name = 'list_settings'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)#https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
 
View
33
views.py
,context_instance=RequestContext(request))
 
@login_required
def user_settings(request, tab = "user",
template = 'mailman-django/user_settings.html'):
template = 'mailman-django/user_settings.html',
fqdn_listname = None,):
"""
Change the user or the membership settings.
The user must be logged in to be allowed to change any settings.
TODO: * add CSS to display tabs ??
"""
member = request.user.username
message = ""
membership_lists = []
fqdn_listname = ""
try:
c = Client('http://localhost:8001/3.0', API_USER, API_PASS)
for user in c.members[member]:
raise Exception(user)
if fqdn_listname:
l = c.get_list(fqdn_listname)
user_object = l.get_member(member)
else:
raise Exception("Error: user not found without a fqdn_listname → LP:820827")
user_object = ""
raise Exception(user_object)
# address_choices for the 'address' field must be a list of
# tuples of length 2
address_choices = [[addr, addr] for addr in user_object.get_email_addresses()]
except Exception, e: #TODO-Exceptions
return HttpResponse(e)
except AttributeError, e:
return render_to_response('mailman-django/errors/generic.html',
{'error': "REST API not found / Offline"},context_instance=RequestContext(request))
except ValueError, e:
return render_to_response('mailman-django/errors/generic.html',
{'error': e},context_instance=RequestContext(request))
except HTTPError,e :
return render_to_response('mailman-django/errors/generic.html',
{'error': _("List ")+fqdn_listname+_(" does not exist")},context_instance=RequestContext(request))
if request.method == 'POST':
# The form enables both user and member settings. As a result
# we must find out which was the case.
if tab == "membership":