Exemplo n.º 1
0
class ScheduleSchema(BaseSchema):
    time_slot = TimeSlotValidator(not_empty=True)
    location = LocationValidator(not_empty=True)
    event = EventValidator(not_empty=True)
    overflow = validators.Bool()
    video_url = validators.URL(add_http=True, check_exists=False, if_empty=None)
    audio_url = validators.URL(add_http=True, check_exists=False, if_empty=None)
    slide_url = validators.URL(add_http=True, check_exists=False, if_empty=None)
Exemplo n.º 2
0
 class fields(ew_core.NameList):
     name = ew.InputField(
         field_type='text',
         label='Name',
         validator=formencode.All(fev.UnicodeString(not_empty=True, max=40),
                                  V.MaxBytesValidator(max=40)),
         attrs=dict(
             maxlength=40,
             title=
             "This is the publicly viewable name of the project, and will appear on project listings. It should be what you want to see as the project title in search listing."
         ))
     summary = ew.InputField(field_type="text",
                             label='Short Summary',
                             validator=formencode.All(
                                 fev.UnicodeString(max=70),
                                 V.MaxBytesValidator(max=70)),
                             attrs=dict(maxlength=70))
     short_description = ew.TextArea(
         label='Full Description',
         validator=formencode.All(fev.UnicodeString(max=1000),
                                  V.MaxBytesValidator(max=1000)),
         attrs=dict(
             title=
             "Add a few paragraphs describing your project to new users."))
     icon = ew.FileField(label='Icon')
     external_homepage = ew.InputField(field_type="text",
                                       label='Homepage',
                                       validator=fev.URL(add_http=True))
     support_page = ew.InputField(field_type="text", label='Support Page')
     support_page_url = ew.InputField(field_type="text",
                                      label='Support Page URL',
                                      validator=fev.URL(add_http=True,
                                                        if_empty=''))
     removal = ew.InputField(field_type="text", label='Removal')
     moved_to_url = ew.InputField(field_type="text",
                                  label='Moved Project to URL',
                                  validator=fev.URL(add_http=True,
                                                    if_empty=''))
     export_controlled = ew.InputField(field_type="text",
                                       label='Export Control')
     export_control_type = ew.InputField(field_type="text",
                                         label='Export Control Type')
     delete = ew.InputField(field_type="hidden", label='Delete')
     delete_icon = ew.InputField(field_type="hidden", label='Delete Icon')
     undelete = ew.InputField(field_type="hidden", label='Undelete')
     tracking_id = ew.InputField(field_type="text",
                                 label="Analytics Tracking ID")
     twitter_handle = ew.InputField(field_type="text",
                                    label='Twitter Handle')
     facebook_page = ew.InputField(field_type="text",
                                   label='Facebook page',
                                   validator=fev.URL(add_http=True))
Exemplo n.º 3
0
class ProposalSchema(BaseSchema):
    allow_extra_fields = False

    title = validators.String(not_empty=True)
    abstract = validators.String(not_empty=True)
    private_abstract = validators.String()
    technical_requirements = validators.String(not_empty=False)
    type = ProposalTypeValidator()
    audience = TargetAudienceValidator()
    accommodation_assistance = AccommodationAssistanceTypeValidator()
    travel_assistance = TravelAssistanceTypeValidator()
    project = validators.String()
    url = validators.URL(add_http=True, check_exists=False, not_empty=False)
    abstract_video_url = validators.URL(add_http=True, check_exists=False, not_empty=False)
    video_release = validators.Bool()
    slides_release = validators.Bool()
Exemplo n.º 4
0
class ExistingPersonSchema(BaseSchema):
    allow_extra_fields = False

    experience = validators.String(not_empty=True)
    bio = validators.String(not_empty=True)
    url = validators.URL(add_http=True, check_exists=False, not_empty=False)
    mobile = validators.String(not_empty=True)
Exemplo n.º 5
0
    def set_exfeed(self, new_exfeed=None, **kw):
        exfeed_val = kw.get('exfeed', [])
        if type(exfeed_val) == unicode:
            tmp_exfeed_list = []
            tmp_exfeed_list.append(exfeed_val)
        else:
            tmp_exfeed_list = exfeed_val

        if new_exfeed is not None and new_exfeed != '':
            tmp_exfeed_list.append(new_exfeed)

        exfeed_list = []
        invalid_list = []
        v = validators.URL()
        for link in tmp_exfeed_list:
            try:
                v.to_python(link)
                exfeed_list.append(link)
            except formencode.api.Invalid:
                invalid_list.append(link)

        self.app.external_feeds_list = exfeed_list
        flash('External feeds updated')
        if len(invalid_list) > 0:
            flash(
                'Invalid link(s): %s' % ','.join(link
                                                 for link in invalid_list),
                'error')

        redirect(request.referer)
Exemplo n.º 6
0
class SettingsForm(formencode.Schema):
    """
    Validate Settings Page inputs.
    """

    ADMINISTRATOR_NAME = formencode.All(
        validators.UnicodeString(not_empty=True), validators.PlainText())
    ADMINISTRATOR_PASSWORD = validators.UnicodeString(not_empty=True)
    ADMINISTRATOR_EMAIL = validators.Email(not_empty=True)

    WEB_SERVER_PORT = PortValidator()
    URL_WEB = validators.URL(not_empty=True, require_tld=False)

    SELECTED_DB = validators.UnicodeString(not_empty=True)
    URL_VALUE = validators.UnicodeString(not_empty=True)
    DEPLOY_CLUSTER = validators.Bool()
    CLUSTER_SCHEDULER = validators.UnicodeString(not_empty=True)

    KEYCLOAK_CONFIGURATION = validators.UnicodeString(not_empty=True)
    TVB_STORAGE = validators.UnicodeString(not_empty=True)
    USR_DISK_SPACE = DiskSpaceValidator(not_empty=True)
    MATLAB_EXECUTABLE = MatlabValidator()
    MAXIMUM_NR_OF_THREADS = ThreadNrValidator()
    MAXIMUM_NR_OF_VERTICES_ON_SURFACE = SurfaceVerticesNrValidator()
    MAXIMUM_NR_OF_OPS_IN_RANGE = validators.Int(min=5,
                                                max=5000,
                                                not_empty=True)
Exemplo n.º 7
0
class CommentForm(Schema):
    allow_extra_fields = True
    filter_extra_fields = False
    comment = validators.UnicodeString(not_empty=True, strip=True)
    email = validators.Email(not_empty=True, resolve_domain=True)
    name = validators.UnicodeString(not_empty=True, strip=True)
    url = validators.URL(add_http=True)
Exemplo n.º 8
0
class EventSchema(BaseSchema):
    type = EventTypeValidator(not_empty=True)
    proposal = ProposalValidator()
    title = validators.String()
    url = validators.URL(add_http=True, check_exists=False)
    publish = validators.Bool()
    exclusive = validators.Bool()
Exemplo n.º 9
0
class ProfileForm(Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    delete = validators.StringBoolean(if_missing=False)
    identifier = validators.OpenId(not_empty=True)
    name = validators.UnicodeString(not_empty=True, strip=True)
    email = validators.Email(not_empty=False, resolve_domain=True)
    website = validators.URL(add_http=True)
Exemplo n.º 10
0
class ShortURLAdminController(DefaultAdminController):
    def __init__(self, app):
        self.app = app

    @expose()
    def index(self, **kw):
        redirect(c.project.url() + 'admin/tools')

    @expose('jinja:forgeshorturl:templates/add.html')
    @validate(dict(full_url=All(validators.URL(add_http=True),
                                validators.NotEmpty()),
                   short_url=validators.NotEmpty()))
    def add(self, short_url="",
            full_url="",
            description="",
            private="off", **kw):
        if (request.method == 'POST'):
            if pylons.c.form_errors:
                error_msg = "Error creating Short URL: "
                for msg in list(pylons.c.form_errors):
                    names = {"short_url": "Short name", "full_url": "Full URL"}
                    error_msg += "%s - %s " % (names[msg], c.form_errors[msg])
                    flash(error_msg, "error")
                redirect(request.referer)

            if (short_url != full_url):
                shorturl = ShortUrl.query.find({
                    'app_config_id': self.app.config._id,
                    'short_name': short_url}).first()
                if shorturl is None:
                    shorturl = ShortUrl()
                    shorturl.created = datetime.utcnow()
                    log_msg = 'create short url %s for %s' %\
                              (short_url,
                               full_url)
                else:
                    log_msg = 'update short url %s from %s to %s' %\
                              (short_url,
                               shorturl.full_url,
                               full_url)
                shorturl.full_url = full_url
                shorturl.short_name = short_url
                shorturl.description = description
                shorturl.create_user = c.user._id
                shorturl.app_config_id = self.app.config._id
                if private == "on":
                    shorturl.private = True
                else:
                    shorturl.private = False
                shorturl.last_updated = datetime.utcnow()
                M.AuditLog.log(log_msg)
                flash("Short url created")
            else:
                flash("Error creating Short URL: "
                      "Short Name and Full URL must be different", "error")
            redirect(request.referer)
        return dict(app=self.app)
Exemplo n.º 11
0
class Profile(models.base.BaseThing):
    _invalid_link = {'badURL': u'链接格式不正确',
                   'noTLD': u'链接格式不正确'}

    link_weibo = validators.URL(
            strip = True,
            add_http = True,
            not_empty = False,
            messages = _invalid_link)

    link_qq = validators.URL(
            strip = True,
            add_http = True,
            not_empty = False,
            messages = _invalid_link)

    link_douban = validators.URL(
            strip = True,
            add_http = True,
            not_empty = False,
            messages = _invalid_link)

    link_flickr = validators.URL(
            strip = True,
            add_http = True,
            not_empty = False,
            messages = _invalid_link)

    link_blog = validators.URL(
            strip = True,
            add_http = True,
            not_empty = False,
            messages = _invalid_link)

    @user_create.connect
    def _user_create(user, **kwargs):
        Profile(
            user_id = user.id,
            link_weibo = '',
            link_qq = '',
            link_douban = '',
            link_flickr = '',
            link_blog = '',
        ).save()
Exemplo n.º 12
0
class Login(formencode.Schema):
    """"""

    filter_extra_fields = True
    allow_extra_fields = True

    username = Username(not_empty=True)
    password = Password(not_empty=True)

    failed = validators.Bool(not_empty=True)
    next = validators.URL(not_empty=True)
Exemplo n.º 13
0
 class fields(ew_core.NameList):
     name = ew.TextField()
     redirect = ew.TextField()
     homepage = ffw.AutoResizeTextarea()
     allow_browse = ew.Checkbox(label='')
     show_title = ew.Checkbox(label='')
     css = ffw.AutoResizeTextarea()
     project_template = ffw.AutoResizeTextarea(validator=V.JsonValidator(
         if_empty=''))
     icon = ew.FileField()
     tracking_id = ew.TextField()
     project_list_url = ew.TextField(validator=fev.URL())
Exemplo n.º 14
0
    def manufacturers_edit(self):
        manufacturer = get_or_404(Manufacturer, self.request.POST.get('pk'))

        if self.request.POST.get('name') == 'name':
            manufacturer.name = self.request.POST.get('value')
            return {'value': manufacturer.name}

        if self.request.POST.get('name') == 'url':
            raw_url = self.request.POST.get('value')
            val = validators.URL(add_http=True)
            try:
                manufacturer.url = val.to_python(raw_url)
                return {'value': manufacturer.url}
            except Invalid as e:
                self.request.response.status = 400
                return {'message': str(e)}
Exemplo n.º 15
0
 def fields(self):
     return [
         ew.SingleSelectField(name='grant',
                              label='Award',
                              options=self.award_options()),
         ffw.NeighborhoodProjectSelect(self._project_select_url,
                                       name='recipient'),
         ew.TextField(name='url', label='Award URL', validator=fev.URL()),
         ew.TextArea(name='comment',
                     label='Comment',
                     validator=fev.UnicodeString(not_empty=False),
                     attrs={
                         'rows': 5,
                         'cols': 30
                     }),
     ]
Exemplo n.º 16
0
class WebhookCreateForm(schema.Schema):
    url = fev.URL(not_empty=True)
    secret = v.UnicodeString()
Exemplo n.º 17
0
 def __init__(self, form, eid, label=NotGiven, vtype=NotGiven, defaultval=NotGiven, strip=True,
              **kwargs):
     vargs = multi_pop(kwargs, 'check_exists', 'add_http', 'require_tld')
     TextElement.__init__(self, form, eid, label, vtype, defaultval, strip, **kwargs)
     self.add_processor(fev.URL(**vargs))
Exemplo n.º 18
0
class LinkForm(Schema):
    username = validators.UnicodeString(not_empty=True)
    url = validators.URL(not_empty=True, add_http=True, check_exists=False)
    title = validators.UnicodeString(not_empty=True)
Exemplo n.º 19
0
class Photo(models.base.BaseThing):
    _photo_soure_error = {
        'empty': u'照片地址不能为空',
        'badURL': u'链接格式不正确',
        'noTLD': u'链接格式不正确'
    }
    _page_soure_error = {
        'empty': u'页面址不能为空',
        'badURL': u'链接格式不正确',
        'noTLD': u'链接格式不正确'
    }

    title = validators.String(not_empty=True,
                              strip=True,
                              messages={
                                  'empty': u'别忘了填写标题哦',
                              })

    photo_source = validators.URL(strip=True,
                                  add_http=True,
                                  not_empty=True,
                                  messages=_photo_soure_error)

    page_source = validators.URL(strip=True,
                                 add_http=True,
                                 not_empty=True,
                                 messages=_page_soure_error)

    @property
    def comments(self):
        return models.Photo_Comment().findall_by_photo_id_and_status(
            self.id, 0)

    def create(self):
        self.status = 0
        self.created = self.updated = time.time()
        self.karma = calculate_photo_karma(0, self.created)
        self.save()
        if self.saved:
            signal(EVENTS['PHOTO_CREATE']).send(self)
            return self.id

    def delete(self):
        self.status = -1
        self.save()
        signal(EVENTS['PHOTO_DELETE']).send(self)

    def get_hot(self, limit, offset):
        return Photo().order_by('-karma').findall_by_status(0,
                                                            limit=limit,
                                                            offset=offset)

    def get_hot_count(self):
        return Photo().count_by_status(0)

    @property
    def creator(self):
        return models.User().find(self.user_id)

    @photo_after_validation.connect
    def _photo_after_validation(photo):
        if not photo.id:
            hashval = process_photo_url(photo.photo_source, photo.user_id)
            if not hashval:
                photo.add_error(photo_source=u'此链接无法被抓取')
            else:
                photo.hash = hashval

    @photo_like.connect
    def _photo_like(photo_like):
        photo = Photo().find(photo_like.photo_id)
        photo.likes_count += 1
        photo.karma = calculate_photo_karma(photo.likes_count, photo.created)
        photo.save()

    @photo_unlike.connect
    def _photo_unlike(photo_like):
        photo = Photo().find(photo_like.photo_id)
        photo.likes_count -= 1
        photo.karma = calculate_photo_karma(photo.likes_count, photo.created)
        photo.save()

    @photo_comment_delete.connect
    def _photo_comment_delete(comment):
        photo = Photo().find(comment.photo_id)
        photo.comments_count -= 1
        photo.save()

    @photo_comment_add.connect
    def _photo_comment_add(comment):
        photo = Photo().find(comment.photo_id)
        photo.comments_count += 1
        photo.save()
 def test_ip_validator(self):
     self.assertEqual(
         validators.URL(require_tld=False).to_python(
             "http://65.18.195.155/cgi-ordoro/bo/start.cgi"),
         "http://65.18.195.155/cgi-ordoro/bo/start.cgi")
Exemplo n.º 21
0
 class fields(ew_core.NameList):
     name = ew.InputField(
         field_type='text',
         label='Name',
         validator=formencode.All(fev.UnicodeString(not_empty=True, max=40),
                                  V.MaxBytesValidator(max=40)),
         attrs={
             'maxlength': 40,
             'title':
             "This is the publicly viewable name of the project, and will appear on project listings. It should be what you want to see as the project title in search listing.",
             'class': 'tooltip',
         })
     summary = ew.InputField(
         field_type="text",
         label='Short Summary',
         validator=formencode.All(fev.UnicodeString(max=70),
                                  V.MaxBytesValidator(max=70)),
         attrs={
             'maxlength': 70,
             'title':
             'Briefly state what your project is and what it does without repeating the project name. This summary appears in Google search results beneath the project name.',
             'class': 'tooltip',
         })
     short_description = ew.TextArea(
         label='Full Description',
         validator=formencode.All(fev.UnicodeString(max=1000),
                                  V.MaxBytesValidator(max=1000)),
         attrs={
             'title':
             'Describe the full functionality of your project using related keywords. The first sentence has the most impact on search. Provide unique content that calls out keywords and describes the merits of your project.',
             'class': 'tooltip'
         })
     # Apparently, child field must be CompoundField with custom template
     # for SortableRepeatedField to work properly, that's why FeaturesField
     # is not just ew.TextField
     features = ffw.SortableRepeatedField(
         label='Features',
         show_msg=False,
         show_button=False,
         append_to='bottom',
         extra_field_on_focus_name='feature',
         field=FeaturesField())
     icon = ew.FileField(label='Icon',
                         attrs={'accept': 'image/*'},
                         validator=V.IconValidator())
     external_homepage = ew.InputField(field_type="text",
                                       label='Homepage',
                                       validator=fev.URL(add_http=True))
     video_url = ew.InputField(field_type="text",
                               label="Video (YouTube)",
                               validator=V.YouTubeConverter())
     support_page = ew.InputField(field_type="text", label='Support Page')
     support_page_url = ew.InputField(field_type="text",
                                      label='Support Page URL',
                                      validator=fev.URL(add_http=True,
                                                        if_empty=''))
     removal = ew.InputField(field_type="text", label='Removal')
     moved_to_url = ew.InputField(field_type="text",
                                  label='Moved Project to URL',
                                  validator=fev.URL(add_http=True,
                                                    if_empty=''))
     export_controlled = ew.InputField(field_type="text",
                                       label='Export Control')
     export_control_type = ew.InputField(field_type="text",
                                         label='Export Control Type')
     delete = ew.InputField(field_type="hidden", label='Delete')
     delete_icon = ew.InputField(field_type="hidden", label='Delete Icon')
     undelete = ew.InputField(field_type="hidden", label='Undelete')
     tracking_id = ew.InputField(field_type="text",
                                 label="Google Analytics ID",
                                 attrs=(dict(placeholder='UA-123456-0',
                                             pattern='UA-[0-9]+-[0-9]+')))
     twitter_handle = ew.InputField(field_type="text",
                                    label='Twitter Handle')
     facebook_page = ew.InputField(field_type="text",
                                   label='Facebook page',
                                   validator=fev.URL(add_http=True))
Exemplo n.º 22
0
 class fields(ew_core.NameList):
     newwebsite = ew.TextField(label='New website url',
                               attrs={'value': ''},
                               validator=fev.URL(not_empty=True))
Exemplo n.º 23
0
class AddReaction(formencode.Schema):
    theme_slug = Slug(not_empty=True)
    timecode = validators.Number(not_empty=True)
    url = validators.URL(add_http=True)
    message = validators.UnicodeString()
Exemplo n.º 24
0
class BlogCreateSchema(BaseSchema):
    blogname = validators.MinLength(6, not_empty=True)
    text = validators.MinLength(10, not_empty=True)
    image_url = validators.URL(add_http=False, check_exists=True)
def linking_response_contains_valid_qr_code_url(context):
    try:
        validators.URL().to_python(
            context.entity_manager.get_current_linking_response().qrcode)
    except Invalid as e:
        raise Exception("Could not parse QR Code as URL: %s" % e)
Exemplo n.º 26
0
class ForgeLinkApp(Application):

    '''This is the Link app for PyForge'''
    __version__ = version.__version__
    tool_description = """
        A link to a URL of your choice, either on this site or somewhere else.
        It will appear in your project menu alongside the other project tools.
    """
    permissions = ['configure', 'read']
    permissions_desc = {
        'read': 'View link.',
    }
    config_options = Application.config_options + [
        ConfigOption(
            'url', str, None,
            label='External Url',
            help_text='URL to which you wish to link',
            validator=fev.URL(not_empty=True, add_http=True),
            extra_attrs={'type': 'url', 'required' : '', 'placeholder' : 'https://example.com'}),
    ]
    config_on_install = ['url']
    searchable = True
    exportable = True
    has_notifications = False
    tool_label = 'External Link'
    default_mount_label = 'Link name'
    default_mount_point = 'link'
    ordinal = 1
    icons = {
        24: 'images/ext_24.png',
        32: 'images/ext_32.png',
        48: 'images/ext_48.png'
    }

    def __init__(self, project, config):
        Application.__init__(self, project, config)
        self.root = RootController()
        self.api_root = RootRestController(self)
        self.admin = AdminController(self)

    @property
    @h.exceptionless([], log)
    def sitemap(self):
        menu_id = self.config.options.mount_label
        return [SitemapEntry(menu_id, self.config.options.get('url') or '.')]

    def sidebar_menu(self):
        return []

    def admin_menu(self):
        return super(ForgeLinkApp, self).admin_menu()

    def install(self, project):
        'Set up any default permissions and roles here'
        self.config.options['project_name'] = project.name
        super(ForgeLinkApp, self).install(project)
        # Setup permissions
        role_admin = M.ProjectRole.by_name('Admin')._id
        role_anon = M.ProjectRole.anonymous()._id
        self.config.acl = [
            M.ACE.allow(role_anon, 'read'),
            M.ACE.allow(role_admin, 'configure'),
        ]

    def uninstall(self, project):
        "Remove all the tool's artifacts from the database"
        super(ForgeLinkApp, self).uninstall(project)

    def bulk_export(self, f, export_path='', with_attachments=False):
        json.dump(RootRestController(self).link_json(),
                  f, cls=jsonify.JSONEncoder, indent=2)
 def setUp(self):
     self.validator = validators.URL()
Exemplo n.º 28
0
class ShortURLAdminController(DefaultAdminController):

    shorturl_validators = All(
        validators.NotEmpty(),
        validators.Regex(
            r'^[-_a-zA-Z0-9]+$',
            messages={'invalid':
                      'must include only letters, numbers, dashes and underscores.'}
        )
    )

    @expose()
    def index(self, **kw):
        redirect(c.project.url() + 'admin/tools')

    @without_trailing_slash
    @expose('json:')
    def remove(self, shorturl, **kw):
        require_access(self.app, 'update')
        ShortUrl.query.remove({
            'app_config_id': self.app.config._id,
            'short_name': shorturl})
        return dict(status='ok')

    @expose('jinja:forgeshorturl:templates/form.html')
    @validate(dict(full_url=All(validators.URL(add_http=True),
                                validators.NotEmpty()),
                   short_url=shorturl_validators))
    def add(self, short_url='', full_url='', description='', private='off',
            update=False, **kw):
        if update:
            require_access(self.app, 'update')
        else:
            require_access(self.app, 'create')
        if request.method == 'POST':
            if c.form_errors:
                error_msg = 'Error: '
                for msg in list(c.form_errors):
                    names = {'short_url': 'Short url', 'full_url': 'Full URL'}
                    error_msg += '%s: %s ' % (names[msg], c.form_errors[msg])
                    flash(error_msg, 'error')
                redirect(request.referer)

            shorturl = ShortUrl.query.find({
                'app_config_id': self.app.config._id,
                'short_name': short_url}).first()

            if shorturl is not None:
                if not update:
                    flash('Short url %s already exists' % short_url, 'error')
                    redirect(request.referer)
                else:
                    msg = ('update short url %s from %s to %s'
                           % (short_url, shorturl.full_url, full_url))
                    flash("Short url updated")

            else:
                shorturl = ShortUrl()
                shorturl.created = datetime.utcnow()
                shorturl.app_config_id = self.app.config._id
                msg = 'create short url %s for %s' % (short_url, full_url)
                flash("Short url created")

            shorturl.short_name = short_url
            shorturl.full_url = full_url
            shorturl.description = description
            shorturl.create_user = c.user._id
            shorturl.private = private == 'on'
            shorturl.last_updated = datetime.utcnow()

            M.AuditLog.log(msg)
            redirect(request.referer)
        return dict(
            app=self.app,
            url_len=len(ShortUrl.build_short_url(c.app, short_name='')))
Exemplo n.º 29
0
class NewsCreateSchema(BaseSchema):
    """ Schema for single news form """
    title = validators.MaxLength(60, not_empty=True)
    text = validators.MinLength(10, not_empty=True)
    image_url = validators.URL(add_http=False, check_exists=True)
Exemplo n.º 30
0
class SocialNetworkSchema(BaseSchema):
    name = validators.String(not_empty=True)
    logo = validators.String(not_empty=True)
    url = validators.URL(add_http=True, check_exists=False)