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.set_password(self.firstpassword)
self.user.save() 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): def __unicode__(self):
if self.group: if self.group:
return "%s (%s)" % (self.user.get_full_name(), 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 csv
import utils.csv_ext import utils.csv_ext
from urllib import urlencode from urllib import urlencode
try: try:
from urlparse import parse_qs 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 cgi import parse_qs
from django.http import HttpResponse from django.http import HttpResponse
@ -33,9 +34,12 @@ from django.db import transaction
from participant.models import Profile from participant.models import Profile
from participant.api import gen_username, gen_password 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 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.pdf import print_userlist, print_passwords
from utils.template import Tab from utils.template import Tab
from system import config from system import config
@ -46,17 +50,6 @@ from django.db.models import Avg, Max, Min, Count
@permission_required('participant.can_see_participant') @permission_required('participant.can_see_participant')
@template('participant/overview.html') @template('participant/overview.html')
def get_overview(request): 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: try:
sortfilter = encodedict(parse_qs(request.COOKIES['participant_sortfilter'])) sortfilter = encodedict(parse_qs(request.COOKIES['participant_sortfilter']))
except KeyError: except KeyError:

View File

@ -110,3 +110,16 @@ def _propper_unicode(text):
res = text res = text
return res 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, ListView as _ListView,
) )
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
from django.views.generic.list import TemplateResponseMixin
from django.utils.importlib import import_module from django.utils.importlib import import_module
from django.core.context_processors import csrf from django.core.context_processors import csrf
import settings import settings
@ -45,6 +46,14 @@ FREE_TO_GO = 'free to go'
View = _View 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): class LoginMixin(object):
@method_decorator(login_required) @method_decorator(login_required)
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
@ -76,7 +85,7 @@ class TemplateView(PermissionMixin, _TemplateView):
return context return context
class ListView(PermissionMixin, _ListView): class ListView(PermissionMixin, SetCookieMixin, _ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(ListView, self).get_context_data(**kwargs) context = super(ListView, self).get_context_data(**kwargs)
template_manipulation.send(sender=self, request=self.request, context=context) template_manipulation.send(sender=self, request=self.request, context=context)