Ejemplo n.º 1
0
class ShopModule_FacebookLike(ShopModule):

    class_id = 'shop_module_facebook_like'
    class_title = MSG(u'Facebook like')
    class_views = ['edit']
    class_description = MSG(u'Facebook like')

    item_schema = {
        'layout': Layout,
        'the_action': Action,
        'width': Integer,
        'height': Integer,
        'colorscheme': ColorScheme,
        'show_faces': Boolean
    }

    item_widgets = [
        SelectWidget('layout', title=MSG(u'Layout'), has_empty_option=False),
        SelectWidget('the_action',
                     title=MSG(u'Action'),
                     has_empty_option=False),
        SelectWidget('colorscheme',
                     title=MSG(u'Color Scheme'),
                     has_empty_option=False),
        TextWidget('width', title=MSG(u'Width (px)')),
        TextWidget('height', title=MSG(u'Height (px)')),
        BooleanRadio('show_faces', title=MSG(u'Show faces ?'))
    ]

    def render(self, resource, context):
        return ShopModule_FacebookLike_View().GET(self, context)
Ejemplo n.º 2
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)
     }
Ejemplo n.º 3
0
Archivo: taxes.py Proyecto: 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)}
Ejemplo n.º 4
0
class ShippingWay_Configure(AutoForm):

    access = 'is_allowed_to_edit'
    title = MSG(u'Edit')

    schema = delivery_schema

    context_menus = [EditLanguageMenu()]

    widgets = [
        TextWidget('title', title=MSG(u'Title')),
        ImageSelectorWidget('logo', title=MSG(u'Logo')),
        MultilineWidget('description', title=MSG(u'Description')),
        BooleanRadio('enabled', title=MSG(u'Enabled ?')),
        SelectWidget('mode', title=MSG(u'Mode ?'), has_empty_option=False),
        TextWidget('insurance', title=MSG(u'Insurance %')),
        BooleanRadio('is_free', title=MSG(u'Shipping way is free ?')),
        SelectWidget('only_this_models',
                     title=MSG(u'Only for this products models')),
        SelectWidget('only_this_groups',
                     title=MSG(u'Only for this user groups')),
    ]

    def get_value(self, resource, context, name, datatype):
        language = resource.get_content_language(context)
        return resource.get_property(name, language)

    def action(self, resource, context, form):
        language = resource.get_content_language(context)
        for key in self.schema.keys():
            if key in ['title', 'description']:
                resource.set_property(key, form[key], language)
            else:
                resource.set_property(key, form[key])
        return context.come_back(messages.MSG_CHANGES_SAVED)
Ejemplo n.º 5
0
 def get_namespace(self, resource, context):
     namespace = {}
     cart = ProductCart(context)
     widget = SelectWidget('delivery_address', has_empty_option=False)
     namespace['delivery_address'] = widget.to_html(Addresses_Enumerate,
                                       cart.addresses['delivery_address'])
     widget = SelectWidget('bill_address', has_empty_option=False)
     namespace['bill_address'] = widget.to_html(Addresses_Enumerate,
                                       cart.addresses['bill_address'])
     return namespace
Ejemplo n.º 6
0
class CrossSelling_Configure(ImprovedAutoForm):

    access = 'is_allowed_to_edit'
    title = MSG(u'Configure cross selling')

    shop_configuration = BooleanRadio('use_shop_configuration',
                                      title=MSG(u'Use shop configuration'))

    actions = [
        Button(access='is_allowed_to_edit',
               name='configure',
               title=MSG(u'Configure'))
    ]

    widgets = [
        BooleanRadio('enabled', title=MSG(u'Enabled')),
        TextWidget('products_quantity',
                   title=MSG(u'Numbers of products'),
                   size=3),
        CrossSelling_Widget('widget', title=MSG(u'Table')),
        TextWidget(
            'filter_text',
            title=MSG(u'Extend with products that contains this title')),
        SelectRadio('categories',
                    title=MSG(u'Extend with products from categories...'),
                    has_empty_option=False),
        SelectRadio('show_product_with_promotion',
                    title=MSG(u'Extend with promotion ?'),
                    is_inline=True,
                    has_empty_option=False),
        SelectWidget('product_model', title=MSG(u'Product Model')),
        DualSelectWidget('tags',
                         title=MSG(u'Extend products associated to this tags'),
                         is_inline=True,
                         has_empty_option=False),
        SelectWidget('sort', title=MSG(u'Selection'), has_empty_option=False),
    ]

    def get_schema(self, resource, context):
        site_root = resource.get_site_root()
        return merge_dicts(cross_selling_schema,
                           tags=TagsList(site_root=site_root, multiple=True))

    def get_widgets(self, resource, context):
        if get_shop(resource) == resource.parent:
            return self.widgets
        return [self.shop_configuration] + self.widgets

    def get_value(self, resource, context, name, datatype):
        return resource.get_property(name)

    def action_configure(self, resource, context, form):
        for key in self.get_schema(resource, context).keys():
            resource.set_property(key, form[key])
        return context.come_back(messages.MSG_CHANGES_SAVED)
Ejemplo n.º 7
0
 def get_widgets(self, resource, context):
     widgets = NeutralWS_Edit.get_widgets(self, resource, context)
     widgets[-1] = SelectWidget('class_skin',
                                title=MSG(u'Class skin'),
                                has_empty_option=False)
     widgets.append(
         SelectWidget('class_skin_administrators',
                      title=MSG(u'Class skin for administrators'),
                      has_empty_option=False))
     widgets.append(
         BooleanRadio('hide_website_title_on_meta_title',
                      title=MSG(u'Hide website title on meta title')))
     return widgets
Ejemplo n.º 8
0
class Payments_AddPayment(AutoForm):

    access = 'is_admin'
    title = MSG(u'Add a new payment')

    schema = {
        'payment_way': PaymentWaysEnumerate(mandatory=True),
        'ref': String(mandatory=True),
        'user': String,
        'state': Boolean,
        'amount': Decimal(mandatory=True),
        'description': Unicode
    }

    widgets = [
        SelectWidget('payment_way', title=MSG(u'Payment way')),
        TextWidget('ref', title=MSG(u'Reference')),
        TextWidget('user', title=MSG(u'User Id')),
        BooleanCheckBox('state', title=MSG(u'Payed ?')),
        TextWidget('amount', title=MSG(u'Amount')),
        MultilineWidget('description', title=MSG(u'Description')),
    ]

    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='./')
Ejemplo n.º 9
0
class CreditPayment_View(AutoForm):

    access = 'is_admin'
    title = MSG(u'Add a voucher')

    schema = {
        'user': Users_Enumerate,
        'amount': Decimal,
        'description': Unicode
    }

    widgets = [
        SelectWidget('user', title=MSG(u'User')),
        TextWidget('amount', title=MSG(u'Amount (€)')),
        MultilineWidget('description', title=MSG(u'Description'))
    ]

    def action(self, resource, context, form):
        users_credit = resource.get_resource('users-credit').handler
        users_credit.add_record({
            'user': form['user'],
            'amount': form['amount'],
            'description': form['description']
        })
        msg = MSG(u'Voucher has been added !')
        return context.come_back(msg, goto='../')
Ejemplo n.º 10
0
class PaymentWay_Configure(DBResource_Edit):

    access = 'is_admin'

    schema = {
        'title': Unicode(mandatory=True, multilingual=True),
        'logo': ImagePathDataType(mandatory=True, multilingual=True),
        'data': XHTMLBody(mandatory=True, multilingual=True),
        'only_this_groups': UserGroup_Enumerate(multiple=True),
        'enabled': Boolean(mandatory=True)
    }

    widgets = [
        TextWidget('title', title=MSG(u'Title')),
        ImageSelectorWidget('logo', title=MSG(u'Logo')),
        BooleanRadio('enabled', title=MSG(u'Enabled ?')),
        RTEWidget('data', title=MSG(u"Description")),
        SelectWidget('only_this_groups', title=MSG(u"Only for this groups"))
    ]

    submit_value = MSG(u'Edit configuration')

    def get_value(self, resource, context, name, datatype):
        language = resource.get_content_language(context)
        return resource.get_property(name, language=language)

    def action(self, resource, context, form):
        language = resource.get_content_language(context)
        for key, datatype in self.schema.items():
            if getattr(datatype, 'multilingual', False):
                resource.set_property(key, form[key], language=language)
            else:
                resource.set_property(key, form[key])
        return context.come_back(messages.MSG_CHANGES_SAVED, goto='./')
Ejemplo n.º 11
0
class ShippingWayTable(Table):

    class_id = 'shipping-way-table'
    class_handler = ShippingWayBaseTable

    form = [
        TextWidget('ref', title=MSG(u'Facture number')),
        SelectWidget('state', title=MSG(u'State')),
        TextWidget('price', title=MSG(u'Price')),
        TextWidget('weight', title=MSG(u'Weight')),
        TextWidget('number', title=MSG(u'Numéro')),
        TextWidget('description', title=MSG(u'Description')),
        ]

    def get_record_namespace(self, context, record):
        namespace = {}
        # Id
        namespace['id'] = record.id
        namespace['shipping_mode'] = self.parent.get_title()
        # Complete id
        namespace['complete_id'] = '%s-%s' % (self.parent.name, record.id)
        # Base namespace
        for key in self.handler.record_properties.keys():
            namespace[key] = self.handler.get_record_value(record, key)
        # State
        namespace['state'] = ShippingStates.get_value(namespace['state'])
        # Timestamp
        accept = context.accept_language
        value = self.handler.get_record_value(record, 'ts')
        namespace['ts'] = format_datetime(value,  accept)
        return namespace
Ejemplo n.º 12
0
class Addresses_Search(SearchTable_View):

    access = 'is_admin'

    search_schema = {
        'user': String,
        'firstname': Unicode,
        'lastname': Unicode,
        'zipcode': String,
        'town': Unicode,
        'country': CountriesEnumerate
    }

    search_widgets = [
        TextWidget('user', title=MSG(u'Id user')),
        TextWidget('firstname', title=MSG(u'Firstname')),
        TextWidget('lastname', title=MSG(u'Lastname')),
        TextWidget('zipcode', title=MSG(u'Zipcode')),
        TextWidget('town', title=MSG(u'Town')),
        SelectWidget('country', title=MSG(u'Country'))
    ]

    def get_table_columns(self, resource, context):
        return (SearchTable_View.get_table_columns(self, resource, context) +
                [('user', MSG(u'Id user'))])

    def get_item_value(self, resource, context, item, column):
        if column == 'user':
            handler = resource.handler
            value = handler.get_record_value(item, column)
            return value, '/users/%s' % value
        return SearchTable_View.get_item_value(self, resource, context, item,
                                               column)
Ejemplo n.º 13
0
class ShopModule_GooglePlusOneButton(ShopModule):

    class_id = 'shop_module_google_plus_one'
    class_title = MSG(u'Google plus one button')
    class_views = ['edit']
    class_description = MSG(u'Google plus one button')

    item_schema = {'size': Size,
                   'count': Count}

    item_widgets = [
        SelectWidget('size', title=MSG(u'Size'), has_empty_option=False),
        SelectWidget('count', title=MSG(u'Show count ?'), has_empty_option=False),
        ]


    def render(self, resource, context):
        return ShopModule_GooglePlusOneButton_View().GET(self, context)
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def get_namespace(self, datatype, value):
     namespace = Widget.get_namespace(self, datatype, value)
     context = get_context()
     if value and value != '1':
         try:
             day, month, year = value.split('/')
             day = int(day)
             month = int(month)
             year = int(year)
         except:
             day = month = year = None
     else:
         day = context.get_form_value('day', type=Integer)
         month = context.get_form_value('month', type=Integer)
         year = context.get_form_value('year', type=Integer)
     namespace['day'] = SelectWidget('day').to_html(Days, day)
     namespace['month'] = SelectWidget('month').to_html(Months, month)
     namespace['year'] = SelectWidget('year').to_html(Years, year)
     return namespace
Ejemplo n.º 16
0
class ShopForm(OrderedTable):

    class_id = 'shop-form'
    class_title = MSG(u'Shop form')
    class_version = '20090609'
    class_handler = ShopFormTable
    class_views = ['display', 'edit', 'view', 'add_record']

    display = ShopForm_Display()
    view = OrderedTable_View(search_template=None, access='is_admin')
    edit = AutomaticEditView()

    add_product = AddProduct_View()

    form = [
        TextWidget('name', title=MSG(u'Name')),
        TextWidget('title', title=MSG(u'Title')),
        BooleanCheckBox('mandatory', title=MSG(u'Mandatory')),
        BooleanCheckBox('multiple', title=MSG(u'Multiple')),
        SelectWidget('datatype', title=MSG(u'Data Type')),
        SelectWidget('widget', title=MSG(u'Widget')),
    ]

    edit_widgets = [
        TextWidget('submit_value', title=MSG(u'Submit value')),
        TextWidget('to_addr', title=MSG(u'To addr')),
        RTEWidget('introduction', title=MSG(u'Introduction')),
        RTEWidget('final_message', title=MSG(u'Final message')),
        BooleanRadio('must_be_authentificated',
                     title=MSG(u'Must be authentificated to see form'))
    ]

    edit_schema = {
        'submit_value': Unicode(multilingual=True, mandatory=True),
        'to_addr': Email(mandatory=True),
        'introduction': XHTMLBody(multilingual=True),
        'final_message': XHTMLBody(multilingual=True),
        'must_be_authentificated': Boolean
    }

    @classmethod
    def get_metadata_schema(cls):
        return merge_dicts(OrderedTable.get_metadata_schema(), cls.edit_schema)
Ejemplo n.º 17
0
 def get_options(cls):
     from products.enumerate import CategoriesEnumerate
     datatype = CategoriesEnumerate
     context = get_context()
     value = context.resource.get_property('specific_category')
     html = SelectWidget('specific_category').to_html(datatype, value)
     opt = [{
         'name': 'one_category',
         'value': list(XMLParser('Only this category')) + list(html)
     }]
     return cls.base_options + opt
Ejemplo n.º 18
0
class CreditAvailable_Table(Table):

    class_id = 'credit-available-table'
    class_handler = CreditAvailable_Basetable
    class_views = ['view', 'back']

    back = GoToSpecificDocument(specific_document='..',
                                title=MSG(u'Back'))

    form = [SelectWidget('user', title=MSG(u'User id')),
            TextWidget('amount', title=MSG(u'Credit amount')),
            TextWidget('description', title=MSG(u'Description'))]
Ejemplo n.º 19
0
 def get_item_value(self, resource, context, item, column):
     handler = resource.handler
     if column == 'checkbox':
         return item.id, False
     elif column == 'title':
         id = item.id
         title = handler.get_record_value(item, 'title')
         link = context.get_link(resource)
         return title, '%s/;edit_record?id=%s' % (link, id)
     elif column == 'countries':
         from countries import CountriesEnumerate
         datatype = CountriesEnumerate(zone=item.id)
         widget = SelectWidget('l_%s' % item.id, has_empty_option=False)
         h_widget = widget.to_html(datatype, None)
         link = '/shop/countries?zone=%i&search=' % item.id
         link = self.link_template % link
         h_link = XMLParser(link)
         return list(h_widget) + list(h_link)
     elif column == 'has_tax':
         has_tax = handler.get_record_value(item, 'has_tax')
         return bool_to_img(has_tax)
Ejemplo n.º 20
0
 def get_item_value(self, resource, context, item, column):
     handler = resource.handler
     if column == 'checkbox':
         return item.id, False
     elif column == 'title':
         id = item.id
         title = handler.get_record_value(item, 'title')
         link = context.get_link(resource)
         return title, '%s/;edit_record?id=%s' % (link, id)
     elif column == 'countries':
         from countries import CountriesEnumerate
         datatype = CountriesEnumerate(zone=item.id)
         widget = SelectWidget('l_%s' % item.id, has_empty_option=False)
         h_widget = widget.to_html(datatype, None)
         link = '/shop/countries?zone=%i&search=' % item.id
         link = self.link_template % link
         h_link = XMLParser(link)
         return list(h_widget) + list(h_link)
     elif column == 'has_tax':
         has_tax = handler.get_record_value(item, 'has_tax')
         return bool_to_img(has_tax)
Ejemplo n.º 21
0
class ShippingPrices(Table):

    class_id = 'shipping-prices'
    class_title = MSG(u'Shipping Prices')
    class_handler = ShippingPricesTable

    class_views = ['view', 'add_record']

    form = [
        SelectWidget('zone', title=MSG(u'Zone')),
        TextWidget('price', title=MSG(u'Price'))]

    quantity_widget = TextWidget('max-quantity', title=MSG(u'Max quantity'))
    weight_widget = TextWidget('max-weight', title=MSG(u'Max Weight (Kg)'))

    def get_form(self):
        if self.parent.get_property('mode') == 'quantity':
            return self.form + [self.quantity_widget]
        return self.form + [self.weight_widget]

    view = SearchTable_View(search_widgets=[SelectWidget('zone', title=MSG(u'Zone'))],
                            search_schema={'zone': CountriesZonesEnumerate})
Ejemplo n.º 22
0
class Advertising_SidebarBox(Box):

    class_id = 'shop_module_advertising_sidebar_box'
    class_title = MSG(u'Box for advertising')
    class_description = MSG(u'Add an advertising on your sidebar')

    view = Advertising_SidebarBox_View()

    edit_schema = {'ads_abspath': Ads_List}

    edit_widgets = [
        SelectWidget('ads_abspath',
                     title=MSG(u'Ads to show'),
                     has_empty_option=False)
    ]
Ejemplo n.º 23
0
 def get_namespace(self, resource, context):
     namespace = {}
     cart = ProductCart(context)
     widget = SelectWidget('delivery_address', has_empty_option=False)
     namespace['delivery_address'] = widget.to_html(
         Addresses_Enumerate, cart.addresses['delivery_address'])
     widget = SelectWidget('bill_address', has_empty_option=False)
     namespace['bill_address'] = widget.to_html(
         Addresses_Enumerate, cart.addresses['bill_address'])
     return namespace
Ejemplo n.º 24
0
class ShopModule_AddThis(ShopModule):

    class_id = 'shop_module_addthis'
    class_title = MSG(u'Add This')
    class_views = ['edit']
    class_description = MSG(u'Add this')

    item_schema = {'username': String, 'style': AddThis_Styles(default=1)}

    item_widgets = [
        TextWidget('username', title=MSG(u'Addthis account username')),
        SelectWidget('style', title=MSG(u'Style'), has_empty_option=False)
    ]

    def render(self, resource, context):
        return ShopModule_AddThis_View().GET(self, context)
Ejemplo n.º 25
0
class ShopModule_TwitterButton(ShopModule):

    class_id = 'shop_module_twitter_button'
    class_title = MSG(u'Twitter button')
    class_views = ['edit']
    class_description = MSG(u'Twitter button')

    item_schema = {'datacount': DataCount}

    item_widgets = [
        SelectWidget('datacount',
                     title=MSG(u'Data count'),
                     has_empty_option=False),
    ]

    def render(self, resource, context):
        return ShopModule_TwitterButton_View().GET(self, context)
Ejemplo n.º 26
0
 def get_item_value(self, resource, context, item, column):
     item_brain, item_resource = item
     if column == 'checkbox':
         if self.get_nb_use(context, item_resource) > 0:
             return None
         return item_brain.name, False
     if column == 'enumerate_preview':
         datatype = EnumerateTable_to_Enumerate(
             enumerate_name=item_brain.name)
         return SelectWidget('html_list', has_empty_option=False).to_html(
             datatype, None)
     elif column == 'title':
         return (item_resource.get_title(), item_brain.name)
     elif column == 'nb':
         return self.get_nb_use(context, item_resource)
     return Folder_BrowseContent.get_item_value(self, resource, context,
                                                item, column)
Ejemplo n.º 27
0
class CrossSelling_Section(Folder):
    """
    XXX That should be a section_view on 0.62
    """

    class_id = 'section-cross-selling'
    class_title = MSG(u'Cross Selling Section')
    class_views = ['view', 'edit']

    view = CrossSelling_Section_View()
    edit = AutomaticEditView()

    # Edit views
    edit_schema = {'product_model': ProductModelsEnumerate}

    edit_widgets = [
        SelectWidget('product_model', title=MSG(u'Product model')),
    ]
Ejemplo n.º 28
0
class Addresses(Table):

    class_id = 'addresses'
    class_title = MSG(u'Adresse')
    class_handler = BaseAddresses
    class_views = ['addresses_book', 'search']

    @property
    def class_views(self):
        context = get_context()
        # Back-Office
        hostname = context.uri.authority
        if hostname[:6] == 'admin.':
            return ['search']
        return ['addresses_book']

    # Views
    addresses_book = Addresses_Book()
    add_address = Addresses_AddAddress()
    edit_address = Addresses_EditAddress()
    search = Addresses_Search()

    view = Table_View(access='is_admin')
    last_changes = None
    add_record = None

    address_title = MSG(u"""
      Please give a name to your address.
      """)

    address_tip = MSG(u"(Example: Home, Office)")

    form = [
        SelectRadio('gender', title=MSG(u'Genre')),
        TextWidget('firstname', title=MSG(u'Firstname')),
        TextWidget('lastname', title=MSG(u'Lastname')),
        TextWidget('address_1', title=MSG(u'Address')),
        TextWidget('address_2', title=MSG(u'Address (next)')),
        TextWidget('zipcode', title=MSG(u'Zip Code')),
        TextWidget('town', title=MSG(u'Town')),
        SelectWidget('country', title=MSG(u'Country')),
        TextWidget('title', title=address_title, tip=address_tip),
    ]
Ejemplo n.º 29
0
class Filter_Criterium_Categorie(Folder):

    class_id = 'sidebar-item-filter-box-criterium-categorie'
    class_title = MSG(u'Catégorie criterium')
    class_views = ['edit']

    edit = AutomaticEditView(access='is_admin')
    edit_show_meta = False
    edit_schema = {'base_abspath': CategoriesEnumerate(mandatory=True)}
    edit_widgets = [SelectWidget('base_abspath', title=MSG(u'Base Abspath'))]

    @classmethod
    def get_metadata_schema(cls):
        return merge_dicts(Folder.get_metadata_schema(),
                           base_abspath=CategoriesEnumerate)

    def get_items(self, context):
        options = []
        root = get_context().root
        base_abspath = self.get_property('base_abspath')
        base_resource = root.get_resource(base_abspath)
        search = root.search(format='category', parent_paths=base_abspath)
        items_list = [base_resource]
        for brain in search.get_documents(sort_by='abspath'):
            items_list.append(root.get_resource(brain.abspath))
        for resource in items_list:
            abspath = str(resource.get_abspath())
            selected = context.resource.get_abspath() == abspath
            uri = get_reference(context.get_link(resource))
            uri.query = context.uri.query
            title = resource.get_title()
            if abspath == base_abspath:
                title = MSG(u'All')
            options.append({
                'name': abspath,
                'criterium': 'category',
                'query': PhraseQuery('parent_paths', abspath),
                'selected': selected,
                'uri': uri,
                'css': 'selected' if selected else None,
                'title': title
            })
        return options
Ejemplo n.º 30
0
class ProductModelSchema(OrderedTable):

    class_id = 'product-model-schema'
    class_title = MSG(u'Model Schema')
    class_version = '20090609'
    class_handler = ProductTypeTable
    class_views = ['view', 'add_record']

    view = ProductModelSchema_View()
    add_record = ProductModelSchema_AddRecord()
    edit_record = ProductModelSchema_EditRecord()

    form = [
        TextWidget('name', title=MSG(u'Name')),
        TextWidget('title', title=MSG(u'Title')),
        BooleanCheckBox('mandatory', title=MSG(u'Mandatory')),
        BooleanCheckBox('multiple', title=MSG(u'Multiple')),
        BooleanCheckBox('multilingual', title=MSG(u'Multilingual')),
        BooleanCheckBox('visible', title=MSG(u'Visible')),
        SelectWidget('datatype', title=MSG(u'Data Type')),
    ]
Ejemplo n.º 31
0
class Countries_View(SearchTable_View):

    columns = [
        ('checkbox', None),
        ('title', MSG(u'Country title')),
        ('zone', MSG(u'Zone title')),
        ('enabled', MSG(u'Is enabled ?')),
    ]

    # XXX Can't delete country
    # We have to check -> User addresses ...
    table_actions = []

    search_schema = {'zone': CountriesZonesEnumerate}
    search_widgets = [SelectWidget('zone', title=MSG(u'Zone'))]

    def get_table_columns(self, resource, context):
        return self.columns

    def get_query_schema(self):
        return merge_dicts(SearchTable_View.get_query_schema(self),
                           batch_size=Integer(default=500),
                           reverse=Boolean(default=False),
                           sort_by=String(default='title'))

    def get_item_value(self, resource, context, item, column):
        handler = resource.handler
        if column == 'checkbox':
            return item.id, False
        elif column == 'title':
            id = item.id
            title = handler.get_record_value(item, 'title')
            link = context.get_link(resource)
            return title, '%s/;edit_record?id=%s' % (link, id)
        elif column == 'zone':
            zone = handler.get_record_value(item, 'zone')
            return CountriesZonesEnumerate.get_value(zone)
        elif column == 'enabled':
            enabled = handler.get_record_value(item, 'enabled')
            return bool_to_img(enabled)
Ejemplo n.º 32
0
class Countries(Table):

    class_id = 'countries'
    class_title = MSG(u'Countries')
    class_handler = BaseCountries
    class_views = ['view', 'add_record']

    view = Countries_View()
    add_record = Table_AddRecord(title=MSG(u'Add a new country'))

    form = [
        TextWidget('title', title=MSG(u'Country title')),
        SelectWidget('zone', title=MSG(u'Zone')),
        BooleanRadio('enabled', title=MSG(u'Enabled')),
    ]

    # XXX Enabled means its enabled for delivery not for registration
    # People from south africa can register on website but not to be delivered
    # This distinction must be explicit

    @staticmethod
    def _make_resource(cls, folder, name, *args, **kw):
        Table._make_resource(cls, folder, name)
        # Import CSV with list of countries
        zones = []
        table = BaseCountries()
        csv = ro_database.get_handler(get_abspath('data/countries.csv'),
                                      CSVFile)
        for line in csv.get_rows():
            country = unicode(line[0], 'utf-8')
            zone = unicode(line[1], 'utf-8')
            if zone not in zones:
                zones.append(zone)
            table.add_record({
                'title': Property(country, language='fr'),
                'zone': str(zones.index(zone)),
                'enabled': True
            })
        folder.set_handler(name, table)
Ejemplo n.º 33
0
class CheckPaymentTable(PaymentWayTable):

    class_id = 'checkpayment-payments'
    class_title = MSG(u'Check payment Module')
    class_handler = CheckPaymentBaseTable

    class_views = ['view', 'add_record']

    form = PaymentWayTable.form + [
        TextWidget('check_number', title=MSG(u'Check number')),
        TextWidget('bank', title=MSG(u'Bank')),
        TextWidget('account_holder', title=MSG(u'Account holder')),
        SelectWidget('advance_state', title=MSG(u'Advance state'))
        ]


    def get_record_namespace(self, context, record):
        namespace = PaymentWayTable.get_record_namespace(self, context, record)
        # Advance State
        advance_state = self.handler.get_record_value(record, 'advance_state')
        namespace['advance_state'] = CheckStates.get_value(advance_state)
        return namespace
Ejemplo n.º 34
0
 def get_namespace(self, resource, context):
     datatype = CategoriesSortEnumerate
     value = str(context.uri)
     widget = SelectWidget('sort_by', has_empty_option=False)
     return {'widget': widget.to_html(datatype, value)}