Example #1
0
 def test_second_book(self):
     authors = set(text_type(x.key.id()) for x in fill_authors(Author))
     authors.add('__None')
     form = model_form(second_ndb_module.SecondBook)
     keys = set()
     for key, b, c in form().author.iter_choices():
         keys.add(key)
Example #2
0
    def test_author(self):
        form = model_form(Author)
        zipped = zip(self.EXPECTED_AUTHOR, form())

        for (expected_name, expected_type), field in zipped:
            self.assertEqual(field.name, expected_name)
            self.assertEqual(type(field), expected_type)
Example #3
0
    def test_author(self):
        form = model_form(Author)
        zipped = zip(self.EXPECTED_AUTHOR, form())

        for (expected_name, expected_type), field in zipped:
            self.assertEqual(field.name, expected_name)
            self.assertEqual(type(field), expected_type)
Example #4
0
 def test_second_book(self):
     authors = set(text_type(x.key.id()) for x in fill_authors(Author))
     authors.add('__None')
     form = model_form(second_ndb_module.SecondBook)
     keys = set()
     for key, b, c in form().author.iter_choices():
         keys.add(key)
Example #5
0
 def scaffold_form(self):
     form_class = wt_ndb.model_form(self.model(),
                                    base_class=FlaskForm,
                                    only=self.form_columns,
                                    exclude=self.form_excluded_columns,
                                    field_args=self.form_args,
                                    converter=self.model_form_converter(),
                                    extra_fields=self.form_extra_fields)
     return form_class
Example #6
0
    def test_book(self):
        authors = set(x.key.urlsafe() for x in fill_authors(Author))
        authors.add('__None')
        form = model_form(Book)
        keys = set()
        for key, b, c in form().author.iter_choices():
            keys.add(key)

        self.assertEqual(authors, keys)
Example #7
0
    def test_book(self):
        authors = set(text_type(x.key.id()) for x in fill_authors(Author))
        authors.add("__None")
        form = model_form(Book)
        keys = set()
        for key, b, c in form().author.iter_choices():
            keys.add(key)

        self.assertEqual(authors, keys)
Example #8
0
    def test_author(self, client):
        with client.context():
            form = model_form(Author)
        x = form()
        zipped = zip(self.EXPECTED_AUTHOR, x)

        for (expected_name, expected_type), field in zipped:
            assert field.name == expected_name
            assert type(field) == expected_type
Example #9
0
    def test_book(self):
        authors = set(x.key.urlsafe() for x in fill_authors(Author))
        authors.add('__None')
        form = model_form(Book)
        keys = set()
        for key, b, c in form().author.iter_choices():
            keys.add(key)

        self.assertEqual(authors, keys)
Example #10
0
 def scaffold_list_form(self, widget=None, validators=None):
     form_class = wt_ndb.model_form(
         self.model(),
         base_class=Form,
         only=self.column_editable_list,
         field_args=self.form_args,
         converter=self.model_form_converter(),
     )
     result = create_editable_list_form(Form, form_class, widget)
     return result
Example #11
0
    def test_choices(self):
        form = model_form(Author)
        bound_form = form()

        # Sort both sets of choices. NDB stores the choices as a frozenset
        # and as such, ends up in the wtforms field unsorted.
        expected = sorted([(v, v) for v in GENRES])

        self.assertEqual(sorted(bound_form['genre'].choices), expected)
        self.assertEqual(sorted(bound_form['genres'].choices), expected)
Example #12
0
 def scaffold_list_form(self, widget=None, validators=None):
     form_class = wt_ndb.model_form(
         self.model(),
         base_class=Form,
         only=self.column_editable_list,
         field_args=self.form_args,
         converter=self.model_form_converter(),
     )
     result = create_editable_list_form(Form, form_class, widget)
     return result
Example #13
0
    def test_choices(self):
        form = model_form(Author)
        bound_form = form()

        # Sort both sets of choices. NDB stores the choices as a frozenset
        # and as such, ends up in the wtforms field unsorted.
        expected = sorted([(v, v) for v in GENRES])

        self.assertEqual(sorted(bound_form['genre'].choices), expected)
        self.assertEqual(sorted(bound_form['genres'].choices), expected)
Example #14
0
    def test_book(self, client):
        with client.context():
            authors = set(x.key.urlsafe() for x in fill_authors(Author))
            authors.add('__None')
            form = model_form(Book)
            keys = set()
            for key, b, c in form().author.iter_choices():
                keys.add(key)

        assert authors == keys
Example #15
0
    def test_second_book(self, client):
        with client.context():
            authors = set(str(x.key.id()) for x in fill_authors(Author))
            authors.add('__None')
            form = model_form(second_ndb_module.SecondBook)
            keys = set()
            for key, b, c in form().author.iter_choices():
                keys.add(key)

        assert authors != keys
Example #16
0
 def scaffold_form(self):
     form_class = wt_ndb.model_form(
         self.model(),
         base_class=Form,
         only=self.form_columns,
         exclude=self.form_excluded_columns,
         field_args=self.form_args,
         converter=self.model_form_converter(),
     )
     return form_class
Example #17
0
    def test_choices(self, client):
        form = model_form(Author)
        bound_form = form()

        # Sort both sets of choices. NDB stores the choices as a frozenset
        # and as such, ends up in the wtforms field unsorted.
        expected = sorted([(v, v) for v in GENRES])

        assert sorted(bound_form.genre.choices) == expected
        assert sorted(bound_form.genres.choices) == expected
    def scaffold_form(self):
        # Start with the standard form as provided by Flask-Admin. We've already told Flask-Admin to exclude the
        # password field from this form.
        # form_class = super(UserAdmin, self).scaffold_form()

        # fix excluded columns since it was not implemented
        form_class = wt_ndb.model_form(self.model(), exclude=self.form_excluded_columns)

        # Add a password field, naming it "password2" and labeling it "New Password".
        form_class.password2 = PasswordField('New Password')
        return form_class
Example #19
0
    def scaffold_form(self):
        # Start with the standard form as provided by Flask-Admin. We've already told Flask-Admin to exclude the
        # password field from this form.
        # form_class = super(UserAdmin, self).scaffold_form()

        # fix excluded columns since it was not implemented
        form_class = wt_ndb.model_form(self.model(), exclude=self.form_excluded_columns)

        # Add a password field, naming it "password2" and labeling it "New Password".
        form_class.password2 = PasswordField('New Password')
        return form_class
Example #20
0
    def test_choices_override(self):
        """
        Check that when we provide additional choices, they override
        what was specified, or set choices on the field.
        """
        choices = ['Cat', 'Pig', 'Cow', 'Spaghetti']
        expected = [(x, x) for x in choices]

        form = model_form(Author, field_args={
            'genres': {'choices': choices},
            'name': {'choices': choices}})

        bound_form = form()

        # For provided choices, they should be in the provided order
        self.assertEqual(bound_form['genres'].choices, expected)
        self.assertEqual(bound_form['name'].choices, expected)
Example #21
0
    def test_choices_override(self):
        """
        Check that when we provide additional choices, they override
        what was specified, or set choices on the field.
        """
        choices = ['Cat', 'Pig', 'Cow', 'Spaghetti']
        expected = [(x, x) for x in choices]

        form = model_form(Author,
                          field_args={
                              'genres': {
                                  'choices': choices
                              },
                              'name': {
                                  'choices': choices
                              }
                          })

        bound_form = form()

        # For provided choices, they should be in the provided order
        assert bound_form.genres.choices == expected
        assert bound_form.name.choices == expected
Example #22
0
#############################
### RSS_Suosikki          ###
#############################

#class RSS_Suosikki(ndb.Model):
#    #user = ndb.KeyProperty(required=True)
#    uutinen = ndb.StringProperty(required=True)
#    #order = ndb.IntegerProperty(required=True,default=0)

####################################
##         BaseFormit             ##
####################################

SyoteBaseForm = model_form(RSS_Syote,
                           base_class=FlaskForm,
                           exclude=['user', 'link'])

####################################
##         Form-validaattorit     ##
####################################


def form_noempty(form, field):
    val = field.data.strip()
    if len(val) == 0:
        raise ValidationError(u"Kenttä ei saa olla tyhjä.")


####################################
##         RSS_Syote_form         ##
Example #23
0
Web forms based on Flask-WTForms

See: http://flask.pocoo.org/docs/patterns/wtforms/
     http://wtforms.simplecodes.com/

"""

from flaskext import wtf
from flaskext.wtf import validators
from wtforms_appengine.ndb import model_form

from models import Security, Order, Portfolio, Comment


SecurityForm = model_form(Security, wtf.Form, field_args={
    'position': dict(validators=[validators.Required()]),
    'name': dict(validators=[validators.Required()]),
    'team': dict(),
})

OrderForm = model_form(Order, wtf.Form, field_args={
    'buysell': dict(validators=[validators.Required()]),
    'price': dict(validators=[validators.Required(), validators.NumberRange(min=1,max=100)]),
    'volume': dict(validators=[validators.Required(), validators.NumberRange(min=1,max=1000)]),
})

CommentForm = model_form(Comment, wtf.Form, field_args={
    'name': dict(validators=[validators.Required()]),
    'comment': dict(validators=[validators.Required()]),
})
Example #24
0
import os
import sys
sys.path.append(os.path.join(os.getcwd(), 'lib'))
from wtforms_appengine.ndb import model_form

from chat import models
import datetime

def home(request):
#  q = models.Chat.query().order(models.Chat.subject)
#  return render_to_response('chat/index.html', {'chats':q})
  return render_to_response('chat/index.html', {'clock': datetime.datetime.now()},)
#  return render_to_response('chat/index.html', {'clock': q},)

ChatForm = model_form(models.Chat)

def form(request, chat_id=None):
  if request.method =='POST':
      if chat_id:
         chat = models.Chat.get_by_id(int(chat_id))
         form = ChatForm(request.POST, obj=chat)
      else:
         chat = models.Chat()
         form = ChatForm(request.POST)
         
      if form.Validate():
        form.populate_obj(chat)
        chat.put()
        return HttpResponseRedirect('/chat/')
Example #25
0
	def scaffold_form(self):
		return wt_ndb.model_form(self.model())
Example #26
0
    def get_form(self):
        assert issubclass(self.model, ndb.Model)

        return model_form(self.model, exclude=self.form_exclude, only=self.form_include, base_class=SeaSurfForm, converter=BetterModelConverter(),
                          field_args=self.wtforms_field_args)
Example #27
0
####################################
##  Rastileimaus (Entity)         ##
####################################


class RastiLeimaus(ndb.Model):

    aika = ndb.DateTimeProperty(required=True)  #,validator=validate_time)
    rasti = ndb.KeyProperty(kind=Rasti, required=True)


####################################
##         BaseFormit             ##
####################################

KilpailutBaseForm = model_form(Kilpailu, base_class=FlaskForm)
SarjatBaseForm = model_form(Sarja, base_class=FlaskForm, exclude=['kilpailu'])
JoukkueetBaseForm = model_form(Joukkue,
                               base_class=FlaskForm,
                               exclude=['sarja', 'jasenet'])
RastitBaseForm = model_form(Rasti, base_class=FlaskForm, exclude=['kilpailu'])
RastileimauksetBaseForm = model_form(RastiLeimaus, base_class=FlaskForm)


def kilpailu_label(kilpailu):
    return kilpailu.nimi


def rasti_label(rasti):
    return rasti.koodi
Example #28
0
 def generate_form(cls):
     return model_form(cls)
Example #29
0
# coding=utf-8
import httplib

from wtforms import validators
from models.producer import Producer
from forms.base_form import BaseForm
from forms import widgets as flotimo_widgets
from wtforms_appengine.ndb import model_form

sys

ProducerForm = model_form(Producer,
                          BaseForm,
                          only=('name', 'price_group'),
                          field_args={
                              'name': {
                                  'label': u'Nazwa',
                                  'validators': [validators.Required()]
                              },
                              'price_group': {
                                  'label':
                                  u'Klasa',
                                  'coerce':
                                  int,
                                  'widget':
                                  flotimo_widgets.ChoicesSelect(
                                      choices=Producer._PRICE_GROUP.items()),
                              }
                          })
Example #30
0
File: view.py Project: skshetry/app
 def scaffold_form(self):
     return wt_ndb.model_form(self.model())
Example #31
0
#!/usr/bin/env python
# coding=utf8

from google.appengine.ext import ndb
from wtforms_appengine.ndb import model_form
from wtforms import Form, validators, fields
from .models import AdminUser, ROLES


class AdminUserBaseForm(Form):
    # Add form-fields not related to model.
    send_welcome_email = fields.BooleanField(label="Send welcome email")


# Use a app-engine plugin for making a form-class from a ndb-model.
AdminUserForm = model_form(
    AdminUser,
    base_class=AdminUserBaseForm,
    field_args={"role": {"choices": list(enumerate(ROLES)), "coerce": int}},  # Make a list of (index, value)
)