mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-19 22:42:17 +00:00
Big pile of minor code cleanups
This commit is contained in:
@@ -79,7 +79,7 @@ class CableType(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
if self.plug and self.socket:
|
||||
return "%s → %s" % (self.plug.description, self.socket.description)
|
||||
return f"{self.plug.description} → {self.socket.description}"
|
||||
else:
|
||||
return "Unknown"
|
||||
|
||||
@@ -148,7 +148,7 @@ class Asset(models.Model, RevisionMixin):
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return "{} | {}".format(self.asset_id, self.description)
|
||||
return f"{self.asset_id} | {self.description}"
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('asset_detail', kwargs={'pk': self.asset_id})
|
||||
|
||||
@@ -180,7 +180,7 @@ class TestAssetForm(AutoLoginTest):
|
||||
def test_asset_edit(self):
|
||||
self.page = pages.AssetEdit(self.driver, self.live_server_url, asset_id=self.parent.asset_id).open()
|
||||
|
||||
self.assertTrue(self.driver.find_element_by_id('id_asset_id').get_attribute('readonly') is not None)
|
||||
self.assertIsNotNone(self.driver.find_element_by_id('id_asset_id').get_attribute('readonly'))
|
||||
|
||||
new_description = "Big Shelf"
|
||||
self.page.description = new_description
|
||||
@@ -335,7 +335,7 @@ class TestAssetAudit(AutoLoginTest):
|
||||
self.assertNotIn(self.asset.asset_id, self.page.assets)
|
||||
|
||||
def test_audit_list(self):
|
||||
self.assertEqual(len(models.Asset.objects.filter(last_audited_at=None)), len(self.page.assets))
|
||||
self.assertEqual(models.Asset.objects.filter(last_audited_at=None).count(), len(self.page.assets))
|
||||
asset_row = self.page.assets[0]
|
||||
self.driver.find_element(By.XPATH, "//a[contains(@class,'btn') and contains(., 'Audit')]").click()
|
||||
self.wait.until(ec.visibility_of_element_located((By.ID, 'modal')))
|
||||
|
||||
@@ -73,7 +73,7 @@ class AssetList(LoginRequiredMixin, generic.ListView):
|
||||
return queryset.select_related('category', 'status')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AssetList, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["form"] = self.form
|
||||
if hasattr(self.form, 'cleaned_data'):
|
||||
context["category_filters"] = self.form.cleaned_data.get('category')
|
||||
@@ -114,7 +114,7 @@ class AssetDetail(LoginRequiredMixin, AssetIDUrlMixin, generic.DetailView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "Asset {}".format(self.object.display_id)
|
||||
context["page_title"] = f"Asset {self.object.display_id}"
|
||||
return context
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class AssetEdit(LoginRequiredMixin, AssetIDUrlMixin, generic.UpdateView):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["edit"] = True
|
||||
context["connectors"] = models.Connector.objects.all()
|
||||
context["page_title"] = "Edit Asset: {}".format(self.object.display_id)
|
||||
context["page_title"] = f"Edit Asset: {self.object.display_id}"
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
@@ -147,7 +147,7 @@ class AssetCreate(LoginRequiredMixin, generic.CreateView):
|
||||
form_class = forms.AssetForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AssetCreate, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["create"] = True
|
||||
context["connectors"] = models.Connector.objects.all()
|
||||
context["page_title"] = "Create Asset"
|
||||
@@ -174,8 +174,9 @@ class AssetDuplicate(DuplicateMixin, AssetIDUrlMixin, AssetCreate):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["create"] = None
|
||||
context["duplicate"] = True
|
||||
context['previous_asset_id'] = self.get_object().asset_id
|
||||
context["page_title"] = "Duplication of Asset: {}".format(context['previous_asset_id'])
|
||||
old_id = self.get_object().asset_id
|
||||
context['previous_asset_id'] = old_id
|
||||
context["page_title"] = f"Duplication of Asset: {old_id}"
|
||||
return context
|
||||
|
||||
|
||||
@@ -198,7 +199,7 @@ class AssetAuditList(AssetList):
|
||||
return self.model.objects.filter(Q(last_audited_at__isnull=True)).select_related('category', 'status')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AssetAuditList, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = "Asset Audit List"
|
||||
return context
|
||||
|
||||
@@ -209,7 +210,7 @@ class AssetAudit(AssetEdit):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "Audit Asset: {}".format(self.object.display_id)
|
||||
context["page_title"] = f"Audit Asset: {self.object.display_id}"
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
@@ -226,7 +227,7 @@ class SupplierList(GenericListView):
|
||||
ordering = ['name']
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SupplierList, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['create'] = 'supplier_create'
|
||||
context['edit'] = 'supplier_update'
|
||||
context['can_edit'] = self.request.user.has_perm('assets.change_supplier')
|
||||
@@ -253,7 +254,7 @@ class SupplierDetail(GenericDetailView):
|
||||
model = models.Supplier
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SupplierDetail, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['history_link'] = 'supplier_history'
|
||||
context['update_link'] = 'supplier_update'
|
||||
context['detail_link'] = 'supplier_detail'
|
||||
@@ -272,7 +273,7 @@ class SupplierCreate(GenericCreateView, ModalURLMixin):
|
||||
form_class = forms.SupplierForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SupplierCreate, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
if is_ajax(self.request):
|
||||
context['override'] = "base_ajax.html"
|
||||
else:
|
||||
@@ -318,8 +319,8 @@ class CableTypeDetail(generic.DetailView):
|
||||
template_name = 'cable_type_detail.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CableTypeDetail, self).get_context_data(**kwargs)
|
||||
context["page_title"] = "Cable Type {}".format(str(self.object))
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = f"Cable Type {self.object}"
|
||||
return context
|
||||
|
||||
|
||||
@@ -329,7 +330,7 @@ class CableTypeCreate(generic.CreateView):
|
||||
form_class = forms.CableTypeForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CableTypeCreate, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["create"] = True
|
||||
context["page_title"] = "Create Cable Type"
|
||||
|
||||
@@ -345,9 +346,9 @@ class CableTypeUpdate(generic.UpdateView):
|
||||
form_class = forms.CableTypeForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CableTypeUpdate, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["edit"] = True
|
||||
context["page_title"] = "Edit Cable Type"
|
||||
context["page_title"] = f"Edit Cable Type {self.object}"
|
||||
|
||||
return context
|
||||
|
||||
@@ -362,10 +363,10 @@ def generate_label(pk):
|
||||
font = ImageFont.truetype("static/fonts/OpenSans-Regular.tff", 20)
|
||||
obj = get_object_or_404(models.Asset, asset_id=pk)
|
||||
|
||||
asset_id = "Asset: {}".format(obj.asset_id)
|
||||
asset_id = f"Asset: {obj.asset_id}"
|
||||
if obj.is_cable:
|
||||
length = "Length: {}m".format(obj.length)
|
||||
csa = "CSA: {}mm²".format(obj.csa)
|
||||
length = f"Length: {obj.length}m"
|
||||
csa = f"CSA: {obj.csa}mm²"
|
||||
|
||||
image = Image.new("RGB", size, white)
|
||||
logo = Image.open("static/imgs/square_logo.png")
|
||||
|
||||
Reference in New Issue
Block a user