Пример #1
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context["object_type"] = self.model._meta.verbose_name
     obj = self.get_object()
     context["title"] = "DELETE {}".format(obj._meta.object_name.upper())
     context["page_title"] = " | ".join([
         settings.APPLICATION_ACRONYM,
         "Delete {}".format(self.get_object().__str__()),
     ])
     context[
         "page_heading"] = "DELETE " + self.model._meta.verbose_name.upper(
         )
     # Create a breadcrumb trail: Home[URL] > Model[URL] > ID > History
     context["breadcrumb_trail"] = breadcrumbs_li([
         (reverse("site_home"), "Home"),
         (
             reverse(
                 "prs_object_list",
                 kwargs={"model": self.model._meta.object_name.lower()},
             ),
             self.model._meta.verbose_name_plural.capitalize(),
         ),
         (obj.get_absolute_url(), str(obj.pk)),
         (None, "Delete"),
     ])
     # If the object is a 'child' of a referral, set the referral's
     # absolute_url as the redirect URL
     if hasattr(obj, "referral"):
         context["next_redirect"] = obj.referral.get_absolute_url()
     return context
Пример #2
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     obj = self.get_object()
     context["title"] = "CHANGE HISTORY: {}".format(obj)
     context["page_title"] = " | ".join([
         settings.APPLICATION_ACRONYM,
         self.get_object().__str__(), "History"
     ])
     context["page_heading"] = (self.model._meta.verbose_name.upper() +
                                " CHANGE HISTORY")
     # Create a breadcrumb trail: Home[URL] > Model[URL] > ID > History
     context["breadcrumb_trail"] = breadcrumbs_li([
         (reverse("site_home"), "Home"),
         (
             reverse(
                 "prs_object_list",
                 kwargs={"model": self.model._meta.object_name.lower()},
             ),
             self.model._meta.verbose_name_plural.capitalize(),
         ),
         (obj.get_absolute_url(), str(obj.pk)),
         (None, "History"),
     ])
     # Get all object versions
     versions = Version.objects.get_for_object(obj).order_by("-id")
     context["obj_versions"] = [(v._object_version, v.revision)
                                for v in versions]
     context["multi_versions"] = len(versions) > 1  # True/False
     return context
Пример #3
0
 def get_context_data(self, **kwargs):
     context = super(ReportView, self).get_context_data(**kwargs)
     context['page_title'] = ' | '.join([settings.APPLICATION_ACRONYM, 'Reports'])
     links = [(reverse('site_home'), 'Home'), (None, 'Reports')]
     context['breadcrumb_trail'] = breadcrumbs_li(links)
     context['no_sidebar'] = True
     context['is_prs_user'] = prs_user(self.request)
     return context
Пример #4
0
 def get_context_data(self, **kwargs):
     context = super(ReportView, self).get_context_data(**kwargs)
     context['page_title'] = ' | '.join(
         [settings.APPLICATION_ACRONYM, 'Reports'])
     links = [(reverse('site_home'), 'Home'), (None, 'Reports')]
     context['breadcrumb_trail'] = breadcrumbs_li(links)
     context['no_sidebar'] = True
     context['is_prs_user'] = prs_user(self.request)
     return context
Пример #5
0
 def test_html_breadcrumbs(self):
     """Test the breadcrumbs_li utility function
     """
     pairs = [('/A', 'A'), ('/A/B', 'B'), (
         '',
         'C',
     )]
     crumbs = breadcrumbs_li(pairs)
     self.assertTrue(isinstance(crumbs, str))
Пример #6
0
 def get_context_data(self, **kwargs):
     context = super(PrsObjectList, self).get_context_data(**kwargs)
     # Pass model headers.
     if hasattr(self.model, 'headers'):
         context['object_list_headers'] = self.model.headers
     # Pass in any query string
     if ('q' in self.request.GET):
         context['query_string'] = self.request.GET['q']
     title = self.model._meta.verbose_name_plural.capitalize()
     object_type_plural = self.model._meta.verbose_name_plural
     context['object_type_plural'] = object_type_plural
     context['page_title'] = ' | '.join([settings.APPLICATION_ACRONYM, title])
     links = [(reverse('site_home'), 'Home'), (None, title)]
     context['breadcrumb_trail'] = breadcrumbs_li(links)
     return context
Пример #7
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     # Pass model headers.
     if hasattr(self.model, "headers"):
         context["object_list_headers"] = self.model.headers
     # Pass in any query string
     if "q" in self.request.GET:
         context["query_string"] = self.request.GET["q"]
     title = self.model._meta.verbose_name_plural.capitalize()
     object_type_plural = self.model._meta.verbose_name_plural
     context["object_type_plural"] = object_type_plural
     context["page_title"] = " | ".join(
         [settings.APPLICATION_ACRONYM, title])
     links = [(reverse("site_home"), "Home"), (None, title)]
     context["breadcrumb_trail"] = breadcrumbs_li(links)
     return context
Пример #8
0
 def get_context_data(self, **kwargs):
     # Standard view context data.
     context = super(PrsObjectCreate, self).get_context_data(**kwargs)
     m = self.model._meta
     model_type = m.verbose_name.capitalize()
     context['model_type'] = model_type
     context['title'] = 'CREATE {}'.format(self.model._meta.object_name.upper())
     context['page_title'] = ' | '.join([
         settings.APPLICATION_ACRONYM, 'Create ' + model_type])
     context['page_heading'] = 'CREATE ' + model_type.upper()
     model_list_url = reverse(
         'prs_object_list',
         kwargs={'model': self.model._meta.verbose_name_plural.replace(' ', '-')})
     context['breadcrumb_trail'] = breadcrumbs_li([
         (reverse('site_home'), 'Home'),
         (model_list_url, m.verbose_name_plural.capitalize()),
         (None, 'Create')])
     return context
Пример #9
0
 def get_context_data(self, **kwargs):
     context = super(PrsObjectUpdate, self).get_context_data(**kwargs)
     obj = self.get_object()
     context['title'] = 'UPDATE {}'.format(obj._meta.object_name).upper()
     context['page_title'] = 'PRS | {} | {} | Update'.format(
         obj._meta.verbose_name_plural.capitalize(),
         obj.pk)
     context['page_heading'] = 'UPDATE ' + obj._meta.verbose_name.upper()
     # Create a breadcrumb trail: Home[URL] > Model[URL] > ID > History
     context['breadcrumb_trail'] = breadcrumbs_li([
         (reverse('site_home'), 'Home'),
         (reverse(
             'prs_object_list',
             kwargs={'model': obj._meta.object_name.lower()}),
             obj._meta.verbose_name_plural.capitalize()),
         (obj.get_absolute_url(), str(obj.pk)),
         (None, 'Update')])
     # If the model type uses tags, pass in a serialised list of tag names.
     if hasattr(self.model, 'tags'):
         context['tags'] = json.dumps([t.name for t in Tag.objects.all()])
     return context
Пример #10
0
 def get_context_data(self, **kwargs):
     context = super(PrsObjectHistory, self).get_context_data(**kwargs)
     obj = self.get_object()
     context['title'] = 'CHANGE HISTORY: {}'.format(obj)
     context['page_title'] = ' | '.join([
         settings.APPLICATION_ACRONYM, self.get_object().__unicode__(),
         'History'])
     context['page_heading'] = self.model._meta.verbose_name.upper() + ' CHANGE HISTORY'
     # Create a breadcrumb trail: Home[URL] > Model[URL] > ID > History
     context['breadcrumb_trail'] = breadcrumbs_li([
         (reverse('site_home'), 'Home'),
         (reverse(
             'prs_object_list',
             kwargs={'model': self.model._meta.object_name.lower()}),
             self.model._meta.verbose_name_plural.capitalize()),
         (obj.get_absolute_url(), str(obj.pk)),
         (None, 'History')])
     # Get all object versions
     versions = Version.objects.get_for_object(obj).order_by('-id')
     context['obj_versions'] = versions
     context['multi_versions'] = len(versions) > 1  # True/False
     return context
Пример #11
0
 def get_context_data(self, **kwargs):
     context = super(PrsObjectDelete, self).get_context_data(**kwargs)
     context['object_type'] = self.model._meta.verbose_name
     obj = self.get_object()
     context['title'] = 'DELETE {}'.format(obj._meta.object_name.upper())
     context['page_title'] = ' | '.join([
         settings.APPLICATION_ACRONYM,
         'Delete {}'.format(self.get_object().__unicode__())])
     context['page_heading'] = 'DELETE ' + self.model._meta.verbose_name.upper()
     # Create a breadcrumb trail: Home[URL] > Model[URL] > ID > History
     context['breadcrumb_trail'] = breadcrumbs_li([
         (reverse('site_home'), 'Home'),
         (reverse(
             'prs_object_list',
             kwargs={'model': self.model._meta.object_name.lower()}),
             self.model._meta.verbose_name_plural.capitalize()),
         (obj.get_absolute_url(), str(obj.pk)),
         (None, 'Delete')])
     # If the object is a 'child' of a referral, set the referral's
     # absolute_url as the redirect URL
     if hasattr(obj, 'referral'):
         context['next_redirect'] = obj.referral.get_absolute_url()
     return context
Пример #12
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     obj = self.get_object()
     context["title"] = "UPDATE {}".format(obj._meta.object_name).upper()
     context["page_title"] = "PRS | {} | {} | Update".format(
         obj._meta.verbose_name_plural.capitalize(), obj.pk)
     context["page_heading"] = "UPDATE " + obj._meta.verbose_name.upper()
     # Create a breadcrumb trail: Home[URL] > Model[URL] > ID > History
     context["breadcrumb_trail"] = breadcrumbs_li([
         (reverse("site_home"), "Home"),
         (
             reverse(
                 "prs_object_list",
                 kwargs={"model": obj._meta.object_name.lower()},
             ),
             obj._meta.verbose_name_plural.capitalize(),
         ),
         (obj.get_absolute_url(), str(obj.pk)),
         (None, "Update"),
     ])
     # If the model type uses tags, pass in a serialised list of tag names.
     if hasattr(self.model, "tags"):
         context["tags"] = json.dumps([t.name for t in Tag.objects.all()])
     return context
Пример #13
0
 def get_context_data(self, **kwargs):
     # Standard view context data.
     context = super().get_context_data(**kwargs)
     m = self.model._meta
     model_type = m.verbose_name.capitalize()
     context["model_type"] = model_type
     context["title"] = "CREATE {}".format(
         self.model._meta.object_name.upper())
     context["page_title"] = " | ".join(
         [settings.APPLICATION_ACRONYM, "Create " + model_type])
     context["page_heading"] = "CREATE " + model_type.upper()
     model_list_url = reverse(
         "prs_object_list",
         kwargs={
             "model":
             self.model._meta.verbose_name_plural.replace(" ", "-")
         },
     )
     context["breadcrumb_trail"] = breadcrumbs_li([
         (reverse("site_home"), "Home"),
         (model_list_url, m.verbose_name_plural.capitalize()),
         (None, "Create"),
     ])
     return context
Пример #14
0
    def get_context_data(self, **kwargs):
        from referral.models import Task, Record, Note, Location

        context = super().get_context_data(**kwargs)
        context["object_type"] = self.model._meta.verbose_name
        context["object_type_plural"] = self.model._meta.verbose_name_plural
        # Does this model type have a tools template?
        if hasattr(self.model, "tools_template"):
            context["object_tools_template"] = self.model.tools_template
        # Does this model type use tags?
        if hasattr(self.model, "tags"):
            context["object_has_tags"] = True
        obj = self.get_object()
        context["page_title"] = " | ".join([
            settings.APPLICATION_ACRONYM,
            self.model._meta.verbose_name_plural.capitalize(),
            str(obj.pk),
        ])
        context["page_heading"] = self.model._meta.verbose_name.upper(
        ) + " DETAILS"
        # Create a breadcrumb trail: Home[URL] > Model[URL] > ID
        context["breadcrumb_trail"] = breadcrumbs_li([
            (reverse("site_home"), "Home"),
            (
                reverse(
                    "prs_object_list",
                    kwargs={"model": self.model._meta.object_name.lower()},
                ),
                self.model._meta.verbose_name_plural.capitalize(),
            ),
            (None, obj.pk),
        ])
        # Related model table headers.
        context["note_headers"] = Note.headers
        context["record_headers"] = Record.headers
        context["task_headers"] = Task.headers
        # Additional context for specific model types.
        if self.model == Task:
            if obj.records.current():  # Related records.
                context["related_records"] = obj.records.current().order_by(
                    F("order_date").desc(nulls_last=True))
            if obj.notes.current():  # Related records.
                context["related_notes"] = obj.notes.current()
            context[
                "task_stopped"] = True if obj.state.name == "Stopped" else False
            context["can_complete"] = True
            if not obj.referral.has_proposed_condition:
                context[
                    "can_complete_msg"] = """You are unable to complete this task
                as 'Response with advice' without first recording proposed condition(s)
                on the referral."""
                context["can_complete"] = False
            if not obj.referral.has_location:
                context[
                    "can_complete_msg"] = """You are unable to complete this task
                as 'Assess a referral' without first recording at least one location
                on the referral."""
                context["can_complete"] = False
        if self.model == Record:
            if Task.objects.current().filter(records=obj):  # Related tasks.
                context["related_tasks"] = Task.objects.current().filter(
                    records=obj)
            if obj.notes.exists():  # Related notes.
                context["related_notes"] = obj.notes.current()
        if self.model == Note:
            if Task.objects.current().filter(notes=obj):  # Related tasks.
                context["related_tasks"] = Task.objects.current().filter(
                    notes=obj)
            if obj.records.exists():  # Related records.
                context["related_records"] = obj.records.current().order_by(
                    F("order_date").desc(nulls_last=True))
        if self.model == Location:
            # Add child locations serialised as GeoJSON (if geometry exists).
            if obj:
                context["geojson_locations"] = serialize("geojson", [obj],
                                                         geometry_field="poly",
                                                         srid=4283)
        return context
Пример #15
0
 def get_context_data(self, **kwargs):
     from referral.models import Task, Record, Note, Location
     context = super(PrsObjectDetail, self).get_context_data(**kwargs)
     context['object_type'] = self.model._meta.verbose_name
     context['object_type_plural'] = self.model._meta.verbose_name_plural
     # Does this model type have a tools template?
     if hasattr(self.model, 'tools_template'):
         context['object_tools_template'] = self.model.tools_template
     # Does this model type use tags?
     if hasattr(self.model, 'tags'):
         context['object_has_tags'] = True
     obj = self.get_object()
     context['page_title'] = ' | '.join([
         settings.APPLICATION_ACRONYM,
         self.model._meta.verbose_name_plural.capitalize(),
         unicode(obj.pk)])
     context['page_heading'] = self.model._meta.verbose_name.upper() + ' DETAILS'
     # Create a breadcrumb trail: Home[URL] > Model[URL] > ID
     context['breadcrumb_trail'] = breadcrumbs_li([
         (reverse('site_home'), 'Home'),
         (reverse(
             'prs_object_list',
             kwargs={'model': self.model._meta.object_name.lower()}),
             self.model._meta.verbose_name_plural.capitalize()),
         (None, unicode(obj.pk))])
     # Related model table headers.
     context['note_headers'] = Note.headers
     context['record_headers'] = Record.headers
     context['task_headers'] = Task.headers
     # Additional context for specific model types.
     if self.model == Task:
         if obj.records.current():  # Related records.
             context['related_records'] = obj.records.current()
         if obj.notes.current():  # Related records.
             context['related_notes'] = obj.notes.current()
         context['task_stopped'] = True if obj.state.name == 'Stopped' else False
         context['can_complete'] = True
         if not obj.referral.has_proposed_condition:
             context['can_complete_msg'] = '''You are unable to complete this task
             as 'Response with advice' without first recording proposed condition(s)
             on the referral.'''
             context['can_complete'] = False
         if not obj.referral.has_location:
             context['can_complete_msg'] = '''You are unable to complete this task
             as 'Assess a referral' without first recording at least one location
             on the referral.'''
             context['can_complete'] = False
     if self.model == Record:
         if Task.objects.current().filter(records=obj):  # Related tasks.
             context['related_tasks'] = Task.objects.current().filter(records=obj)
         if obj.notes.exists():  # Related notes.
             context['related_notes'] = obj.notes.current()
     if self.model == Note:
         if Task.objects.current().filter(notes=obj):  # Related tasks.
             context['related_tasks'] = Task.objects.current().filter(notes=obj)
         if obj.records.exists():  # Related records.
             context['related_records'] = obj.records.current()
     if self.model == Location:
         # Add child locations serialised as GeoJSON (if geometry exists).
         if obj:
             context['geojson_locations'] = serialize(
                 'geojson', [obj], geometry_field='poly', srid=4283)
     return context
Пример #16
0
 def test_html_breadcrumbs(self):
     """Test the breadcrumbs_li utility function
     """
     l = [('/A', 'A'), ('/A/B', 'B'), ('', 'C',)]
     crumbs = breadcrumbs_li(l)
     self.assertIs(type(crumbs), unicode)