From 96ff186913859f61aaa259b377f971bd3916838d Mon Sep 17 00:00:00 2001 From: Uwe Kamper Date: Fri, 25 Oct 2013 01:03:16 +0200 Subject: [PATCH] clean templates, add userdetail and proper landing page --- account/cbase_members.py | 14 +++++- account/forms.py | 5 ++- account/templates/form_base.html | 2 +- account/templates/gastropin.html | 37 ++++++++-------- account/templates/login.html | 14 ++++-- account/templates/member_base.html | 43 +++++++++++++++++++ account/templates/password.html | 23 ++++++++++ account/templates/sippin.html | 23 ++++++++++ account/templates/start.html | 51 ++++++++++++++++++++++ account/urls.py | 7 ++- account/views.py | 68 ++++++++++++++++-------------- cbmi/templates/base.html | 44 ++++++++++--------- cbmi/urls.py | 2 +- 13 files changed, 253 insertions(+), 80 deletions(-) create mode 100644 account/templates/member_base.html create mode 100644 account/templates/password.html create mode 100644 account/templates/sippin.html create mode 100644 account/templates/start.html diff --git a/account/cbase_members.py b/account/cbase_members.py index eddbebd..5845382 100644 --- a/account/cbase_members.py +++ b/account/cbase_members.py @@ -32,7 +32,13 @@ class MemberValues(object): self._new = copy.deepcopy(self._old) def get(self, key, default=None): - value = self._new.get(key, default)[0] + value_list = self._new.get(key, default) + if value_list: + value = value_list[0] + else: + value = default + + # Decode if value == 'TRUE': return True elif value == 'FALSE': @@ -78,6 +84,12 @@ class MemberValues(object): result = l.modify_s(dn, mod_attrs) print "result is: ", result + def to_dict(self): + result = {} + for key, value in self._new.items(): + result[key] = self.get(key) + return result + def _get_bind_dn(self): """ Adds the uid=userid, to the base dn and returns that. diff --git a/account/forms.py b/account/forms.py index 376002b..7bf72f1 100644 --- a/account/forms.py +++ b/account/forms.py @@ -32,7 +32,7 @@ class WlanPresenceForm(forms.Form): help_text=_('Enable WiFi presence?')) -class PaswordForm(forms.Form): +class PasswordForm(forms.Form): password1 = forms.CharField(max_length=255, widget=forms.PasswordInput, help_text=_('New password')) password2 = forms.CharField(max_length=255, widget=forms.PasswordInput, @@ -42,6 +42,9 @@ class PaswordForm(forms.Form): class RFIDForm(forms.Form): rfid = forms.CharField(max_length=255, help_text=_('Your RFID')) +class SIPPinForm(forms.Form): + sippin = forms.CharField(max_length=255, help_text=_('Your SIP PIN')) + class NRF24Form(forms.Form): nrf24 = forms.CharField(max_length=255, diff --git a/account/templates/form_base.html b/account/templates/form_base.html index 5b8727f..c10f3fc 100644 --- a/account/templates/form_base.html +++ b/account/templates/form_base.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "member_base.html" %} {% load i18n %} {% block container %} diff --git a/account/templates/gastropin.html b/account/templates/gastropin.html index b1480f1..ecade02 100644 --- a/account/templates/gastropin.html +++ b/account/templates/gastropin.html @@ -1,20 +1,23 @@ -{% extends "base.html" %} +{% extends "form_base.html" %} +{% load i18n %} +{% load crispy_forms_tags %} -{% block body %} -
-
-
-

Gastro-Pin

- {% if message %} -
{{ message }}
- {% endif %} -
- {{ form.non_field_errors }} - {% csrf_token %} - {{ form.as_p }} - -
+{% block form_title %}{% trans "Gastro PIN"%}{% endblock %} + +{% block form_description %} +

{% blocktrans %}Change your Gastro PIN to access the vending machines.{% endblocktrans %}

+{% endblock %} + +{% block form_fields %} + {{ form.non_field_errors }} +
+ {% csrf_token %} + {{ form|crispy }} + +
+
+
-
-{% endblock %} + +{% endblock form_fields %} \ No newline at end of file diff --git a/account/templates/login.html b/account/templates/login.html index 8d90e55..615cb97 100644 --- a/account/templates/login.html +++ b/account/templates/login.html @@ -1,4 +1,6 @@ {% extends "base.html" %} +{% load i18n %} +{% load crispy_forms_tags %} {% block body %}
@@ -7,11 +9,15 @@
-
-
+
+ {% csrf_token %} - {{ form.as_p }} - + {{ form|crispy }} +
+
+ +
+
diff --git a/account/templates/member_base.html b/account/templates/member_base.html new file mode 100644 index 0000000..c2f1be4 --- /dev/null +++ b/account/templates/member_base.html @@ -0,0 +1,43 @@ +{% extends "base.html" %} +{% load i18n %} + +{% block body %} +
+ + {% block container %}{% endblock container %} + +
+
+ Copyright © 2013 by c-base e.V. +
+
+{% endblock body %} diff --git a/account/templates/password.html b/account/templates/password.html new file mode 100644 index 0000000..f81d9a9 --- /dev/null +++ b/account/templates/password.html @@ -0,0 +1,23 @@ +{% extends "form_base.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block form_title %}{% trans "Password"%}{% endblock %} + +{% block form_description %} +

{% blocktrans %}You can change your password here.{% endblocktrans %}

+{% endblock %} + +{% block form_fields %} + {{ form.non_field_errors }} +
+ {% csrf_token %} + {{ form|crispy }} + +
+
+ +
+
+
+{% endblock form_fields %} \ No newline at end of file diff --git a/account/templates/sippin.html b/account/templates/sippin.html new file mode 100644 index 0000000..b894a1d --- /dev/null +++ b/account/templates/sippin.html @@ -0,0 +1,23 @@ +{% extends "form_base.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block form_title %}{% trans "SIP PIN"%}{% endblock %} + +{% block form_description %} +

{% blocktrans %}The SIP PIN is your access to the c-base SIP server for voice telephony.{% endblocktrans %}

+{% endblock %} + +{% block form_fields %} + {{ form.non_field_errors }} +
+ {% csrf_token %} + {{ form|crispy }} + +
+
+ +
+
+
+{% endblock form_fields %} \ No newline at end of file diff --git a/account/templates/start.html b/account/templates/start.html new file mode 100644 index 0000000..c2b7861 --- /dev/null +++ b/account/templates/start.html @@ -0,0 +1,51 @@ +{% extends "member_base.html" %} +{% load i18n %} + +{% block container %} +
+
+

{% trans "Welcome to the c-base member interface" %}

+

{% blocktrans %}Here you can change + some parameters of your c-base member account.{% endblocktrans %}

+ +

{% trans "Basic information about your account" %}

+ +
    + +
  • {% trans "Your user ID:" %} + {{ member.uid }}
  • +
  • {% trans "Numeric user ID:" %} + {{ member.uidNumber }}
    + {% blocktrans %}The numeric user ID can be used to login with + the vending machines and network connected combination + locks.{% endblocktrans %}
  • +
  • + {% trans "Your c-base e-mail address:" %} + {{ member.mail }} +
  • +
+ +

{% trans "Management information" %}

+ +
    +
  • {% trans "Name:" %} + {{ member.displayName }} +
  • +
  • + {% trans "External e-mail address:" %} + {{ member.externalEmail }}
    + {% blocktrans %}The external e-mail address is used by the + board of c-base to reach you in cases where your c-base + address (see above) is not working. To change your + externe e-mail address please contact the c-base board + (vorstand@c-base.org).{% endblocktrans %} +
  • +
  • + {% trans "Your c-base member account balance:" %} + {% trans "Check balance" %} +
  • +
+ +
+
+{% endblock container %} \ No newline at end of file diff --git a/account/urls.py b/account/urls.py index 755e7f5..f904146 100644 --- a/account/urls.py +++ b/account/urls.py @@ -3,11 +3,14 @@ from django.conf.urls import patterns, url urlpatterns = patterns( '', - url(r'^login/$', 'account.views.auth_login', name="auth_login"), + url(r'^login/$', 'account.views.auth_login', name="cbase_auth_login"), url(r'^logout/$', 'account.views.auth_logout', name="auth_logout"), url(r'^gastropin/$', 'account.views.gastropin', name='gastropin'), url(r'^wlan_presence/$', 'account.views.wlan_presence', name='wlan_presence'), url(r'^rfid/$', 'account.views.rfid', name='rfid'), - url(r'^nrf24/$', 'account.views.nrf24', name='rfid'), + url(r'^nrf24/$', 'account.views.nrf24', name='nrf24'), + url(r'^password/$', 'account.views.password', name='password'), + url(r'^sippin/$', 'account.views.sippin', name='sippin'), + url(r'^$', 'account.views.home', name="home"), url(r'^groups/(?P[^/]+)/', 'account.views.groups_list'), ) \ No newline at end of file diff --git a/account/views.py b/account/views.py index 4dd1fa2..c50f831 100644 --- a/account/views.py +++ b/account/views.py @@ -12,10 +12,34 @@ from django.contrib.auth.models import Group from django.shortcuts import render from django.utils.translation import ugettext as _ -from forms import GastroPinForm, WlanPresenceForm, LoginForm, PaswordForm, \ - RFIDForm, NRF24Form +from forms import GastroPinForm, WlanPresenceForm, LoginForm, PasswordForm, \ + RFIDForm, NRF24Form, SIPPinForm from cbase_members import MemberValues, retrieve_member + +def landingpage(request): + if request.user.is_authenticated(): + return HttpResponseRedirect('/account') + form = LoginForm() + is_ceymaster = is_admin = False + if 'ceymaster' in [g.name for g in request.user.groups.all()]: + is_ceymaster = True + if 'ldap_admins' in [g.name for g in request.user.groups.all()]: + is_admin = True + groups = Group.objects.all() + admins = Group.objects.get(name="ldap_admins").user_set.all() + + # values = get_user_values(request.user.username, request.session['ldap_password']) + #return render_to_response("dashboard.html", locals()) + return render(request, 'base.html', {'form': form, 'admins': admins}) + +@login_required +def home(request): + member = retrieve_member(request) + context = {'member': member.to_dict()} + print context + return render(request, 'start.html', context) + def auth_login(request): redirect_to = request.GET.get('next', '') or '/' if request.method == 'POST': @@ -44,6 +68,7 @@ def auth_login(request): return render_to_response('login.html', RequestContext(request, locals())) +@login_required def auth_logout(request): redirect_to = request.GET.get('next', '') or '/' logout(request) @@ -51,19 +76,6 @@ def auth_logout(request): response.delete_cookie('sessionkey') return response -def landingpage(request): - is_ceymaster = is_admin = False - if 'ceymaster' in [g.name for g in request.user.groups.all()]: - is_ceymaster = True - if 'ldap_admins' in [g.name for g in request.user.groups.all()]: - is_admin = True - groups = Group.objects.all() - admins = Group.objects.get(name="ldap_admins").user_set.all() - if request.user.is_authenticated(): - # values = get_user_values(request.user.username, request.session['ldap_password']) - return render_to_response("dashboard.html", locals()) - return render_to_response("base.html", locals()) - @login_required(redirect_field_name="/" ,login_url="/account/login/") def groups_list(request, group_name): group = get_object_or_404(Group, name=group_name) @@ -76,24 +88,13 @@ def groups_list(request, group_name): @login_required def gastropin(request): - if request.method == 'POST': - form = GastroPinForm(request.POST) - if form.is_valid(): - user = request.user - user_profile = user.get_profile() - user_profile.gastropin = form.cleaned_data['gastropin'] - user_profile.save() - return render(request, 'gastropin.html', - {'message': _('Your Gastro-PIN was changed. Thank you!'), - 'form:': form}) - else: - return render(request, 'gastropin.html', {'form:': form}) - - else: - form = GastroPinForm() - - return render(request, 'gastropin.html', {'form': form}) + return set_ldap_field(request, GastroPinForm, + [('gastropin', 'gastropin')], 'gastropin.html') +@login_required +def sippin(request): + return set_ldap_field(request, SIPPinForm, [('sippin', 'sippin')], + 'sippin.html') def set_ldap_field(request, form_type, field_names, template_name): """ @@ -135,4 +136,7 @@ def rfid(request): def nrf24(request): return set_ldap_field(request, NRF24Form, [('nrf24', 'nrf24')], 'nrf24.html') +@login_required +def password(request): + return set_ldap_field(request, PasswordForm, [('password1', 'password')], 'password.html') diff --git a/cbmi/templates/base.html b/cbmi/templates/base.html index c3dc12b..aecd898 100644 --- a/cbmi/templates/base.html +++ b/cbmi/templates/base.html @@ -1,4 +1,6 @@ {% load i18n %} +{% load crispy_forms_tags %} + @@ -64,33 +66,18 @@
{% block body %}
- {% block container %}
-
+

c-base member-interface

- Auf dieser Seite kann jedes Member seine LDAP-Daten editieren und u.A. sein Passwort neu setzen. + {% blocktrans %}On this website any member can view and + edit their data stored in the LDAP directory of + c-base.{% endblocktrans %}
- neumember können sich ihr initiales passwort mit einem der folgenden member setzen: + {% blocktrans %}If you are a new member and don't have a + password yet, please contact one of the following people:{% endblocktrans %}
    {% for admin in admins %}
  • {{ admin}}
  • @@ -98,6 +85,21 @@
+
+
+

Login

+
+ {% csrf_token %} + {{ form|crispy }} +
+
+ +
+
+
+
+
{% endblock container %}
diff --git a/cbmi/urls.py b/cbmi/urls.py index 10bebbb..e52b3b9 100644 --- a/cbmi/urls.py +++ b/cbmi/urls.py @@ -11,6 +11,6 @@ urlpatterns = patterns('', url(r'account/', include('account.urls')), - url(r'^$', 'account.views.landingpage'), + url(r'^$', 'account.views.landingpage', name="landingpage"), )