Ejemplo n.º 1
0
class ReuseForm(ModelForm):
    model_class = Reuse

    title = fields.StringField(
        _('Title'),
        [validators.DataRequired(),
         validators.Length(max=TITLE_SIZE_LIMIT)])
    description = fields.MarkdownField(
        _('Description'), [
            validators.DataRequired(),
            validators.Length(max=DESCRIPTION_SIZE_LIMIT)
        ],
        description=_('The details about the reuse (build process, specifics, '
                      'self-critics...).'))
    type = fields.SelectField(_('Type'), choices=list(REUSE_TYPES.items()))
    url = fields.URLField(
        _('URL'), [validators.DataRequired(), check_url_does_not_exists])
    image = fields.ImageField(_('Image'),
                              sizes=IMAGE_SIZES,
                              placeholder='reuse')
    tags = fields.TagField(_('Tags'), description=_('Some taxonomy keywords'))
    datasets = fields.DatasetListField(_('Used datasets'))
    private = fields.BooleanField(
        _('Private'),
        description=_('Restrict the dataset visibility to you or '
                      'your organization only.'))
    topic = fields.SelectField(_('Topic'), choices=list(REUSE_TOPICS.items()))

    owner = fields.CurrentUserField()
    organization = fields.PublishAsField(_('Publish as'))
    deleted = fields.DateTimeField()
Ejemplo n.º 2
0
class OrganizationForm(ModelForm):
    model_class = Organization

    name = fields.StringField(
        _('Name'),
        [validators.DataRequired(),
         validators.Length(max=TITLE_SIZE_LIMIT)])
    acronym = fields.StringField(_('Acronym'),
                                 description=_('Shorter organization name'))
    description = fields.MarkdownField(
        _('Description'), [
            validators.DataRequired(),
            validators.Length(max=DESCRIPTION_SIZE_LIMIT)
        ],
        description=_('The details about your organization'))
    url = fields.URLField(_('Website'),
                          description=_('The organization website URL'))
    logo = fields.ImageField(_('Logo'), sizes=LOGO_SIZES)

    deleted = fields.DateTimeField()
    extras = fields.ExtrasField()

    def save(self, commit=True, **kwargs):
        '''Register the current user as admin on creation'''
        org = super(OrganizationForm, self).save(commit=False, **kwargs)

        if not org.id:
            user = current_user._get_current_object()
            member = Member(user=user, role='admin')
            org.members.append(member)

        if commit:
            org.save()

        return org
Ejemplo n.º 3
0
class DatasetForm(ModelForm):
    model_class = Dataset

    title = fields.StringField(
        _('Title'),
        [validators.DataRequired(),
         validators.Length(max=TITLE_SIZE_LIMIT)])
    acronym = fields.StringField(_('Acronym'),
                                 description=_('An optional acronym'))
    description = fields.MarkdownField(
        _('Description'), [
            validators.DataRequired(),
            validators.Length(max=DESCRIPTION_SIZE_LIMIT)
        ],
        description=_('The details about the dataset '
                      '(collection process, specifics...).'))
    license = fields.ModelSelectField(_('License'),
                                      model=License,
                                      allow_blank=True)
    frequency = fields.SelectField(
        _('Update frequency'),
        choices=list(UPDATE_FREQUENCIES.items()),
        default=DEFAULT_FREQUENCY,
        validators=[validators.optional()],
        preprocessors=[map_legacy_frequencies],
        description=_('The frequency at which data are updated.'))
    frequency_date = fields.DateTimeField(_('Expected frequency date'))
    deleted = fields.DateTimeField()
    archived = fields.DateTimeField()
    temporal_coverage = fields.DateRangeField(
        _('Temporal coverage'),
        description=_('The period covered by the data'))
    spatial = SpatialCoverageField(
        _('Spatial coverage'),
        description=_('The geographical area covered by the data.'))
    tags = fields.TagField(_('Tags'), description=_('Some taxonomy keywords'))
    private = fields.BooleanField(
        _('Private'),
        description=_('Restrict the dataset visibility to you or '
                      'your organization only.'))

    owner = fields.CurrentUserField()
    organization = fields.PublishAsField(_('Publish as'))
    extras = fields.ExtrasField()
    resources = fields.NestedModelList(ResourceForm)
Ejemplo n.º 4
0
class DiscussionCreateForm(ModelForm):
    model_class = Discussion

    title = fields.StringField(_('Title'), [validators.DataRequired()])
    comment = fields.StringField(
        _('Comment'),
        [validators.DataRequired(),
         validators.Length(max=COMMENT_SIZE_LIMIT)])
    subject = fields.ModelField(_('Subject'), [validators.DataRequired()])
    extras = fields.ExtrasField()
Ejemplo n.º 5
0
class BaseResourceForm(ModelForm):
    title = fields.StringField(
        _('Title'),
        [validators.DataRequired(),
         validators.Length(max=TITLE_SIZE_LIMIT)])
    description = fields.MarkdownField(
        _('Description'), [validators.Length(max=DESCRIPTION_SIZE_LIMIT)])
    filetype = fields.RadioField(
        _('File type'), [validators.DataRequired()],
        choices=list(RESOURCE_FILETYPES.items()),
        default='file',
        description=_('Whether the resource is an uploaded file, '
                      'a remote file or an API'))
    type = fields.RadioField(
        _('Type'), [validators.DataRequired()],
        choices=list(RESOURCE_TYPES.items()),
        default='other',
        description=_('Resource type (documentation, API...)'))
    url = fields.UploadableURLField(_('URL'), [validators.DataRequired()],
                                    storage=resources)
    format = fields.StringField(
        _('Format'),
        filters=[normalize_format],
    )
    checksum = fields.FormField(ChecksumForm)
    mime = fields.StringField(_('Mime type'),
                              description=_(
                                  'The mime type associated to the extension. '
                                  '(ex: text/plain)'))
    filesize = fields.IntegerField(_('Size'), [validators.optional()],
                                   description=_('The file size in bytes'))
    published = fields.DateTimeField(
        _('Publication date'),
        description=_('The publication date of the resource'))
    extras = fields.ExtrasField()
    schema = fields.DictField(
        _('Schema'),
        default={},
        validators=[validators.optional(), enforce_allowed_schemas],
        description=_('The schema slug the resource adheres to'))
Ejemplo n.º 6
0
class DiscussionCommentForm(Form):
    comment = fields.StringField(
        _('Comment'),
        [validators.DataRequired(),
         validators.Length(max=COMMENT_SIZE_LIMIT)])
    close = fields.BooleanField(default=False)