From 731f9865c6296998fba335f9af1633aec83ed46c Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Thu, 6 Feb 2020 23:59:49 +0000 Subject: [PATCH] Delete unused code Much less effort way to increase coverage stats :D --- assets/apps.py | 5 - assets/filters.py | 9 - assets/management/commands/import_old_db.py | 229 ------------------ .../management/commands/update_old_db_file.py | 110 --------- assets/templates/asset_create.html | 1 - assets/templates/asset_update.html | 2 - assets/templates/partials/asset_form.html | 1 - assets/templates/partials/cable_form.html | 1 - assets/templates/partials/parent_form.html | 1 - .../partials/purchasedetails_form.html | 1 - assets/templatetags/__init__.py | 0 assets/templatetags/asset_templatetags.py | 21 -- 12 files changed, 381 deletions(-) delete mode 100644 assets/apps.py delete mode 100644 assets/filters.py delete mode 100644 assets/management/commands/import_old_db.py delete mode 100644 assets/management/commands/update_old_db_file.py delete mode 100644 assets/templatetags/__init__.py delete mode 100644 assets/templatetags/asset_templatetags.py diff --git a/assets/apps.py b/assets/apps.py deleted file mode 100644 index 5569d303..00000000 --- a/assets/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class AssetsConfig(AppConfig): - name = 'assets' diff --git a/assets/filters.py b/assets/filters.py deleted file mode 100644 index b7cc8ffa..00000000 --- a/assets/filters.py +++ /dev/null @@ -1,9 +0,0 @@ -import django_filters - -from assets import models - - -class AssetFilter(django_filters.FilterSet): - class Meta: - model = models.Asset - fields = ['asset_id', 'description', 'serial_number', 'category', 'status'] diff --git a/assets/management/commands/import_old_db.py b/assets/management/commands/import_old_db.py deleted file mode 100644 index 0fcff787..00000000 --- a/assets/management/commands/import_old_db.py +++ /dev/null @@ -1,229 +0,0 @@ -import os -import datetime -import xml.etree.ElementTree as ET -from django.core.management.base import BaseCommand -from django.conf import settings - -from assets import models - - -class Command(BaseCommand): - help = 'Imports old db from XML dump' - - epoch = datetime.date(1970, 1, 1) - - def handle(self, *args, **options): - self.import_categories() - self.import_statuses() - self.import_suppliers() - self.import_collections() - self.import_assets() - self.import_cables() - - @staticmethod - def xml_path(file): - return os.path.join(settings.BASE_DIR, 'data/DB_Dump/{}'.format(file)) - - @staticmethod - def parse_xml(file): - tree = ET.parse(file) - - return tree.getroot() - - def import_categories(self): - # 0: updated, 1: created - tally = [0, 0] - root = self.parse_xml(self.xml_path('TEC_Asset_Categories.xml')) - - for child in root: - obj, created = models.AssetCategory.objects.update_or_create( - pk=int(child.find('AssetCategoryID').text), - name=child.find('AssetCategory').text - ) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Categories - Updated: {}, Created: {}'.format(tally[0], tally[1])) - - def import_statuses(self): - # 0: updated, 1: created - tally = [0, 0] - root = self.parse_xml(self.xml_path('TEC_Asset_Status_new.xml')) - - for child in root: - obj, created = models.AssetStatus.objects.update_or_create( - pk=int(child.find('StatusID').text), - name=child.find('Status').text - ) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Statuses - Updated: {}, Created: {}'.format(tally[0], tally[1])) - - def import_suppliers(self): - # 0: updated, 1: created - tally = [0, 0] - root = self.parse_xml(self.xml_path('TEC_Asset_Suppliers_new.xml')) - - for child in root: - obj, created = models.Supplier.objects.update_or_create( - pk=int(child.find('Supplier_x0020_Id').text), - name=child.find('Supplier_x0020_Name').text - ) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Suppliers - Updated: {}, Created: {}'.format(tally[0], tally[1])) - - def import_assets(self): - # 0: updated, 1: created - tally = [0, 0] - root = self.parse_xml(self.xml_path('TEC_Assets.xml')) - - for child in root: - defaults = dict() - - # defaults['pk'] = int(child.find('ID').text) - defaults['asset_id'] = child.find('AssetID').text - - try: - defaults['description'] = child.find('AssetDescription').text - except AttributeError: - defaults['description'] = 'None' - - defaults['category'] = models.AssetCategory.objects.get(pk=int(child.find('AssetCategoryID').text)) - defaults['status'] = models.AssetStatus.objects.get(pk=int(child.find('StatusID').text)) - - try: - defaults['serial_number'] = child.find('SerialNumber').text - except AttributeError: - pass - - try: - defaults['purchased_from'] = models.Supplier.objects.get(pk=int(child.find('Supplier_x0020_Id').text)) - except AttributeError: - pass - - try: - defaults['date_acquired'] = datetime.datetime.strptime(child.find('DateAcquired').text, '%d/%m/%Y').date() - except AttributeError: - defaults['date_acquired'] = self.epoch - - try: - defaults['date_sold'] = datetime.datetime.strptime(child.find('DateSold').text, '%d/%m/%Y').date() - except AttributeError: - pass - - try: - defaults['purchase_price'] = float(child.find('Replacement_x0020_Value').text) - except AttributeError: - pass - - try: - defaults['salvage_value'] = float(child.find('SalvageValue').text) - except AttributeError: - pass - - try: - defaults['comments'] = child.find('Comments').text - except AttributeError: - pass - - try: - date = child.find('NextSchedMaint').text.split('T')[0] - defaults['next_sched_maint'] = datetime.datetime.strptime(date, '%Y-%m-%d').date() - except AttributeError: - pass - - print(defaults) - - obj, created = models.Asset.objects.update_or_create(**defaults) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Assets - Updated: {}, Created: {}'.format(tally[0], tally[1])) - - def import_collections(self): - tally = [0, 0] - root = self.parse_xml(self.xml_path('TEC_Cable_Collections.xml')) - - for child in root: - defaults = dict() - - defaults['pk'] = int(child.find('ID').text) - defaults['name'] = child.find('Cable_x0020_Trunk').text - - obj, created = models.Collection.objects.update_or_create(**defaults) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Collections - Updated: {}, Created: {}'.format(tally[0], tally[1])) - - def import_cables(self): - tally = [0, 0] - root = self.parse_xml(self.xml_path('TEC_Cables.xml')) - - for child in root: - defaults = dict() - - defaults['asset_id'] = child.find('Asset_x0020_Number').text - - try: - defaults['description'] = child.find('Type_x0020_of_x0020_Cable').text - except AttributeError: - defaults['description'] = 'None' - - defaults['is_cable'] = True - defaults['category'] = models.AssetCategory.objects.get(pk=9) - - try: - defaults['length'] = child.find('Length_x0020__x0028_m_x0029_').text - except AttributeError: - pass - - defaults['status'] = models.AssetStatus.objects.get(pk=int(child.find('Status').text)) - - try: - defaults['comments'] = child.find('Comments').text - except AttributeError: - pass - - try: - collection_id = int(child.find('Collection').text) - if collection_id != 0: - defaults['collection'] = models.Collection.objects.get(pk=collection_id) - except AttributeError: - pass - - try: - defaults['purchase_price'] = float(child.find('Purchase_x0020_Price').text) - except AttributeError: - pass - - defaults['date_acquired'] = self.epoch - - print(defaults) - - obj, created = models.Asset.objects.update_or_create(**defaults) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Collections - Updated: {}, Created: {}'.format(tally[0], tally[1])) diff --git a/assets/management/commands/update_old_db_file.py b/assets/management/commands/update_old_db_file.py deleted file mode 100644 index bff0fe22..00000000 --- a/assets/management/commands/update_old_db_file.py +++ /dev/null @@ -1,110 +0,0 @@ -import os -import datetime -import xml.etree.ElementTree as ET -from django.core.management.base import BaseCommand -from django.conf import settings - - -class Command(BaseCommand): - help = 'Imports old db from XML dump' - - epoch = datetime.date(1970, 1, 1) - - def handle(self, *args, **options): - # self.update_statuses() - # self.update_suppliers() - self.update_cable_statuses() - - @staticmethod - def xml_path(file): - return os.path.join(settings.BASE_DIR, 'data/DB_Dump/{}'.format(file)) - - @staticmethod - def parse_xml(file): - tree = ET.parse(file) - - return tree.getroot() - - def update_statuses(self): - file = self.xml_path('TEC_Assets.xml') - tree = ET.parse(file) - root = tree.getroot() - - # map old status pk to new status pk - status_map = { - 2: 2, - 3: 4, - 4: 3, - 5: 5, - 6: 1 - } - - for child in root: - status = int(child.find('StatusID').text) - child.find('StatusID').text = str(status_map[status]) - - tree.write(file) - - def update_suppliers(self): - old_file = self.xml_path('TEC_Asset_Suppliers.xml') - old_tree = ET.parse(old_file) - old_root = old_tree.getroot() - - new_file = self.xml_path('TEC_Asset_Suppliers_new.xml') - new_tree = ET.parse(new_file) - new_root = new_tree.getroot() - - # map old supplier pk to new supplier pk - supplier_map = dict() - - def find_in_old(name, root): - for child in root: - found_id = child.find('Supplier_x0020_Id').text - found_name = child.find('Supplier_x0020_Name').text - - if found_name == name: - return found_id - - for new_child in new_root: - new_id = new_child.find('Supplier_x0020_Id').text - new_name = new_child.find('Supplier_x0020_Name').text - - old_id = find_in_old(new_name, old_root) - - supplier_map[int(old_id)] = int(new_id) - - file = self.xml_path('TEC_Assets.xml') - tree = ET.parse(file) - root = tree.getroot() - - for child in root: - try: - supplier = int(child.find('Supplier_x0020_Id').text) - child.find('Supplier_x0020_Id').text = str(supplier_map[supplier]) - except AttributeError: - pass - - tree.write(file) - - def update_cable_statuses(self): - file = self.xml_path('TEC_Cables.xml') - tree = ET.parse(file) - root = tree.getroot() - - # map old status pk to new status pk - status_map = { - 0: 7, - 1: 3, - 3: 2, - 4: 5, - 6: 6, - 7: 1, - 8: 4, - 9: 2, - } - - for child in root: - status = int(child.find('Status').text) - child.find('Status').text = str(status_map[status]) - - tree.write(file) diff --git a/assets/templates/asset_create.html b/assets/templates/asset_create.html index bc953d2d..14b4b66a 100644 --- a/assets/templates/asset_create.html +++ b/assets/templates/asset_create.html @@ -1,6 +1,5 @@ {% extends 'base_assets.html' %} {% load widget_tweaks %} -{% load asset_templatetags %} {% block title %}Asset {{ object.asset_id }}{% endblock %} {% block content %} diff --git a/assets/templates/asset_update.html b/assets/templates/asset_update.html index 6e950887..4f576130 100644 --- a/assets/templates/asset_update.html +++ b/assets/templates/asset_update.html @@ -1,6 +1,5 @@ {% extends 'base_assets.html' %} {% load widget_tweaks %} -{% load asset_templatetags %} {% block title %}Asset {{ object.asset_id }}{% endblock %} {% block content %} @@ -40,7 +39,6 @@
{% include 'partials/asset_buttons.html' %} -
diff --git a/assets/templates/partials/asset_form.html b/assets/templates/partials/asset_form.html index 08f82d18..45424992 100644 --- a/assets/templates/partials/asset_form.html +++ b/assets/templates/partials/asset_form.html @@ -1,5 +1,4 @@ {% load widget_tweaks %} -{% load asset_templatetags %}
Asset Details diff --git a/assets/templates/partials/cable_form.html b/assets/templates/partials/cable_form.html index 9390a73c..e5deb006 100644 --- a/assets/templates/partials/cable_form.html +++ b/assets/templates/partials/cable_form.html @@ -1,5 +1,4 @@ {% load widget_tweaks %} -{% load asset_templatetags %}
Cable Details diff --git a/assets/templates/partials/parent_form.html b/assets/templates/partials/parent_form.html index c21e0ab1..f252db36 100644 --- a/assets/templates/partials/parent_form.html +++ b/assets/templates/partials/parent_form.html @@ -1,5 +1,4 @@ {% load widget_tweaks %} -{% load asset_templatetags %}
Collection Details diff --git a/assets/templates/partials/purchasedetails_form.html b/assets/templates/partials/purchasedetails_form.html index b098e656..a19dfa1f 100644 --- a/assets/templates/partials/purchasedetails_form.html +++ b/assets/templates/partials/purchasedetails_form.html @@ -1,5 +1,4 @@ {% load widget_tweaks %} -{% load asset_templatetags %} {% load static %} diff --git a/assets/templatetags/__init__.py b/assets/templatetags/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/assets/templatetags/asset_templatetags.py b/assets/templatetags/asset_templatetags.py deleted file mode 100644 index 905f9ce2..00000000 --- a/assets/templatetags/asset_templatetags.py +++ /dev/null @@ -1,21 +0,0 @@ -from django import template -from django.template.defaultfilters import stringfilter -from django.utils.safestring import SafeData, mark_safe -from django.utils.text import normalize_newlines -from django.utils.html import escape - -register = template.Library() - - -@register.filter(is_safe=True, needs_autoescape=True) -@stringfilter -def linebreaksn(value, autoescape=True): - """ - Convert all newlines in a piece of plain text to jQuery line breaks - (`\n`). - """ - autoescape = autoescape and not isinstance(value, SafeData) - value = normalize_newlines(value) - if autoescape: - value = escape(value) - return mark_safe(value.replace('\n', '\\n'))