diff --git a/RIGS/models.py b/RIGS/models.py index 75e641ec..31ab3e86 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -9,6 +9,7 @@ from django.utils.encoding import python_2_unicode_compatible import reversion import string import random +from collections import Counter from django.core.urlresolvers import reverse_lazy from django.core.exceptions import ValidationError @@ -92,9 +93,13 @@ class Person(models.Model, RevisionMixin): def organisations(self): o = [] for e in Event.objects.filter(person=self).select_related('organisation'): - if e.organisation and e.organisation not in o: + if e.organisation: o.append(e.organisation) - return o + + #Count up occurances and put them in descending order + c = Counter(o) + stats = c.most_common() + return stats @property def latest_events(self): @@ -132,9 +137,13 @@ class Organisation(models.Model, RevisionMixin): def persons(self): p = [] for e in Event.objects.filter(organisation=self).select_related('person'): - if e.person and e.person not in p: + if e.person: p.append(e.person) - return p + + #Count up occurances and put them in descending order + c = Counter(p) + stats = c.most_common() + return stats @property def latest_events(self): diff --git a/RIGS/templates/RIGS/organisation_detail.html b/RIGS/templates/RIGS/organisation_detail.html index 098d4a42..7743086c 100644 --- a/RIGS/templates/RIGS/organisation_detail.html +++ b/RIGS/templates/RIGS/organisation_detail.html @@ -1,82 +1,109 @@ {% extends request.is_ajax|yesno:"base_ajax.html,base.html" %} {% load widget_tweaks %} -{% block title %}{{ object.name }}{% endblock %} +{% block title %}Organisation | {{ object.name }}{% endblock %} {% block content %} - {% if not request.is_ajax %} -
-
-

{{ object.name }}
- - Last edited at {{ object.last_edited_at|date:"d/m/Y H:i" }} by {{ object.last_edited_by.name }} - -

-
-
- Edit -
-
-
-
- {% endif %}
+ {% if not request.is_ajax %} +
+

Organisation | {{ object.name }}

+
+ +
+
+ Edit +
+
+ {% endif %}
-

Details

-
-
Name
-
{{ object.name }}
+
+
Organisation Details
+
+
+
Name
+
{{ object.name }}
-
Phone
-
{{ object.phone }}
+
Phone
+
{{ object.phone }}
-
Email
-
{{ object.email }}
+
Email
+
{{ object.email }}
-
Address
-
{{ object.address|linebreaksbr }}
+
Address
+
{{ object.address|linebreaksbr }}
-
Notes
-
{{ object.notes|linebreaksbr }}
+
Notes
+
{{ object.notes|linebreaksbr }}
-
Union Account
-
{{ object.union_account|yesno|capfirst }}
-
+
Union Account
+
{{ object.union_account|yesno|capfirst }}
+
+
+
-

People

- +
+
Associated People
+
+
+ {% for person,count in object.persons %} + {{ person.pk|stringformat:"05d" }} | {{ person.name }} {{count}} + {% endfor %} +
+
+
-

Events

- {% with object.latest_events as events %} - {% include 'RIGS/event_table.html' %} - {% endwith %} +
+
Associated Events
+
+ {% with object.latest_events as events %} + {% include 'RIGS/event_table.html' %} + {% endwith %} +
+
+ + + {% if not request.is_ajax %} +
+
+
+ Edit +
+
+ + Last edited {{ object.last_edited_at }} by {{ object.last_edited_by.name }} + +
+
+
+ {% endif %} + {% endblock %} {% if request.is_ajax %} {% block footer %}
-
- - Last edited at {{ object.last_edited_at }} by {{ object.last_edited_by.name }} - -
-
- diff --git a/RIGS/templates/RIGS/organisation_form.html b/RIGS/templates/RIGS/organisation_form.html index f0298ffb..7ef77e0d 100644 --- a/RIGS/templates/RIGS/organisation_form.html +++ b/RIGS/templates/RIGS/organisation_form.html @@ -1,7 +1,7 @@ {% 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 title %}{% if object.pk %}Edit {{ object.name }}{% else %}Add Organisation{% endif %}{% endblock %} {% block content %}
diff --git a/RIGS/templates/RIGS/person_detail.html b/RIGS/templates/RIGS/person_detail.html index cd666a7f..10c995ae 100644 --- a/RIGS/templates/RIGS/person_detail.html +++ b/RIGS/templates/RIGS/person_detail.html @@ -1,74 +1,106 @@ {% extends request.is_ajax|yesno:"base_ajax.html,base.html" %} {% load widget_tweaks %} -{% block title %}{{ object.name }}{% endblock %} +{% block title %}Person | {{ object.name }}{% endblock %} {% block content %}
-
-

Details

- {% if not request.is_ajax %} -

{{ object.name }}
- - Last edited at {{ object.last_edited_at|date:"d/m/Y H:i" }} by {{ object.last_edited_by.name }} - -

-
- Edit + {% if not request.is_ajax %} +
+

Person | {{ object.name }}

+
+ +
+ - {% endif %} -
-
-
Name
-
{{ object.name }}
+
+ {% endif %} +
+
+
Person Details
+
+
+
Name
+
{{ object.name }}
-
Phone
-
{{ object.phone }}
+
Phone
+
{{ object.phone }}
-
Email
-
{{ object.email }}
+
Email
+
{{ object.email }}
-
Address
-
{{ object.address|linebreaksbr }}
+
Address
+
{{ object.address|linebreaksbr }}
-
Notes
-
{{ object.notes|linebreaksbr }}
-
+
Notes
+
{{ object.notes|linebreaksbr }}
+ +
+
-

Organisations

- +
+
Associated Organisations
+
+
+ {% for organisation,count in object.organisations %} + {{ organisation.pk|stringformat:"05d" }} | {{ organisation.name }} {{count}} + {% endfor %} +
+
+
-

Events

- {% with object.latest_events as events %} - {% include 'RIGS/event_table.html' %} - {% endwith %} +
+
Associated Events
+
+ {% with object.latest_events as events %} + {% include 'RIGS/event_table.html' %} + {% endwith %} +
+
+ + + {% if not request.is_ajax %} + + {% endif %} + {% endblock %} {% if request.is_ajax %} {% block footer %}
- -
- diff --git a/RIGS/templates/RIGS/venue_detail.html b/RIGS/templates/RIGS/venue_detail.html index a2fd4c7f..ede9d4ec 100644 --- a/RIGS/templates/RIGS/venue_detail.html +++ b/RIGS/templates/RIGS/venue_detail.html @@ -1,64 +1,96 @@ {% extends request.is_ajax|yesno:"base_ajax.html,base.html" %} {% load widget_tweaks %} -{% block title %}{{ object.name }}{% endblock %} +{% block title %}Venue | {{ object.name }}{% endblock %} {% block content %}
-
- {% if not request.is_ajax %} -

{{ object.name }}
- - Last edited at {{ object.last_edited_at|date:"d/m/Y H:i" }} by {{ object.last_edited_by.name }} - -

-
- Edit + {% if not request.is_ajax %} +
+

Venue | {{ object.name }}

+
+ +
+ - {% endif %} -
-
-
Name
-
{{ object.name }}
+
+ {% endif %} +
+
+
Venue Details
+
+
+
Name
+
{{ object.name }}
-
Phone
-
{{ object.phone }}
+
Phone
+
{{ object.phone }}
-
Email
-
{{ object.email }}
+
Email
+
{{ object.email }}
-
Address
-
{{ object.address|linebreaksbr }}
+
Address
+
{{ object.address|linebreaksbr }}
-
Notes
-
{{ object.notes|linebreaksbr }}
-
+
Notes
+
{{ object.notes|linebreaksbr }}
+ +
Three Phase Available
+
{{ object.three_phase_available|yesno|capfirst }}
+ +
- {% with object.latest_events as events %} - {% include 'RIGS/event_table.html' %} - {% endwith %} +
+
Associated Events
+
+ {% with object.latest_events as events %} + {% include 'RIGS/event_table.html' %} + {% endwith %} +
+
+ + {% if not request.is_ajax %} + + {% endif %} + {% endblock %} + {% if request.is_ajax %} {% block footer %}
- -
- diff --git a/RIGS/templates/RIGS/venue_form.html b/RIGS/templates/RIGS/venue_form.html index 8d058502..4d99af7e 100644 --- a/RIGS/templates/RIGS/venue_form.html +++ b/RIGS/templates/RIGS/venue_form.html @@ -58,7 +58,21 @@ {% render_field form.notes class+="form-control" placeholder=form.notes.label %}
+ + +
+
+
+ +
+
+
+
+ +
diff --git a/RIGS/test_models.py b/RIGS/test_models.py index 5f94f9e3..91923ca1 100644 --- a/RIGS/test_models.py +++ b/RIGS/test_models.py @@ -144,16 +144,16 @@ class EventTestCase(TestCase): events = models.Event.objects.all() # Check person's organisations - self.assertIn(o1, p1.organisations) - self.assertIn(o2, p1.organisations) - self.assertIn(o1, p2.organisations) - self.assertNotIn(o2, p2.organisations) + self.assertIn((o1,2), p1.organisations) + self.assertIn((o2,1), p1.organisations) + self.assertIn((o1,2), p2.organisations) + self.assertEqual(len(p2.organisations), 1) # Check organisation's persons - self.assertIn(p1, o1.persons) - self.assertIn(p2, o1.persons) - self.assertIn(p1, o2.persons) - self.assertNotIn(p2, o2.persons) + self.assertIn((p1,2), o1.persons) + self.assertIn((p2,2), o1.persons) + self.assertIn((p1,1), o2.persons) + self.assertEqual(len(o2.persons),1) def test_cancelled_property(self): event = models.Event.objects.all()[0] diff --git a/RIGS/views.py b/RIGS/views.py index 0894d800..772d92a7 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -176,7 +176,7 @@ class VenueDetail(generic.DetailView): class VenueCreate(generic.CreateView): model = models.Venue - fields = ['name','phone','email','address','notes'] + fields = ['name','phone','email','address','notes','three_phase_available'] def get_success_url(self): if self.request.is_ajax(): @@ -193,7 +193,7 @@ class VenueCreate(generic.CreateView): class VenueUpdate(generic.UpdateView): model = models.Venue - fields = ['name','phone','email','address','notes'] + fields = ['name','phone','email','address','notes','three_phase_available'] def get_success_url(self): if self.request.is_ajax():