Example #1
0
File: taxes.py Project: hforge/shop
 def get_namespace(self, datatype, value):
     # XXX Hack to get tax value (and keep it when submit form)
     context = get_context()
     submit = (context.method == 'POST')
     prefix = self.prefix
     if submit:
         tax_value = context.get_form_value('%stax' % prefix, type=TaxesEnumerate)
         has_reduction = context.get_form_value('%shas_reduction' % prefix, type=Boolean)
         reduce_pre_tax_price = context.get_form_value('%sreduce-pre-tax-price' % prefix)
     else:
         tax_value = context.resource.get_property('%stax' % prefix)
         has_reduction = context.resource.get_property('%shas_reduction' % prefix)
         reduce_pre_tax_price = context.resource.get_property('%sreduce-pre-tax-price' % prefix)
     taxes = SelectWidget('%stax' % prefix, css='tax-widget', has_empty_option=False)
     # Devise
     shop = get_shop(context.resource)
     devise = shop.get_property('devise')
     symbol = Devises.get_symbol(devise)
     # Return namespace
     return {'widget_name': self.name,
             'pre-tax-price': value,
             'prefix': prefix,
             'devise': symbol,
             'reduce-pre-tax-price': reduce_pre_tax_price,
             'has_reduction': has_reduction,
             'taxes': taxes.to_html(TaxesEnumerate, tax_value)}
Example #2
0
 def action_import_ods(self, resource, context, form):
     # Check if lpod is install ?
     if lpod_is_install is False:
         msg = ERROR(u'Please install LPOD')
         return context.come_back(msg)
     # Get models
     root = context.root
     shop = get_shop(resource)
     models = shop.get_resource('products-models').get_resources()
     # Open ODF file
     filename, mimetype, body = form['file']
     f = StringIO(body)
     document = odf_get_document(f)
     for table in document.get_body().get_tables():
         model_name = table.get_name()
         csv = CSVFile(string=table.to_csv())
         for row in csv.get_rows():
             reference = row[0]
             declination_name = row[1]
             stock = row[-3]
             price1 = row[-2]
             price2 = row[-1]
             product_brains = root.search(reference=reference).get_documents()
             if len(product_brains) > 1:
                 print 'Reference %s %s' % (reference, len(product_brains))
                 continue
             product_brain = product_brains[0]
             product = root.get_resource(product_brain.abspath)
             declination = product.get_resource(declination_name)
             # Set change
             declination.set_property('stock-quantity', int(stock))
     context.message = MSG(u'Import has been done')
     return
Example #3
0
    def is_valid(cls, value):
        # Get private key
        context = get_context()
        shop = get_shop(context.resource)
        recaptcha_modules = shop.get_resource('modules/recaptcha')
        private_key = recaptcha_modules.get_property('private_key')
        # Get remote ip
        remote_ip = context.get_remote_ip() or '127.0.0.1'
        # Get Captcha fields
        recaptcha_challenge_field = context.get_form_value(
            'recaptcha_challenge_field', type=String)
        recaptcha_response_field = context.get_form_value(
            'recaptcha_response_field', type=String)
        # Test if captcha value is valid
        params = urllib.urlencode ({
                'privatekey': private_key,
                'remoteip' :  remote_ip,
                'challenge':  recaptcha_challenge_field,
                'response' :  recaptcha_response_field,
                })

        request = urllib2.Request (
            url = "http://api-verify.recaptcha.net/verify",
            data = params,
            headers = {
                "Content-type": "application/x-www-form-urlencoded",
                "User-agent": "reCAPTCHA Python"
                }
            )
        httpresp = urllib2.urlopen (request)
        return_values = httpresp.read ().splitlines ();
        httpresp.close();
        return_code = return_values [0]
        return return_code == 'true'
Example #4
0
 def get_price_prefix(self):
     shop = get_shop(self)
     context = get_context()
     group_name = get_group_name(shop, context)
     if get_uri_name(group_name) == 'pro':
         return 'pro-'
     return ''
Example #5
0
    def action(self, resource, context, form):
        name = self.get_new_resource_name(form)
        cls = ShopModule_AReport
        child = cls.make_resource(cls, resource, name)
        # The metadata
        metadata = child.metadata
        language = resource.get_content_language(context)

        # Anonymous ? Accepted XXX
        if context.user:
            metadata.set_property('author', context.user.name)
        # Workflow
        metadata.set_property('ctime', datetime.now())
        metadata.set_property('description', form['description'], language)
        metadata.set_property('remote_ip', context.get_remote_ip())

        # Notification
        shop = get_shop(resource)
        subject = MSG(u'A report on a review has been made').gettext()
        body = MSG(u'Go on your backoffice to see it.').gettext()
        for to_addr in shop.get_property('order_notification_mails'):
            context.root.send_email(to_addr, subject, text=body)

        goto = context.get_link(resource.parent)
        message = MSG(u'Your report has been added')
        return context.come_back(message, goto=goto)
Example #6
0
 def action_import_ods(self, resource, context, form):
     # Check if lpod is install ?
     if lpod_is_install is False:
         msg = ERROR(u'Please install LPOD')
         return context.come_back(msg)
     # Get models
     root = context.root
     shop = get_shop(resource)
     models = shop.get_resource('products-models').get_resources()
     # Open ODF file
     filename, mimetype, body = form['file']
     f = StringIO(body)
     document = odf_get_document(f)
     for table in document.get_body().get_tables():
         model_name = table.get_name()
         csv = CSVFile(string=table.to_csv())
         for row in csv.get_rows():
             reference = row[0]
             declination_name = row[1]
             stock = row[-3]
             price1 = row[-2]
             price2 = row[-1]
             product_brains = root.search(
                 reference=reference).get_documents()
             if len(product_brains) > 1:
                 print 'Reference %s %s' % (reference, len(product_brains))
                 continue
             product_brain = product_brains[0]
             product = root.get_resource(product_brain.abspath)
             declination = product.get_resource(declination_name)
             # Set change
             declination.set_property('stock-quantity', int(stock))
     context.message = MSG(u'Import has been done')
     return
Example #7
0
 def generate_pdf_order(self, context):
     shop = get_shop(self)
     # Delete old pdf
     if self.get_resource('order', soft=True):
         self.del_resource('order')
     # Get template
     document = self.get_resource('/ui/backoffice/orders/order_pdf.xml')
     # Build namespace
     path = context.database.fs.get_absolute_path(self.handler.key)
     namespace = self.get_namespace(context)
     for product in namespace['products']:
         product['key'] = context.database.fs.get_absolute_path(
             product['key'])
         product['cover']['key'] = context.database.fs.get_absolute_path(
             product['cover']['key'])
     namespace['logo'] = shop.get_pdf_logo_key(context)
     namespace['pdf_signature'] = format_for_pdf(
         shop.get_property('pdf_signature'))
     barcode = self.get_resource('barcode', soft=True)
     if barcode:
         key = barcode.handler.key
         path = context.database.fs.get_absolute_path(key)
         namespace['order_barcode'] = path
     else:
         namespace['order_barcode'] = None
     # Build pdf
     body = stl_pmltopdf(document, namespace=namespace)
     metadata = {'title': {'en': u'Bill'}, 'filename': 'order.pdf'}
     return PDF.make_resource(PDF, self, 'order', body=body, **metadata)
Example #8
0
 def get_purchase_options_namespace(self, declinations):
     namespace = []
     shop = get_shop(self)
     purchase_options_names = self.get_purchase_options_names()
     values = {}
     # Has declination ?
     if not declinations:
         return namespace
     # Get uniques purchase option values
     for declination in declinations:
         dynamic_schema = declination.get_dynamic_schema()
         for name in purchase_options_names:
             value = declination.get_dynamic_property(name, dynamic_schema)
             if not value:
                 continue
             if not values.has_key(name):
                 values[name] = set([])
             values[name].add(value)
     # Build datatype / widget
     enumerates_folder = shop.get_resource('enumerates')
     for name in purchase_options_names:
         if values.get(name) is None or len(values[name]) == 0:
             continue
         enumerate_table = enumerates_folder.get_resource(name)
         datatype = Restricted_EnumerateTable_to_Enumerate(
             enumerate_name=name, values=values[name])
         widget_cls = enumerate_table.widget_cls
         widget = widget_cls(name, has_empty_option=False)
         namespace.append({
             'title': enumerate_table.get_title(),
             'html': widget.to_html(datatype, None)
         })
     return namespace
Example #9
0
 def get_purchase_options_namespace(self, declinations):
     namespace = []
     shop = get_shop(self)
     purchase_options_names = self.get_purchase_options_names()
     values = {}
     # Has declination ?
     if not declinations:
         return namespace
     # Get uniques purchase option values
     for declination in declinations:
         dynamic_schema = declination.get_dynamic_schema()
         for name in purchase_options_names:
             value = declination.get_dynamic_property(name, dynamic_schema)
             if not value:
                 continue
             if not values.has_key(name):
                 values[name] = set([])
             values[name].add(value)
     # Build datatype / widget
     enumerates_folder = shop.get_resource('enumerates')
     for name in purchase_options_names:
         if values.get(name) is None or len(values[name]) == 0:
             continue
         enumerate_table = enumerates_folder.get_resource(name)
         datatype = Restricted_EnumerateTable_to_Enumerate(
                       enumerate_name=name, values=values[name])
         widget_cls = enumerate_table.widget_cls
         widget = widget_cls(name, has_empty_option=False)
         namespace.append(
             {'title': enumerate_table.get_title(),
              'html': widget.to_html(datatype, None)})
     return namespace
Example #10
0
 def onenter_open(self):
     context = get_context()
     shop = get_shop(self)
     root = context.root
     # Remove product from stock
     order_products = self.get_resource('products')
     get_value = order_products.handler.get_record_value
     for record in order_products.handler.get_records():
         name = get_value(record, 'name')
         product_resource = context.root.get_resource(name, soft=True)
         if product_resource is None:
             continue
         quantity = get_value(record, 'quantity')
         id_declination = get_value(record, 'declination')
         product_resource.remove_from_stock(quantity, id_declination)
     # E-Mail confirmation / notification -> Order creation
     customer_email = self.get_customer_email(context)
     # Build email informations
     kw = {'order_name': self.name}
     # Send confirmation to client
     kw['order_uri'] = self.get_frontoffice_uri()
     subject = mail_confirmation_title.gettext()
     body = mail_confirmation_body.gettext(**kw)
     root.send_email(customer_email, subject, text=body)
     # Send confirmation to the shop
     subject = mail_notification_title.gettext()
     kw['order_uri'] = self.get_backoffice_uri()
     body = mail_notification_body.gettext(**kw)
     for to_addr in shop.get_property('order_notification_mails'):
         root.send_email(to_addr, subject, text=body)
Example #11
0
    def action(self, resource, context, form):
        name = self.get_new_resource_name(form)
        cls = ShopModule_AReport
        child = cls.make_resource(cls, resource, name)
        # The metadata
        metadata = child.metadata
        language = resource.get_content_language(context)

        # Anonymous ? Accepted XXX
        if context.user:
            metadata.set_property('author', context.user.name)
        # Workflow
        metadata.set_property('ctime', datetime.now())
        metadata.set_property('description', form['description'], language)
        metadata.set_property('remote_ip', context.get_remote_ip())

        # Notification
        shop = get_shop(resource)
        subject = MSG(u'A report on a review has been made').gettext()
        body = MSG(u'Go on your backoffice to see it.').gettext()
        for to_addr in shop.get_property('order_notification_mails'):
            context.root.send_email(to_addr, subject, text=body)

        goto = context.get_link(resource.parent)
        message = MSG(u'Your report has been added')
        return context.come_back(message, goto=goto)
Example #12
0
 def get_namespace(self, datatype, value):
     # XXX Hack to get tax value (and keep it when submit form)
     context = get_context()
     submit = (context.method == 'POST')
     prefix = self.prefix
     if submit:
         tax_value = context.get_form_value('%stax' % prefix,
                                            type=TaxesEnumerate)
         has_reduction = context.get_form_value('%shas_reduction' % prefix,
                                                type=Boolean)
         reduce_pre_tax_price = context.get_form_value(
             '%sreduce-pre-tax-price' % prefix)
     else:
         tax_value = context.resource.get_property('%stax' % prefix)
         has_reduction = context.resource.get_property('%shas_reduction' %
                                                       prefix)
         reduce_pre_tax_price = context.resource.get_property(
             '%sreduce-pre-tax-price' % prefix)
     taxes = SelectWidget('%stax' % prefix,
                          css='tax-widget',
                          has_empty_option=False)
     # Devise
     shop = get_shop(context.resource)
     devise = shop.get_property('devise')
     symbol = Devises.get_symbol(devise)
     # Return namespace
     return {
         'widget_name': self.name,
         'pre-tax-price': value,
         'prefix': prefix,
         'devise': symbol,
         'reduce-pre-tax-price': reduce_pre_tax_price,
         'has_reduction': has_reduction,
         'taxes': taxes.to_html(TaxesEnumerate, tax_value)
     }
Example #13
0
 def onenter_open(self):
     context = get_context()
     shop = get_shop(self)
     root = context.root
     # Remove product from stock
     order_products = self.get_resource('products')
     get_value = order_products.handler.get_record_value
     for record in order_products.handler.get_records():
         name = get_value(record, 'name')
         product_resource = context.root.get_resource(name, soft=True)
         if product_resource is None:
             continue
         quantity = get_value(record, 'quantity')
         id_declination = get_value(record, 'declination')
         product_resource.remove_from_stock(quantity, id_declination)
     # E-Mail confirmation / notification -> Order creation
     customer_email = self.get_customer_email(context)
     # Build email informations
     kw = {'order_name': self.name}
     # Send confirmation to client
     kw['order_uri'] = self.get_frontoffice_uri()
     subject = mail_confirmation_title.gettext()
     body = mail_confirmation_body.gettext(**kw)
     root.send_email(customer_email, subject, text=body)
     # Send confirmation to the shop
     subject = mail_notification_title.gettext()
     kw['order_uri'] = self.get_backoffice_uri()
     body = mail_notification_body.gettext(**kw)
     for to_addr in shop.get_property('order_notification_mails'):
         root.send_email(to_addr, subject, text=body)
Example #14
0
 def get_namespace(self, datatype, value):
     context = get_context()
     total_price = self.total_price
     namespace = {'payments': [],
                  'title1': self.title1,
                  'title2': self.title2,
                  'total_price_with_tax': total_price['with_tax'] or None,
                  'total_price': total_price}
     payments = get_shop(context.resource).get_resource('payments')
     for mode in payments.search_resources(cls=PaymentWay):
         logo = mode.get_property('logo')
         if logo:
             logo = mode.get_resource(logo, soft=True)
         shipping_groups = mode.get_property('only_this_groups')
         user_group = context.user.get_property('user_group')
         if len(shipping_groups)>0 and user_group not in shipping_groups:
             continue
         if mode.is_enabled(context) is False:
             continue
         namespace['payments'].append(
             {'name': mode.name,
              'value': mode.get_title(),
              'description': mode.get_payment_way_description(context, total_price),
              'logo': str(context.resource.get_pathto(logo)) if logo else None,
              'enabled': True,
              'selected': None})
     # Select first mode by default
     if namespace['payments'] != []:
         namespace['payments'][0]['selected'] = True
     return namespace
Example #15
0
 def get_price_prefix(self):
     shop = get_shop(self)
     context = get_context()
     group_name = get_group_name(shop, context)
     if get_uri_name(group_name) == 'pro':
         return 'pro-'
     return ''
Example #16
0
 def generate_pdf_order(self, context):
     shop = get_shop(self)
     # Delete old pdf
     if self.get_resource('order', soft=True):
         self.del_resource('order')
     # Get template
     document = self.get_resource('/ui/backoffice/orders/order_pdf.xml')
     # Build namespace
     path = context.database.fs.get_absolute_path(self.handler.key)
     namespace = self.get_namespace(context)
     for product in namespace['products']:
         product['key'] = context.database.fs.get_absolute_path(product['key'])
         product['cover']['key'] = context.database.fs.get_absolute_path(
                                        product['cover']['key'])
     namespace['logo'] = shop.get_pdf_logo_key(context)
     namespace['pdf_signature'] = format_for_pdf(shop.get_property('pdf_signature'))
     barcode = self.get_resource('barcode', soft=True)
     if barcode:
         key = barcode.handler.key
         path = context.database.fs.get_absolute_path(key)
         namespace['order_barcode'] = path
     else:
         namespace['order_barcode'] = None
     # Build pdf
     body = stl_pmltopdf(document, namespace=namespace)
     metadata =  {'title': {'en': u'Bill'},
                  'filename': 'order.pdf'}
     return PDF.make_resource(PDF, self, 'order', body=body, **metadata)
Example #17
0
 def get_widgets(self, resource, context):
     widgets = []
     shop = get_shop(resource)
     enumerates_folder = shop.get_resource('enumerates')
     for name in resource.get_purchase_options_names():
         title = enumerates_folder.get_resource(name).get_title()
         widgets.append(SelectWidget(name, title=title, has_empty_option=True))
     return declination_widgets + widgets
Example #18
0
 def action_export_as_ods(self, resource, context, form):
     if lpod_is_install is False:
         msg = ERROR(u'Please install LPOD')
         return context.come_back(msg)
     # XXX Create a new process and send ODS file by mail for performances ?
     # XXX We do not export product without declination
     # XXX We do not export product without product model
     # Get list of groups
     groups = []
     for option in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(option['name'])
         if group.get_property('use_default_price') is True:
             continue
         groups.append(group)
     # DB
     root = context.root
     shop = get_shop(resource)
     document = odf_new_document_from_type('spreadsheet')
     body = document.get_body()
     models = shop.get_resource('products-models').get_resources()
     for product_model in models:
         lines = []
         # We create one TAB by product model
         table = odf_create_table(product_model.get_title())
         search = root.search(product_model=str(product_model.get_abspath()))
         for brain in search.get_documents():
               product = root.get_resource(brain.abspath)
               for d in product.search_resources(cls=Declination):
                   # Ref - Declination name - Declination title
                   line = [product.get_property('reference'),
                           d.name,
                           d.get_declination_title().encode('utf-8')]
                   # Stock
                   line.append(str(d.get_quantity_in_stock()))
                   # Price by group (HT or TTC)
                   for group in groups:
                       k_price = {'id_declination': d.name,
                                  'prefix': group.get_prefix(),
                                  'pretty': True}
                       if group.get_property('show_ht_price'):
                           price = product.get_price_without_tax(**k_price)
                       else:
                           price = product.get_price_with_tax(**k_price)
                       line.append(str(price))
                   # Add row
                   lines.append(','.join(line))
         data = '\n'.join(lines)
         table = import_from_csv(StringIO(data), product_model.name)
         body.append(table)
     # Extport as ODS
     f = StringIO()
     document.save(f)
     content = f.getvalue()
     f.close()
     # Return ODS
     context.set_content_type('application/vnd.oasis.opendocument.spreadsheet')
     context.set_content_disposition('attachment', 'export.ods')
     return content
Example #19
0
 def cover_uri(self):
     shop = get_shop(self)
     site_root = shop.get_site_root()
     cover = self.get_preview_thumbnail()
     if not cover:
         return None
     base_uri = shop.get_property('shop_uri')
     end_uri = site_root.get_pathto(cover)
     return str('%s/;download' % get_reference(base_uri).resolve(end_uri))
Example #20
0
 def get_namespace(self, datatype, value):
     context = get_context()
     product = context.resource
     shop = get_shop(product)
     return merge_dicts(
         Widget.get_namespace(self, datatype, value),
         shop_uri=product.get_pathto(shop),
         show_barcode=shop.get_property('barcode_format') != None,
         reference=product.get_property('reference'))
Example #21
0
 def action_delete(self, resource, context, form):
     shop = get_shop(resource)
     try:
         resource.parent.del_resource(resource.name)
     except ConsistencyError:
         # TODO improve message
         context.message = ERROR(u"You can't delete this product")
         return
     return context.come_back(INFO(u'Product deleted !'), goto='../')
Example #22
0
 def get_widgets(self, resource, context):
     widgets = []
     shop = get_shop(resource)
     enumerates_folder = shop.get_resource('enumerates')
     for name in resource.get_purchase_options_names():
         title = enumerates_folder.get_resource(name).get_title()
         widgets.append(
             SelectWidget(name, title=title, has_empty_option=True))
     return declination_widgets + widgets
Example #23
0
 def cover_uri(self):
     shop = get_shop(self)
     site_root = shop.get_site_root()
     cover = self.get_preview_thumbnail()
     if not cover:
         return None
     base_uri = shop.get_property('shop_uri')
     end_uri = site_root.get_pathto(cover)
     return str('%s/;download' % get_reference(base_uri).resolve(end_uri))
Example #24
0
File: taxes.py Project: hforge/shop
 def get_options(cls):
     if get_context().resource is None:
         return []
     shop = get_shop(get_context().resource)
     taxes = shop.get_resource('taxes').handler
     return [
         {'name': str(x.id),
          'value': taxes.get_record_value(x, 'value')}
         for x in taxes.get_records_in_order()]
Example #25
0
 def get_options(cls):
     if get_context().resource is None:
         return []
     shop = get_shop(get_context().resource)
     taxes = shop.get_resource('taxes').handler
     return [{
         'name': str(x.id),
         'value': taxes.get_record_value(x, 'value')
     } for x in taxes.get_records_in_order()]
Example #26
0
 def get_namespace(self, datatype, value):
     context = get_context()
     product = context.resource
     shop = get_shop(product)
     return merge_dicts(
         Widget.get_namespace(self, datatype, value),
         shop_uri=product.get_pathto(shop),
         show_barcode=shop.get_property('barcode_format') != None,
         reference=product.get_property('reference'))
Example #27
0
 def send_alert_stock(self):
     shop = get_shop(self)
     context = get_context()
     root = context.root
     product_uri = context.uri.resolve('/shop/products/%s/' % self.name)
     kw = {'product_title': self.get_title(), 'product_uri': product_uri}
     body = mail_stock_body_template.gettext(**kw)
     for to_addr in shop.get_property('order_notification_mails'):
         root.send_email(to_addr=to_addr,
                         subject=mail_stock_subject_template.gettext(),
                         text=body)
Example #28
0
 def __getitem__(self, key):
     shop = get_shop(self.context.resource)
     module = shop.get_resource("modules/%s" % key, soft=True)
     if module is None:
         # XXX Log it
         ac = shop.get_access_control()
         user = self.context.user
         if ac.is_admin(user, shop) is False:
             return None
         return MSG(u"Module {name} not initialized").gettext(name=key)
     return module.render(self.here, self.context)
Example #29
0
 def __getitem__(self, key):
     shop = get_shop(self.context.resource)
     module = shop.get_resource('modules/%s' % key, soft=True)
     if module is None:
         # XXX Log it
         ac = shop.get_access_control()
         user = self.context.user
         if ac.is_admin(user, shop) is False:
             return None
         return MSG(u'Module {name} not initialized').gettext(name=key)
     return module.render(self.here, self.context)
Example #30
0
 def send_alert_stock(self):
     shop = get_shop(self)
     context = get_context()
     root = context.root
     product_uri = context.uri.resolve('/shop/products/%s/' % self.name)
     kw = {'product_title': self.get_title(), 'product_uri': product_uri}
     body = mail_stock_body_template.gettext(**kw)
     for to_addr in shop.get_property('order_notification_mails'):
         root.send_email(to_addr=to_addr,
                         subject=mail_stock_subject_template.gettext(),
                         text=body)
Example #31
0
 def save_barcode(self, reference):
     shop = get_shop(self)
     format = shop.get_property('barcode_format')
     barcode = generate_barcode(format, reference)
     if not barcode:
         return
     self.del_resource('barcode', soft=True)
     metadata =  {'title': {'en': u'Barcode'},
                  'filename': 'barcode.png',
                  'format': 'image/png'}
     Image.make_resource(Image, self, 'barcode', body=barcode, **metadata)
Example #32
0
 def action(self, resource, context, form):
     root = context.root
     if root.get_resource('users/%s' % form['user'], soft=True) is None:
         context.message = ERROR(u'User do not exist')
         return
     shop = get_shop(resource)
     payments_table = shop.get_resource('payments/%s/payments' %
                                        form['payment_way']).handler
     del form['payment_way']
     payments_table.add_record(form)
     return context.come_back(MSG(u'New payment added !'), goto='./')
Example #33
0
 def action(self, resource, context, form):
     root = context.root
     if root.get_resource('users/%s' % form['user'], soft=True) is None:
         context.message = ERROR(u'User do not exist')
         return
     shop = get_shop(resource)
     payments_table = shop.get_resource(
         'payments/%s/payments' % form['payment_way']).handler
     del form['payment_way']
     payments_table.add_record(form)
     return context.come_back(MSG(u'New payment added !'), goto='./')
Example #34
0
 def get_namespace(self, datatype, value):
     context = get_context()
     shop = get_shop(context.resource)
     recaptcha_module = shop.get_resource('modules/recaptcha', soft=True)
     if recaptcha_module is None:
         return {'module_is_install': False}
     public_key = recaptcha_module.get_property('public_key')
     theme = recaptcha_module.get_property('theme')
     return {'name': self.name,
             'module_is_install': True,
             'public_key': public_key,
             'theme': theme}
Example #35
0
 def get_namespace(self, resource, context):
     shop = get_shop(resource)
     images = resource.get_images_namespace(context)
     site_root = context.site_root
     frontoffice_uri = '%s/%s' % (shop.get_property('shop_uri'),
                                  site_root.get_pathto(resource))
     cover = resource.get_cover_namespace(context)
     if cover:
         cover = cover['href']
     return {'images': images,
             'frontoffice_uri': frontoffice_uri,
             'cover_uri': cover,
             'nb_photos': len(images)}
Example #36
0
 def get_options(cls):
     options = []
     context = get_context()
     shop = get_shop(context.resource)
     shippings = shop.get_resource('shippings')
     for way in shippings.search_resources(cls=ShippingWay):
         shipping_groups = way.get_property('only_this_groups')
         if context.user.get_property('user_group') not in shipping_groups:
             continue
         options.append({'name': way.name,
                         'value': way.get_title(),
                         'enabled': way.get_property('enabled')})
     return options
Example #37
0
 def get_product_value(self, product, column, context):
     if column == 'id':
         return product.get_property('reference')
     elif column == 'title':
         return product.get_title()
     elif column == 'description':
         description = product.get_property('description')
         description = description.replace('\r', '')
         return description.replace('\n', '')
     elif column == 'google_product_category':
         dynamic_schema = product.get_dynamic_schema()
         if "categorie-google" not in dynamic_schema.keys():
             return u''
         return product.get_dynamic_property("categorie-google") or u''
     elif column == 'product_type':
         l = []
         resource = product.parent
         while resource.name != 'categories':
             l.append(resource.get_title())
             resource = resource.parent
         l.reverse()
         return ' > '.join(l)
     elif column == 'link':
         return product.frontoffice_uri
     elif column == 'image_link':
         return product.cover_uri
     elif column == 'additional_image_link':
         # XXX we return only one image because of tabulation
         shop = get_shop(product)
         base_uri = shop.get_property('shop_uri')
         images = product.get_images_namespace(context)
         if not images:
             return ''
         l = ['%s%s/;download' % (base_uri, x['href']) for x in images]
         return l[0]
     elif column == 'condition':
         return 'new'
     elif column == 'price':
         return '%s EUR' % get_arrondi(product.get_price_with_tax())
     elif column == 'mpn':
         dynamic_schema = product.get_dynamic_schema()
         if "reference-fabricant" not in dynamic_schema.keys():
             return u''
         return product.get_dynamic_property("reference-fabricant") or u''
     elif column == 'brand':
         value = product.get_property('manufacturer')
         if not value:
             return u''
         return ManufacturersEnumerate.get_value(value)
     elif column == 'shipping_weight':
         return '{weight} kg'.format(weight=product.get_property('weight'))
Example #38
0
 def get_product_value(self, product, column, context):
     if column == 'id':
         return product.get_property('reference')
     elif column == 'title':
         return product.get_title()
     elif column == 'description':
         description = product.get_property('description')
         description = description.replace('\r', '')
         return description.replace('\n', '')
     elif column == 'google_product_category':
         dynamic_schema = product.get_dynamic_schema()
         if "categorie-google" not in dynamic_schema.keys():
             return u''
         return product.get_dynamic_property("categorie-google") or u''
     elif column == 'product_type':
         l = []
         resource = product.parent
         while resource.name != 'categories':
             l.append(resource.get_title())
             resource = resource.parent
         l.reverse()
         return ' > '.join(l)
     elif column == 'link':
         return product.frontoffice_uri
     elif column == 'image_link':
         return product.cover_uri
     elif column == 'additional_image_link':
         # XXX we return only one image because of tabulation
         shop = get_shop(product)
         base_uri = shop.get_property('shop_uri')
         images = product.get_images_namespace(context)
         if not images:
             return ''
         l = ['%s%s/;download' % (base_uri, x['href']) for x in images]
         return l[0]
     elif column == 'condition':
         return 'new'
     elif column == 'price':
         return '%s EUR' % get_arrondi(product.get_price_with_tax())
     elif column == 'mpn':
         dynamic_schema = product.get_dynamic_schema()
         if "reference-fabricant" not in dynamic_schema.keys():
             return u''
         return product.get_dynamic_property("reference-fabricant") or u''
     elif column == 'brand':
         value = product.get_property('manufacturer')
         if not value:
             return u''
         return ManufacturersEnumerate.get_value(value)
     elif column == 'shipping_weight':
         return '{weight} kg'.format(weight=product.get_property('weight'))
Example #39
0
 def action_edit_payment(self, resource, context, form):
     shop = get_shop(resource)
     # We get shipping way
     payment_way = shop.get_resource('payments/%s/' % form['payment_way'])
     # We get order_edit_view
     view = payment_way.order_edit_view
     # We get schema
     schema = view.schema
     # We get form
     try:
         form = process_form(context.get_form_value, schema)
     except FormError, error:
         context.form_error = error
         return self.on_form_error(resource, context)
Example #40
0
 def action_edit_payment(self, resource, context, form):
     shop = get_shop(resource)
     # We get shipping way
     payment_way = shop.get_resource('payments/%s/' % form['payment_way'])
     # We get order_edit_view
     view = payment_way.order_edit_view
     # We get schema
     schema = view.schema
     # We get form
     try:
         form = process_form(context.get_form_value, schema)
     except FormError, error:
         context.form_error = error
         return self.on_form_error(resource, context)
Example #41
0
 def notify_new_message(self, message, context):
     shop = get_shop(self)
     root = context.root
     customer_id = self.get_property('customer_id')
     customer = context.root.get_resource('/users/%s' % customer_id)
     contact = customer.get_property('email')
     subject = new_message_subject.gettext(n=self.name)
     # Send mail to customer
     text = message + new_message_footer.gettext(uri=self.get_frontoffice_uri())
     root.send_email(contact, subject, text=text, subject_with_host=False)
     # Send mail to administrators
     text = message + new_message_footer.gettext(uri=self.get_backoffice_uri())
     for to_addr in shop.get_property('order_notification_mails'):
         root.send_email(to_addr, subject, text=text, subject_with_host=False)
Example #42
0
 def get_namespace(self, resource, context):
     track_end_of_order = isinstance(context.view, PaymentWay_EndView)
     namespace = {'tracking_id': resource.get_property('tracking_id'),
                  'track_end_of_order': track_end_of_order}
     if track_end_of_order:
         shop = get_shop(resource)
         ref_order = context.query['ref']
         order = shop.get_resource('orders/%s' % ref_order)
         # XXX We have to add country
         namespace['order'] = {
             'name': order.name,
             'total_price': order.get_property('total_price'),
             'shipping_price': order.get_property('shipping_price')}
     return namespace
Example #43
0
 def action_add_shipping(self, resource, context, form):
     shop = get_shop(resource)
     # We get shipping way
     shipping_way = shop.get_resource('shippings/%s/' % form['shipping_way'])
     # We get add_record view
     add_record_view = shipping_way.order_add_view
     # We get shipping way add form schema
     schema = add_record_view.schema
     # We get form
     try:
         form = process_form(context.get_form_value, schema)
     except FormError, error:
         context.form_error = error
         return self.on_form_error(resource, context)
Example #44
0
 def get_declination_namespace(self, declination_name):
     namespace = []
     shop = get_shop(self)
     declination = self.get_resource(declination_name)
     dynamic_schema = declination.get_dynamic_schema()
     enumerates_folder = shop.get_resource('enumerates')
     for name in self.get_purchase_options_names():
         value = declination.get_dynamic_property(name, dynamic_schema)
         if not value:
             continue
         enumerate_table = enumerates_folder.get_resource(name)
         datatype = EnumerateTable_to_Enumerate(enumerate_name=name)
         namespace.append({'title': enumerate_table.get_title(),
                           'value': datatype.get_value(value)})
     return namespace
Example #45
0
 def save_barcode(self, reference):
     shop = get_shop(self)
     format = shop.get_property('barcode_format')
     barcode = generate_barcode(format, reference)
     if not barcode:
         return
     self.del_resource('barcode', soft=True)
     metadata = {
         'title': {
             'en': u'Barcode'
         },
         'filename': 'barcode.png',
         'format': 'image/png'
     }
     Image.make_resource(Image, self, 'barcode', body=barcode, **metadata)
Example #46
0
 def get_schema(self, resource, context):
     product_model = resource.get_product_model()
     site_root = resource.get_site_root()
     shop = get_shop(site_root)
     # Cover is mandatory
     mandatory = shop.get_property('product_cover_is_mandatory')
     product_schema['cover'].mandatory = mandatory
     # Return schema
     return merge_dicts(
               product_schema,
               (product_model.get_model_schema() if product_model else {}),
               data=XHTMLBody(multilingual=True),
               category=CategoriesEnumerate,
               not_buyable_by_groups=UserGroup_Enumerate(multiple=True),
               tags=TagsList(site_root=site_root, multiple=True))
Example #47
0
 def get_namespace(self, resource, context):
     cart = ProductCart(context)
     nb_products = cart.get_nb_products()
     shop = get_shop(context.resource)
     # Get total price
     total = cart.get_total_price(shop, with_delivery=False)
     if shop.show_ht_price(context):
         total = total['without_tax']
     else:
         total = total['with_tax']
     # Return namespace
     return {'nb_products': nb_products,
             'total': total,
             'txts_class': 'hidden' if nb_products < 2 else '',
             'txt_class': 'hidden' if nb_products > 1 else ''}
Example #48
0
 def action_add_shipping(self, resource, context, form):
     shop = get_shop(resource)
     # We get shipping way
     shipping_way = shop.get_resource('shippings/%s/' %
                                      form['shipping_way'])
     # We get add_record view
     add_record_view = shipping_way.order_add_view
     # We get shipping way add form schema
     schema = add_record_view.schema
     # We get form
     try:
         form = process_form(context.get_form_value, schema)
     except FormError, error:
         context.form_error = error
         return self.on_form_error(resource, context)
Example #49
0
 def get_namespace(self, resource, context):
     track_end_of_order = isinstance(context.view, PaymentWay_EndView)
     namespace = {'id': resource.get_property('id'),
                  'track_end_of_order': track_end_of_order}
     if track_end_of_order:
         shop = get_shop(resource)
         ref_order = context.query['ref']
         order = shop.get_resource('orders/%s' % ref_order, soft=True)
         if order is None:
             #  Can be none for wishlist
             namespace['track_end_of_order'] = False
             return namespace
         order_namespace = order.get_namespace(context)
         amount = order_namespace['price']['products']['without_tax']
         namespace['order'] = {'name': order.name,
                               'amount': amount}
     return namespace
Example #50
0
 def get_declination_namespace(self, declination_name):
     namespace = []
     shop = get_shop(self)
     declination = self.get_resource(declination_name)
     dynamic_schema = declination.get_dynamic_schema()
     enumerates_folder = shop.get_resource('enumerates')
     for name in self.get_purchase_options_names():
         value = declination.get_dynamic_property(name, dynamic_schema)
         if not value:
             continue
         enumerate_table = enumerates_folder.get_resource(name)
         datatype = EnumerateTable_to_Enumerate(enumerate_name=name)
         namespace.append({
             'title': enumerate_table.get_title(),
             'value': datatype.get_value(value)
         })
     return namespace
Example #51
0
 def get_tax_value(self, prefix=None):
     shop = get_shop(self)
     if prefix is None:
         prefix = self.get_price_prefix()
     # Get zone from cookie
     id_zone = ProductCart(get_context()).id_zone
     # If not define... get default zone
     if id_zone is None:
         id_zone = shop.get_property('shop_default_zone')
     # Check if zone has tax ?
     zones = shop.get_resource('countries-zones').handler
     zone_record = zones.get_record(int(id_zone))
     if zones.get_record_value(zone_record, 'has_tax') is True:
         tax = self.get_property('%stax' % prefix)
         tax_value = TaxesEnumerate.get_value(tax) or decimal(0)
         return (tax_value / decimal(100) + 1)
     return decimal(1)
Example #52
0
 def get_tax_value(self, prefix=None):
     shop = get_shop(self)
     if prefix is None:
         prefix = self.get_price_prefix()
     # Get zone from cookie
     id_zone = ProductCart(get_context()).id_zone
     # If not define... get default zone
     if id_zone is None:
         id_zone = shop.get_property('shop_default_zone')
     # Check if zone has tax ?
     zones = shop.get_resource('countries-zones').handler
     zone_record = zones.get_record(int(id_zone))
     if zones.get_record_value(zone_record, 'has_tax') is True:
         tax = self.get_property('%stax'% prefix)
         tax_value = TaxesEnumerate.get_value(tax) or decimal(0)
         return (tax_value/decimal(100) + 1)
     return decimal(1)
Example #53
0
 def get_namespace(self, resource, context):
     track_end_of_order = isinstance(context.view, PaymentWay_EndView)
     namespace = {
         'tracking_id': resource.get_property('tracking_id'),
         'track_end_of_order': track_end_of_order
     }
     if track_end_of_order:
         shop = get_shop(resource)
         ref_order = context.query['ref']
         order = shop.get_resource('orders/%s' % ref_order)
         # XXX We have to add country
         namespace['order'] = {
             'name': order.name,
             'total_price': order.get_property('total_price'),
             'shipping_price': order.get_property('shipping_price')
         }
     return namespace
Example #54
0
 def get_namespace(self, resource, context):
     cart = ProductCart(context)
     nb_products = cart.get_nb_products()
     shop = get_shop(context.resource)
     # Get total price
     total = cart.get_total_price(shop, with_delivery=False)
     if shop.show_ht_price(context):
         total = total['without_tax']
     else:
         total = total['with_tax']
     # Return namespace
     return {
         'nb_products': nb_products,
         'total': total,
         'txts_class': 'hidden' if nb_products < 2 else '',
         'txt_class': 'hidden' if nb_products > 1 else ''
     }
Example #55
0
    def action(self, resource, context, form):
        name = form['name']
        title = form['title']
        # Create the resource
        shop = get_shop(resource)
        cls = shop.product_class
        root = context.root
        category = root.get_resource(form['category'])
        child = cls.make_resource(cls, category, name)
        # The metadata
        metadata = child.metadata
        language = resource.get_content_language(context)
        metadata.set_property('title', title, language=language)
        metadata.set_property('product_model', form['product_model'])
        metadata.set_property('state', 'private')

        goto = context.get_link(child)
        return context.come_back(messages.MSG_NEW_RESOURCE, goto=goto)
Example #56
0
 def notify_new_message(self, message, context):
     shop = get_shop(self)
     root = context.root
     customer_id = self.get_property('customer_id')
     customer = context.root.get_resource('/users/%s' % customer_id)
     contact = customer.get_property('email')
     subject = new_message_subject.gettext(n=self.name)
     # Send mail to customer
     text = message + new_message_footer.gettext(
         uri=self.get_frontoffice_uri())
     root.send_email(contact, subject, text=text, subject_with_host=False)
     # Send mail to administrators
     text = message + new_message_footer.gettext(
         uri=self.get_backoffice_uri())
     for to_addr in shop.get_property('order_notification_mails'):
         root.send_email(to_addr,
                         subject,
                         text=text,
                         subject_with_host=False)
Example #57
0
 def get_table_columns(self, resource, context):
     columns = []
     shop = get_shop(resource)
     enumerates_folder = shop.get_resource('enumerates')
     # Purchase options columns
     for name in resource.get_purchase_options_names():
         title = enumerates_folder.get_resource(name).get_title()
         columns.append((name, title))
     # Groups price
     for group in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(group['name'])
         if group.get_property('use_default_price') is True:
             continue
         if group.get_property('show_ht_price'):
             tax = 'HT'
         else:
             tax = 'TTC'
         title = MSG(u'Price {g} {t}').gettext(g=group.get_title(), t=tax)
         columns.append(('price-%s' % group.name, title))
     return self.base_columns + columns