Esempio n. 1
0
        class defaultCrudRestController(EasyCrudRestController):
            response_type = 'text/html'
            remember_values = ['file']

            _get_current_user = lambda: instance_primary_key(request.identity[
                'user'])

            __form_options__ = {
                '__hide_fields__': ['author'],
                '__omit_fields__': ['uid', '_id', 'updated_at', 'created_at'],
                '__field_widget_args__':
                addopts(author={'value': Deferred(_get_current_user)},
                        file={'required': True})
            }

            __form_edit_options__ = {
                '__field_widget_args__':
                addopts(**{'file': {
                    'required': False
                }})
            }

            __table_options__ = {
                '__omit_fields__': ['_id', 'uid', 'author_id', 'created_at'],
                '__xml_fields__': ['file'],
                'file':
                lambda filler, o: Markup('<a href="%s">%s</a>' %
                                         (o.url, o.url))
            }
Esempio n. 2
0
    def activate(self, code, **kw):
        reg = config['registration_dal'].get_inactive(code)
        if not reg:
            flash(_('Registration not found or already activated'), 'error')
            return redirect(self.mount_point)

        u = app_model.User(user_name=reg.user_name,
                           display_name=reg.user_name,
                           email_address=reg.email_address,
                           password=reg.password)

        hooks.notify('registration.before_activation', (reg, u))

        try:
            u = config['registration_dal'].out_of_uow_flush(u)
        except DalIntegrityError:
            flash(_('Username already activated'), 'error')
            return redirect(self.mount_point)

        reg.user_id = instance_primary_key(u)
        reg.password = '******'
        reg.activated = datetime.now()

        hooks.notify('registration.after_activation', (reg, u))

        flash(_('Account succesfully activated'))
        return redirect('/')
Esempio n. 3
0
     def _build_actions(self, obj):
         baseactions = super(self.table_filler.__class__, self.table_filler).__actions__(obj)
         if config['_flatpages']['format'] == 'rst':
             extraactions = Markup('''
 <a href="%s/download" class="btn btn-default">
     <span class="glyphicon glyphicon-download-alt"></span>
 </a>''' % instance_primary_key(obj))
         else:
             extraactions = ''
         return extraactions + baseactions
Esempio n. 4
0
 def get_by_recipient(cls, recipient):
     return cls.query.find({
         '$or': [{
             '_recipients._id': instance_primary_key(recipient)
         }, {
             '_recipients': {
                 '$eq': None
             }
         }]
     }).sort('timestamp', DESCENDING)
Esempio n. 5
0
     def _build_actions(self, obj):
         baseactions = super(self.table_filler.__class__,
                             self.table_filler).__actions__(obj)
         if config['_flatpages']['format'] == 'rst':
             extraactions = Markup('''
 <a href="%s/download" class="btn btn-default">
     <span class="glyphicon glyphicon-download-alt"></span>
 </a>''' % instance_primary_key(obj))
         else:
             extraactions = ''
         return extraactions + baseactions
Esempio n. 6
0
    def add_comment(cls, entity, user, body):
        entity_type, entity_id = cls.get_entity_descriptor(entity)

        c = dict(body=body, entity_type=entity_type, entity_id=entity_id)
        if isinstance(user, dict):
            c['author_username'] = user['user_name']
            c['author_name'] = user['name']
            c['author_pic'] = user.get('avatar')
        else:
            c['user_id'] = instance_primary_key(user)
            c['user'] = user
            c['author_username'] = user.user_name
            c['author_name'] = user.display_name
            c['author_pic'] = get_user_avatar(user)

        return model.provider.create(cls, c)
Esempio n. 7
0
 def count_not_seen_by_recipient(cls, recipient):
     return cls.query.find({
         '$or': [
             {
                 '_recipients._id': instance_primary_key(recipient)
             },
             {
                 '_recipients': {
                     '$eq': None
                 }
             },
         ],
         'timestamp': {
             '$gt': recipient.last_activity_seen
         },
     }).count()
Esempio n. 8
0
    def test_edit_category_validator(self):
        self.app.get(
            '/tgappcategories/create_category',
            params={
                'name': 'category one',
                'description': 'pretty description'
            },
            extra_environ={'REMOTE_USER': '******'},
            status=302,
        )
        __, cats = model.provider.query(model.Category,
                                        filters=dict(name='category one'))

        resp = self.app.get('/tgappcategories/update_category/' +
                            instance_primary_key(cats[0], True),
                            params={
                                'name': '',
                                'description': ''
                            },
                            extra_environ={'REMOTE_USER': '******'})
        assert 'id="name:error">Enter a value', resp
Esempio n. 9
0
    def create(self,
               actor,
               verb,
               target=None,
               action_obj=None,
               description=None,
               extra=None,
               recipients=None):

        actor_id = primary_key(actor.__class__).name
        target_id = primary_key(target.__class__).name if target else ''
        action_obj_id = primary_key(
            action_obj.__class__).name if action_obj else ''

        _recipients = None
        if recipients:
            _recipients = [{
                '_type': r.__class__.__name__,
                '_id': instance_primary_key(r)
            } for r in recipients]

        return model.provider.create(
            model.Action,
            dict(
                actor_type=actor.__class__.__name__,
                actor_id=getattr(actor, actor_id),
                verb=verb,
                target_type=target.__class__.__name__ if target else None,
                target_id=getattr(target, target_id, None),
                action_obj_type=action_obj.__class__.__name__
                if action_obj else None,
                action_obj_id=getattr(action_obj, action_obj_id, None),
                description=description,
                extra=extra,
                _recipients=_recipients,
            ))
Esempio n. 10
0
        class defaultCrudRestController(EasyCrudRestController):
            response_type = 'text/html'
            crud_resources = [
                CSSSource(location='headbottom',
                          src='''
        .crud-sidebar .active {
            font-weight: bold;
            border-left: 3px solid #eee;
        }

        @media (max-width: 991px) {
            .pull-sm-right {
                float: right;
            }
        }

        @media (min-width: 992px) {
            .pull-md-right {
                float: right;
            }
        }
        ''')
            ]

            # Helpers to retrieve form data
            _get_current_user = lambda: instance_primary_key(request.identity[
                'user'])
            _get_templates = lambda: config['_flatpages']['templates']
            if config.get('use_sqlalchemy', False):
                _get_permissions = lambda: [
                    ('public', 'Public'), ('not_anonymous', 'Only Registered Users')] + \
                    DBSession.query(app_model.Permission.permission_name,
                                    app_model.Permission.description).all()
            else:
                _get_permissions = lambda: [
                    ('public', 'Public'), ('not_anonymous', 'Only Registered Users')] + \
                    [(p.permission_name, p.description)
                     for p in app_model.Permission.query.find().all()]

            __form_options__ = {
                '__hide_fields__': ['author', 'updated_at'],
                '__omit_fields__': ['uid', '_id', 'created_at'],
                '__field_order__':
                ['slug', 'title', 'template', 'required_permission'],
                '__field_widget_types__':
                addopts(
                    **{
                        'template': SingleSelectField,
                        'slug': TextField,
                        'title': TextField,
                        'required_permission': SingleSelectField,
                        'content': MarkitUpArea
                    }),
                '__field_widget_args__':
                addopts(
                    **{
                        'author': {
                            'value': Deferred(_get_current_user)
                        },
                        'required_permission': {
                            'prompt_text': None,
                            'options': Deferred(_get_permissions)
                        },
                        'content': {
                            'rows': 20
                        },
                        'template': {
                            'prompt_text': None,
                            'options': Deferred(_get_templates)
                        },
                    })
            }

            __table_options__ = {
                '__omit_fields__': [
                    '_id', 'uid', 'author_id', 'created_at', 'template',
                    'content'
                ],
                '__xml_fields__': ['slug'],
                'slug':
                lambda filler, o: Markup('<a href="%s">%s</a>' %
                                         (o.url, o.slug)),
                '__actions__':
                lambda self, obj: request.controller_state.controller.
                _build_actions(obj)
            }

            def _build_actions(self, obj):
                baseactions = super(self.table_filler.__class__,
                                    self.table_filler).__actions__(obj)
                if config['_flatpages']['format'] == 'rst':
                    extraactions = Markup('''
        <a href="%s/download" class="btn btn-default">
            <span class="glyphicon glyphicon-download-alt"></span>
        </a>''' % instance_primary_key(obj))
                else:
                    extraactions = ''
                return extraactions + baseactions

            @expose(content_type='application/pdf')
            def download(self, pageid):
                p = model.FlatPage.by_id(pageid) or abort(404)
                out = BytesIO()

                rst2pdf = RstToPdf()
                rst2pdf.createPdf(p.content, output=out)

                out.seek(0)
                return out.read()
Esempio n. 11
0
 def my_vote(self):
     values = [
         vote.value for vote in self.votes if vote.user_id ==
         instance_primary_key(tg.request.identity['user'])
     ]
     return values[0] if len(values) != 0 else None
Esempio n. 12
0
 def _query_groups():  # default implementation
     _, groups = model.provider.query(app_model.Group)
     return [(instance_primary_key(group), group.display_name)
             for group in groups]