added form and view for changing gastro-PINs

This commit is contained in:
Uwe Kamper 2013-10-23 00:27:31 +02:00
parent e0f53cd529
commit 032bc5acaa
11 changed files with 191 additions and 2 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
*.pyc *.pyc
.idea .idea
local_settings.py local_settings.py
build
*.sqlite3

View file

@ -4,3 +4,5 @@ from django import forms
class LoginForm(forms.Form): class LoginForm(forms.Form):
username = forms.CharField(max_length=255) username = forms.CharField(max_length=255)
password = forms.CharField(max_length=255, widget=forms.PasswordInput) password = forms.CharField(max_length=255, widget=forms.PasswordInput)

21
cbmi/forms.py Normal file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
from django import forms
from django.utils.translation import ugettext as _
class GastroPinField(forms.CharField):
def validate(self, value):
"""
Check if the value is all numeric and 4 - 6 chars long.
"""
match = re.match(r'^\d{4,6}$', value)
if not match:
raise forms.ValidationError(_('PIN must be 4 to 6 digits.'))
class GastroPinForm(forms.Form):
gastropin = GastroPinField()

View file

@ -0,0 +1,57 @@
# Django settings for cbmi project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Brian Wiborg', 'baccenfutter@c-base.org')
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'cbmi.sqlite3',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/home/smile/projects/cbmi/src/static',
)
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
AUTH_LDAP_START_TLS = False

57
cbmi/local_settings.py.uk Normal file
View file

@ -0,0 +1,57 @@
# Django settings for cbmi project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Brian Wiborg', 'baccenfutter@c-base.org')
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'cbmi.sqlite3',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/home/smile/projects/cbmi/src/static',
)
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
AUTH_LDAP_START_TLS = False

View file

@ -199,3 +199,8 @@ LOGGING = {
}, },
} }
} }
try:
from local_settings import *
except ImportError, e:
print 'Unable to load local_settings.py:', e

View file

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block body %}
<div class="container">
<div class="row">
<div class="span12">
<h2>Gastro-Pin</h2>
{% if message %}
<div class="alert alert-success">{{ message }}</div>
{% endif %}
<form action="/gastropin/" method="post">
{{ form.non_field_errors }}
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
{% endblock %}

View file

@ -11,5 +11,6 @@ urlpatterns = patterns('',
url(r'account/', include('account.urls')), url(r'account/', include('account.urls')),
url(r'^groups/(?P<group_name>[^/]+)/', 'cbmi.views.groups_list'), url(r'^groups/(?P<group_name>[^/]+)/', 'cbmi.views.groups_list'),
url(r'^$', 'cbmi.views.landingpage') url(r'^$', 'cbmi.views.landingpage'),
url(r'^gastropin/$', 'cbmi.views.gastropin', name='gastropin'),
) )

View file

@ -1,8 +1,12 @@
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.shortcuts import render
from django.utils.translation import ugettext as _
from forms import GastroPinForm
def landingpage(request): def landingpage(request):
is_ceymaster = is_admin = False is_ceymaster = is_admin = False
if 'ceymaster' in [g.name for g in request.user.groups.all()]: if 'ceymaster' in [g.name for g in request.user.groups.all()]:
@ -25,3 +29,23 @@ def groups_list(request, group_name):
if 'ldap_admins' in [g.name for g in request.user.groups.all()]: if 'ldap_admins' in [g.name for g in request.user.groups.all()]:
is_admin = True is_admin = True
return render_to_response("group_list.html", locals()) return render_to_response("group_list.html", locals())
@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})

0
manage.py Normal file → Executable file
View file

View file

@ -1,4 +1,4 @@
Django==1.4.2 Django==1.4.2
MySQL-python==1.2.4 MySQL-python==1.2.4
django-auth-ldap==1.1.4 django-auth-ldap==1.1.4
django-json-rpc==0.6.1 django-json-rpc==0.6.1