add quickinfo app
This commit is contained in:
@ -102,6 +102,7 @@ INSTALLED_APPS = [
|
||||
'procat2',
|
||||
'dashboard',
|
||||
'products',
|
||||
'quickinfo',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@ -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:
|
||||
|
||||
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