From e0d351410c20a03b8dbe86284bfb096658db485a Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Fri, 2 Aug 2019 15:37:45 -0700 Subject: [PATCH 1/3] products/models.py: remove big sql comment --- products/models.py | 48 ---------------------------------------------- 1 file changed, 48 deletions(-) diff --git a/products/models.py b/products/models.py index c129f8e..04e5fc6 100644 --- a/products/models.py +++ b/products/models.py @@ -38,51 +38,3 @@ class Product(models.Model): } -""" - create view adilog_product as - SELECT DISTINCT ks.style AS id, ks.sap_article_number, - (((kr.ranksection || '-'::text) || kr.rankcategory) || '-'::text) || kr.modelrank - AS grouping_number, - km.name AS short_name, kr.model, kr.color, - kr.category AS product_type, km.category AS model_product_type, - kr.men_women AS gender, kr.segmentation AS segment, ks.color_name AS colorway, - km.summary AS blurb, km.description, - km.tech_icon_1, km.tech_icon_2, km.tech_icon_3, km.tech_icon_4, - km.tech_icon_5, km.tech_icon_6, km.tech_icon_7, km.tech_icon_8, - km.tech_icon_9, km.tech_icon_10, km.tech_icon_11, km.tech_icon_12, - km.tech_icon_13, km.tech_icon_14, km.tech_icon_15, - km.sizing AS size, - km.tech_call_out_1 AS point0, km.tech_call_out_2 AS point1, - km.tech_call_out_3 AS point2, km.tech_call_out_4 AS point3, - km.tech_call_out_5 AS point4, km.tech_call_out_6 AS point5, - km.tech_call_out_7 AS point6, km.tech_call_out_8 AS point7, - km.tech_call_out_9 AS point8, km.tech_call_out_10 AS point9, - km.tech_call_out_11 AS point10, km.tech_call_out_12 AS point11, - km.tech_call_out_13 AS point12, km.tech_call_out_14 AS point13, - km.tech_call_out_15 AS point14, km.tech_call_out_16 AS point15, - km.tech_call_out_17 AS point16, km.tech_call_out_18 AS point17, - km.tech_call_out_19 AS point18, km.tech_call_out_20 AS point19, - kr.modelstatus, kr.stylestatus, kr.hero, kr.alt_hero, ks.hero AS stylehero, - kr.stylerank, km.relatedkidsmodel1, km.relatedkidsmodel2, - km.dimensions, km.height, km.weight, km.capacity, km.origin, km.fiber, - km.upper, km.lining, km.tooling, kr.in_current_season, km.imageistall, - km.retail, km.wholesale, kr.country, kr.pagination, km.legal, -- km.legal2, - km.duty_type, - km.heavy_metal_fabrication, - km.masonry, - km.energy, - km.construction, - km.utilities, - km.landscaping, - km.transportation, - km.maintenance, - km.manufacturing, - km.warehouse_distribution, - km.service, --- km.public_safety_duty, - km.extra_1, km.extra_2, km.extra_3, km.extra_4, km.extra_5, km.extra_6, - km.product_family - FROM keen_ranking kr - JOIN keen_style ks ON kr.style = ks.sap_article_number - JOIN keen_model km ON kr.model = km.model; -""" From 02a4080c487d7947832583da8b22a1558071ab63 Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Fri, 2 Aug 2019 15:38:26 -0700 Subject: [PATCH 2/3] products/models.py: add basic product image classes --- products/models.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/products/models.py b/products/models.py index 04e5fc6..8426a66 100644 --- a/products/models.py +++ b/products/models.py @@ -1,5 +1,7 @@ import logging import re +from enum import Enum +import os.path from django.conf import settings from django.db import models @@ -38,3 +40,33 @@ class Product(models.Model): } +class ProductImageFormat(Enum): + THUMB_PNG = 'thumb.png' + LARGE_JPG = 'large.jpg' + LARGE_PNG = 'large.png' + MED_JPG = 'med.jpg' + MED_PNG = 'med.png' + + +class ProductImage: + THUMB_DIR = os.path.join(settings.ASSET_DIR, 'products/thumbs') + THUMB_URL = '/images/products/thumbs' + # ordered by thumbnail preference + VIEW_TYPES = ['C', '3Q', '3QL', '3QR', '3QRL', 'P', 'PL', 'P2', 'P2L', + 'F3Q', 'L', 'PLA', 'PPS', 'PPS_WORN', 'PLD', 'OS', 'OSL', + 'T', 'TL', 'PACK', 'F', 'B', 'INT', 'ALT_INT', 'FLR', + 'FRONT', 'BACK'] + + @staticmethod + def get_image_path(sap, image_format): + for view in ProductImage.VIEW_TYPES: + path = os.path.join(ProductImage.THUMB_DIR, + '{}_{}-{}'.format(sap, view, image_format.value)) + if os.path.isfile(path): + return path + + @staticmethod + def get_image_url(sap, image_format): + path = ProductImage.get_image_path(sap, image_format) + if path: + return path.replace(ProductImage.THUMB_DIR, ProductImage.THUMB_URL) From 6c23d30897fc02fa812d51eab7955fc4e067f35b Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Fri, 2 Aug 2019 15:40:51 -0700 Subject: [PATCH 3/3] add quickinfo app --- procat2/settings.py | 1 + procat2/urls.py | 2 + quickinfo/__init__.py | 0 quickinfo/apps.py | 5 ++ quickinfo/migrations/__init__.py | 0 quickinfo/tests.py | 26 ++++++++++ quickinfo/urls.py | 8 +++ quickinfo/views.py | 37 ++++++++++++++ templates/quickinfo/result.html | 85 ++++++++++++++++++++++++++++++++ templates/quickinfo/search.html | 24 +++++++++ 10 files changed, 188 insertions(+) create mode 100644 quickinfo/__init__.py create mode 100644 quickinfo/apps.py create mode 100644 quickinfo/migrations/__init__.py create mode 100644 quickinfo/tests.py create mode 100644 quickinfo/urls.py create mode 100644 quickinfo/views.py create mode 100644 templates/quickinfo/result.html create mode 100644 templates/quickinfo/search.html diff --git a/procat2/settings.py b/procat2/settings.py index 3618e33..67e2223 100644 --- a/procat2/settings.py +++ b/procat2/settings.py @@ -102,6 +102,7 @@ INSTALLED_APPS = [ 'procat2', 'dashboard', 'products', + 'quickinfo', ] MIDDLEWARE = [ diff --git a/procat2/urls.py b/procat2/urls.py index 143e885..a2334b1 100644 --- a/procat2/urls.py +++ b/procat2/urls.py @@ -48,6 +48,8 @@ urlpatterns = [ path("account/", include("account.urls")), path('convert/', convert, { 'form_class': UserCreationForm }, name='lazysignup_convert'), path('convert/done/', lazy_convert_done, name='lazysignup_convert_done'), + + path('quickinfo/', include('quickinfo.urls')), ] if settings.DJDT: diff --git a/quickinfo/__init__.py b/quickinfo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/quickinfo/apps.py b/quickinfo/apps.py new file mode 100644 index 0000000..204220b --- /dev/null +++ b/quickinfo/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class QuickinfoConfig(AppConfig): + name = 'quickinfo' diff --git a/quickinfo/migrations/__init__.py b/quickinfo/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/quickinfo/tests.py b/quickinfo/tests.py new file mode 100644 index 0000000..1d09bfd --- /dev/null +++ b/quickinfo/tests.py @@ -0,0 +1,26 @@ +from django.test import SimpleTestCase + +from . import views + + +class IDCleanTest(SimpleTestCase): + + def test_clean_nothing(self): + self.assertEqual(None, views.clean_id(None)) + + def test_clean_digit(self): + self.assertEqual('1', views.clean_id('1')) + + def test_clean_character(self): + self.assertEqual(None, views.clean_id('a')) + + def test_clean_digits(self): + self.assertEqual('123456', views.clean_id('123456')) + + def test_clean_digits_space(self): + self.assertEqual('123456', views.clean_id("\t 123456 \t ")) + + def test_clean_multiple(self): + self.assertEqual('123456', views.clean_id('123456 2')) + self.assertEqual('123456', views.clean_id('123456,2')) + self.assertEqual('123456', views.clean_id('123456b2x')) diff --git a/quickinfo/urls.py b/quickinfo/urls.py new file mode 100644 index 0000000..206515d --- /dev/null +++ b/quickinfo/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('search', views.search, name='quickinfo_search'), + path('result', views.result, name='quickinfo_result'), +] diff --git a/quickinfo/views.py b/quickinfo/views.py new file mode 100644 index 0000000..63a0ce9 --- /dev/null +++ b/quickinfo/views.py @@ -0,0 +1,37 @@ +import re + +from django.shortcuts import render, get_object_or_404 +from django.core.exceptions import ObjectDoesNotExist + +from products.models import Product, ProductImage, ProductImageFormat + + +def search(request): + return render(request, 'quickinfo/search.html') + + +def result(request): + id = clean_id(request.GET['id']) + + context = { + 'id': id, + } + + try: + context['prod'] = Product.objects.filter(sap=id).first() + except ObjectDoesNotExist: + context['prod'] = None + + context['image'] = ProductImage.get_image_url(id, ProductImageFormat.MED_JPG) + + return render(request, 'quickinfo/result.html', context) + + +def clean_id(text): + if not text: return None + + words = list(filter(None, re.compile(r'[^\d]').split(text))) + if len(words): + return words[0] + else: + return None diff --git a/templates/quickinfo/result.html b/templates/quickinfo/result.html new file mode 100644 index 0000000..37f599c --- /dev/null +++ b/templates/quickinfo/result.html @@ -0,0 +1,85 @@ +{% load staticfiles i18n %} + + + + + + {{ settings.CUSTOMER_NAME }} ProCatalog: {% trans "Material Search"%}: {{ id }} + + + + +
+ + {% if image %} +
+ +
+ {% else %} +

Image not found

+ {% endif %} +
+ {% if prod %} +

{{ prod.name }}

+

{{ prod.sap }}

+

{{ prod.gender | title }} {{ prod.category | title }}

+

{{ prod.color }}

+ {% else %} +

{{ id }}

+

No data

+ {% endif %} +
+
+ + diff --git a/templates/quickinfo/search.html b/templates/quickinfo/search.html new file mode 100644 index 0000000..5365fc2 --- /dev/null +++ b/templates/quickinfo/search.html @@ -0,0 +1,24 @@ +{% load staticfiles i18n %} + + + + + + {{ settings.CUSTOMER_NAME }} ProCatalog: {% trans "Material Search"%} + + + + + {% trans "KEEN Quick Image Search" %} + {% trans "please input material number" %} +
+ + +
+ +