Esempio n. 1
0
class ShopRoot_Edit(DBResource_Edit):

    access = 'is_admin'

    schema = {'administrators': MultiLinesTokens(mandatory=True)}
    widgets = [MultilineWidget('administrators', title=MSG(u"Administrators"))]

    def action(self, resource, context, form):
        values = [x.strip() for x in form['administrators']]
        resource.set_property('administrators', values)
        context.message = MSG_CHANGES_SAVED
        return
Esempio n. 2
0
class SetupConf(ConfigFile):

    schema = {
        'name': String,
        'package_name': String,
        'package_root': String(default='.'),
        'title': String,
        'url': String,
        'author_name': String,
        'author_email': Email,
        'license': String,
        'description': String,
        'classifiers': MultiLinesTokens(default=()),
        'packages': Tokens,
        'scripts': Tokens,
        'source_language': String,
        'target_languages': Tokens,
        'repository': URI,
        'username': String}
Esempio n. 3
0
class MassSubscriptionForm(AutoForm):

    access = 'is_admin'
    title = MSG(u"Mass Subscription")
    description = MSG(
        u"An invitation will be sent to every address typen below, one by"
        u" line.")
    schema = freeze({'emails': MultiLinesTokens(mandatory=True)})
    widgets = freeze([MultilineWidget(
        'emails',
        focus=False,
    )])
    actions = [MassSubscribeButton, Button]  # len(actions) > 1

    def get_value(self, resource, context, name, datatype):
        if name == 'emails':
            return ''
        proxy = super(MassSubscriptionForm, self)
        return proxy.get_value(resource, context, name, datatype)

    def action_mass_subscribe(self, resource, context, form):
        root = context.root

        already = []
        unallowed = []
        invited = []
        invalid = []
        subscribed_users = resource.get_subscribed_users()
        for email in form['emails']:
            email = email.strip()
            if not email:
                continue
            # Check if email is valid
            if not Email.is_valid(email):
                invalid.append(email)
                continue

            # Checks
            user = root.get_user_from_login(email)
            if user:
                if user.name in subscribed_users:
                    already.append(user)
                    continue
                if not resource.is_subscription_allowed(user.name):
                    unallowed.append(user)
                    continue

            # Subscribe
            user = resource.subscribe_user(email=email, user=user)
            key = resource.set_register_key(user.name)
            # Send invitation
            subject = resource.invitation_subject.gettext()
            confirm_url = context.uri.resolve(';accept_invitation')
            confirm_url.query = {'key': key, 'email': email}
            text = resource.invitation_text.gettext(uri=confirm_url)
            root.send_email(email, subject, text=text)
            invited.append(user)

        # Ok
        context.message = []
        add_subscribed_message(MSG_ALREADY, already, context)
        add_subscribed_message(MSG_INVALID,
                               invalid,
                               context,
                               users_is_resources=False)
        add_subscribed_message(MSG_INVITED, invited, context)
        add_subscribed_message(MSG_UNALLOWED, unallowed, context)
Esempio n. 4
0
class Shop_Configure(DBResource_Edit):

    access = 'is_admin'
    title = MSG(u'Configure shop')

    schema = {
        'shop_uri': String(mandatory=True),
        'shop_backoffice_uri': String(mandatory=True),
        'order_notification_mails': MultiLinesTokens(mandatory=True),
        'shop_default_zone': CountriesZonesEnumerate(mandatory=True),
        'shop_sort_by': SortBy_Enumerate(mandatory=True),
        'shop_sort_reverse': Boolean(mandatory=True),
        'devise': Devises(mandatory=True),
        'hide_not_buyable_products': Boolean(mandatory=True),
        'categories_batch_size': Integer(mandatory=True),
        'show_sub_categories': Boolean,
        'product_cover_is_mandatory': Boolean,
        'log_authentification': Boolean,
        'registration_need_email_validation': Boolean,
        'bill_logo': ImagePathDataType,
        'pdf_signature': Unicode,
        'barcode_format': BarcodesFormat
    }

    widgets = [
        TextWidget('shop_uri', title=MSG(u'Website uri')),
        TextWidget('shop_backoffice_uri',
                   title=MSG(u'Website backoffice uri')),
        MultilineWidget(
            'order_notification_mails',
            title=MSG(u'New order notification emails (1 per line)'),
            rows=8,
            cols=50),
        MultilineWidget('pdf_signature',
                        title=MSG(u'PDF signature'),
                        rows=8,
                        cols=50),
        SelectWidget('shop_default_zone', title=MSG(u'Shop default zone')),
        SelectWidget('devise', title=MSG(u'Devises'), has_empty_option=False),
        TextWidget('categories_batch_size',
                   title=MSG(u'Batch size for categories ?')),
        SelectWidget('shop_sort_by',
                     title=MSG(u'Sort products by ...'),
                     has_empty_option=False),
        BooleanRadio('shop_sort_reverse', title=MSG(u'Reverse sort ?')),
        BooleanRadio('show_sub_categories',
                     title=MSG(u'Show sub categories ?')),
        BooleanRadio('product_cover_is_mandatory',
                     title=MSG(u'Product cover is mandatory ?')),
        BooleanRadio('hide_not_buyable_products',
                     title=MSG(u'Hide not buyable products ?')),
        BooleanRadio('log_authentification',
                     title=MSG(u'Log users authentification ?')),
        BooleanRadio('registration_need_email_validation',
                     title=MSG(u'Ask for mail validation on registration ?')),
        ImageSelectorWidget('bill_logo', title=MSG(u'Bill logo')),
        SelectWidget('barcode_format',
                     title=MSG(u'Barcode format'),
                     has_empty_option=False),
    ]

    submit_value = MSG(u'Edit configuration')

    def action(self, resource, context, form):
        for key in self.schema.keys():
            if key == 'order_notification_mails':
                continue
            resource.set_property(key, form[key])
        values = [x.strip() for x in form['order_notification_mails']]
        resource.set_property('order_notification_mails', values)
        context.message = MSG_CHANGES_SAVED
        return