Ejemplo n.º 1
0
 def test_model_to_dict(self):
     obj = self.data['DummyModel'][0]
     data = model_to_dict(obj, ('name', 'value'))
     eq_(data, {'name': u'one', 'value': u'two'})
     data = model_to_dict(obj, fields=('name',))
     eq_(data, {'name': u'one'})
     data = model_to_dict(obj, exclude=('id',))
     eq_(data, {'name': u'one', 'value': u'two'})
     data = model_to_dict(obj, fields=('id', 'name'), exclude=('id',))
     eq_(data, {'name': u'one'})
Ejemplo n.º 2
0
 def test_model_to_dict(self):
     obj = self.data['DummyModel'][0]
     data = model_to_dict(obj, ('name', 'value'))
     eq_(data, {'name': u'one', 'value': u'two'})
     data = model_to_dict(obj, fields=('name', ))
     eq_(data, {'name': u'one'})
     data = model_to_dict(obj, exclude=('id', ))
     eq_(data, {'name': u'one', 'value': u'two'})
     data = model_to_dict(obj, fields=('id', 'name'), exclude=('id', ))
     eq_(data, {'name': u'one'})
Ejemplo n.º 3
0
    def edit_forum(self, request, forum=None):
        if forum:
            forum = Forum.query.filter_by(slug=forum).first()
            initial = model_to_dict(forum)
        else:
            forum = None
            initial = {}

        form = EditForumForm(request.form, **initial)

        if form.validate_on_submit():
            if forum:
                forum = update_model(
                    forum, form,
                    ('name', 'slug', 'parent', 'description', 'tags'))
            else:
                forum = Forum(name=form.name.data,
                              slug=form.slug.data,
                              parent=form.parent.data,
                              description=form.description.data,
                              tags=form.tags.data)
            db.session.commit()
            return redirect_to('forum/index')

        return {
            'forum': forum,
            'form': form,
        }
Ejemplo n.º 4
0
    def edit_forum(self, request, forum=None):
        if forum:
            forum = Forum.query.filter_by(slug=forum).first()
            initial = model_to_dict(forum)
        else:
            forum = None
            initial = {}

        form = EditForumForm(request.form, **initial)

        if form.validate_on_submit():
            if forum:
                forum = update_model(forum, form,
                    ('name', 'slug', 'parent', 'description', 'tags'))
            else:
                forum = Forum(
                    name=form.name.data,
                    slug=form.slug.data,
                    parent=form.parent.data,
                    description=form.description.data,
                    tags=form.tags.data
                )
            db.session.commit()
            return redirect_to('forum/index')

        return {
            'forum': forum,
            'form': form,
        }
Ejemplo n.º 5
0
    def edit_paste(self, request, id):
        entry = PasteEntry.query.get(id)
        form = EditPasteForm(
            request.form, **model_to_dict(entry, exclude=('id', 'author_id')))
        if form.validate_on_submit():
            entry = update_model(
                entry, form, ('text', 'language', 'title', 'author', 'hidden'))
            db.session.commit()
            return redirect_to(entry)

        return {
            'paste': entry,
            'form': form,
        }
Ejemplo n.º 6
0
    def edit_paste(self, request, id):
        entry = PasteEntry.query.get(id)
        form = EditPasteForm(request.form, **model_to_dict(
            entry, exclude=('id', 'author_id')
        ))
        if form.validate_on_submit():
            entry = update_model(entry, form,
                ('text', 'language', 'title', 'author', 'hidden'))
            db.session.commit()
            return redirect_to(entry)

        return {
            'paste': entry,
            'form': form,
        }
Ejemplo n.º 7
0
    def articles_edit(self, request, slug=None):
        new = slug is None
        if new:
            article, data = Article(), {'tags': []}
        else:
            article = Article.query.filter_by(slug=slug).one()
            data = model_to_dict(article, exclude=('slug'))

        form = EditArticleForm(request.form, **data)
        if 'delete' in request.form:
            return redirect_to('news/article_delete', slug=article.slug)
        elif form.validate_on_submit():
            article = update_model(article, form, ('pub_date', 'updated',
                'title', 'intro', 'text', 'public', 'tags',
                'author'))
            db.session.commit()
            msg = slug and _(u'Updated article “%s”') \
                       or _(u'Created article “%s”')
            request.flash(msg % article.title, True)
            return redirect_to(article)
        return {
            'form': form,
            'article': article,
        }
Ejemplo n.º 8
0
    def tags_edit(self, request, slug=None):
        new = slug is None
        if new:
            tag, data = Tag(), {}
        else:
            tag = Tag.query.filter_by(slug=slug).one()
            data = model_to_dict(tag, exclude=('slug'))

        form = EditTagForm(request.form, **data)

        if 'delete' in request.form:
            return redirect_to('portal/tag_delete', slug=tag.slug)
        elif form.validate_on_submit():
            tag = update_model(tag, form, ('name'))
            db.session.commit()
            if new:
                request.flash(_(u'Created tag “%s”' % tag.name), True)
            else:
                request.flash(_(u'Updated tag “%s”' % tag.name), True)

        return {
            'form': form,
            'tag': tag,
        }
Ejemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     self.profile = profile = kwargs.pop('profile')
     if profile is not None:
         kwargs.update(model_to_dict(profile, exclude=['user', 'user_id']))
     super(ProfileForm, self).__init__(*args, **kwargs)
Ejemplo n.º 10
0
 def __init__(self, *args, **kwargs):
     self.profile = profile = kwargs.pop('profile')
     if profile is not None:
         kwargs.update(model_to_dict(profile, exclude=['user', 'user_id']))
     super(ProfileForm, self).__init__(*args, **kwargs)