some clean up in participant app

This commit is contained in:
Oskar Hahn 2012-04-13 11:35:53 +02:00
parent f1261ae2a7
commit f889c49c1b
4 changed files with 46 additions and 16 deletions

View File

@ -42,6 +42,21 @@ class Profile(models.Model):
self.user.set_password(self.firstpassword)
self.user.save()
@models.permalink
def get_absolute_url(self, link='edit'):
"""
Return the URL to this user.
link can be:
* edit
* delete
"""
if link == 'edit':
return ('user_edit', [str(self.user.id)])
if link == 'delete':
return ('user_delete', [str(self.user.id)])
def __unicode__(self):
if self.group:
return "%s (%s)" % (self.user.get_full_name(), self.group)

View File

@ -15,9 +15,10 @@ from __future__ import with_statement
import csv
import utils.csv_ext
from urllib import urlencode
try:
from urlparse import parse_qs
except ImportError: # old python version, grab it from cgi
except ImportError: # python <= 2.5 grab it from cgi
from cgi import parse_qs
from django.http import HttpResponse
@ -33,9 +34,12 @@ from django.db import transaction
from participant.models import Profile
from participant.api import gen_username, gen_password
from participant.forms import UserNewForm, UserEditForm, ProfileForm, UsersettingsForm, UserImportForm, GroupForm, AdminPasswordChangeForm
from participant.forms import (UserNewForm, UserEditForm, ProfileForm,
UsersettingsForm, UserImportForm, GroupForm,
AdminPasswordChangeForm)
from application.models import Application
from utils.utils import template, permission_required, gen_confirm_form, ajax_request
from utils.utils import (template, permission_required, gen_confirm_form,
ajax_request, decodedict, encodedict)
from utils.pdf import print_userlist, print_passwords
from utils.template import Tab
from system import config
@ -46,17 +50,6 @@ from django.db.models import Avg, Max, Min, Count
@permission_required('participant.can_see_participant')
@template('participant/overview.html')
def get_overview(request):
def decodedict(dict):
newdict = {}
for key in dict:
newdict[key] = [dict[key][0].encode('utf-8')]
return newdict
def encodedict(dict):
newdict = {}
for key in dict:
newdict[key] = [unicode(dict[key][0].decode('utf-8'))]
return newdict
try:
sortfilter = encodedict(parse_qs(request.COOKIES['participant_sortfilter']))
except KeyError:

View File

@ -110,3 +110,16 @@ def _propper_unicode(text):
res = text
return res
def decodedict(dict):
newdict = {}
for key in dict:
newdict[key] = [dict[key][0].encode('utf-8')]
return newdict
def encodedict(dict):
newdict = {}
for key in dict:
newdict[key] = [unicode(dict[key][0].decode('utf-8'))]
return newdict

View File

@ -31,6 +31,7 @@ from django.views.generic import (
ListView as _ListView,
)
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.list import TemplateResponseMixin
from django.utils.importlib import import_module
from django.core.context_processors import csrf
import settings
@ -45,6 +46,14 @@ FREE_TO_GO = 'free to go'
View = _View
class SetCookieMixin(object):
def render_to_response(self, context, **response_kwargs):
response = TemplateResponseMixin.render_to_response(self, context, **response_kwargs)
if 'cookie' in context:
response.set_cookie(context['cookie'][0], context['cookie'][1])
return response
class LoginMixin(object):
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
@ -76,7 +85,7 @@ class TemplateView(PermissionMixin, _TemplateView):
return context
class ListView(PermissionMixin, _ListView):
class ListView(PermissionMixin, SetCookieMixin, _ListView):
def get_context_data(self, **kwargs):
context = super(ListView, self).get_context_data(**kwargs)
template_manipulation.send(sender=self, request=self.request, context=context)