From 6a4620b4d1a8832fbfd303a198eb434c80b3db7a Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Thu, 2 Feb 2012 05:47:43 +0100 Subject: [PATCH] UI --- README | 3 +++ main/forms.py | 23 ++++++++++++++------- main/pdf.py | 3 +++ main/templates/private/list.html | 12 +++++++++++ main/templates/private/new.html | 8 +++++-- main/templates/private/system.html | 5 +++-- main/templates/public/index.html | 5 +++-- main/templates/registration/login_form.html | 4 ++-- main/urls.py | 3 ++- main/views.py | 17 ++++++++++++++- 10 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 README create mode 100644 main/templates/private/list.html diff --git a/README b/README new file mode 100644 index 0000000..1d2f981 --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +Requirements: +============= +sudo pip install reportlab pisa html5lib pypdf pil diff --git a/main/forms.py b/main/forms.py index d6ff21a..39faef0 100644 --- a/main/forms.py +++ b/main/forms.py @@ -1,8 +1,17 @@ -from django.forms import ModelForm +from django import forms -from main.models import * - -class TempUserForm(ModelForm): - # TODO : Move this to radius? - class Meta: - model = TempUser +#from radius.models import * +# +#class TempUserForm(forms.ModelForm): +# # TODO : Move this to radius? +# class Meta: +# model = TempUser +class TempUserForm(forms.Form): + who = forms.CharField(label='Hvem') + RANGE_CHOICES = ( + ('1 day', '1 dag'), + ('2 days', '2 dager'), + ('7 days', '1 uke (7 dager)'), + ) + duration = forms.ChoiceField(label='Varighet', choices=RANGE_CHOICES) + why = forms.CharField(label='Hvorfor') diff --git a/main/pdf.py b/main/pdf.py index fe72a06..ca00580 100644 --- a/main/pdf.py +++ b/main/pdf.py @@ -4,6 +4,7 @@ # - http://stackoverflow.com/questions/1377446/html-to-pdf-for-a-django-site # - http://stackoverflow.com/questions/2179958/django-pisa-adding-images-to-pdf-output ? +import uuid import cStringIO as StringIO import ho.pisa as pisa from django.template.loader import get_template @@ -22,3 +23,5 @@ def render_to_pdf(template_src, context_dict): return HttpResponse(result.getvalue(), mimetype='application/pdf') return HttpResponse('We had some errors
%s
' % escape(html)) +def unique_filename(): + return uuid.uuid4() diff --git a/main/templates/private/list.html b/main/templates/private/list.html new file mode 100644 index 0000000..e9fbd01 --- /dev/null +++ b/main/templates/private/list.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block content %} +

Liste over midlertidige brukere

+

+Tabell her:
+{{ table }} +Vis utgåtte ... +

+« Tilbake + +{% endblock %} diff --git a/main/templates/private/new.html b/main/templates/private/new.html index 3ee331d..6c32067 100644 --- a/main/templates/private/new.html +++ b/main/templates/private/new.html @@ -5,7 +5,11 @@

OK, du skal få lage en, men først...

-{{ form }} -Avbryt +
+ {% csrf_token %} + {{ form.as_p }} + + Avbryt +
{% endblock %} diff --git a/main/templates/private/system.html b/main/templates/private/system.html index 8609954..ed118bb 100644 --- a/main/templates/private/system.html +++ b/main/templates/private/system.html @@ -2,7 +2,8 @@ {% block content %} -Lag ny midlertidig bruker -Logg ut +Lag ny midlertidig bruker +Vis midlertidige +Logg ut {% endblock %} diff --git a/main/templates/public/index.html b/main/templates/public/index.html index baece00..cc3752b 100644 --- a/main/templates/public/index.html +++ b/main/templates/public/index.html @@ -2,6 +2,7 @@ {% block content %} MBFTNS kan lage Midlertidige Brukere For Trådløst Nettverk på Chateau Neuf. - - {% include "registration/login_form.html" %} +

+ {% include "registration/login_form.html" %} +

{% endblock %} diff --git a/main/templates/registration/login_form.html b/main/templates/registration/login_form.html index a811da4..323922c 100644 --- a/main/templates/registration/login_form.html +++ b/main/templates/registration/login_form.html @@ -1,4 +1,4 @@ -
+ {% if form.non_field_errors %} {{ form.non_field_errors }}
{% endif %} @@ -9,6 +9,6 @@
{{ form.password }} {{ form.password.errors }}

- +
diff --git a/main/urls.py b/main/urls.py index 56854fc..75d4f5e 100644 --- a/main/urls.py +++ b/main/urls.py @@ -1,6 +1,7 @@ from django.conf.urls.defaults import patterns, include, url urlpatterns = patterns('main.views', - url(r'^new/', 'new'), url(r'^system/', 'system'), + url(r'^new/', 'new'), + url(r'^list/', 'list_users'), ) diff --git a/main/views.py b/main/views.py index 1dd9113..f507667 100644 --- a/main/views.py +++ b/main/views.py @@ -12,8 +12,9 @@ from django.template import RequestContext from django.views.decorators.csrf import csrf_protect from models import * +from forms import * -from pdf import render_to_pdf +from pdf import render_to_pdf, unique_filename def index(request): if request.method == "POST": @@ -31,8 +32,22 @@ def index(request): @login_required def new(request): + if request.method == "POST": + form = TempUserForm(data=request.POST) + if form.is_valid(): + # generate and save the filename for the new pdf + fn = unique_filename() + download_pdf() + + form = TempUserForm() + return render_to_response('private/new.html', locals(), context_instance=RequestContext(request)) +@login_required +def list_users(request): + # generic view? + return render_to_response('private/list.html', locals(), context_instance=RequestContext(request)) + @login_required def system(request): return render_to_response('private/system.html', locals(), context_instance=RequestContext(request))