mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-24 00:42:17 +00:00
Versioning module now does magic
Automatic creation of views/urls for anything registered with reversion, with a small amount of hackage to preserve legacy stuff. (and the DAMNED asset IDs!) I would never get distracted...
This commit is contained in:
@@ -184,6 +184,10 @@ class Asset(models.Model, RevisionMixin):
|
||||
def activity_feed_string(self):
|
||||
return str(self)
|
||||
|
||||
@property
|
||||
def display_id(self):
|
||||
return str(self.asset_id)
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Asset)
|
||||
def pre_save_asset(sender, instance, **kwargs):
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
{% if perms.assets.view_asset %}
|
||||
<li class="nav-item"><a class="nav-link" href="{% url 'asset_activity_table' %}">Recent Changes</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{% url 'assets_activity_table' %}">Recent Changes</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{% url 'asset_audit_list' %}">Audit</a></li>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{% 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='None' %}
|
||||
{% 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='' %}
|
||||
|
||||
@@ -17,10 +17,6 @@ urlpatterns = [
|
||||
(views.AssetEdit.as_view()), name='asset_update'),
|
||||
path('asset/id/<str:pk>/duplicate/', permission_required_with_403('assets.add_asset')
|
||||
(views.AssetDuplicate.as_view()), name='asset_duplicate'),
|
||||
path('asset/id/<str:pk>/history/', permission_required_with_403('assets.view_asset')(views.AssetVersionHistory.as_view()),
|
||||
name='asset_history', kwargs={'model': models.Asset}),
|
||||
path('activity', permission_required_with_403('assets.view_asset')
|
||||
(views.ActivityTable.as_view()), name='asset_activity_table'),
|
||||
|
||||
path('cabletype/list/', views.CableTypeList.as_view(), name='cable_type_list'),
|
||||
path('cabletype/create/', permission_required_with_403('assets.add_cable_type')(views.CableTypeCreate.as_view()), name='cable_type_create'),
|
||||
@@ -39,14 +35,12 @@ urlpatterns = [
|
||||
path('asset/audit/', permission_required_with_403('assets.change_asset')(views.AssetAuditList.as_view()), name='asset_audit_list'),
|
||||
path('asset/id/<str:pk>/audit/', permission_required_with_403('assets.change_asset')(views.AssetAudit.as_view()), name='asset_audit'),
|
||||
|
||||
path('supplier/list', views.SupplierList.as_view(), name='supplier_list'),
|
||||
path('supplier/<int:pk>', views.SupplierDetail.as_view(), name='supplier_detail'),
|
||||
path('supplier/create', permission_required_with_403('assets.add_supplier')
|
||||
path('supplier/list/', views.SupplierList.as_view(), name='supplier_list'),
|
||||
path('supplier/<int:pk>/', views.SupplierDetail.as_view(), name='supplier_detail'),
|
||||
path('supplier/create/', permission_required_with_403('assets.add_supplier')
|
||||
(views.SupplierCreate.as_view()), name='supplier_create'),
|
||||
path('supplier/<int:pk>/edit', permission_required_with_403('assets.change_supplier')
|
||||
path('supplier/<int:pk>/edit/', permission_required_with_403('assets.change_supplier')
|
||||
(views.SupplierUpdate.as_view()), name='supplier_update'),
|
||||
path('supplier/<int:pk>/history/', views.SupplierVersionHistory.as_view(),
|
||||
name='supplier_history', kwargs={'model': models.Supplier}),
|
||||
|
||||
path('supplier/search/', views.SupplierSearch.as_view(), name='supplier_search_json'),
|
||||
]
|
||||
|
||||
@@ -240,43 +240,6 @@ class SupplierUpdate(generic.UpdateView):
|
||||
template_name = 'supplier_update.html'
|
||||
|
||||
|
||||
class SupplierVersionHistory(versioning.VersionHistory):
|
||||
template_name = "asset_version_history.html"
|
||||
|
||||
|
||||
class AssetVersionHistory(versioning.VersionHistory):
|
||||
template_name = "version_history.html"
|
||||
|
||||
def get_object(self, **kwargs):
|
||||
return get_object_or_404(models.Asset, asset_id=self.kwargs['pk'])
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AssetVersionHistory, self).get_context_data(**kwargs)
|
||||
context['object'] = self.get_object()
|
||||
context['id'] = self.get_object().asset_id
|
||||
context['override'] = 'base_assets.html'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class ActivityTable(versioning.ActivityTable):
|
||||
model = versioning.RIGSVersion
|
||||
template_name = "activity_table.html"
|
||||
paginate_by = 25
|
||||
|
||||
def get_queryset(self):
|
||||
versions = versioning.RIGSVersion.objects.get_for_multiple_models(
|
||||
[models.Asset, models.Supplier])
|
||||
return versions
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ActivityTable, self).get_context_data(**kwargs)
|
||||
context['override'] = 'base_assets.html'
|
||||
context['title'] = 'Asset Database'
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class CableTypeList(generic.ListView):
|
||||
model = models.CableType
|
||||
template_name = 'cable_type_list.html'
|
||||
|
||||
Reference in New Issue
Block a user