Example #1
0
class _LeadSchema(ResourceSchema):
    lead_date = colander.SchemaNode(Date())
    customer_id = colander.SchemaNode(SelectInteger(Person), )
    advsource_id = colander.SchemaNode(SelectInteger(Advsource), )
    status = colander.SchemaNode(colander.String(), )
    lead_offer_id = colander.SchemaNode(colander.Set(), missing=[])
    lead_item_id = colander.SchemaNode(colander.Set(), )
    descr = colander.SchemaNode(colander.String(),
                                validator=colander.Length(max=255),
                                missing=None)

    def deserialize(self, cstruct):
        if ('lead_item_id' in cstruct
                and not isinstance(cstruct.get('lead_item_id'), list)):
            val = cstruct['lead_item_id']
            cstruct['lead_item_id'] = list()
            cstruct['lead_item_id'].append(val)

        if ('lead_offer_id' in cstruct
                and not isinstance(cstruct.get('lead_offer_id'), list)):
            val = cstruct['lead_offer_id']
            cstruct['lead_offer_id'] = list()
            cstruct['lead_offer_id'].append(val)

        return super(_LeadSchema, self).deserialize(cstruct)
Example #2
0
class SendSchema(Schema):

    winners = colander.SchemaNode(
        colander.Set(),
        widget=winners_widget,
        title=_('Winners')
        )

    participants = colander.SchemaNode(
        colander.Set(),
        widget=participants_widget,
        title=_('Participants')
        )

    subject = colander.SchemaNode(
        colander.String(),
        default=default_subject,
        title=_('Subject'),
        )

    message = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=2000),
        default=default_message,
        widget=deform.widget.TextAreaWidget(rows=10, cols=60),
        )
Example #3
0
class _SupplierSchema(ResourceSchema):
    name = colander.SchemaNode(colander.String(), validator=name_validator)
    descr = colander.SchemaNode(colander.String(),
                                validator=colander.Length(max=255),
                                missing=u'')
    status = colander.SchemaNode(colander.String(), )
    supplier_type_id = colander.SchemaNode(colander.Integer(), )
    bperson_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )
    bank_detail_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )

    def deserialize(self, cstruct):
        if ('bperson_id' in cstruct
                and not isinstance(cstruct.get('bperson_id'), list)):
            val = cstruct['bperson_id']
            cstruct['bperson_id'] = list()
            cstruct['bperson_id'].append(val)

        if ('bank_detail_id' in cstruct
                and not isinstance(cstruct.get('bank_detail_id'), list)):
            val = cstruct['bank_detail_id']
            cstruct['bank_detail_id'] = list()
            cstruct['bank_detail_id'].append(val)

        return super(_SupplierSchema, self).deserialize(cstruct)
Example #4
0
class ResourceSchema(CSRFSchema):
    note_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )
    task_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )

    def deserialize(self, cstruct):
        if (
            'note_id' in cstruct
            and not isinstance(cstruct.get('note_id'), list)
        ):
            val = cstruct['note_id']
            cstruct['note_id'] = list()
            cstruct['note_id'].append(val)
        if (
            'task_id' in cstruct
            and not isinstance(cstruct.get('task_id'), list)
        ):
            val = cstruct['task_id']
            cstruct['task_id'] = list()
            cstruct['task_id'].append(val)

        return super(ResourceSchema, self).deserialize(cstruct)
Example #5
0
class CopyAgendaSchema(colander.Schema):
    meeting_name = colander.SchemaNode(
        colander.String(),
        title=_("Copy Agenda from a previous meeting."),
        description=_(
            "You can only pick meeting where you've been a moderator. "),
        widget=deferred_copy_from_meeting_widget,
    )
    copy_types = colander.SchemaNode(
        colander.Set(),
        title=_("Copy these types"),
        missing=(),
        default=[x[0] for x in _TYPES_CHOICES],
        widget=deform.widget.CheckboxChoiceWidget(values=_TYPES_CHOICES))
    only_copy_prop_states = colander.SchemaNode(
        colander.Set(),
        title=_("Only copy proposals in these states"),
        missing=(),
        default=('published', 'approved', 'denied'),
        widget=prop_states_choice,
    )
    all_props_published = colander.SchemaNode(
        colander.Bool(),
        title=_("Make all proposals published?"),
        description=_("Uncheck this to retain workflow state"))
Example #6
0
class GameSchema(VisualisableElementSchema, SearchableEntitySchema):
    """Schema for Web advertising"""

    name = NameSchemaNode(editing=context_is_a_game, )

    description = colander.SchemaNode(colander.String(),
                                      widget=RichTextWidget(),
                                      title=_("Description"),
                                      missing="")

    winners = colander.SchemaNode(colander.Set(),
                                  widget=winners_widget,
                                  title=_('Winners'))

    winner_number = colander.SchemaNode(colander.Int(),
                                        title=_('Winner number'))

    participants = colander.SchemaNode(colander.Set(),
                                       widget=participants_widget,
                                       title=_('Participants'))

    start_date = colander.SchemaNode(colander.DateTime(),
                                     title=_('Start date'))

    end_date = colander.SchemaNode(colander.DateTime(), title=_('End date'))

    announcement = colander.SchemaNode(ObjectType(),
                                       widget=announcement_choice,
                                       missing=None,
                                       title=_("Cultural event"))

    picture = colander.SchemaNode(ObjectData(Image),
                                  widget=picture_widget,
                                  title=_('Picture'),
                                  missing=None)
Example #7
0
    def __init__(self, request):
        chosen_assets.need()

        self.request = request
        self.schema = SQLAlchemySchemaNode(Mailing, includes=self.fields)

        # we don't like the way ColanderAlchemy renders SA Relationships so
        # we manually inject a suitable SchemaNode for groups
        choices = [(group.id, group.name) for group in Group.get_all()]
        self.schema.add_before(
            'trigger',
            node=colander.SchemaNode(
                colander.Set(),
                name='groups',
                missing=[],
                widget=deform.widget.CheckboxChoiceWidget(values=choices),
            ),
        )
        self.schema.add_before(
            'trigger',
            node=colander.SchemaNode(
                colander.Set(),
                name='exclude_groups',
                missing=[],
                widget=deform.widget.CheckboxChoiceWidget(values=choices),
            ),
        )
Example #8
0
class _PersonSchema(ResourceSchema):
    person_category_id = colander.SchemaNode(
        colander.Integer(),
        missing=None,
    )
    first_name = colander.SchemaNode(colander.String(), )
    last_name = colander.SchemaNode(colander.String(), missing=u"")
    second_name = colander.SchemaNode(colander.String(), missing=u"")
    gender = colander.SchemaNode(
        colander.String(),
        missing=None,
    )
    birthday = colander.SchemaNode(
        Date(),
        missing=None,
    )
    email_subscription = colander.SchemaNode(
        colander.Boolean(),
        missing=False,
    )
    sms_subscription = colander.SchemaNode(
        colander.Boolean(),
        missing=False,
    )
    descr = colander.SchemaNode(colander.String(),
                                validator=colander.Length(max=255),
                                missing=None)
    contact_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )
    passport_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )
    address_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )

    def deserialize(self, cstruct):
        if ('address_id' in cstruct
                and not isinstance(cstruct.get('address_id'), list)):
            val = cstruct['address_id']
            cstruct['address_id'] = list()
            cstruct['address_id'].append(val)
        if ('contact_id' in cstruct
                and not isinstance(cstruct.get('contact_id'), list)):
            val = cstruct['contact_id']
            cstruct['contact_id'] = list()
            cstruct['contact_id'].append(val)
        if ('passport_id' in cstruct
                and not isinstance(cstruct.get('passport_id'), list)):
            val = cstruct['passport_id']
            cstruct['passport_id'] = list()
            cstruct['passport_id'].append(val)

        return super(_PersonSchema, self).deserialize(cstruct)
Example #9
0
class _StructureSchema(ResourceSchema):
    parent_id = colander.SchemaNode(
        colander.Integer(),
        missing=None,
        validator=parent_validator
    )
    name = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=128)
    )
    contact_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )
    address_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )
    bank_detail_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )

    def deserialize(self, cstruct):
        if (
            'contact_id' in cstruct
            and not isinstance(cstruct.get('contact_id'), list)
        ):
            val = cstruct['contact_id']
            cstruct['contact_id'] = list()
            cstruct['contact_id'].append(val)

        if (
            'address_id' in cstruct
            and not isinstance(cstruct.get('address_id'), list)
        ):
            val = cstruct['address_id']
            cstruct['address_id'] = list()
            cstruct['address_id'].append(val)

        if (
            'bank_detail_id' in cstruct
            and not isinstance(cstruct.get('bank_detail_id'), list)
        ):
            val = cstruct['bank_detail_id']
            cstruct['bank_detail_id'] = list()
            cstruct['bank_detail_id'].append(val)

        return super(_StructureSchema, self).deserialize(cstruct)
Example #10
0
def get_add_edit_schema(edit=False):
    """
    Add a form schema for login add/edit

    :returns: A colander form schema
    """
    schema = SQLAlchemySchemaNode(Login)
    set_widgets(schema)

    schema.add(
        colander.SchemaNode(
            colander.String(),
            name="primary_group",
            validator=_deferred_primary_group_validator,
            widget=_deferred_primary_group_widget,
            title=u"Rôle de l'utilisateur",
        ))
    schema.add(
        colander.SchemaNode(
            colander.Set(),
            name="groups",
            validator=_deferred_group_validator,
            widget=_deferred_group_widget,
            title=u"Droits spécifiques",
        ))

    if edit:
        schema['login'].validator = _deferred_login_validator
        schema['pwd_hash'].missing = colander.drop
        schema['user_id'].validator = _deferred_user_id_validator
    else:
        schema['user_id'].validator = _get_unique_user_id_validator()
        schema['login'].validator = _get_unique_login_validator()
    return schema
Example #11
0
class ProcessesSchema(Schema):

    processes = colander.SchemaNode(
        colander.Set(),
        widget=processes_choice,
        title=_('Processes to update'),
    )
Example #12
0
class RolesSchema(Schema):

    roles = colander.SchemaNode(colander.Set(),
                                validator=colander.All(roles_validator),
                                widget=roles_choice,
                                title=_('Roles'),
                                missing='Member')
Example #13
0
class InvoiceAttachSchema(colander.Schema):
    invoice_ids = colander.SchemaNode(
        colander.Set(),
        widget=deferred_invoice_widget,
        missing=colander.drop,
        title=u"Factures à rattacher à ce devis",
    )
Example #14
0
class LabelsSchema(Schema):

    labels = colander.SchemaNode(
        colander.Set(),
        widget=labels_choices,
        title=_('Labels'),
        description=_('You can add labels to this object.'),
        default=[],
        missing=[]
        )

    new_labels = colander.SchemaNode(
        colander.Sequence(),
        omit(select(LabelSchema(
            name='new_label',
            factory=Label,
            editable=True,
            widget=SimpleMappingWidget(
               css_class='label-well object-well default-well')),
            ['title', 'picture']),
        ['_csrf_token_']),
        widget=SequenceWidget(
            add_subitem_text_template=_('Add a new label')),
        title=_('New labels'),
        )
Example #15
0
class ExplanationGroupSchema(Schema):

    title = colander.SchemaNode(colander.String(),
                                missing="",
                                widget=TextInputWidget(
                                    css_class="title-select-item",
                                    item_css_class="col-md-4",
                                    readonly=True))

    explanations = colander.SchemaNode(
        colander.Set(),
        widget=explanations_choice,
        missing=[],
        default=[],
        title=_('Improvements'),
    )

    justification = colander.SchemaNode(
        colander.String(),
        widget=LimitedTextAreaWidget(limit=350,
                                     css_class="justification-select-item",
                                     item_css_class="col-md-4",
                                     placeholder=_("Justification")),
        missing="",
        title=_("Justification"))
Example #16
0
class UserForm(colander.MappingSchema):
    group = colander.SchemaNode(colander.String(encoding='utf-8'),
                                title=_(u"Role"),
                                widget=user_role_widget)

    clinics = colander.SchemaNode(colander.Set(),
                                  title=_(u"Clinic"),
                                  missing='',
                                  widget=clinic_selection_widget)

    municipality = colander.SchemaNode(colander.String(encoding='utf-8'),
                                       title=_(u"Municipality"),
                                       missing='',
                                       widget=municipality_selection_widget)

    state = colander.SchemaNode(colander.String(encoding='utf-8'),
                                title=_(u"State"),
                                missing='',
                                widget=state_selection_widget)

    password = colander.SchemaNode(colander.String(encoding='utf-8'),
                                   validator=colander.Length(min=5),
                                   widget=CheckedPasswordWidget(),
                                   missing='',
                                   title=_(u"Change Password"))

    def validator(self, node, value):
        exc = colander.Invalid(node, "")
        valid = True
        if value['group'] not in GROUPS:
            valid = False
        if not valid:
            raise exc
Example #17
0
class OrganizationSchema(Schema):
    """Schema for Organization"""

    members = colander.SchemaNode(colander.Set(),
                                  widget=members_choice,
                                  title=_('Members'),
                                  missing=[])
Example #18
0
class PrincipalFull(PrincipalBasic):
    name = colander.SchemaNode(
        colander.String(),
        title=_("Name"),
        validator=colander.All(name_pattern_validator, name_new_validator),
    )
    password = colander.SchemaNode(
        colander.String(),
        title=_("Password"),
        validator=colander.Length(min=5),
        missing=None,
        widget=CheckedPasswordWidget(),
    )
    active = colander.SchemaNode(
        colander.Boolean(),
        title=_("Active"),
        description=_("Untick this to deactivate the account."),
    )
    roles = colander.SchemaNode(
        colander.Set(),
        validator=roleset_validator,
        missing=[],
        title=_("Global roles"),
        widget=CheckboxChoiceWidget(),
    )
    groups = Groups(
        title=_("Groups"),
        missing=[],
        # XXX min_len doesn't really do what we want here.  We'd like
        # the close buttons to appear nevertheless (maybe the now
        # deprecated render_initial_item did exactly that).
        widget=SequenceWidget(min_len=1),
    )
Example #19
0
class _CampaignSchema(ResourceSchema):
    MAX_TAGS = 10
    name = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=32),
    )
    start_dt = colander.SchemaNode(DateTime(), validators=start_dt_validator)
    mail_id = colander.SchemaNode(SelectInteger(Mail), )
    person_category_id = colander.SchemaNode(
        SelectInteger(PersonCategory),
        missing=None,
    )
    tag_id = colander.SchemaNode(
        colander.Set(),
        validator=colander.Length(max=MAX_TAGS,
                                  max_err=_(u'Max %s tags allowed') %
                                  MAX_TAGS),
        missing=[],
    )
    status = colander.SchemaNode(colander.String(), validator=status_validator)

    def deserialize(self, cstruct):
        if ('tag_id' in cstruct
                and not isinstance(cstruct.get('tag_id'), list)):
            val = cstruct['tag_id']
            cstruct['tag_id'] = list()
            cstruct['tag_id'].append(val)

        return super(_CampaignSchema, self).deserialize(cstruct)
Example #20
0
class PublishProposalSchema(Schema):

    vote = colander.SchemaNode(
        colander.Boolean(false_val='False', true_val='True'),
        default=False,
        title=_('Options'),
        )

    work_mode = colander.SchemaNode(
        colander.String(),
        widget=mode_choice,
        default=mode_choice_default,
        title=_('Work mode'),
        description=_('Choose the work mode')
        )

    elected = colander.SchemaNode(
        colander.String(),
        title=_('Duration of the amendment cycle'),
    )

    members_to_invite = colander.SchemaNode(
        colander.Set(),
        widget=members_choice,
        validator=colander.All(emails_validator),
        title=_('Members to invite'),
        description= _('You can invite members to join the workgroup'),
        default=[],
        missing=[]
        )
Example #21
0
class ExtractionSchema(FilterSchema):

    attributes_to_extract = colander.SchemaNode(
        colander.Set(),
        widget=attr_choice,
        title=_('Attributes to extract'),
        missing=[])
Example #22
0
class PresentIdeaSchema(Schema):

    members = colander.SchemaNode(
        colander.Set(),
        widget=members_choice,
        validator=colander.All(
            Length(_,
                   min=1,
                   min_message="""Vous devez sélectionner """
                   """au moins {min} membre, ou saisir {min}"""
                   """ adresse courrier électronique."""), emails_validator),
        title=_('Recipients'))

    subject = colander.SchemaNode(
        colander.String(),
        default=default_subject,
        title=_('Subject'),
    )

    message = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=2000),
        default=default_message,
        widget=deform.widget.TextAreaWidget(rows=10, cols=60),
    )

    send_to_me = colander.SchemaNode(colander.Boolean(),
                                     widget=deform.widget.CheckboxWidget(),
                                     label=_('Put me in copy'),
                                     title='',
                                     missing=False)
Example #23
0
class _ContractSchema(ResourceSchema):
    supplier_id = colander.SchemaNode(
        SelectInteger(Supplier),
    )
    num = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(min=2, max=32)
    )
    date = colander.SchemaNode(
        Date(),
    )
    status = colander.SchemaNode(
        colander.String(),
    )
    descr = colander.SchemaNode(
        colander.String(),
        validator=colander.Length(max=255),
        missing=u''
    )
    commission_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )

    def deserialize(self, cstruct):
        if (
            'commission_id' in cstruct
            and not isinstance(cstruct.get('commission_id'), list)
        ):
            val = cstruct['commission_id']
            cstruct['commission_id'] = list()
            cstruct['commission_id'].append(val)
        return super(_ContractSchema, self).deserialize(cstruct)
Example #24
0
class ManageKeywordsSchema(Schema):

    targets = colander.SchemaNode(colander.Set(),
                                  widget=targets_choice,
                                  title=_("Keywords"))

    source = colander.SchemaNode(colander.String(), title=_("New keyword"))
Example #25
0
class KeywordsConfSchema(Schema):

    keywords = colander.SchemaNode(
        colander.Set(),
        widget=keywords_choice,
        title='Keywords',
        description=_("To add keywords, you need to separate them by commas "
                      "and then tap the « Enter » key to validate your selection."),
        missing=[]
        )

    can_add_keywords = colander.SchemaNode(
        colander.Boolean(),
        widget=deform.widget.CheckboxWidget(),
        label=_('Authorize the addition of keywords'),
        title='',
        default=True,
        missing=True
    )

    @invariant
    def contact_invariant(self, appstruct):
        can_add_keywords = appstruct.get('can_add_keywords', 'false')
        can_add_keywords = False if can_add_keywords == 'false' else True
        keywords = appstruct.get('keywords', colander.null)
        if not can_add_keywords and keywords is colander.null:
            raise colander.Invalid(
                self, _('You must enter at least one keyword.'))
Example #26
0
    def __init__(self, request):
        self.request = request
        self.schema = SQLAlchemySchemaNode(
            User,
            includes=self.fields,
            overrides={
                'properties': {'includes': ['key', 'value']},
                'email': {'validator': deferred_user_email_validator},
                'billing_email': {
                    'validator': deferred_user_billing_email_validator}
            }
        )

        # we don't like the way ColanderAlchemy renders SA Relationships so
        # we manually inject a suitable SchemaNode for groups
        choices = [(group.id, group.name) for group in Group.get_all()]
        enabled = Group.by_name('enabled')
        choices.remove((enabled.id, enabled.name))
        if not request.user.admin:
            admins = Group.by_name('admins')
            choices.remove((admins.id, admins.name))
        self.schema.add(
            node=colander.SchemaNode(
                colander.Set(),
                name='groups',
                missing=[],
                widget=deform.widget.CheckboxChoiceWidget(values=choices),
                validator=deferred_groups_validator,
            ),
        )
Example #27
0
class NotificationsSchema(CSRFSchema):
    types = (("reply", _("Email me when someone replies to one of my annotations.")),)

    notifications = colander.SchemaNode(
        colander.Set(),
        widget=deform.widget.CheckboxChoiceWidget(omit_label=True, values=types),
    )
Example #28
0
class TOSSettingsSchema(colander.Schema):
    data_consent_managers = colander.SchemaNode(
        colander.Set(),
        title=_("Data Consent Manager(s)"),
        descruption=_(
            "Users handling consent issues - must have administrator rights"),
        widget=UserReferenceWidget(),
        validator=OnlyAdministratorsWithEmailValidator,
    )
    email_consent_managers = colander.SchemaNode(
        colander.Bool(),
        title=_("Notify via email?"),
        description=_(
            "email_consent_managers_desc",
            default=
            "Email consent managers when a user revokes an important agreement.",
        ),
    )
    tos_folder = colander.SchemaNode(
        colander.String(),
        title=_("Folder to place TOS in"),
        description=_(
            "tos_folder_schema_description",
            default=
            "If you don't have any folders yet, create one in the root of your site."
        ),
        widget=ReferenceWidget(multiple=False,
                               query_params={"type_name": "Folder"}))
Example #29
0
class ContactSchema(Schema):

    services = colander.SchemaNode(colander.Set(),
                                   widget=contact_choice,
                                   title=_("Services to contact"),
                                   validator=colander.Length(min=1))

    name = colander.SchemaNode(colander.String(),
                               title=_('Name'),
                               missing='',
                               description=_('Please enter your full name'))

    email = colander.SchemaNode(
        colander.String(),
        widget=EmailInputWidget(),
        validator=colander.All(colander.Email(), colander.Length(max=100)),
        title=_('Email'),
        description=_('Please enter your email address'))

    subject = colander.SchemaNode(colander.String(), title=_('Subject'))

    message = colander.SchemaNode(
        colander.String(),
        widget=deform.widget.TextAreaWidget(rows=4, cols=60),
        title=_('Message'),
        description=_('Please enter the message you want to send.'))
Example #30
0
class PurchaseSchema(MappingSchema):
    db = sqlite()
    categories = db.getAllCategories()
    categories = [(cat, cat) for (cat, comment) in categories]
    availableFlags = (
            ('L', 'Ledger'),
    )
    shop = SchemaNode(String(),
                        description = 'Shop')
    payment_method = SchemaNode(
                String(),
                widget=widget.SelectWidget(values=categories),
                        description = 'Bezahlmethode'
                )
    date = SchemaNode(Date(),
                      description = 'Rechnungsdatum')
    flags = SchemaNode(colander.Set(),
                       widget=widget.CheckboxChoiceWidget(values=availableFlags),
                       )
    positions = PositionsSchema()
    title='Neue Transaktion'

    def update(self):
        categories = self.db.getAllCategories()
        categories = [(cat, cat) for (cat, comment) in categories]
        self['payment_method'].widget = widget.SelectWidget(values=categories)
        self['positions'].update()