Ejemplo n.º 1
0
from app import utils
from app.forms import custom_validators, CustomFieldSet, create_date_field, \
    CustomGrid, create_generic_date_field
from app.models import Poll
from app.utils import formatting
from formalchemy.fields import Field
from web import config
import datetime

# Patterns & formats used by the validators
DT_FORMAT = "%d/%m/%Y"

# Lambda methods used to enrich the fields with labels & validators
TITLE = lambda field: field.label(u"Titre")
FORMATTED_START_DT = lambda field: field.label(u"Date de début").required(
).validate(custom_validators.dt_validator(DT_FORMAT))
FORMATTED_END_DT = lambda field: field.label(u"Date de fin").validate(
    custom_validators.dt_validator(DT_FORMAT)).validate(
        custom_validators.poll_dt_range_validator(DT_FORMAT))
FORMATTED_POSSIBLE_DATES_READONLY = lambda field: field.label(u"Choix"
                                                              ).readonly()
FORMATTED_POSSIBLE_DT = lambda field, i: (field.required() if i<=2 else field).label(u"Choix %s" % i)                                                   \
                                                                              .validate(custom_validators.dt_validator(DT_FORMAT))                      \
                                                                              .validate(custom_validators.poll_choice_dt_uniqueness_validator)          \
                                                                              .validate(custom_validators.poll_dt_range_validator(DT_FORMAT))


class EditPollsGrid(CustomGrid):
    """ Administration grid used to edit polls """
    def __init__(self):
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-

""" Administration forms used to edit news """

from app.forms import custom_validators, CustomGrid, CustomFieldSet, \
    create_date_field
from app.models import News
from web import config
import datetime

# Patterns & formats used by the validators
DT_FORMAT = "%d/%m/%Y"

# Lambda methods used to enrich the fields with labels & validators
FORMATTED_DT = lambda field: field.label(u"Date").validate(custom_validators.dt_validator(DT_FORMAT))
NEWS = lambda field: field.label(u"News")

class EditNewsGrid(CustomGrid):
    """ Administration grid used to edit news """
    
    def __init__(self):

        # Grid initialization
        super(EditNewsGrid, self).__init__(News, News.all())
        
        # Creation of a customized date field to edit the news' date
        self.append(create_date_field("formatted_news_dt", "news_dt", DT_FORMAT))
        
        # Grid configuration
        inc = [FORMATTED_DT(self.formatted_news_dt), NEWS(self.news)] 
        self.configure(include=inc)
Ejemplo n.º 3
0
from app import utils
from app.forms import custom_validators, CustomFieldSet, create_date_field, \
    CustomGrid, create_generic_date_field
from app.models import Poll
from app.utils import formatting
from formalchemy.fields import Field
from web import config
import datetime

# Patterns & formats used by the validators
DT_FORMAT = "%d/%m/%Y"

# Lambda methods used to enrich the fields with labels & validators
TITLE = lambda field: field.label(u"Titre")
FORMATTED_START_DT = lambda field: field.label(u"Date de début").required().validate(custom_validators.dt_validator(DT_FORMAT))
FORMATTED_END_DT = lambda field: field.label(u"Date de fin").validate(custom_validators.dt_validator(DT_FORMAT)).validate(custom_validators.poll_dt_range_validator(DT_FORMAT))
FORMATTED_POSSIBLE_DATES_READONLY = lambda field: field.label(u"Choix").readonly()
FORMATTED_POSSIBLE_DT = lambda field, i: (field.required() if i<=2 else field).label(u"Choix %s" % i)                                                   \
                                                                              .validate(custom_validators.dt_validator(DT_FORMAT))                      \
                                                                              .validate(custom_validators.poll_choice_dt_uniqueness_validator)          \
                                                                              .validate(custom_validators.poll_dt_range_validator(DT_FORMAT))

class EditPollsGrid(CustomGrid):
    """ Administration grid used to edit polls """
    
    def __init__(self):
        
        # Grid initialization
        super(EditPollsGrid, self).__init__(Poll, Poll.all(joined_attrs=["choices"])) #@UndefinedVariable
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
""" Administration forms used to edit news """

from app.forms import custom_validators, CustomGrid, CustomFieldSet, \
    create_date_field
from app.models import News
from web import config
import datetime

# Patterns & formats used by the validators
DT_FORMAT = "%d/%m/%Y"

# Lambda methods used to enrich the fields with labels & validators
FORMATTED_DT = lambda field: field.label(u"Date").validate(
    custom_validators.dt_validator(DT_FORMAT))
NEWS = lambda field: field.label(u"News")


class EditNewsGrid(CustomGrid):
    """ Administration grid used to edit news """
    def __init__(self):

        # Grid initialization
        super(EditNewsGrid, self).__init__(News, News.all())

        # Creation of a customized date field to edit the news' date
        self.append(
            create_date_field("formatted_news_dt", "news_dt", DT_FORMAT))

        # Grid configuration
        inc = [FORMATTED_DT(self.formatted_news_dt), NEWS(self.news)]