From 85a20dac263ca4c4ea9b3d21bf50e631f9cbc848 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Mon, 14 Oct 2019 14:07:06 +0100 Subject: [PATCH] Assets now conforms to pep8 --- RIGS/forms.py | 1 + .../management/commands/generateSampleData.py | 15 ++++++++-- RIGS/rigboard.py | 2 ++ RIGS/views.py | 2 +- .../management/commands/createSampleData.py | 13 +++++---- assets/models.py | 4 +-- assets/urls.py | 1 - assets/views.py | 29 ++++++++++++------- 8 files changed, 45 insertions(+), 22 deletions(-) diff --git a/RIGS/forms.py b/RIGS/forms.py index 9caf3016..18a81e14 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -39,6 +39,7 @@ class EmbeddedAuthenticationForm(AuthenticationForm): super().__init__(*args, **kwargs) self.fields['username'].widget.attrs.pop('autofocus', None) + class PasswordReset(PasswordResetForm): captcha = ReCaptchaField(label='Captcha') diff --git a/RIGS/management/commands/generateSampleData.py b/RIGS/management/commands/generateSampleData.py index e17e2ff4..3c82fe57 100644 --- a/RIGS/management/commands/generateSampleData.py +++ b/RIGS/management/commands/generateSampleData.py @@ -121,8 +121,19 @@ class Command(BaseCommand): self.keyholder_group = Group.objects.create(name='Keyholders') self.finance_group = Group.objects.create(name='Finance') - keyholderPerms = ["add_event", "change_event", "view_event", "add_eventitem", "change_eventitem", "delete_eventitem", "add_organisation", "change_organisation", "view_organisation", "add_person", "change_person", "view_person", "view_profile", "add_venue", "change_venue", "view_venue", "add_asset", "change_asset", "delete_asset", "asset_finance"] - financePerms = ["change_event", "view_event", "add_eventitem", "change_eventitem", "add_invoice", "change_invoice", "view_invoice", "add_organisation", "change_organisation", "view_organisation", "add_payment", "change_payment", "delete_payment", "add_person", "change_person", "view_person", "asset_finance", "change_asset"] + keyholderPerms = ["add_event", "change_event", "view_event", + "add_eventitem", "change_eventitem", "delete_eventitem", + "add_organisation", "change_organisation", "view_organisation", + "add_person", "change_person", "view_person", "view_profile", + "add_venue", "change_venue", "view_venue", + "add_asset", "change_asset", "delete_asset", + "asset_finance"] + financePerms = ["change_event", "view_event", "add_eventitem", + "change_eventitem", "add_invoice", "change_invoice", "view_invoice", + "add_organisation", "change_organisation", "view_organisation", + "add_payment", "change_payment", "delete_payment", + "add_person", "change_person", "view_person", + "asset_finance", "change_asset"] for permId in keyholderPerms: self.keyholder_group.permissions.add(Permission.objects.get(codename=permId)) diff --git a/RIGS/rigboard.py b/RIGS/rigboard.py index e6112b31..99c80601 100644 --- a/RIGS/rigboard.py +++ b/RIGS/rigboard.py @@ -83,6 +83,7 @@ class EventEmbed(EventDetail): class EventRA(generic.base.RedirectView): permanent = False + def get_redirect_url(self, *args, **kwargs): event = get_object_or_404(models.Event, pk=kwargs['pk']) @@ -406,6 +407,7 @@ class EventAuthoriseRequestEmailPreview(generic.DetailView): context['to_name'] = self.request.GET.get('to_name', None) return context + @method_decorator(csrf_exempt, name='dispatch') class LogRiskAssessment(generic.View): http_method_names = ["post"] diff --git a/RIGS/views.py b/RIGS/views.py index aaaac7da..b197334c 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -62,7 +62,7 @@ def login_embed(request, **kwargs): messages.warning(request, 'Cookies do not seem to be enabled. Try logging in using a new tab.') request.method = 'GET' # Render the page without trying to login - return login(request, template_name="registration/login_embed.html", authentication_form=forms.EmbeddedAuthenticationForm) + return login(request, template_name="registration/login_embed.html", authentication_form=forms.EmbeddedAuthenticationForm) """ diff --git a/assets/management/commands/createSampleData.py b/assets/management/commands/createSampleData.py index d054b17d..616cff7c 100644 --- a/assets/management/commands/createSampleData.py +++ b/assets/management/commands/createSampleData.py @@ -36,7 +36,8 @@ class Command(BaseCommand): models.AssetStatus.objects.create(name=stat) def create_suppliers(self): - suppliers = ["Acme, inc.","Widget Corp","123 Warehousing","Demo Company","Smith and Co.","Foo Bars","ABC Telecom","Fake Brothers","QWERTY Logistics","Demo, inc.","Sample Company","Sample, inc","Acme Corp","Allied Biscuit","Ankh-Sto Associates","Extensive Enterprise","Galaxy Corp","Globo-Chem","Mr. Sparkle","Globex Corporation","LexCorp","LuthorCorp","North Central Positronics","Omni Consimer Products","Praxis Corporation","Sombra Corporation","Sto Plains Holdings","Tessier-Ashpool","Wayne Enterprises","Wentworth Industries","ZiffCorp","Bluth Company","Strickland Propane","Thatherton Fuels","Three Waters","Water and Power","Western Gas & Electric","Mammoth Pictures","Mooby Corp","Gringotts","Thrift Bank","Flowers By Irene","The Legitimate Businessmens Club","Osato Chemicals","Transworld Consortium","Universal Export","United Fried Chicken","Virtucon","Kumatsu Motors","Keedsler Motors","Powell Motors","Industrial Automation","Sirius Cybernetics Corporation","U.S. Robotics and Mechanical Men","Colonial Movers","Corellian Engineering Corporation","Incom Corporation","General Products","Leeding Engines Ltd.","Blammo","Input, Inc.","Mainway Toys","Videlectrix","Zevo Toys","Ajax","Axis Chemical Co.","Barrytron","Carrys Candles","Cogswell Cogs","Spacely Sprockets","General Forge and Foundry","Duff Brewing Company","Dunder Mifflin","General Services Corporation","Monarch Playing Card Co.","Krustyco","Initech","Roboto Industries","Primatech","Sonky Rubber Goods","St. Anky Beer","Stay Puft Corporation","Vandelay Industries","Wernham Hogg","Gadgetron","Burleigh and Stronginthearm","BLAND Corporation","Nordyne Defense Dynamics","Petrox Oil Company","Roxxon","McMahon and Tate","Sixty Second Avenue","Charles Townsend Agency","Spade and Archer","Megadodo Publications","Rouster and Sideways","C.H. Lavatory and Sons","Globo Gym American Corp","The New Firm","SpringShield","Compuglobalhypermeganet","Data Systems","Gizmonic Institute","Initrode","Taggart Transcontinental","Atlantic Northern","Niagular","Plow King","Big Kahuna Burger","Big T Burgers and Fries","Chez Quis","Chotchkies","The Frying Dutchman","Klimpys","The Krusty Krab","Monks Diner","Milliways","Minuteman Cafe","Taco Grande","Tip Top Cafe","Moes Tavern","Central Perk","Chasers"] + suppliers = ["Acme, inc.", "Widget Corp", "123 Warehousing", "Demo Company", "Smith and Co.", "Foo Bars", "ABC Telecom", "Fake Brothers", "QWERTY Logistics", "Demo, inc.", "Sample Company", "Sample, inc", "Acme Corp", "Allied Biscuit", "Ankh-Sto Associates", "Extensive Enterprise", "Galaxy Corp", "Globo-Chem", "Mr. Sparkle", "Globex Corporation", "LexCorp", "LuthorCorp", "North Central Positronics", "Omni Consimer Products", "Praxis Corporation", "Sombra Corporation", "Sto Plains Holdings", "Tessier-Ashpool", "Wayne Enterprises", "Wentworth Industries", "ZiffCorp", "Bluth Company", "Strickland Propane", "Thatherton Fuels", "Three Waters", "Water and Power", "Western Gas & Electric", "Mammoth Pictures", "Mooby Corp", "Gringotts", "Thrift Bank", "Flowers By Irene", "The Legitimate Businessmens Club", "Osato Chemicals", "Transworld Consortium", "Universal Export", "United Fried Chicken", "Virtucon", "Kumatsu Motors", "Keedsler Motors", "Powell Motors", "Industrial Automation", "Sirius Cybernetics Corporation", "U.S. Robotics and Mechanical Men", "Colonial Movers", "Corellian Engineering Corporation", "Incom Corporation", "General Products", "Leeding Engines Ltd.", "Blammo", + "Input, Inc.", "Mainway Toys", "Videlectrix", "Zevo Toys", "Ajax", "Axis Chemical Co.", "Barrytron", "Carrys Candles", "Cogswell Cogs", "Spacely Sprockets", "General Forge and Foundry", "Duff Brewing Company", "Dunder Mifflin", "General Services Corporation", "Monarch Playing Card Co.", "Krustyco", "Initech", "Roboto Industries", "Primatech", "Sonky Rubber Goods", "St. Anky Beer", "Stay Puft Corporation", "Vandelay Industries", "Wernham Hogg", "Gadgetron", "Burleigh and Stronginthearm", "BLAND Corporation", "Nordyne Defense Dynamics", "Petrox Oil Company", "Roxxon", "McMahon and Tate", "Sixty Second Avenue", "Charles Townsend Agency", "Spade and Archer", "Megadodo Publications", "Rouster and Sideways", "C.H. Lavatory and Sons", "Globo Gym American Corp", "The New Firm", "SpringShield", "Compuglobalhypermeganet", "Data Systems", "Gizmonic Institute", "Initrode", "Taggart Transcontinental", "Atlantic Northern", "Niagular", "Plow King", "Big Kahuna Burger", "Big T Burgers and Fries", "Chez Quis", "Chotchkies", "The Frying Dutchman", "Klimpys", "The Krusty Krab", "Monks Diner", "Milliways", "Minuteman Cafe", "Taco Grande", "Tip Top Cafe", "Moes Tavern", "Central Perk", "Chasers"] for supplier in suppliers: models.Supplier.objects.create(name=supplier) @@ -64,11 +65,11 @@ class Command(BaseCommand): def create_connectors(self): connectors = [ - { "description":"13A UK", "current_rating":13, "voltage_rating":230, "num_pins":3 }, - { "description":"16A", "current_rating":16, "voltage_rating":230, "num_pins":3 }, - { "description":"32/3", "current_rating":32, "voltage_rating":400, "num_pins":5 }, - { "description":"Socapex", "current_rating":23, "voltage_rating":600, "num_pins":19 }, + {"description": "13A UK", "current_rating": 13, "voltage_rating": 230, "num_pins": 3}, + {"description": "16A", "current_rating": 16, "voltage_rating": 230, "num_pins": 3}, + {"description": "32/3", "current_rating": 32, "voltage_rating": 400, "num_pins": 5}, + {"description": "Socapex", "current_rating": 23, "voltage_rating": 600, "num_pins": 19}, ] for connector in connectors: conn = models.Connector.objects.create(**connector) - conn.save() \ No newline at end of file + conn.save() diff --git a/assets/models.py b/assets/models.py index 193b7642..005beadd 100644 --- a/assets/models.py +++ b/assets/models.py @@ -6,6 +6,7 @@ from polymorphic.models import PolymorphicModel import datetime import re + class AssetCategory(models.Model): class Meta: verbose_name = 'Asset Category' @@ -54,7 +55,7 @@ class Asset(models.Model): permissions = ( ('asset_finance', 'Can see financial data for assets'), ) - + parent = models.ForeignKey(to='self', related_name='asset_parent', blank=True, null=True, on_delete=models.SET_NULL) asset_id = models.CharField(max_length=10, unique=True) description = models.CharField(max_length=120) @@ -123,4 +124,3 @@ class Asset(models.Model): raise ValidationError({"circuits": "There must be at least one circuit in a cable"}) elif self.cores <= 0: raise ValidationError({"cores": "There must be at least one core in a cable"}) - \ No newline at end of file diff --git a/assets/urls.py b/assets/urls.py index d8d87ce1..c7dcf2fc 100644 --- a/assets/urls.py +++ b/assets/urls.py @@ -25,4 +25,3 @@ urlpatterns = [ path('', include(router.urls)), ] - diff --git a/assets/views.py b/assets/views.py index 0d134603..c706f949 100644 --- a/assets/views.py +++ b/assets/views.py @@ -13,14 +13,15 @@ from dateutil import parser import simplejson as json from assets import models, forms + class AssetList(LoginRequiredMixin, generic.ListView): model = models.Asset template_name = 'asset_list.html' paginate_by = 40 ordering = ['-pk'] - + def get_queryset(self): - #TODO Feedback to user when search fails + # TODO Feedback to user when search fails query = self.request.GET.get('query', "") if len(query) == 0: queryset = self.model.objects.all() @@ -28,7 +29,7 @@ class AssetList(LoginRequiredMixin, generic.ListView): queryset = self.model.objects.filter(Q(asset_id__exact=query) | Q(description__icontains=query)) else: queryset = self.model.objects.filter(Q(asset_id__exact=query)) - + cat = self.request.GET.get('cat', "") status = self.request.GET.get('status', "") if cat != "": @@ -37,7 +38,7 @@ class AssetList(LoginRequiredMixin, generic.ListView): queryset = queryset.filter(status__name__exact=status) return queryset - + def get_context_data(self, **kwargs): context = super(AssetList, self).get_context_data(**kwargs) context["search_name"] = self.request.GET.get('query', "") @@ -49,19 +50,22 @@ class AssetList(LoginRequiredMixin, generic.ListView): context["status_select"] = self.request.GET.get('status', "") return context + class AssetSearch(AssetList): def render_to_response(self, context, **response_kwargs): result = [] for asset in context["object_list"]: - result.append({"id":asset.pk, "label":(asset.asset_id + " | " + asset.description)}) - + result.append({"id": asset.pk, "label": (asset.asset_id + " | " + asset.description)}) + return JsonResponse(result, safe=False) + class AssetDetail(LoginRequiredMixin, generic.DetailView): model = models.Asset template_name = 'asset_update.html' + class AssetEdit(LoginRequiredMixin, generic.UpdateView): template_name = 'asset_update.html' model = models.Asset @@ -75,7 +79,8 @@ class AssetEdit(LoginRequiredMixin, generic.UpdateView): return context def get_success_url(self): - return reverse("asset_detail", kwargs={"pk":self.object.id}) + return reverse("asset_detail", kwargs={"pk": self.object.id}) + class AssetCreate(LoginRequiredMixin, generic.CreateView): template_name = 'asset_create.html' @@ -84,14 +89,15 @@ class AssetCreate(LoginRequiredMixin, generic.CreateView): def get_context_data(self, **kwargs): context = super(AssetCreate, self).get_context_data(**kwargs) - + context["create"] = True context["connectors"] = models.Connector.objects.all() return context - + def get_success_url(self): - return reverse("asset_detail", kwargs={"pk":self.object.id}) + return reverse("asset_detail", kwargs={"pk": self.object.id}) + class DuplicateMixin: def get(self, request, *args, **kwargs): @@ -99,6 +105,7 @@ class DuplicateMixin: self.object.pk = None return self.render_to_response(self.get_context_data()) + class AssetDuplicate(DuplicateMixin, AssetCreate): model = models.Asset @@ -110,6 +117,7 @@ class AssetDuplicate(DuplicateMixin, AssetCreate): context["previous_asset_pk"] = self.kwargs.get(self.pk_url_kwarg) return context + @login_required() def asset_delete(request): context = dict() @@ -121,6 +129,7 @@ def asset_delete(request): return HttpResponse(json.dumps(context), content_type='application/json') + class SupplierList(generic.ListView): model = models.Supplier template_name = 'supplier_list.html'