Assets now conforms to pep8

This commit is contained in:
Matthew Smith
2019-10-14 14:07:06 +01:00
parent 743d290405
commit 85a20dac26
8 changed files with 45 additions and 22 deletions

View File

@@ -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')

View File

@@ -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))

View File

@@ -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"]

View File

@@ -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)
"""

View File

@@ -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()
conn.save()

View File

@@ -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"})

View File

@@ -25,4 +25,3 @@ urlpatterns = [
path('', include(router.urls)),
]

View File

@@ -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'