diff --git a/app/admin/views.py b/app/admin/views.py index 4af0329..4477e74 100644 --- a/app/admin/views.py +++ b/app/admin/views.py @@ -4,9 +4,6 @@ from flask_admin.form import FileUploadField, SecureForm from flask_login import current_user -from wtforms import StringField -from wtforms.validators import DataRequired - from app.config import config @@ -17,15 +14,15 @@ class BaseAdminModelView(ModelView): can_delete = True column_display_pk = True - column_exclude_list = ['created_at', 'updated_at'] - form_excluded_columns = ['created_at', 'updated_at'] + column_exclude_list = ["created_at", "updated_at"] + form_excluded_columns = ["created_at", "updated_at"] def __init__(self, model, session, **kwargs): super().__init__(model, session, **kwargs) def on_model_change(self, form, model, is_created): return super().on_model_change(form, model, is_created) - + def is_accessible(self): return current_user.is_authenticated and current_user.is_admin @@ -66,15 +63,11 @@ class ProjectView(BaseAdminModelView): "img": FileUploadField("Image", base_path=config.UPLOAD_FOLDER) } form_columns = ["name", "img", "description", "created", "url", "category"] - form_ajax_refs = { - "category": { - "fields": ['name'], - 'page_size': 10 - } - } + form_ajax_refs = {"category": {"fields": ["name"], "page_size": 10}} + class CategoryView(BaseAdminModelView): - form_columns = ['name'] + form_columns = ["name"] class SocialView(BaseAdminModelView): @@ -95,5 +88,3 @@ class ContactView(BaseAdminModelView): class UserView(BaseAdminModelView): pass - - diff --git a/app/routes/site.py b/app/routes/site.py index 51c10c0..e0ffcd0 100644 --- a/app/routes/site.py +++ b/app/routes/site.py @@ -1,7 +1,16 @@ import random import os -from flask import Blueprint, render_template, abort, send_from_directory, flash, url_for, redirect, request +from flask import ( + Blueprint, + render_template, + abort, + send_from_directory, + flash, + url_for, + redirect, + request, +) from flask_mail import Message from app.models import Resume, About, Skill, Service, Project, Category, Contact from app.extensions import db, mail @@ -19,16 +28,16 @@ def uploaded_file(filename): return send_from_directory(config.UPLOAD_FOLDER, filename) -@dp.route('/upload', methods=['POST']) +@dp.route("/upload", methods=["POST"]) def uplod_file(): - if 'file' not in request.files: + if "file" not in request.files: return "No File part", 400 - file = request.files['file'] - if file.filename == '': + file = request.files["file"] + if file.filename == "": return "No selected file", 400 file.save(os.path.join(config.UPLOAD_FOLDER, file.filename)) - file_url = url_for('site.uploaded_file', filename=file.filename) + file_url = url_for("site.uploaded_file", filename=file.filename) return redirect(file_url)