From a95dd34bea8fbdec764425aa033519456d72d37b Mon Sep 17 00:00:00 2001 From: Tom Price Date: Thu, 21 May 2015 16:04:12 +0100 Subject: [PATCH 1/8] Working saving of registration data, need this doesn't create the required registration profile though. Might need to find a way to invoke automatically then just append the new user data to the end. --- PyRIGS/urls.py | 3 +-- RIGS/forms.py | 6 +++++- RIGS/views.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index 82d0c209..a4c8e2a3 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -11,8 +11,7 @@ urlpatterns = patterns('', # url(r'^blog/', include('blog.urls')), url(r'^', include('RIGS.urls')), - url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail), - name="registration_register"), + url('^user/register/$', RIGS.views.ProfileRegistrationView.as_view()), url('^user/', include('django.contrib.auth.urls')), url('^user/', include('registration.backends.default.urls')), diff --git a/RIGS/forms.py b/RIGS/forms.py index 8a019409..5b4941ec 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -16,7 +16,11 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): last_name = forms.CharField(required=False, max_length=50) initials = forms.CharField(required=True, max_length=5) phone = forms.CharField(required=False, max_length=13) - captcha = ReCaptchaField() + # captcha = ReCaptchaField() + + class Meta: + model = models.Profile + fields = ('first_name','last_name','initials','phone') def clean_initials(self): """ diff --git a/RIGS/views.py b/RIGS/views.py index 472f20ec..0d00680e 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -9,6 +9,7 @@ from django.core import serializers import simplejson from django.contrib import messages import datetime +from registration.views import RegistrationView from RIGS import models, forms @@ -33,6 +34,17 @@ def login(request, **kwargs): return login(request, authentication_form=forms.LoginForm) +class ProfileRegistrationView(RegistrationView): + form_class = forms.ProfileRegistrationFormUniqueEmail + + def register(self, request, **form): + model = models.Profile() + for (key,value) in form.items(): + setattr(model, key, value) + model.set_password(form['password1']) + model.is_active = False + return model.save() + """ Called from a modal window (e.g. when an item is submitted to an event/invoice). May optionally also include some javascript in a success message to cause a load of From e685fa2f7c849abcee97d8a7fb9e2da45e38b60a Mon Sep 17 00:00:00 2001 From: Tom Price Date: Thu, 21 May 2015 21:45:01 +0100 Subject: [PATCH 2/8] Change adding extra user data to on a signal instead. Not sure if this data is clean or not. --- PyRIGS/urls.py | 4 +++- RIGS/regbackend.py | 13 +++++++++++++ RIGS/views.py | 12 ------------ 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 RIGS/regbackend.py diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index a4c8e2a3..9821ae20 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -4,6 +4,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf import settings from registration.backends.default.views import RegistrationView import RIGS +from RIGS import regbackend urlpatterns = patterns('', # Examples: @@ -11,7 +12,8 @@ urlpatterns = patterns('', # url(r'^blog/', include('blog.urls')), url(r'^', include('RIGS.urls')), - url('^user/register/$', RIGS.views.ProfileRegistrationView.as_view()), + url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail), + name="registration_register"), url('^user/', include('django.contrib.auth.urls')), url('^user/', include('registration.backends.default.urls')), diff --git a/RIGS/regbackend.py b/RIGS/regbackend.py new file mode 100644 index 00000000..90828a39 --- /dev/null +++ b/RIGS/regbackend.py @@ -0,0 +1,13 @@ +from RIGS.models import Profile +from RIGS.forms import ProfileRegistrationFormUniqueEmail + +def user_created(sender, user, request, **kwargs): + form = ProfileRegistrationFormUniqueEmail(request.POST) + user.first_name = form.data['first_name'] + user.last_name = form.data['last_name'] + user.initials = form.data['initials'] + user.phone = form.data['phone'] + user.save() + +from registration.signals import user_registered +user_registered.connect(user_created) \ No newline at end of file diff --git a/RIGS/views.py b/RIGS/views.py index 0d00680e..265e2dd5 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -33,18 +33,6 @@ def login(request, **kwargs): return login(request, authentication_form=forms.LoginForm) - -class ProfileRegistrationView(RegistrationView): - form_class = forms.ProfileRegistrationFormUniqueEmail - - def register(self, request, **form): - model = models.Profile() - for (key,value) in form.items(): - setattr(model, key, value) - model.set_password(form['password1']) - model.is_active = False - return model.save() - """ Called from a modal window (e.g. when an item is submitted to an event/invoice). May optionally also include some javascript in a success message to cause a load of From caf0e6cf454a6d2fe712d1ec2f95d0ee37a463fe Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 22 May 2015 15:20:43 +0100 Subject: [PATCH 3/8] Added invoice paperwork functionality --- RIGS/finance.py | 34 ++++ RIGS/templates/RIGS/event_print.xml | 12 +- RIGS/templates/RIGS/event_print_page.xml | 235 +++++++++++++++-------- RIGS/templates/RIGS/invoice_detail.html | 8 +- RIGS/urls.py | 3 + 5 files changed, 204 insertions(+), 88 deletions(-) diff --git a/RIGS/finance.py b/RIGS/finance.py index 46e4a6eb..a6be584c 100644 --- a/RIGS/finance.py +++ b/RIGS/finance.py @@ -1,10 +1,16 @@ +import cStringIO as StringIO + from django.core.urlresolvers import reverse_lazy from django.db import connection from django.http import Http404, HttpResponseRedirect from django.views import generic +from django.template import RequestContext +from django.template.loader import get_template +from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.contrib import messages import datetime +from z3c.rml import rml2pdf from RIGS import models @@ -33,6 +39,34 @@ class InvoiceIndex(generic.ListView): class InvoiceDetail(generic.DetailView): model = models.Invoice +class InvoicePrint(generic.View): + def get(self, request, pk): + invoice = get_object_or_404(models.Invoice, pk=pk) + object = invoice.event + template = get_template('RIGS/event_print.xml') + copies = ('TEC', 'Client') + context = RequestContext(request, { + 'object': object, + 'fonts': { + 'opensans': { + 'regular': 'RIGS/static/fonts/OPENSANS-REGULAR.TTF', + 'bold': 'RIGS/static/fonts/OPENSANS-BOLD.TTF', + } + }, + 'invoice':invoice, + }) + + rml = template.render(context) + buffer = StringIO.StringIO() + + buffer = rml2pdf.parseString(rml) + + pdfData = buffer.read() + + response = HttpResponse(content_type='application/pdf') + response['Content-Disposition'] = "filename=Invoice %05d | %s.pdf" % (invoice.pk, object.name) + response.write(pdfData) + return response class InvoiceVoid(generic.View): def get(self, *args, **kwargs): diff --git a/RIGS/templates/RIGS/event_print.xml b/RIGS/templates/RIGS/event_print.xml index 03790b13..bf5f798f 100644 --- a/RIGS/templates/RIGS/event_print.xml +++ b/RIGS/templates/RIGS/event_print.xml @@ -22,17 +22,25 @@ + + + + + + + + @@ -91,7 +99,7 @@ - [{{ copy }} Copy] + {% if not invoice %}[{{ copy }} Copy]{% endif %} [Page of ] @@ -101,7 +109,7 @@ - [{{ copy }} Copy] + {% if not invoice %}[{{ copy }} Copy]{% endif %} [Page of ] diff --git a/RIGS/templates/RIGS/event_print_page.xml b/RIGS/templates/RIGS/event_print_page.xml index 7529b113..0668da63 100644 --- a/RIGS/templates/RIGS/event_print_page.xml +++ b/RIGS/templates/RIGS/event_print_page.xml @@ -1,16 +1,59 @@ +{% if invoice %} + + + + + {% endif %} +

N{{ object.pk|stringformat:"05d" }}: '{{ object.name }}'

{{object.start_date|date:"D jS N Y"}} + - -{{ object.description|default_if_none:""|linebreaks }} - + + {{ object.description|default_if_none:""|linebreaks }} + + +{% if invoice %} + + + + INVOICE + + + + Invoice Number + + {{ invoice.pk|stringformat:"05d" }} + + + + Invoice Date + + {{ invoice.invoice_date|date:"d/m/Y" }} + + + + PO Number + + {{ object.purchase_order|default_if_none:"" }}hello + + + + + + +
+ + +{% endif %} + @@ -18,7 +61,15 @@

Hirer

{{ object.person.name }}

{{ object.organisation.name|default_if_none:"" }}

- + {% if invoice %} + + {% if object.organisation.address %} + {{ object.organisation.address|default_if_none:""|linebreaksbr }} + {% elif object.person.address %} + {{ object.person.address|default_if_none:""|linebreaksbr }} + {% endif %} + + {% endif %} {% if object.person.phone %} {{ object.person.phone }} @@ -27,19 +78,29 @@ {% endif %} - {% if object.person.email %} - {{ object.person.email }} - {% elif object.organisation.email %} - {{ object.organisation.email }} + {% if invoice %} + {% if object.organisation.email %} + {{ object.organisation.email }} + {% elif object.person.email %} + {{ object.person.email }} + {% endif %} + {% else %} + {% if object.person.email %} + {{ object.person.email }} + {% elif object.organisation.email %} + {{ object.organisation.email }} + {% endif %} {% endif %}

Venue

{{ object.venue.name }}

+ {% if not invoice %} {{ object.venue.address|default_if_none:""|linebreaks }} + {% endif %} @@ -61,7 +122,7 @@ - {% if object.access_at %} + {% if object.access_at and not invoice%}

Access

@@ -139,9 +200,11 @@ + The full hire fee is payable at least 10 days before the event. + @@ -156,88 +219,90 @@
- - - - - Bookings will - not - be confirmed until payment is received and the contract is signed. - - - - - 24 Hour Emergency Contacts: 07825 065681 or 07825 065678 - - - - - - - -To be signed on booking: - -{% if object.organisation.union_account %} - - - I agree that am authorised to sign this invoice. I agree that I am the President/Treasurer of the hirer, or - that I have provided written permission from either the President or Treasurer of the hirer stating that I can - sign for this invoice. - - - - - I have read, understood and fully accepted the current conditions of hire. I agree to return any dry hire - items to TEC PA & Lighting in the same condition at the end of the hire period. - - - - - - Conditions of hire available on request or on the TEC PA & Lighting website. E&OE - - - - - Please return this form directly to TEC PA & Lighting and not the Students' Union Finance Department. - - - +{% if not invoice %} + + - Account Code - - + + Bookings will + not + be confirmed until payment is received and the contract is signed. + + + + + 24 Hour Emergency Contacts: 07825 065681 or 07825 065678 - -{% else %} - - - I, the hirer, have read, understand and fully accept the current conditions of hire. This document forms a - binding contract between TEC PA & Lighting and the hirer, the aforementioned conditions of hire forming - an integral part of it. - - + + + - - Conditions of hire available on request or on the TEC PA & Lighting website. E&OE - + To be signed on booking: + {% if object.organisation.union_account %} + + + I agree that am authorised to sign this invoice. I agree that I am the President/Treasurer of the hirer, or + that I have provided written permission from either the President or Treasurer of the hirer stating that I can + sign for this invoice. + + + + + I have read, understood and fully accepted the current conditions of hire. I agree to return any dry hire + items to TEC PA & Lighting in the same condition at the end of the hire period. + + + + + + Conditions of hire available on request or on the TEC PA & Lighting website. E&OE + + + + + Please return this form directly to TEC PA & Lighting and not the Students' Union Finance Department. + + + + + Account Code + + + + + + {% else %} + + + I, the hirer, have read, understand and fully accept the current conditions of hire. This document forms a + binding contract between TEC PA & Lighting and the hirer, the aforementioned conditions of hire forming + an integral part of it. + + + + + + Conditions of hire available on request or on the TEC PA & Lighting website. E&OE + + + + {% include "RIGS/event_print_signature.xml" %} + + + To be signed on the day of the event/hire: + + + + I, the hirer, have received the goods/services as requested and in good order. I agree to return any dry hire + items to TEC PA & Lighting in a similar condition at the end of the hire period. + + + {% endif %} {% include "RIGS/event_print_signature.xml" %} - - - To be signed on the day of the event/hire: - - - - I, the hirer, have received the goods/services as requested and in good order. I agree to return any dry hire - items to TEC PA & Lighting in a similar condition at the end of the hire period. - - -{% endif %} - -{% include "RIGS/event_print_signature.xml" %} - + + {% endif %} \ No newline at end of file diff --git a/RIGS/templates/RIGS/invoice_detail.html b/RIGS/templates/RIGS/invoice_detail.html index 8d7a950c..a3be5320 100644 --- a/RIGS/templates/RIGS/invoice_detail.html +++ b/RIGS/templates/RIGS/invoice_detail.html @@ -10,9 +10,15 @@ diff --git a/RIGS/urls.py b/RIGS/urls.py index cab2532c..012e3e81 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -99,6 +99,9 @@ urlpatterns = patterns('', url(r'^invoice/(?P\d+)/$', permission_required_with_403('RIGS.view_invoice')(finance.InvoiceDetail.as_view()), name='invoice_detail'), + url(r'^invoice/(?P\d+)/print/$', + permission_required_with_403('RIGS.view_invoice')(finance.InvoicePrint.as_view()), + name='invoice_print'), url(r'^invoice/(?P\d+)/void/$', permission_required_with_403('RIGS.change_invoice')(finance.InvoiceVoid.as_view()), name='invoice_void'), From 5898fa75ff4655c4305e4e26f1c1af3a40afc8e1 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 22 May 2015 15:44:48 +0100 Subject: [PATCH 4/8] Fixed impending fail --- RIGS/templates/RIGS/event_print_page.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RIGS/templates/RIGS/event_print_page.xml b/RIGS/templates/RIGS/event_print_page.xml index 0668da63..d6e5ec24 100644 --- a/RIGS/templates/RIGS/event_print_page.xml +++ b/RIGS/templates/RIGS/event_print_page.xml @@ -42,7 +42,7 @@ PO Number - {{ object.purchase_order|default_if_none:"" }}hello + {{ object.purchase_order|default_if_none:"" }} From fe0dcb65f101816242a5101a8231cd54f1502881 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 22 May 2015 17:02:06 +0100 Subject: [PATCH 5/8] Removed payment terms from invoice --- RIGS/templates/RIGS/event_print_page.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/RIGS/templates/RIGS/event_print_page.xml b/RIGS/templates/RIGS/event_print_page.xml index d6e5ec24..016456ff 100644 --- a/RIGS/templates/RIGS/event_print_page.xml +++ b/RIGS/templates/RIGS/event_print_page.xml @@ -194,7 +194,7 @@ £ {{ object.sum_total|floatformat:2 }} - VAT Registration Number: 116252989 + {% if not invoice %}VAT Registration Number: 116252989{% endif %} VAT @ {{ object.vat_rate.as_percent|floatformat:2 }}% £ {{ object.vat|floatformat:2 }} @@ -202,7 +202,11 @@ - The full hire fee is payable at least 10 days before the event. + {% if invoice %} + VAT Registration Number: 116252989 + {% else %} + The full hire fee is payable at least 10 days before the event. + {% endif %} From 7e582c5f60606b12a15ce2ba4d909473e590458a Mon Sep 17 00:00:00 2001 From: Nathan Penney Date: Sun, 24 May 2015 10:15:18 +0000 Subject: [PATCH 6/8] README.md edited online with Bitbucket --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 866fa8ee..d3df89b8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # TEC PA & Lighting - PyRIGS # -Welcome to TEC PA & Lightings PyRIGS program. This is a reiplmentation of the exisiting Rig Information Gathering System (RIGS) that was developed using Ruby on Rails. +Welcome to TEC PA & Lightings PyRIGS program. This is a reimplementation of the existing Rig Information Gathering System (RIGS) that was developed using Ruby on Rails. The purpose of this project is to make the system more compatible and easier to understand such that should future changes be needed they can be made without having to understand the intricacies of Rails. @@ -16,7 +16,7 @@ Most of the documents here assume a basic knowledge of how Python and Django wor ### Editing ### It is recommended that you use the PyCharm IDE by JetBrains. Whilst other editors are available, this is the best for integration with Django as it can automatically manage all the pesky admin commands that frequently need running, as well as nice integration with git. -For the more experienced developer/somebody who doesn't want a full IDE and wants it to open in less than the age of the universe, I can strongly recommend [Sublime Text](http://www.sublimetext.com/). It has a bit of a steaper learning curve, and won't manage anything Django/git related out of the box, but once you get the hang of it is by far the fastest and most powerful editor I have used (for any type of project). +For the more experienced developer/somebody who doesn't want a full IDE and wants it to open in less than the age of the universe, I can strongly recommend [Sublime Text](http://www.sublimetext.com/). It has a bit of a steeper learning curve, and won't manage anything Django/git related out of the box, but once you get the hang of it is by far the fastest and most powerful editor I have used (for any type of project). Please contact TJP for details on how to acquire these. From 1c95f7ef8b3693fa98b6ea74594646d48957db2b Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sun, 24 May 2015 12:09:20 +0100 Subject: [PATCH 7/8] Fixed linebreaks in paperwork descriptions --- RIGS/templates/RIGS/event_print_page.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RIGS/templates/RIGS/event_print_page.xml b/RIGS/templates/RIGS/event_print_page.xml index 016456ff..1559818c 100644 --- a/RIGS/templates/RIGS/event_print_page.xml +++ b/RIGS/templates/RIGS/event_print_page.xml @@ -16,7 +16,7 @@ - {{ object.description|default_if_none:""|linebreaks }} + {{ object.description|default_if_none:""|linebreaksbr }} @@ -98,7 +98,7 @@

{{ object.venue.name }}

{% if not invoice %} - {{ object.venue.address|default_if_none:""|linebreaks }} + {{ object.venue.address|default_if_none:""|linebreaksbr }} {% endif %} @@ -174,7 +174,7 @@ {% if item.description %} - {{ item.description|linebreaks }} + {{ item.description|linebreaksbr }} {% endif %} From 06f9bf6eecef4d1c6f55086f835642afe499e834 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sun, 24 May 2015 12:14:43 +0100 Subject: [PATCH 8/8] Uncommented captcha --- RIGS/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RIGS/forms.py b/RIGS/forms.py index 5b4941ec..98ccb9c6 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -16,7 +16,7 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): last_name = forms.CharField(required=False, max_length=50) initials = forms.CharField(required=True, max_length=5) phone = forms.CharField(required=False, max_length=13) - # captcha = ReCaptchaField() + captcha = ReCaptchaField() class Meta: model = models.Profile