class FilmModel(ModelView): form_extra_fields = { 'file': FileUploadField('Загрузка файла', base_path=app.config['UPLOAD_FOLDER'], namegen=prefix_name) } form_excluded_columns = ('episodes') column_labels = dict(name='Название', url='Ссылка') create_template = 'admin_edit.html' edit_template = 'admin_edit.html' def is_accessible(self): if not basic_auth.authenticate(): raise AuthException('Not authenticated. Refresh the page.') else: return True def inaccessible_callback(self, name, **kwargs): return redirect(basic_auth.challenge()) def on_model_change(self, form, Film, is_created=False): if not form.video.data: try: Film.video = os.path.join(app.config['UPLOAD_FOLDER'], form.file.data.filename) except: pass
class SettingsModel(ModelView): form_extra_fields = { 'file': FileUploadField('file', base_path=app.config['UPLOAD_FOLDER'], namegen=prefix_name) } form_widget_args = { 'name': { 'readonly': True }, } def is_accessible(self): if not basic_auth.authenticate(): raise AuthException('Not authenticated. Refresh the page.') else: return True def inaccessible_callback(self, name, **kwargs): return redirect(basic_auth.challenge()) def on_model_change(self, form, Setting, is_created=False): if not form.value.data: Setting.value = os.path.join(app.config['UPLOAD_FOLDER'], form.file.data.filename)
class StorageAdminModel(ModelView): form_extra_fields = { 'file': FileUploadField('file', base_path=app.config['UPLOAD_FOLDER'], namegen=prefix_name) } def on_model_change(self, form, Setting, is_created=False): if not form.value.data: Setting.value = os.path.join(app.config['UPLOAD_FOLDER'], form.file.data.filename)
class PersonView(sqla.ModelView): """Create customized model view class.""" edit_template = 'admin/person_edit.html' # Change edit in the admin can_view_details = False column_searchable_list = ['login', 'name', 'surname'] form_columns = ('login', 'photo', 'name', 'surname', 'job', 'skype', 'email', 'fixe', 'mobile', 'subordinates', 'team', 'manager', 'birthday', 'arrival') column_labels = dict(login='******', photo='Photo de la personne', name='Nom', surname='Prénom', job='Métier', skype='Suite Métier', email='Mail', fixe='Téléphone', mobile='Numéro du poste', subordinates='Vérification', team='Service', manager='Chef de service', birthday='Date de saisie', arrival='Date de sauvegarde') def is_accessible(self): """Check if the current user can access the view.""" return login.current_user.is_authenticated def image_name(obj, file_data): return obj.login + ".jpg" form_extra_fields = { 'photo': FileUploadField('Photo', base_path=config.PHOTOS_FOLDER, namegen=image_name) }
class ClientForm(Form): tbl = FileUploadField('File', namegen=prefix_name, validators=[DataRequired()])
class Comment(form.Form): title = fields.StringField("title") name = fields.StringField("name") profession = fields.StringField("prof") img = FileUploadField(label="image", base_path=path) text = CKTextAreaField("text")
class Article(form.Form): title = fields.StringField("title") img = FileUploadField(label="image", base_path=path) text = CKTextAreaField("text") tags = fields.StringField("tags")