Skip to content

Commit

Permalink
fix: change bag
Browse files Browse the repository at this point in the history
  • Loading branch information
RustamovAkrom committed Oct 29, 2024
1 parent 8439586 commit 79ee105
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
31 changes: 28 additions & 3 deletions app/admin/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
from flask import redirect, url_for, request
from flask_admin import AdminIndexView, expose
from flask_admin.contrib.sqla import ModelView
from flask_admin.form import FileUploadField
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


class BaseAdminModelView(ModelView):
form_base_class = SecureForm

can_create = True
can_delete = True

column_display_pk = True
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

Expand Down Expand Up @@ -48,10 +66,15 @@ 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
}
}

class CategoryView(BaseAdminModelView):
pass
form_columns = ['name']


class SocialView(BaseAdminModelView):
Expand All @@ -72,3 +95,5 @@ class ContactView(BaseAdminModelView):

class UserView(BaseAdminModelView):
pass


37 changes: 22 additions & 15 deletions app/routes/site.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
import os

from flask import Blueprint, render_template, abort, send_from_directory, flash, 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
Expand All @@ -18,18 +19,37 @@ def uploaded_file(filename):
return send_from_directory(config.UPLOAD_FOLDER, filename)


@dp.route('/upload', methods=['POST'])
def uplod_file():
if 'file' not in request.files:
return "No File part", 400
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)
return redirect(file_url)


@dp.route("/")
@dp.route("/home")
@htmx_route()
def index():
resume_data = Resume.query.first()
about_avatar_url = About.query.first()

if about_avatar_url:
about_avatar_url = about_avatar_url
else:
about_avatar_url = None

context = {
"template_name": "site/index.html",
# "template_title": "Rustamov Akrom",
"template_body_class_name": "index",
"resume": resume_data,
"about_avatar_url": about_avatar_url.avatar,
"about_avatar_url": about_avatar_url,
"baground_image": f"{random.randint(1, 3)}.jpg",
}
return context
Expand Down Expand Up @@ -116,19 +136,6 @@ def portfolio():
return context


@dp.route("/portfolio/details/<int:portfolio_id>")
@htmx_route()
def portfolio_details(portfolio_id):
project_data = Project.query.get(portfolio_id)
context = {
"template_name": "site/portfolio_detail.html",
"template_title": project_data.name,
"template_body_class_name": "portfolio-details",
"project": project_data,
}
return context


@dp.route("/resume")
@htmx_route()
def resume():
Expand Down
2 changes: 2 additions & 0 deletions app/templates/site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ <h2>Rustamov Akrom</h2>
<!-- Avatar -->
<div class="col-lg-4 ml-auto">
<div class="avatar-wrapper">
{% if about_avatar_url %}
<img src="{{ url_for('site.uploaded_file', filename=about_avatar_url) }}" class="img-fluid rounded-circle" alt="Akrom Rustamov - Python Developer">
{% endif %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/site/portfolio.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1>Portfolio</h1>
<h4>{{ project.name }}</h4>
<p>{{ project.description }}</p>
<a href="{{ url_for('site.uploaded_file', filename=project.img) }}" title="{{ project.name }}" data-gallery="portfolio-gallery-app" class="glightbox preview-link"><i class="bi bi-zoom-in"></i></a>
<a href="{{ url_for('site.portfolio_details', portfolio_id=project.id) }}" title="More Details" class="details-link"><i class="bi bi-link-45deg"></i></a>
<a href="{{ project.url }}" title="More Details" class="details-link"><i class="bi bi-link-45deg"></i></a>
</div>
</div>
</div><!-- End Portfolio Item -->
Expand Down

0 comments on commit 79ee105

Please sign in to comment.