class CommitteeMeetingView(EventView): column_list = ('date', 'title', 'committee', 'featured') column_labels = { 'committee': 'Committee', } column_sortable_list = ( 'date', ('committee', 'committee.name'), ) column_default_sort = (Event.date, True) column_searchable_list = ('committee.name', 'title') column_filters = ['committee.name', 'date'] column_export_exclude_list = ['summary', 'body'] form_edit_rules = ('committee', 'title', 'date', 'chairperson', 'featured', 'public_participation', 'bills', 'summary', 'body', 'files', rules.FieldSet([ 'actual_start_time', 'actual_end_time', 'attendance' ], 'Member Attendance Record')) form_create_rules = form_edit_rules form_args = { 'summary': { 'default': '<p>Report of the meeting to follow.</p>' }, 'committee': { 'validators': [data_required()] }, 'files': { 'widget': widgets.InlineFileWidget() }, } form_widget_args = { 'body': { 'class': 'ckeditor' }, 'summary': { 'class': 'ckeditor' } } form_ajax_refs = {'bills': {'fields': ('title', ), 'page_size': 50}} inline_models = [ InlineFile(EventFile), InlineCommitteeMeetingAttendance(CommitteeMeetingAttendance), ] def on_model_change(self, form, model, is_created): super(CommitteeMeetingView, self).on_model_change(form, model, is_created) # make sure the new times are timezone aware for attr in ['actual_start_time', 'actual_end_time']: if getattr(model, attr): setattr(model, attr, getattr(model, attr).replace(tzinfo=SAST)) if model.committee.ad_hoc: # reset the active flag on this ad-hoc committee? self.session.flush() model.committee.reset_active()
class ViewWithFiles(object): """ Mixin to pre-fill inline file forms. """ form_args = { 'files': { 'widget': widgets.InlineFileWidget() }, } def on_form_prefill(self, form, id): if hasattr(form, 'files'): for f in form.files: f.title.data = f.object_data.file.title
class CommitteeQuestionView(MyModelView): list_template = 'admin/committee_question_list.html' create_template = 'admin/committee_question_create.html' column_list = ( 'code', 'committee', 'question_number', 'date', ) column_default_sort = ('date', True) column_searchable_list = ('code', ) form_columns = ( 'code', 'date', 'intro', 'question', 'asked_by_name', 'asked_by_member', 'question_to_name', 'committee', 'answer', 'source_file', 'written_number', 'oral_number', 'president_number', 'deputy_president_number', ) column_labels = { 'question_to_name': "Question To", 'committee': "Question To Committee", } form_args = { 'files': { 'widget': widgets.InlineFileWidget() }, } form_widget_args = { 'answer': { 'class': 'ckeditor' }, } form_ajax_refs = { 'source_file': { 'fields': ('title', 'file_path'), 'page_size': 10, }, 'asked_by_member': { 'fields': ('name', ), 'page_size': 25 }, } inline_models = [InlineFile(CommitteeQuestionFile)] @expose('/upload', methods=['POST']) def upload(self): return_url = request.headers['Referer'] file_data = request.files.get('file') try: question = CommitteeQuestion.import_from_uploaded_answer_file( file_data) if question.id: # it already existed flash("That question has already been imported.", "warn") return redirect( get_url('.edit_view', id=question.id, url=return_url)) db.session.add(question) db.session.commit() flash("Successfully imported from %s" % (file_data.filename, )) return redirect( get_url('.edit_view', id=question.id, url=return_url)) except ValueError as e: flash( "Couldn't import from %s: %s" % (file_data.filename, e.message), 'error') return redirect(return_url) def frontend_url(self, model): if model.id and model.committee: return url_for('committee_question', question_id=model.id) return None