Esempio n. 1
0
 def actions(self):
     actions = [
         {'id': 'shop',
          'klass': 'home',
          'active': self.is_current(cid='shop'),
          'url': self.portal_url + '/shop',
          'title': _(u"Shop Dashboard"),
          'desc': _(u"Add and manage shop content"),
          },
         {'id': 'item-collection-repository',
          'klass': 'box',
          'active': self.is_current(cid='item--collection-repository'),
          'url': self.portal_url + '/shop/item-collection-repository',
          'title': _(u"Item Collections"),
          'desc': _(u"Manage item collections by assigning orderable items,"
                    u" adding categories and by saving predefined layouts"),
          },
         {'id': 'item-repository',
          'klass': 'beaker',
          'active': self.is_current(cid='item-repository'),
          'url': self.portal_url + '/shop/item-repository',
          'title': _(u"Orderable Items"),
          'desc': _(u"Add and manage orderable items"),
          },
         {'id': 'back',
          'klass': 'switch',
          'active': False,
          'url': self.portal_url,
          'title': _(u"Shop View"),
          'desc': _(u"Return to the shop view as seen by anonymous users"),
          },
     ]
     return actions
Esempio n. 2
0
 def update(self):
     context = aq_inner(self.context)
     self.errors = {}
     if 'form.button.Delete' in self.request:
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         form = self.request.form
         current_layout = context.layout_order
         try:
             headlines = json.loads(context.headlines)
         except TypeError:
             headlines = {}
         uuid = form.get('headline.uid', None)
         del headlines[uuid]
         new_headlines = json.dumps(headlines)
         setattr(context, 'headlines', new_headlines)
         current_layout.remove(uuid)
         setattr(context, 'layout_order', current_layout)
         modified(context)
         context.reindexObject(idxs='modified')
         api.portal.show_message(
             message=_(u"Headline successfully removed."),
             request=self.request)
         next_url = context.absolute_url() + '/@@edit-layout'
         return self.request.response.redirect(next_url)
Esempio n. 3
0
 def update(self):
     context = aq_inner(self.context)
     self.errors = {}
     if 'form.button.Submit' in self.request:
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         form = self.request.form
         current_layout = context.layout_order
         try:
             headlines = json.loads(context.headlines)
         except TypeError:
             headlines = {}
         new_item = {}
         new_uuid = base64.b64encode(os.urandom(24))
         new_item['title_de'] = form['headline-de']
         new_item['title_en'] = form['headline-en']
         headlines[new_uuid] = new_item
         new_headlines = json.dumps(headlines)
         setattr(context, 'headlines', new_headlines)
         if self.has_open_session():
             session = self.open_session()
             if session is not None:
                 session.append(new_uuid)
         current_layout.append(new_uuid)
         setattr(context, 'layout_order', current_layout)
         modified(context)
         context.reindexObject(idxs='modified')
         api.portal.show_message(
             message=_(u"Item successfully added."), request=self.request)
         next_url = context.absolute_url() + '/@@edit-layout'
         return self.request.response.redirect(next_url)
Esempio n. 4
0
 def update(self):
     context = aq_inner(self.context)
     self.context_url = context.absolute_url()
     unwanted = ('_authenticator', 'form.button.Submit')
     required = self.required_fields()
     self.errors = {}
     if 'form.button.Submit' in self.request:
         form = self.request.form
         formdata = {}
         formerrors = {}
         errorIdx = 0
         for value in form:
             if value not in unwanted:
                 formdata[value] = form[value]
                 if value in required and not form[value]:
                     error = {}
                     error['active'] = True
                     error['msg'] = _(u"This field is required")
                     formerrors[value] = error
                     errorIdx += 1
                 else:
                     error = {}
                     error['active'] = False
                     error['msg'] = form[value]
                     formerrors[value] = error
         if errorIdx > 0:
             self.errors = formerrors
         else:
             self.createContent(formdata)
Esempio n. 5
0
 def update(self):
     self.product = self.resolveItem()
     context = aq_inner(self.context)
     self.errors = {}
     unwanted = ('_authenticator', 'form.button.Submit')
     if 'form.button.Submit' in self.request:
         form = self.request.form
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         idx = 0
         for item in form:
             if item not in unwanted:
                 fieldname = item.split('.')
                 uuid = fieldname[0]
                 quantity = form[item]
                 if quantity is not '0':
                     updater = getUtility(ICartUpdaterUtility)
                     updater.add(uuid, quantity)
                     idx += 1
         IStatusMessage(self.request).add(
             _(u"Item successfully added to cart"),
             type="info")
         redirect_url = self.context.absolute_url() + '/@@cart'
         return self.request.response.redirect(redirect_url)
Esempio n. 6
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     api.portal.set_registry_record(
         'chromsystems.shopcontent.quicklinks_de', data['quicklinks'])
     msg = _(u"Frontpage quicklinks DE have been updated")
     api.portal.show_message(message=msg, request=self.request)
     next_url = context.absolute_url() + '/view'
     return self.request.response.redirect(next_url)
Esempio n. 7
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     api.portal.set_registry_record('chromsystems.shopcontent.menu_en',
                                    data['menu_en'])
     msg = _(u"Menu settings EN have succsessfully been updated")
     api.portal.show_message(message=msg, request=self.request)
     next_url = context.absolute_url() + '/view'
     return self.request.response.redirect(next_url)
Esempio n. 8
0
 def resolveItem(self):
     uid = self.request.get('uid', '')
     if uid:
         obj = uuidToObject(uid)
         if not obj:
             msg = _(u"The requested item could not be retrieved")
             api.portal.show_message(message=msg,
                                     request=self.request)
         else:
             return obj
Esempio n. 9
0
 def createContent(self, data):
     context = aq_inner(self.context)
     assert IShopFolder.providedBy(context)
     container = context['item-repository']
     item = createContentInContainer(
         container,
         'chromsystems.shopcontent.itemcollection',
         checkConstraints=True, **data)
     modified(item)
     item.reindexObject(idxs='modified')
     api.portal.show_message(
         message=_(u"Item successfully added."), request=self.request)
     return self.request.response.redirect(context.absolute_url())
Esempio n. 10
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        # Process uploaded file and import recipients
        importdata = data['csvfile'].data
        imported_records = self.processImportFile(importdata)
        if imported_records is not None:
            IStatusMessage(self.request).addStatusMessage(
                _(u"Imported records: ") + unicode(imported_records),
                type='info')
Esempio n. 11
0
 def update(self):
     context = aq_inner(self.context)
     self.errors = {}
     if 'form.button.Submit' in self.request:
         form = self.request.form
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         product_code = form['productcode']
         uuid = self._getItemUID(product_code)
         if not uuid or uuid is None:
             self.errors['productcode'] = _(u"Product code is not valid")
         else:
             updater = getUtility(ICartUpdaterUtility)
             quantity = 1
             updater.add(uuid, quantity)
             IStatusMessage(self.request).add(
                 _(u"Item successfully added to cart"),
                 type="info")
             redirect_url = self.context.absolute_url() + '/@@cart'
             return self.request.response.redirect(redirect_url)
Esempio n. 12
0
 def render(self):
     context = aq_inner(self.context)
     uuid = context.UID()
     editor = getUtility(ILayoutEditorUtility)
     session = editor.get()
     edited_layout = session[uuid]
     setattr(context, 'layout_order', edited_layout)
     modified(context)
     context.reindexObject(idxs='modified')
     session.clear()
     api.portal.show_message(
         message=_(u"Item successfully added."), request=self.request)
     next_url = context.absolute_url() + '/@@edit-layout'
     return self.request.response.redirect(next_url)
Esempio n. 13
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     assert IItemCollectionRepository.providedBy(context)
     container = context
     item = createContentInContainer(
         container,
         'chromsystems.shopcontent.itemcollection',
         checkConstraints=True, **data)
     setattr(item, 'title_de', data['title'])
     modified(item)
     item.reindexObject(idxs='modified')
     IStatusMessage(self.request).addStatusMessage(
         _(u"A new orderable item has successfully been added"),
         type='info')
     return self.request.response.redirect(context.absolute_url() + '/view')
Esempio n. 14
0
 def render(self):
     context = aq_inner(self.context)
     items = self.orderable_items()
     idx = 0
     for item in items:
         obj = item.getObject()
         title = obj.Title()
         code = obj.productCode
         new_title = safe_unicode(code) + ' - ' + safe_unicode(title)
         obj.setTitle(new_title)
         modified(context)
         context.reindexObject(idxs='modified')
         idx += 1
     msg = _(u"%s item titles updated") % idx
     api.portal.show_message(message=msg, request=self.request)
     return self.request.response.redirect(context.absolute_url())
Esempio n. 15
0
 def render(self):
     context = aq_inner(self.context)
     editor = getUtility(ILayoutEditorUtility)
     session = editor.get()
     session.clear()
     items = context.relatedProducts
     clean_layout = list()
     for item in items:
         obj = item.to_object
         clean_layout.append(obj.UID)
     setattr(context, 'layout_order', clean_layout)
     modified(context)
     context.reindexObject(idxs='modified')
     api.portal.show_message(
         message=_(u"Layout successfully resetted"), request=self.request)
     next_url = context.absolute_url()
     return self.request.response.redirect(next_url)
Esempio n. 16
0
 def update(self):
     context = aq_inner(self.context)
     self.errors = {}
     if 'form.button.Submit' in self.request:
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         empty_list = list()
         setattr(context, 'layout_order', empty_list)
         setattr(context, 'relatedProducts', empty_list)
         modified(context)
         context.reindexObject(idxs='modified')
         api.portal.show_message(
             message=_(u"Item errors cleaned up."), request=self.request)
         next_url = context.absolute_url()
         return self.request.response.redirect(next_url)
Esempio n. 17
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     assert IItemRepository.providedBy(context)
     container = context
     code = safe_unicode(data['productCode'])
     title = safe_unicode((data['title_de']))
     new_title = code + ' - ' + title
     data['title'] = new_title
     item = createContentInContainer(
         container,
         'chromsystems.shopcontent.orderableitem',
         checkConstraints=True, **data)
     modified(item)
     item.reindexObject(idxs='modified')
     IStatusMessage(self.request).addStatusMessage(
         _(u"A new orderable item has successfully been added"),
         type='info')
     return self.request.response.redirect(context.absolute_url() + '/view')
Esempio n. 18
0
 def update(self):
     context = aq_inner(self.context)
     self.errors = {}
     if 'form.button.Submit' in self.request:
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         if self.has_open_session():
             session = self.open_session()
             if session is not None:
                 editor = getUtility(ILayoutEditorUtility)
                 editor.delete(context.UID())
                 editor.clear()
         api.portal.show_message(
             message=_(u"Item successfully added."), request=self.request)
         next_url = context.absolute_url()
         return self.request.response.redirect(next_url)
Esempio n. 19
0
 def render(self):
     context = aq_inner(self.context)
     uuid = context.UID()
     editor = getUtility(ILayoutEditorUtility)
     layout_list = context.layout_order
     new_layout = list()
     sort_query = list(self.query.split(','))
     for x in sort_query:
         index = x[6:]
         value = layout_list[int(index)]
         new_layout.append(value)
     editor.add(uuid, new_layout)
     msg = _(u"Item order successfully updated")
     results = {'success': True,
                'message': msg
                }
     self.request.response.setHeader('Content-Type',
                                     'application/json; charset=utf-8')
     return json.dumps(results)
Esempio n. 20
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     assert IItemCollection.providedBy(context)
     fti = getUtility(IDexterityFTI,
                      name='chromsystems.shopcontent.itemcollection')
     schema = fti.lookupSchema()
     fields = getFieldsInOrder(schema)
     for key, value in fields:
         try:
             new_value = data[key]
             setattr(context, key, new_value)
         except KeyError:
             continue
     modified(context)
     context.reindexObject(idxs='modified')
     IStatusMessage(self.request).addStatusMessage(
         _(u"Item collection keyword has successfully been updated"),
         type='info')
     return self.request.response.redirect(context.absolute_url() + '/view')
Esempio n. 21
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     cats = getattr(context, 'category', None)
     new_categories = data['categories']
     catlist = category_source(context)
     newcats = list()
     for cat in new_categories:
         cat_name = catlist.getTerm(cat)
         newcats.append(cat_name.title)
     if cats is None:
         updated = tuple(newcats)
     else:
         updated = cats + tuple(newcats)
     setattr(context, 'category', updated)
     modified(context)
     context.reindexObject(idxs='modified')
     IStatusMessage(self.request).addStatusMessage(
         _(u"Item collection categorization has successfully been updated"),
         type='info')
     return self.request.response.redirect(context.absolute_url() + '/view')
Esempio n. 22
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     intids = getUtility(IIntIds)
     current_relations = context.relatedProducts
     relations = []
     for brain in data['relatedProducts']:
         target_id = intids.getId(brain)
         relation = RelationValue(target_id)
         relations.append(relation)
     stored_layout = context.layout_order
     base_layout = self._generateLayout(relations)
     setattr(context, 'relatedProducts', relations)
     context.relatedProducts = relations
     if stored_layout:
         if len(current_relations) > len(relations):
             old_layout = self._generateLayout(current_relations)
             new = []
             trashcan = []
             for i in old_layout:
                 if i not in base_layout:
                     trashcan.append(i)
             for x in stored_layout:
                 if x not in trashcan:
                     new.append(x)
             layout = new
         else:
             for x in base_layout:
                 if x not in stored_layout:
                     stored_layout.append(x)
             layout = stored_layout
     else:
         layout = base_layout
     setattr(context, 'layout_order', layout)
     modified(context)
     context.reindexObject(idxs='modified')
     IStatusMessage(self.request).addStatusMessage(
         _(u"Item collection has successfully been updated"),
         type='info')
     return self.request.response.redirect(context.absolute_url() + '/view')
Esempio n. 23
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     assert IOrderableItem.providedBy(context)
     code = safe_unicode(data['productCode'])
     title = safe_unicode((data['title_de']))
     new_title = code + ' - ' + title
     data['title'] = new_title
     fti = getUtility(IDexterityFTI,
                      name='chromsystems.shopcontent.orderableitem')
     schema = fti.lookupSchema()
     fields = getFieldsInOrder(schema)
     for key, value in fields:
         try:
             new_value = data[key]
             setattr(context, key, new_value)
         except KeyError:
             continue
     modified(context)
     context.reindexObject(idxs='modified')
     IStatusMessage(self.request).addStatusMessage(
         _(u"The orderable item has successfully been updated"),
         type='info')
     return self.request.response.redirect(context.absolute_url() + '/view')
Esempio n. 24
0
def editbar_actions():
        actions = {
            'editbar-quit': _(u"Quit Shop Editor"),
            'editbar-add': _(u"Add"),
            'editbar-edit': _(u"Edit"),
            'editbar-preview': _(u"Preview"),
            'editbar-delete': _(u"Delete"),
            'editbar-parent': _(u"Go to parent"),
            'editbar-categorization': _(u"Categorization"),
            'editbar-keywords': _(u"Keywords"),
            'editbar-layout': _(u"Layout"),
            'editbar-items': _(u"Orderable Items"),
            'editbar-state': _(u"State"),
        }
        return actions
Esempio n. 25
0
 def handleCancel(self, action):
     context = aq_inner(self.context)
     IStatusMessage(self.request).addStatusMessage(
         _(u"Orderable item edit has been cancelled."),
         type='info')
     return self.request.response.redirect(context.absolute_url())
Esempio n. 26
0
 def generate_placeholder(self):
     msg = _(u"Order no., parameter")
     return msg
Esempio n. 27
0
 def generate_placeholder(self):
     msg = _(u"Order no.")
     return msg
Esempio n. 28
0
 def handleCancel(self, action):
     context = aq_inner(self.context)
     msg = _(u"Orderable item edit has been cancelled.")
     api.portal.show_message(message=msg, request=self.request)
     return self.request.response.redirect(context.absolute_url())
Esempio n. 29
0
 def handleCancel(self, action):
     context = aq_inner(self.context)
     msg = _(u"Setting frontpage quicklinks has been cancelled.")
     api.portal.show_message(message=msg, request=self.request)
     return self.request.response.redirect(context.absolute_url())
Esempio n. 30
0
 def handleCancel(self, action):
     context = aq_inner(self.context)
     IStatusMessage(self.request).addStatusMessage(
         _(u"Updating categorization has been cancelled."),
         type='info')
     return self.request.response.redirect(context.absolute_url())