Also apply better approach to generic detail pages

This commit is contained in:
2020-10-08 23:15:55 +01:00
parent 3903481b3d
commit 5d56f4f7b0
11 changed files with 71 additions and 34 deletions

View File

@@ -155,7 +155,7 @@ class GenericListView(generic.ListView):
paginate_by = 20 paginate_by = 20
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(generic.ListView, self).get_context_data(**kwargs) context = super(GenericListView, self).get_context_data(**kwargs)
context['page_title'] = self.model.__name__ + "s" context['page_title'] = self.model.__name__ + "s"
if self.request.is_ajax(): if self.request.is_ajax():
context['override'] = "base_ajax.html" context['override'] = "base_ajax.html"
@@ -183,6 +183,17 @@ class GenericListView(generic.ListView):
return object_list return object_list
class GenericDetailView(generic.DetailView):
template_name = "generic_detail.html"
def get_context_data(self, **kwargs):
context = super(GenericDetailView, self).get_context_data(**kwargs)
context['page_title'] = "{} | {}".format(self.model.__name__, self.object.name)
if self.request.is_ajax():
context['override'] = "base_ajax.html"
return context
class SearchHelp(generic.TemplateView): class SearchHelp(generic.TemplateView):
template_name = 'search_help.html' template_name = 'search_help.html'

View File

@@ -1 +0,0 @@
{% include 'generic_detail.html' with type='Organisation' history_link='organisation_history' detail_link='organisation_detail' update_link='organisation_update' associated='partials/associated_people.html' associated2='partials/associated_events.html' %}

View File

@@ -1 +0,0 @@
{% include 'generic_detail.html' with type='Person' history_link='person_history' detail_link='person_detail' update_link='person_update' associated='partials/associated_organisations.html' associated2='partials/associated_events.html' %}

View File

@@ -1 +0,0 @@
{% include 'generic_detail.html' with type='Venue' history_link='venue_history' detail_link='venue_detail' update_link='venue_update' associated2='partials/associated_events.html' %}

View File

@@ -20,7 +20,7 @@ from RIGS import models, forms
from assets import models as asset_models from assets import models as asset_models
from functools import reduce from functools import reduce
from PyRIGS.views import GenericListView from PyRIGS.views import GenericListView,GenericDetailView
class PersonList(GenericListView): class PersonList(GenericListView):
@@ -35,10 +35,18 @@ class PersonList(GenericListView):
return context return context
class PersonDetail(generic.DetailView): class PersonDetail(GenericDetailView):
template_name = 'person_detail.html'
model = models.Person model = models.Person
def get_context_data(self, **kwargs):
context = super(PersonDetail, self).get_context_data(**kwargs)
context['history_link'] = 'person_history'
context['detail_link'] = 'person_detail'
context['update_link'] = 'person_update'
context['associated'] ='partials/associated_organisations.html'
context['associated2'] ='partials/associated_events.html'
return context
class PersonCreate(generic.CreateView): class PersonCreate(generic.CreateView):
template_name = 'person_form.html' template_name = 'person_form.html'
@@ -87,10 +95,17 @@ class OrganisationList(GenericListView):
context['union_account'] = True context['union_account'] = True
return context return context
class OrganisationDetail(generic.DetailView): class OrganisationDetail(GenericDetailView):
template_name = 'organisation_detail.html'
model = models.Organisation model = models.Organisation
def get_context_data(self, **kwargs):
context = super(OrganisationDetail, self).get_context_data(**kwargs)
context['history_link'] = 'organisation_history'
context['detail_link'] = 'organisation_detail'
context['update_link'] = 'organisation_update'
context['associated'] ='partials/associated_people.html'
context['associated2'] ='partials/associated_events.html'
return context
class OrganisationCreate(generic.CreateView): class OrganisationCreate(generic.CreateView):
template_name = 'organisation_form.html' template_name = 'organisation_form.html'
@@ -139,10 +154,17 @@ class VenueList(GenericListView):
return context return context
class VenueDetail(generic.DetailView): class VenueDetail(GenericDetailView):
template_name = 'venue_detail.html'
model = models.Venue model = models.Venue
def get_context_data(self, **kwargs):
context = super(VenueDetail, self).get_context_data(**kwargs)
context['history_link'] = 'venue_history'
context['detail_link'] = 'venue_detail'
context['update_link'] = 'venue_update'
context['associated2'] = 'partials/associated_events.html'
return context
class VenueCreate(generic.CreateView): class VenueCreate(generic.CreateView):
template_name = 'venue_form.html' template_name = 'venue_form.html'

View File

@@ -1 +0,0 @@
{% include 'generic_detail.html' with type='Supplier' history_link='supplier_history' detail_link='supplier_detail' update_link='supplier_update' associated='partials/associated_assets.html' associated2='' %}

View File

@@ -14,7 +14,7 @@ from django.utils.decorators import method_decorator
from django.views import generic from django.views import generic
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from versioning import versioning from versioning import versioning
from PyRIGS.views import GenericListView from PyRIGS.views import GenericListView, GenericDetailView
@method_decorator(csrf_exempt, name='dispatch') @method_decorator(csrf_exempt, name='dispatch')
@@ -214,6 +214,10 @@ class SupplierList(GenericListView):
context['create'] = 'supplier_create' context['create'] = 'supplier_create'
context['edit'] = 'supplier_update' context['edit'] = 'supplier_update'
context['detail'] = 'supplier_detail' context['detail'] = 'supplier_detail'
if self.request.is_ajax():
context['override'] = "base_ajax.html"
else:
context['override'] = 'base_assets.html'
return context return context
@@ -228,9 +232,21 @@ class SupplierSearch(SupplierList):
return JsonResponse(result, safe=False) return JsonResponse(result, safe=False)
class SupplierDetail(generic.DetailView): class SupplierDetail(GenericDetailView):
model = models.Supplier model = models.Supplier
template_name = 'supplier_detail.html'
def get_context_data(self, **kwargs):
context = super(SupplierDetail, self).get_context_data(**kwargs)
context['history_link'] = 'supplier_history'
context['update_link'] = 'supplier_update'
context['detail_link'] = 'supplier_detail'
context['associated'] = 'partials/associated_assets.html'
context['associated2'] = ''
if self.request.is_ajax():
context['override'] = "base_ajax.html"
else:
context['override'] = 'base_assets.html'
return context
class SupplierCreate(generic.CreateView): class SupplierCreate(generic.CreateView):

View File

@@ -7,7 +7,7 @@
xml:lang="{% firstof LANGUAGE_CODE 'en' %}" xml:lang="{% firstof LANGUAGE_CODE 'en' %}"
lang="{% firstof LANGUAGE_CODE 'en' %}"> lang="{% firstof LANGUAGE_CODE 'en' %}">
<head> <head>
<title>{{page_title}}{% block title %}{% endblock %} | Rig Information Gathering System</title> <title>{% block title %}{{page_title}}{% endblock %} | Rig Information Gathering System</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
@@ -70,7 +70,7 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% if page_title %}<h2>{{page_title}}</h2>{% endif %} {% if page_title and not request.is_ajax %}<h2>{{page_title}}</h2>{% endif %}
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>

View File

@@ -1,7 +1,7 @@
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title">{% block title %}{% endblock %}</h4> <h4 class="modal-title">{{page_title}}{% block title %}{% endblock %}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>

View File

@@ -1,15 +1,9 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %} {% extends override|default:"base_rigs.html" %}
{% load widget_tweaks %} {% load widget_tweaks %}
{% load button from filters %}
{% block title %}{{ type }} | {{ object.name }}{% endblock %}
{% block content %} {% block content %}
<div class="row"> <div class="row">
{% if not request.is_ajax %}
<div class="col-sm-12">
<h1>{{ type }} | {{ object.name }}</h1>
</div>
{% endif %}
<div class="col"> <div class="col">
<div class="card border-info"> <div class="card border-info">
<div class="card-header">{{ type }} Details</div> <div class="card-header">{{ type }} Details</div>
@@ -52,11 +46,10 @@
{% endif %} {% endif %}
{% if not request.is_ajax %} {% if not request.is_ajax %}
<div class="row"> <div class="row py-2">
<div class="col-sm-12 text-right"> <div class="col-sm-12 text-right">
<div class="btn-group"> <div class="btn-group">
<a href="{% url update_link object.pk %}" class="btn btn-warning"><span {% button 'edit' update_link object.pk %}
class="fas fa-edit"></span> Edit</a>
</div> </div>
{% include 'partials/last_edited.html' with target=history_link %} {% include 'partials/last_edited.html' with target=history_link %}
</div> </div>
@@ -65,13 +58,12 @@
{% endblock %} {% endblock %}
{% if request.is_ajax %} {% if request.is_ajax %}
{% block footer %} {% block footer %}
<div class="row"> <div class="row py-2">
<div class="col-sm-12 text-right"> <div class="col-sm-12 text-right">
<div class="btn-group btn-page"> <div class="btn-group btn-page">
<a href="{% url detail_link object.pk %}" class="btn btn-primary"><span <a href="{% url detail_link object.pk %}" class="btn btn-primary"><span
class="fas fa-eye"></span> Open Page</a> class="fas fa-eye"></span> Open Page</a>
<a href="{% url update_link object.pk %}" class="btn btn-warning"><span {% button 'edit' update_link object.pk %}
class="fas fa-edit"></span> Edit</a>
</div> </div>
{% include 'partials/last_edited.html' with target=history_link %} {% include 'partials/last_edited.html' with target=history_link %}
</div> </div>

View File

@@ -7,8 +7,8 @@
{% block content %} {% block content %}
<div class="row"> <div class="row">
<div class="col text-right"> <div class="col">
<form class="form-inline"> <form class="form-inline justify-content-end">
{% csrf_token %} {% csrf_token %}
<div class="input-group"> <div class="input-group">
<input type="search" name="q" placeholder="Search" value="{{ request.GET.q }}" <input type="search" name="q" placeholder="Search" value="{{ request.GET.q }}"