mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-03-03 10:38:23 +00:00
Create the training database (#463)
Co-authored-by: josephjboyden <josephjboyden@gmail.com>
This commit is contained in:
@@ -1 +0,0 @@
|
||||
default_app_config = 'assets.apps.AssetsAppConfig'
|
||||
|
||||
@@ -46,11 +46,3 @@ class CableTypeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = models.CableType
|
||||
fields = '__all__'
|
||||
|
||||
def clean(self):
|
||||
form_data = self.cleaned_data
|
||||
queryset = models.CableType.objects.filter(Q(plug=form_data['plug']) & Q(socket=form_data['socket']) & Q(circuits=form_data['circuits']) & Q(cores=form_data['cores']))
|
||||
# Being identical to itself shouldn't count...
|
||||
if queryset.exists() and self.instance.pk != queryset[0].pk:
|
||||
raise forms.ValidationError("A cable type that exactly matches this one already exists, please use that instead.", code="notunique")
|
||||
return form_data
|
||||
|
||||
@@ -20,6 +20,7 @@ class Command(BaseCommand):
|
||||
assets = []
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
print("Generating sample assets data")
|
||||
from django.conf import settings
|
||||
|
||||
if not (settings.DEBUG or settings.STAGING):
|
||||
@@ -34,6 +35,7 @@ class Command(BaseCommand):
|
||||
self.create_assets()
|
||||
self.create_connectors()
|
||||
self.create_cables()
|
||||
print("Done generating sample assets data")
|
||||
|
||||
def create_categories(self):
|
||||
choices = ['Case', 'Video', 'General', 'Sound', 'Lighting', 'Rigging']
|
||||
|
||||
17
assets/migrations/0022_alter_cabletype_unique_together.py
Normal file
17
assets/migrations/0022_alter_cabletype_unique_together.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.2.11 on 2022-01-12 19:11
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0021_auto_20210302_1204'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='cabletype',
|
||||
unique_together={('plug', 'socket', 'circuits', 'cores')},
|
||||
),
|
||||
]
|
||||
@@ -76,10 +76,11 @@ class CableType(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ['plug', 'socket', '-circuits']
|
||||
unique_together = ['plug', 'socket', 'circuits', 'cores']
|
||||
|
||||
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 +149,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})
|
||||
|
||||
@@ -64,16 +64,16 @@
|
||||
<div class="form-group form-row">
|
||||
{% include 'partials/form_field.html' with field=form.length append=form.length.help_text col="col-6" %}
|
||||
<div class="col-4">
|
||||
<button class="btn btn-danger" onclick="setFieldValue('{{ form.length.id_for_label }}','5');" tabindex="-1">5{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-success" onclick="setFieldValue('{{ form.length.id_for_label }}','10');" tabindex="-1">10{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-info" onclick="setFieldValue('{{ form.length.id_for_label }}','20');" tabindex="-1">20{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-danger" onclick="setFieldValue('{{ form.length.id_for_label }}','5');" tabindex="-1" type="button">5{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-success" onclick="setFieldValue('{{ form.length.id_for_label }}','10');" tabindex="-1" type="button">10{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-info" onclick="setFieldValue('{{ form.length.id_for_label }}','20');" tabindex="-1" type="button">20{{ form.length.help_text }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
{% include 'partials/form_field.html' with field=form.csa append=form.csa.help_text title='CSA' col="col-6" %}
|
||||
<div class="col-4">
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '1.5');" tabindex="-1">1.5{{ form.csa.help_text }}</button>
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '2.5');" tabindex="-1">2.5{{ form.csa.help_text }}</button>
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '1.5');" tabindex="-1" type="button">1.5{{ form.csa.help_text }}</button>
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '2.5');" tabindex="-1" type="button">2.5{{ form.csa.help_text }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
});
|
||||
$('#searchButton').click(function (e) {
|
||||
e.preventDefault();
|
||||
var url = "{% url 'asset_audit' None %}";
|
||||
var id = $("#{{form.q.id_for_label}}").val();
|
||||
url = url.replace('None', id);
|
||||
var url = "{% url 'asset_audit' None %}".replace('None', $("#{{form.q.id_for_label}}").val());
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(){
|
||||
|
||||
@@ -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')))
|
||||
|
||||
@@ -64,11 +64,11 @@ def test_x_frame_headers(client, django_user_model, test_asset):
|
||||
|
||||
response = client.get(asset_url, follow=True)
|
||||
with pytest.raises(KeyError):
|
||||
response._headers["X-Frame-Options"]
|
||||
response.headers["X-Frame-Options"]
|
||||
|
||||
response = client.get(login_url, follow=True)
|
||||
with pytest.raises(KeyError):
|
||||
response._headers["X-Frame-Options"]
|
||||
response.headers["X-Frame-Options"]
|
||||
|
||||
|
||||
def test_oembed(client, test_asset):
|
||||
@@ -105,7 +105,6 @@ def test_asset_edit(admin_client, test_asset):
|
||||
|
||||
def test_cable_edit(admin_client, test_cable):
|
||||
url = reverse('asset_update', kwargs={'pk': test_cable.asset_id})
|
||||
# TODO Why do I have to send is_cable=True here?
|
||||
response = admin_client.post(url, {'is_cable': True, 'length': -3, 'csa': -3})
|
||||
|
||||
# TODO Can't figure out how to select the 'none' option...
|
||||
|
||||
@@ -76,7 +76,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')
|
||||
@@ -117,7 +117,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
|
||||
|
||||
|
||||
@@ -130,7 +130,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):
|
||||
@@ -150,7 +150,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"
|
||||
@@ -177,8 +177,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
|
||||
|
||||
|
||||
@@ -201,7 +202,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
|
||||
|
||||
@@ -212,7 +213,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):
|
||||
@@ -229,7 +230,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')
|
||||
@@ -256,7 +257,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'
|
||||
@@ -275,7 +276,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:
|
||||
@@ -321,8 +322,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
|
||||
|
||||
|
||||
@@ -332,7 +333,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"
|
||||
|
||||
@@ -348,9 +349,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
|
||||
|
||||
@@ -365,10 +366,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