Merge branch 'quickinfo'

This commit is contained in:
Seth Ladygo
2019-08-02 15:45:49 -07:00
11 changed files with 220 additions and 48 deletions

View File

@ -102,6 +102,7 @@ INSTALLED_APPS = [
'procat2',
'dashboard',
'products',
'quickinfo',
]
MIDDLEWARE = [

View File

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

View File

@ -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,51 +40,33 @@ 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;
"""
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)

0
quickinfo/__init__.py Normal file
View File

5
quickinfo/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class QuickinfoConfig(AppConfig):
name = 'quickinfo'

View File

26
quickinfo/tests.py Normal file
View File

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

8
quickinfo/urls.py Normal file
View File

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

37
quickinfo/views.py Normal file
View File

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

View File

@ -0,0 +1,85 @@
{% load staticfiles i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ settings.CUSTOMER_NAME }} ProCatalog: {% trans "Material Search"%}: {{ id }}</title>
<link href="{% static 'img/favicon.ico' %}" rel="shortcut icon" />
<style>
html, body {
font-family: sans-serif;
height: 100%;
padding: 10px;
background-color: #535353;
}
#both {
width: 400px;
background-color: #fff;
box-shadow: 8px 8px 12px 0 rgba(0, 0, 0, 0.3);
position: relative;
}
#image {
padding: 15px;
}
#data {
border-top: 4px solid hsl(52, 100%, 50%);
background-color: #e1e1e1;
padding: 10px 15px;
}
img {
max-width: 100%;
max-height: 100%;
}
p {
font-size: 12pt;
margin: 0;
line-height: 1.75;
}
p.large {
font-size: 16pt;
}
p.notfound {
padding: 18px 15px;
color: #777;
}
img.logo {
float: right;
margin: 0;
padding: 0;
position: absolute;
top: 15px;
right: 15px;
z-index: 5;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
</style>
</head>
<body>
<div id="both">
<img class="logo" src="/static/img/keen_logo.svg" width="90">
{% if image %}
<div id="image">
<a href="{{ image }}"><img src="{{ image }}"/></a>
</div>
{% else %}
<p class="notfound">Image not found</p>
{% endif %}
<div id="data">
{% if prod %}
<p class="large"><b>{{ prod.name }}</b></p>
<p>{{ prod.sap }}</p>
<p>{{ prod.gender | title }} {{ prod.category | title }}</p>
<p>{{ prod.color }}</p>
{% else %}
<p class="large"><b>{{ id }}</b></p>
<p>No data</p>
{% endif %}
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,24 @@
{% load staticfiles i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ settings.CUSTOMER_NAME }} ProCatalog: {% trans "Material Search"%}</title>
<link href="{% static 'img/favicon.ico' %}" rel="shortcut icon" />
<style>
html {
background-color: white;
font-family: sans-serif;
}
</style>
</head>
<body>
<b>{% trans "KEEN Quick Image Search" %}</b>
<font size="-2"> {% trans "please input material number" %}</font>
<form action="{% url 'quickinfo_result' %}" method='get'>
<input type="text" name="id">
<input type="submit" value="Go">
</form>
</body>
</html>