Skip to content

Instantly share code, notes, and snippets.

@mdornseif
Last active January 14, 2016 16:15
Show Gist options
  • Save mdornseif/32252707d34b5cec0e54 to your computer and use it in GitHub Desktop.
Save mdornseif/32252707d34b5cec0e54 to your computer and use it in GitHub Desktop.
diff --git i/modules/market/mk_forms.py w/modules/market/mk_forms.py
index dd3646a..e78a8d8 100644
--- i/modules/market/mk_forms.py
+++ w/modules/market/mk_forms.py
@@ -6,6 +6,8 @@ modules/market/mk_forms.py
Created by Christian Klein on 2015-12-01.
Copyright (c) 2015 HUDORA GmbH. All rights reserved.
"""
+import logging
+
import huTools.checksumming
import wtforms
@@ -28,6 +30,10 @@ class UniqueMPN(object):
mk_Product.mpn == field.data)
product = query.get()
if product and product != self.product:
+ logging.debug("product: %r", product )
+ logging.debug("self.product: %r", self.product)
+ logging.debug("self.source.source_id:%r", self.source.source_id,)
+ logging.debug("field.data:%r", field.data)
raise wtforms.validators.ValidationError(u'MPN muss eindeutig sein')
@@ -47,6 +53,7 @@ class BrandValidator(object):
def __call__(self, form, field):
"""Überprüfe, ob der Lieferant die angegebene Marke vertreiben darf."""
if field.data not in self.source.brands:
+ logging.debug("%r %r %r", self.source.source_id, self.source.brands, field.data)
raise wtforms.validators.ValidationError(
u'Sie haben keine Berechtigung für die Marke {}'.format(field.data))
@@ -57,7 +64,7 @@ ProductForm = model_form(
mk_Product,
only=['name', 'brand', 'description', 'gtin13', 'preis', 'menge_verfuegbar', 'liefertage', 'sperrgut'],
field_args=dict(
- gtin13=dict(label=u'GTIN-13', validators=[ean_validator, wtforms.validators.Optional()]),
+ gtin13=dict(label=u'EAN', validators=[ean_validator, wtforms.validators.Optional()]),
)
)
@@ -85,6 +92,7 @@ def get_form(source, product=None, *args, **kwargs):
Fügt dynamisch erzeugten Validator für MPN ein.
"""
form = ProductCreateForm(*args, **kwargs)
+ logging.debug("get_form: %r", source.source_id)
form.mpn.validators.append(UniqueMPN(source, product=product))
form.brand.choices = [(brand, brand) for brand in source.brands]
form.brand.validators.insert(0, BrandValidator(source))
diff --git i/modules/market/mkb_views.py w/modules/market/mkb_views.py
index ff0aa39..070c35f 100644
--- i/modules/market/mkb_views.py
+++ w/modules/market/mkb_views.py
@@ -113,18 +113,21 @@ class ListProducts(AuthenticatedHandler):
class ShowProduct(AuthenticatedHandler):
"""Produkt Administrationanzeigen"""
- def get(self, source_id, sku, fmt='html'):
- """Template anzeigen"""
- source = mk_models.get_source(source_id)
-
+ def get_product(self, source_id, sku):
+ assert self.source.source_id == source_id
product = mk_models.mk_Product.get_by_id(sku)
if not product:
raise gaetk.handler.HTTP404_NotFound
elif product.source != source_id:
raise gaetk.handler.HTTP403_Forbidden
+ return product
+
+ def get(self, source_id, sku, fmt='html'):
+ """Template anzeigen"""
+ product = self.get_product(source_id, sku)
if not product.liefertage:
- product.liefertage = source.liefertage_default
+ product.liefertage = self.source.liefertage_default
self.multirender(
fmt, dict(product=product),
@@ -137,15 +140,7 @@ class ShowProduct(AuthenticatedHandler):
def post(self, source_id, sku, fmt='html'):
"""Formular validieren"""
- source = mk_models.get_source(source_id)
- if source.key != self.credential.source:
- raise gaetk.handler.HTTP403_Forbidden
-
- product = mk_models.mk_Product.get_by_id(sku)
- if not product:
- raise gaetk.handler.HTTP404_NotFound
- elif product.source != source_id:
- raise gaetk.handler.HTTP403_Forbidden
+ product = self.get_product(source_id, sku)
# TODO: Das ist noch ein bisschen hacky:
self.request.POST.add('mpn', product.mpn)
@@ -153,6 +148,8 @@ class ShowProduct(AuthenticatedHandler):
form = mk_forms.get_form(self.source, product=product, formdata=self.request.POST, mpn=product.mpn)
if form.validate():
form.populate_obj(product)
+ if product.liefertage == self.source.liefertage_default:
+ product.liefertage = None
product.put()
raise gaetk.handler.HTTP302_Found(location='/mkb/{}/p/{}.{}'.format(source_id, sku, fmt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment