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