from apps.extensions import ( admin, db, ) from apps.common.admins import ImageUploadField from . import ( models, upload_sets, ) class QuestionModelView(ModelView): inline_models = (models.Answer, ) form_extra_fields = { 'image_filename': ImageUploadField( upload_set=upload_sets.questions, label='Image', base_path=os.path.join( current_app.config['UPLOADS_DEFAULT_DEST'], 'questions', ), thumbnail_size=(200, 200, True), ), } admin.add_view(ModelView(models.Answer, db.session)) admin.add_view(QuestionModelView(models.Question, db.session))
from apps.common.admins import ImageUploadField from apps.extensions import ( admin, db, ) from . import ( models, upload_sets, ) class DetectionObjectModelView(ModelView): form_extra_fields = { 'image_filename': ImageUploadField( upload_set=upload_sets.detections, label='Image', base_path=os.path.join( current_app.config['UPLOADS_DEFAULT_DEST'], 'detections', ), thumbnail_size=(200, 200, True), ), } admin.add_view(DetectionObjectModelView(models.DetectionObject, db.session)) admin.add_view(ModelView(models.Transaction, db.session))
from flask_admin.contrib.sqla import ModelView from apps.extensions import ( admin, db, ) from . import models admin.add_view(ModelView(models.User, db.session))
@action( 'clear_accepted_by', 'Clear accepted_by', ('Are you sure you want to clear `accepted_by` field for ' + 'selected help requests?'), ) def clear_accepted_by(self, ids): try: self.session.bulk_update_mappings( self.model, [{ 'id': user_id, 'accepted_by_id': None, 'accepted_at': None } for user_id in ids], ) self.session.flush() self.session.commit() flash( f'Successfully cleared accepted_by of {len(ids)} help requests', 'success', ) except Exception as exc: if not self.handle_view_exception(exc): raise flash(f'Failed to clear approved_by. {exc}', 'error') admin.add_view(HelpRequestModelView(models.HelpRequest, db.session))