renaming lotAnnotations to Lotproperty
This commit is contained in:
parent
aff13a04eb
commit
95fb09bd69
|
@ -20,9 +20,9 @@
|
|||
{% trans 'Exports' %}
|
||||
</a>
|
||||
{% if lot %}
|
||||
<a href="{% url 'lot:annotations' object.id %}" type="button" class="btn btn-green-admin">
|
||||
<a href="{% url 'lot:properties' object.id %}" type="button" class="btn btn-green-admin">
|
||||
<i class="bi bi-tag"></i>
|
||||
{% trans 'Annotations' %}
|
||||
{% trans 'properties' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -7,8 +7,8 @@ from utils.constants import (
|
|||
)
|
||||
|
||||
from user.models import User, Institution
|
||||
from device.models import Property
|
||||
# from device.models import Device
|
||||
# from evidence.models import Annotation
|
||||
|
||||
|
||||
class LotTag(models.Model):
|
||||
|
@ -45,17 +45,6 @@ class Lot(models.Model):
|
|||
for d in DeviceLot.objects.filter(lot=self, device_id=v):
|
||||
d.delete()
|
||||
|
||||
class LotProperty (Property):
|
||||
|
||||
class LotAnnotation(models.Model):
|
||||
class Type(models.IntegerChoices):
|
||||
SYSTEM= 0, "System"
|
||||
USER = 1, "User"
|
||||
DOCUMENT = 2, "Document"
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
lot = models.ForeignKey(Lot, on_delete=models.CASCADE)
|
||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
type = models.SmallIntegerField(choices=Type)
|
||||
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
<div class="row">
|
||||
<div class="tab-pane fade show active" id="details">
|
||||
<div class="btn-group dropdown ml-1 mt-1" uib-dropdown="">
|
||||
<a href="{% url 'lot:add_annotation' lot.pk %}" class="btn btn-primary">
|
||||
<a href="{% url 'lot:add_property' lot.pk %}" class="btn btn-primary">
|
||||
|
||||
<i class="bi bi-plus"></i>
|
||||
Add new annotation
|
||||
Add new lot Property
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h5 class="card-title mt-2">Annotations</h5>
|
||||
<h5 class="card-title mt-2">Properties</h5>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -31,7 +31,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for a in annotations %}
|
||||
{% for a in properties %}
|
||||
<tr>
|
||||
<td>{{ a.key }}</td>
|
||||
<td>{{ a.value }}</td>
|
|
@ -12,6 +12,6 @@ urlpatterns = [
|
|||
path("tag/<int:pk>/", views.LotsTagsView.as_view(), name="tag"),
|
||||
path("<int:pk>/document/", views.LotDocumentsView.as_view(), name="documents"),
|
||||
path("<int:pk>/document/add", views.LotAddDocumentView.as_view(), name="add_document"),
|
||||
path("<int:pk>/annotation", views.LotAnnotationsView.as_view(), name="annotations"),
|
||||
path("<int:pk>/annotation/add", views.LotAddAnnotationView.as_view(), name="add_annotation"),
|
||||
path("<int:pk>/property", views.LotPropertiesView.as_view(), name="properties"),
|
||||
path("<int:pk>/property/add", views.LotAddPropertyView.as_view(), name="add_property"),
|
||||
]
|
||||
|
|
44
lot/views.py
44
lot/views.py
|
@ -9,9 +9,9 @@ from django.views.generic.edit import (
|
|||
FormView,
|
||||
)
|
||||
from dashboard.mixins import DashboardView
|
||||
from lot.models import Lot, LotTag, LotAnnotation
|
||||
from lot.models import Lot, LotTag, LotProperty
|
||||
from lot.forms import LotsForm
|
||||
|
||||
from device.models import Property
|
||||
|
||||
class NewLotView(DashboardView, CreateView):
|
||||
template_name = "new_lot.html"
|
||||
|
@ -143,18 +143,18 @@ class LotsTagsView(DashboardView, TemplateView):
|
|||
|
||||
|
||||
class LotAddDocumentView(DashboardView, CreateView):
|
||||
template_name = "new_annotation.html"
|
||||
template_name = "new_property.html"
|
||||
title = _("New Document")
|
||||
breadcrumb = "Device / New document"
|
||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||
model = LotAnnotation
|
||||
model = LotProperty
|
||||
fields = ("key", "value")
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
form.instance.lot = self.lot
|
||||
form.instance.type = LotAnnotation.Type.DOCUMENT
|
||||
form.instance.type = Property.Type.DOCUMENT
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
|
@ -169,16 +169,16 @@ class LotAddDocumentView(DashboardView, CreateView):
|
|||
class LotDocumentsView(DashboardView, TemplateView):
|
||||
template_name = "documents.html"
|
||||
title = _("New Document")
|
||||
breadcrumb = "Device / New document"
|
||||
breadcrumb = "Devicce / New document"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
self.pk = kwargs.get('pk')
|
||||
context = super().get_context_data(**kwargs)
|
||||
lot = get_object_or_404(Lot, owner=self.request.user.institution, id=self.pk)
|
||||
documents = LotAnnotation.objects.filter(
|
||||
documents = LotProperty.objects.filter(
|
||||
lot=lot,
|
||||
owner=self.request.user.institution,
|
||||
type=LotAnnotation.Type.DOCUMENT,
|
||||
type=Property.Type.DOCUMENT,
|
||||
)
|
||||
context.update({
|
||||
'lot': lot,
|
||||
|
@ -189,48 +189,48 @@ class LotDocumentsView(DashboardView, TemplateView):
|
|||
return context
|
||||
|
||||
|
||||
class LotAnnotationsView(DashboardView, TemplateView):
|
||||
template_name = "annotations.html"
|
||||
title = _("New Annotation")
|
||||
breadcrumb = "Device / New annotation"
|
||||
class LotPropertiesView(DashboardView, TemplateView):
|
||||
template_name = "properties.html"
|
||||
title = _("New Lot Property")
|
||||
breadcrumb = "Lot / New property"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
self.pk = kwargs.get('pk')
|
||||
context = super().get_context_data(**kwargs)
|
||||
lot = get_object_or_404(Lot, owner=self.request.user.institution, id=self.pk)
|
||||
annotations = LotAnnotation.objects.filter(
|
||||
properties = LotProperty.objects.filter(
|
||||
lot=lot,
|
||||
owner=self.request.user.institution,
|
||||
type=LotAnnotation.Type.USER,
|
||||
type=Property.Type.USER,
|
||||
)
|
||||
context.update({
|
||||
'lot': lot,
|
||||
'annotations': annotations,
|
||||
'properties': properties,
|
||||
'title': self.title,
|
||||
'breadcrumb': self.breadcrumb
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
class LotAddAnnotationView(DashboardView, CreateView):
|
||||
template_name = "new_annotation.html"
|
||||
title = _("New Annotation")
|
||||
breadcrumb = "Device / New annotation"
|
||||
class LotAddPropertyView(DashboardView, CreateView):
|
||||
template_name = "new_property.html"
|
||||
title = _("New Lot Property")
|
||||
breadcrumb = "Device / New property"
|
||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||
model = LotAnnotation
|
||||
model = LotProperty
|
||||
fields = ("key", "value")
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
form.instance.lot = self.lot
|
||||
form.instance.type = LotAnnotation.Type.USER
|
||||
form.instance.type = Property.Type.USER
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
def get_form_kwargs(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
self.lot = get_object_or_404(Lot, pk=pk, owner=self.request.user.institution)
|
||||
self.success_url = reverse_lazy('lot:annotations', args=[pk])
|
||||
self.success_url = reverse_lazy('lot:properties', args=[pk])
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
|
Loading…
Reference in a new issue