Merge branch 'quickinfo'
This commit is contained in:
@ -102,6 +102,7 @@ INSTALLED_APPS = [
|
|||||||
'procat2',
|
'procat2',
|
||||||
'dashboard',
|
'dashboard',
|
||||||
'products',
|
'products',
|
||||||
|
'quickinfo',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
@ -48,6 +48,8 @@ urlpatterns = [
|
|||||||
path("account/", include("account.urls")),
|
path("account/", include("account.urls")),
|
||||||
path('convert/', convert, { 'form_class': UserCreationForm }, name='lazysignup_convert'),
|
path('convert/', convert, { 'form_class': UserCreationForm }, name='lazysignup_convert'),
|
||||||
path('convert/done/', lazy_convert_done, name='lazysignup_convert_done'),
|
path('convert/done/', lazy_convert_done, name='lazysignup_convert_done'),
|
||||||
|
|
||||||
|
path('quickinfo/', include('quickinfo.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DJDT:
|
if settings.DJDT:
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
from enum import Enum
|
||||||
|
import os.path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -38,51 +40,33 @@ class Product(models.Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"""
|
class ProductImageFormat(Enum):
|
||||||
create view adilog_product as
|
THUMB_PNG = 'thumb.png'
|
||||||
SELECT DISTINCT ks.style AS id, ks.sap_article_number,
|
LARGE_JPG = 'large.jpg'
|
||||||
(((kr.ranksection || '-'::text) || kr.rankcategory) || '-'::text) || kr.modelrank
|
LARGE_PNG = 'large.png'
|
||||||
AS grouping_number,
|
MED_JPG = 'med.jpg'
|
||||||
km.name AS short_name, kr.model, kr.color,
|
MED_PNG = 'med.png'
|
||||||
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,
|
class ProductImage:
|
||||||
km.tech_icon_1, km.tech_icon_2, km.tech_icon_3, km.tech_icon_4,
|
THUMB_DIR = os.path.join(settings.ASSET_DIR, 'products/thumbs')
|
||||||
km.tech_icon_5, km.tech_icon_6, km.tech_icon_7, km.tech_icon_8,
|
THUMB_URL = '/images/products/thumbs'
|
||||||
km.tech_icon_9, km.tech_icon_10, km.tech_icon_11, km.tech_icon_12,
|
# ordered by thumbnail preference
|
||||||
km.tech_icon_13, km.tech_icon_14, km.tech_icon_15,
|
VIEW_TYPES = ['C', '3Q', '3QL', '3QR', '3QRL', 'P', 'PL', 'P2', 'P2L',
|
||||||
km.sizing AS size,
|
'F3Q', 'L', 'PLA', 'PPS', 'PPS_WORN', 'PLD', 'OS', 'OSL',
|
||||||
km.tech_call_out_1 AS point0, km.tech_call_out_2 AS point1,
|
'T', 'TL', 'PACK', 'F', 'B', 'INT', 'ALT_INT', 'FLR',
|
||||||
km.tech_call_out_3 AS point2, km.tech_call_out_4 AS point3,
|
'FRONT', 'BACK']
|
||||||
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,
|
@staticmethod
|
||||||
km.tech_call_out_9 AS point8, km.tech_call_out_10 AS point9,
|
def get_image_path(sap, image_format):
|
||||||
km.tech_call_out_11 AS point10, km.tech_call_out_12 AS point11,
|
for view in ProductImage.VIEW_TYPES:
|
||||||
km.tech_call_out_13 AS point12, km.tech_call_out_14 AS point13,
|
path = os.path.join(ProductImage.THUMB_DIR,
|
||||||
km.tech_call_out_15 AS point14, km.tech_call_out_16 AS point15,
|
'{}_{}-{}'.format(sap, view, image_format.value))
|
||||||
km.tech_call_out_17 AS point16, km.tech_call_out_18 AS point17,
|
if os.path.isfile(path):
|
||||||
km.tech_call_out_19 AS point18, km.tech_call_out_20 AS point19,
|
return path
|
||||||
kr.modelstatus, kr.stylestatus, kr.hero, kr.alt_hero, ks.hero AS stylehero,
|
|
||||||
kr.stylerank, km.relatedkidsmodel1, km.relatedkidsmodel2,
|
@staticmethod
|
||||||
km.dimensions, km.height, km.weight, km.capacity, km.origin, km.fiber,
|
def get_image_url(sap, image_format):
|
||||||
km.upper, km.lining, km.tooling, kr.in_current_season, km.imageistall,
|
path = ProductImage.get_image_path(sap, image_format)
|
||||||
km.retail, km.wholesale, kr.country, kr.pagination, km.legal, -- km.legal2,
|
if path:
|
||||||
km.duty_type,
|
return path.replace(ProductImage.THUMB_DIR, ProductImage.THUMB_URL)
|
||||||
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;
|
|
||||||
"""
|
|
||||||
|
|||||||
0
quickinfo/__init__.py
Normal file
0
quickinfo/__init__.py
Normal file
5
quickinfo/apps.py
Normal file
5
quickinfo/apps.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class QuickinfoConfig(AppConfig):
|
||||||
|
name = 'quickinfo'
|
||||||
0
quickinfo/migrations/__init__.py
Normal file
0
quickinfo/migrations/__init__.py
Normal file
26
quickinfo/tests.py
Normal file
26
quickinfo/tests.py
Normal 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
8
quickinfo/urls.py
Normal 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
37
quickinfo/views.py
Normal 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
|
||||||
85
templates/quickinfo/result.html
Normal file
85
templates/quickinfo/result.html
Normal 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>
|
||||||
24
templates/quickinfo/search.html
Normal file
24
templates/quickinfo/search.html
Normal 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>
|
||||||
Reference in New Issue
Block a user