From 21530b978a43fa7e73125a07dbc0a85d0b6e6a0f Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Wed, 5 Nov 2014 15:22:50 +0000 Subject: [PATCH] Added organisation things. Need to do the form. Committing to push and pull onto server with access to legacy database. --- RIGS/importer.py | 26 ++++--- RIGS/templates/RIGS/organisation_detail.html | 55 ++++++++++++++ RIGS/templates/RIGS/organisation_form.html | 53 ++++++++++++++ RIGS/templates/RIGS/organisation_list.html | 71 +++++++++++++++++++ RIGS/urls.py | 20 +++++- RIGS/views.py | 34 +++++++++ db.sqlite3 | Bin 698368 -> 698368 bytes 7 files changed, 246 insertions(+), 13 deletions(-) create mode 100644 RIGS/templates/RIGS/organisation_detail.html create mode 100644 RIGS/templates/RIGS/organisation_form.html create mode 100644 RIGS/templates/RIGS/organisation_list.html diff --git a/RIGS/importer.py b/RIGS/importer.py index b9ff30ac..7a68ef00 100644 --- a/RIGS/importer.py +++ b/RIGS/importer.py @@ -1,7 +1,9 @@ __author__ = 'Ghost' import os + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PyRIGS.settings") import django + django.setup() from django.db import connections @@ -11,6 +13,7 @@ from django.db import transaction from RIGS import models import reversion + def setup_cursor(): try: cursor = connections['legacy'].cursor() @@ -20,6 +23,7 @@ def setup_cursor(): print(connections._databases) return None + def import_people(): cursor = setup_cursor() if cursor is None: @@ -33,10 +37,11 @@ def import_people(): email += "@nottingham.ac.uk" notes = "" - if row[5] != "Normal": + if row[5] != "Normal": notes = row[5] - person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email, address=row[4], notes=notes) + person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email, + address=row[4], notes=notes) if created: print("Created: " + person.__unicode__()) with transaction.atomic(), reversion.create_revision(): @@ -44,6 +49,7 @@ def import_people(): else: print("Found: " + person.__unicode__()) + def import_organisations(): cursor = setup_cursor() if cursor is None: @@ -51,15 +57,13 @@ def import_organisations(): sql = """SELECT `id`, `name`, `phone`, `address`, `union_account`, `status` FROM `organisations`""" cursor.execute(sql) for row in cursor.fetchall(): - unionAccount = False - if row[4] == "1": - unionAccount = True - notes = "" - if row[5] != "Normal": + if row[5] != "Normal": notes = row[5] - object, created = models.Organisation.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], address=row[3], unionAccount=unionAccount, notes=notes) + object, created = models.Organisation.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], + address=row[3], + unionAccount=row[4], notes=notes) if created: print("Created: " + object.__unicode__()) with transaction.atomic(), reversion.create_revision(): @@ -67,9 +71,11 @@ def import_organisations(): else: print("Found: " + object.__unicode__()) + def main(): - #import_people() + # import_people() import_organisations() -if __name__=="__main__": + +if __name__ == "__main__": main() \ No newline at end of file diff --git a/RIGS/templates/RIGS/organisation_detail.html b/RIGS/templates/RIGS/organisation_detail.html new file mode 100644 index 00000000..c5d54ad0 --- /dev/null +++ b/RIGS/templates/RIGS/organisation_detail.html @@ -0,0 +1,55 @@ +{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %} +{% load widget_tweaks %} + +{% block title %}{{ object.name }}{% endblock %} + +{% block content %} +
+ {% if not request.is_ajax %} +

{{ object.name }}

+
+ Edit +
+ {% endif %} +
+
+
+
Name
+
{{ object.name }}
+ +
Phone
+
{{ object.phone }}
+ +
Email
+
{{ object.email }}
+ +
Address
+
{{ object.address|linebreaksbr }}
+ +
Notes
+
{{ object.notes|linebreaksbr }}
+ +
Union Account
+
{{ object.unionAccount|yesno }}
+
+
+
+
+{% endblock %} + +{% if request.is_ajax %} + {% block footer %} +
+
+ Lasted edited at {{ object.last_edited_at|date:"SHORT_DATE_FORMAT" }} by {{ object.last_edited_by }} +
+
+
+ Edit +
+
+
+ {% endblock %} +{% endif %} \ No newline at end of file diff --git a/RIGS/templates/RIGS/organisation_form.html b/RIGS/templates/RIGS/organisation_form.html new file mode 100644 index 00000000..f1161571 --- /dev/null +++ b/RIGS/templates/RIGS/organisation_form.html @@ -0,0 +1,53 @@ +{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %} +{% load widget_tweaks %} + +{% block title %}{% if object.pk %}Edit {{ object.name }}{% else %}Add Person{% endif %}{% endblock %} + +{% block content %} +
+

Add Person

+
+
{% csrf_token %} + {% include 'form_errors.html' %} +
+ +
+ {% render_field form.name class+="form-control" placeholder=form.name.label %} +
+
+ +
+ +
+ {% render_field form.phone class+="form-control" type="tel" placeholder=form.phone.label %} +
+
+ +
+ +
+ {% render_field form.email class+="form-control" type="email" placeholder=form.email.label %} +
+
+ +
+ +
+ {% render_field form.address class+="form-control" placeholder=form.address.label %} +
+
+ +
+ +
+ {% render_field form.notes class+="form-control" placeholder=form.notes.label %} +
+
+ +
+ +
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/RIGS/templates/RIGS/organisation_list.html b/RIGS/templates/RIGS/organisation_list.html new file mode 100644 index 00000000..ca0c26c1 --- /dev/null +++ b/RIGS/templates/RIGS/organisation_list.html @@ -0,0 +1,71 @@ +{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %} +{% load widget_tweaks %} +{% load paginator from filters %} +{% load url_replace from filters %} +{% load orderby from filters %} + +{% block title %}Organisations{% endblock %} + +{% block content %} +
+
+
+

Organisations

+
+
+ New +
+
+
+
+ +
+
+
+
+
{% paginator %}
+
+ + + + + + + + + l + + + + + + {% for object in object_list %} + + + + + + + + + + {% empty %} + + + + + {% endfor %} + +
NameEmailPhoneNotesUnion Account
{{ object.pk }}{{ object.name }}{{ object.email }}{{ object.phone }}{{ object.notes|yesno|capfirst }}{{ object.unionAccount|yesno|capfirst }} + + + + +
No people stored
+
+
{% paginator %}
+
+{% endblock %} \ No newline at end of file diff --git a/RIGS/urls.py b/RIGS/urls.py index 4cc829e4..0350888e 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -15,14 +15,28 @@ urlpatterns = patterns('', # People url(r'^people/$', permission_required_with_403('RIGS.view_person')(views.PersonIndex.as_view()), name='person_list'), - url(r'^people/(?P\d+)/$', - permission_required_with_403('RIGS.view_person')(views.PersonDetail.as_view()), - name='person_detail'), url(r'^people/add/$', permission_required_with_403('RIGS.add_person')(views.PersonCreate.as_view()), name='person_add'), + url(r'^people/(?P\d+)/$', + permission_required_with_403('RIGS.view_person')(views.PersonDetail.as_view()), + name='person_detail'), url(r'^people/(?P\d+)/edit/$', permission_required_with_403('RIGS.change_person')(views.PersonUpdate.as_view()), name='person_update'), + + # Organisations + url(r'^organisations/$', + permission_required_with_403('RIGS.view_organisation')(views.OrganisationIndex.as_view()), + name='organisation_index'), + url(r'^organisations/add/$', + permission_required_with_403('RIGS.add_organisation')(views.OrganisationCreate.as_view()), + name='organisation_create'), + url(r'^organisations/(?P\d+)/$', + permission_required_with_403('RIGS.view_organisation')(views.OrganisationDetail.as_view()), + name='organisation_detail'), + url(r'^organisation/(?P\d+)/edit/$', + permission_required_with_403('RIGS.change_organisation')(views.OrganisationUpdate.as_view()), + name='organisation_update'), ) diff --git a/RIGS/views.py b/RIGS/views.py index 2cf03ef0..9d061625 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -58,4 +58,38 @@ class PersonUpdate(generic.UpdateView): def get_success_url(self): return reverse_lazy('person_detail', kwargs={ 'pk': self.object.pk, + }) + +class OrganisationIndex(generic.ListView): + model = models.Organisation + paginate_by = 20 + + def get_queryset(self): + q = self.request.GET.get('q', "") + if len(q) >= 3: + object_list = self.model.objects.filter(Q(name__icontains=q) | Q(address__icontains=q)) + else: + object_list = self.model.objects.all() + orderBy = self.request.GET.get('orderBy', "") + if orderBy is not "": + object_list = object_list.order_by(orderBy) + return object_list + +class OrganisationDetail(generic.DetailView): + model = models.Organisation + +class OrganisationCreate(generic.CreateView): + model = models.Organisation + + def get_success_url(self): + return reverse_lazy('organisation_detail', kwargs={ + 'pk': self.object.pk, + }) + +class OrganisationUpdate(generic.UpdateView): + model = models.Organisation + + def get_success_url(self): + return reverse_lazy('organisation_detail', kwargs={ + 'pk': self.object.pk, }) \ No newline at end of file diff --git a/db.s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