class PostCommentSchema(Schema): name = TextField.validator( not_empty=True, maxlength=50, messages={'empty': N_('Please enter your name!')}) email = email_validator() body = XHTMLValidator(not_empty=True)
class UserForm(ListForm): template = 'admin/box-form.html' id = 'user-form' css_class = 'form' submit_text = None show_children_errors = True _name = 'user-form' # TODO: Figure out why this is required?? event = events.Admin.UserForm fields = [ TextField('display_name', label_text=N_('Display Name'), validator=TextField.validator(not_empty=True), maxlength=255), TextField('email_address', label_text=N_('Email Address'), validator=email_validator(not_empty=True), maxlength=255), ListFieldSet('login_details', suppress_label=True, legend=N_('Login Details:'), css_classes=['details_fieldset'], validator = Schema(chained_validators=[ FieldsMatch('password', 'confirm_password', messages={'invalidNoMatch': N_("Passwords do not match"),})] ), children=[ CheckBoxList('groups', label_text=N_('Groups'), options=lambda: Group.custom_groups(Group.group_id, Group.display_name).all()), TextField('user_name', label_text=N_('Username'), maxlength=16, validator=All(PlainText(), UniqueUsername(not_empty=True))), PasswordField('password', label_text=N_('Password'), validators=NotEmpty, maxlength=80, attrs={'autocomplete': 'off'}), PasswordField('confirm_password', label_text=N_('Confirm password'), validators=NotEmpty, maxlength=80, attrs={'autocomplete': 'off'}), ] ), SubmitButton('save', default=N_('Save'), named_button=True, css_classes=['btn', 'btn-save', 'blue', 'f-rgt']), SubmitButton('delete', default=N_('Delete'), named_button=True, css_classes=['btn', 'btn-delete']), ]
class GroupForm(ListForm): template = 'admin/box-form.html' id = 'group-form' css_class = 'form' submit_text = None show_children_errors = True event = events.Admin.GroupForm fields = [ TextField('display_name', label_text=N_('Display Name'), validator=TextField.validator(not_empty=True), maxlength=255), TextField('group_name', label_text=N_('Groupname'), validator=All(PlainText(not_empty=True), UniqueGroupname()), maxlength=16), CheckBoxList( 'permissions', label_text=N_('Group Permissions'), css_classes=['details_fieldset'], options=lambda: DBSession.query(Permission.permission_id, Permission.description).all()), SubmitButton('save', default=N_('Save'), named_button=True, css_classes=['btn', 'btn-save', 'blue', 'f-rgt']), SubmitButton('delete', default=N_('Delete'), named_button=True, css_classes=['btn', 'btn-delete']), ]
class MediaForm(ListForm): template = 'admin/box-form.html' id = 'media-form' css_class = 'form' submit_text = None show_children_errors = True _name = 'media-form' # TODO: Figure out why this is required?? event = events.Admin.MediaForm fields = [ SingleSelectField('podcast', label_text=N_('Include in the Podcast'), css_classes=['dropdown-select'], help_text=N_('Optional'), options=lambda: [(None, None)] + DBSession.query(Podcast.id, Podcast.title).all()), TextField('slug', label_text=N_('Permalink'), maxlength=50), TextField('title', label_text=N_('Title'), validator=TextField.validator(not_empty=True), maxlength=255), TextField('author_name', label_text=N_('Author Name'), maxlength=50), TextField('author_email', label_text=N_('Author Email'), validator=email_validator(not_empty=True), maxlength=255), XHTMLTextArea('description', label_text=N_('Description'), attrs=dict(rows=5, cols=25)), CategoryCheckBoxList('categories', label_text=N_('Categories'), options=lambda: DBSession.query(Category.id, Category.name).all()), TextArea('tags', label_text=N_('Tags'), attrs=dict(rows=3, cols=15), help_text=N_(u'e.g.: puppies, great dane, adorable')), TextArea('notes', label_text=N_('Administrative Notes'), attrs=dict(rows=3, cols=25), container_attrs = lambda: ({'class': 'hidden'}, {})[bool(request.settings.get('wording_display_administrative_notes', ''))], default=lambda: request.settings['wording_administrative_notes']), SubmitButton('save', default=N_('Save'), named_button=True, css_classes=['btn', 'blue', 'f-rgt']), SubmitButton('delete', default=N_('Delete'), named_button=True, css_classes=['btn', 'f-lft']), ]
class fields(WidgetsList): name = TextField(validator=TextField.validator(not_empty=True), label_text=N_('Name')) slug = TextField(validator=NotEmpty, label_text=N_('Permalink')) parent_id = SingleSelectField(label_text=N_('Parent Category'), options=category_options) cancel = ResetButton(default=N_('Cancel'), css_classes=['btn', 'f-lft', 'btn-cancel']) save = SubmitButton(default=N_('Save'), named_button=True, css_classes=['f-rgt', 'btn', 'blue', 'btn-save'])
class PlayerPrefsForm(ListForm): template = 'admin/box-form.html' id = 'player-form' css_class = 'form playerform' submit_text = None show_children_errors = True _name = 'player-form' # TODO: Figure out why this is required?? params = ['player'] fields = [ ListFieldSet( 'general', legend=N_('General Options:'), suppress_label=True, children=[ TextField( 'display_name', label_text=N_('Display Name'), validator=TextField.validator(not_empty=True), maxlength=100, ), ], ), ] buttons = [ SubmitButton( 'save', default=N_('Save'), css_classes=['btn', 'btn-save', 'blue', 'f-rgt'], ), ] def display(self, value, player, **kwargs): """Display the form with default values from the given player. If the value dict is not fully populated, populate any missing entries with the values from the given player's :attr:`_data <mediacore.model.player.PlayerPrefs._data>` dict. :param value: A (sparse) dict of values to populate the form with. :type value: dict :param player: The player prefs mapped object to retrieve the default values from. :type player: :class:`mediacore.model.player.PlayerPrefs` subclass """ return ListForm.display(self, value, **kwargs) def save_data(self, player, **kwargs): """Map validated field values to `PlayerPrefs.data`.
from tw.api import WidgetsList, CSSLink import formencode from tw.forms.validators import NotEmpty, FieldStorageUploadConverter from pylons import config from mediacore.lib import helpers from mediacore.lib.filetypes import external_embedded_containers from mediacore.forms import ListForm, TextField, XHTMLTextArea, FileField, SubmitButton, email_validator validators = dict( description = XHTMLTextArea.validator( messages = {'empty': 'At least give it a short description...'}, not_empty = True, ), name = TextField.validator( messages = {'empty': "You've gotta have a name!"}, not_empty = True, ), tags = TextField.validator( not_empty = False, ), title = TextField.validator( messages = {'empty': "You've gotta have a title!"}, not_empty = True, ), ) class EmbedURLValidator(formencode.FancyValidator): def _to_python(self, value, state): if value: for info in external_embedded_containers.itervalues(): match = info['pattern'].match(value)
class PodcastForm(ListForm): template = 'admin/box-form.html' id = 'podcast-form' css_class = 'form' submit_text = None event = events.Admin.PodcastForm # required to support multiple named buttons to differentiate between Save & Delete? _name = 'vf' explicit_options = lambda: ( ('no', ''), ('yes', _('Parental Advisory')), ('clean', _('Clean')), ) category_options = [ 'Arts', 'Arts > Design', 'Arts > Fashion & Beauty', 'Arts > Food', 'Arts > Literature', 'Arts > Performing Arts', 'Arts > Visual Arts', 'Business', 'Business > Business News', 'Business > Careers', 'Business > Investing', 'Business > Management & Marketing', 'Business > Shopping', 'Comedy', 'Education', 'Education > Education Technology', 'Education > Higher Education', 'Education > K-12', 'Education > Language Courses', 'Education > Training', 'Games & Hobbies', 'Games & Hobbies > Automotive', 'Games & Hobbies > Aviation', 'Games & Hobbies > Hobbies', 'Games & Hobbies > Other Games', 'Games & Hobbies > Video Games', 'Government & Organizations', 'Government & Organizations > Local', 'Government & Organizations > National', 'Government & Organizations > Non-Profit', 'Government & Organizations > Regional', 'Health', 'Health > Alternative Health', 'Health > Fitness & Nutrition', 'Health > Self-Help', 'Health > Sexuality', 'Kids & Family', 'Music', 'News & Politics', 'Religion & Spirituality', 'Religion & Spirituality > Buddhism', 'Religion & Spirituality > Christianity', 'Religion & Spirituality > Hinduism', 'Religion & Spirituality > Islam', 'Religion & Spirituality > Judaism', 'Religion & Spirituality > Other', 'Religion & Spirituality > Spirituality', 'Science & Medicine', 'Science & Medicine > Medicine', 'Science & Medicine > Natural Sciences', 'Science & Medicine > Social Sciences', 'Society & Culture', 'Society & Culture > History', 'Society & Culture > Personal Journals', 'Society & Culture > Philosophy', 'Society & Culture > Places & Travel', 'Sports & Recreation', 'Sports & Recreation > Amateur', 'Sports & Recreation > College & High School', 'Sports & Recreation > Outdoor', 'Sports & Recreation > Professional', 'Technology', 'Technology > Gadgets', 'Technology > Tech News', 'Technology > Podcasting', 'Technology > Software How-To', 'TV & Film', ] fields = [ TextField('slug', label_text=N_('Permalink'), validator=NotEmpty, maxlength=50), TextField('title', label_text=N_('Title'), validator=TextField.validator(not_empty=True), maxlength=50), TextField('subtitle', label_text=N_('Subtitle'), maxlength=255), TextField('author_name', label_text=N_('Author Name'), validator=TextField.validator(not_empty=True), maxlength=50), TextField('author_email', label_text=N_('Author Email'), validator=email_validator(not_empty=True), maxlength=50), XHTMLTextArea('description', label_text=N_('Description'), attrs=dict(rows=5, cols=25)), ListFieldSet('details', suppress_label=True, legend=N_('Podcast Details:'), css_classes=['details_fieldset'], children=[ SingleSelectField('explicit', label_text=N_('Explicit?'), options=explicit_options), SingleSelectField('category', label_text=N_('Category'), options=category_options), TextField('copyright', label_text=N_('Copyright'), maxlength=50), ]), ListFieldSet('feed', suppress_label=True, legend=N_('Advanced Options:'), css_classes=['details_fieldset'], template='/admin/podcasts/feed_fieldset.html', children=[ TextField('feed_url', maxlength=50, label_text=N_('Your Feed URL'), attrs={'readonly': True}), TextField('itunes_url', validator=URL, label_text=N_('iTunes URL'), maxlength=80), TextField('feedburner_url', validator=URL, label_text=N_('Feedburner URL'), maxlength=80), ]), SubmitButton('save', default=N_('Save'), named_button=True, css_classes=['btn', 'blue', 'f-rgt']), SubmitButton('delete', default=N_('Delete'), named_button=True, css_classes=['btn']), ]
# See LICENSE.txt in the main project directory, for more information. from tw.api import WidgetsList from tw.forms.validators import FieldStorageUploadConverter from mediacore.lib.i18n import N_ from mediacore.forms import ListForm, TextField, XHTMLTextArea, FileField, SubmitButton, email_validator from mediacore.plugin import events validators = dict( description = XHTMLTextArea.validator( messages = {'empty': N_('At least give it a short description...')}, not_empty = True, ), name = TextField.validator( messages = {'empty': N_("You've gotta have a name!")}, not_empty = True, ), title = TextField.validator( messages = {'empty': N_("You've gotta have a title!")}, not_empty = True, ), url = TextField.validator( if_missing = None, ), ) class UploadForm(ListForm): template = 'upload/form.html' id = 'upload-form' css_class = 'form' show_children_errors = False
class StorageForm(ListForm): template = 'admin/box-form.html' id = 'storage-form' css_class = 'form storageform' submit_text = None show_children_errors = True _name = 'storage-form' # TODO: Figure out why this is required?? params = ['engine'] fields = [ ListFieldSet( 'general', legend=N_('General Options:'), suppress_label=True, children=[ TextField( 'display_name', label_text=N_('Display Name'), validator=TextField.validator(not_empty=True), maxlength=100, ), ], ), ] buttons = [ SubmitButton( 'save', default=N_('Save'), css_classes=['btn', 'btn-save', 'blue', 'f-rgt'], ), ] def display(self, value, engine, **kwargs): """Display the form with default values from the given StorageEngine. If the value dict is not fully populated, populate any missing entries with the values from the given StorageEngine's :attr:`_data <mediacore.lib.storage.StorageEngine._data>` dict. :param value: A (sparse) dict of values to populate the form with. :type value: dict :param engine: An instance of the storage engine implementation. :type engine: :class:`mediacore.lib.storage.StorageEngine` subclass """ general = value.setdefault('general', {}) if not general.get('display_name', None): general['display_name'] = engine.display_name return ListForm.display(self, value, engine=engine, **kwargs) def save_engine_params(self, engine, general, **kwargs): """Map validated field values to engine data. Since form widgets may be nested or named differently than the keys in the :attr:`mediacore.lib.storage.StorageEngine._data` dict, it is necessary to manually map field values to the data dictionary. :type engine: :class:`mediacore.lib.storage.StorageEngine` subclass :param engine: An instance of the storage engine implementation. :param \*\*kwargs: Validated and filtered form values. :raises formencode.Invalid: If some post-validation error is detected in the user input. This will trigger the same error handling behaviour as with the @validate decorator. """ engine.display_name = general['display_name']
from tw.forms.validators import NotEmpty, FieldStorageUploadConverter from pylons import config from pylons.i18n import _ from mediacore.lib import helpers from mediacore.lib.filetypes import accepted_extensions, guess_container_format from mediacore.lib.embedtypes import parse_embed_url from mediacore.forms import ListForm, TextField, XHTMLTextArea, FileField, SubmitButton, email_validator validators = dict( description = XHTMLTextArea.validator( messages = {'empty': _('At least give it a short description...')}, not_empty = True, ), name = TextField.validator( messages = {'empty': _("You've gotta have a name!")}, not_empty = True, ), title = TextField.validator( messages = {'empty': _("You've gotta have a title!")}, not_empty = True, ), ) class EmbedURLValidator(formencode.FancyValidator): def _to_python(self, value, state): if value == '': return value embed = parse_embed_url(value) if embed: return value