forked from AFPy/afpy.org
Enhancing the admin interface.
This commit is contained in:
parent
85ba4bfb03
commit
0fd8f901fa
|
@ -23,7 +23,7 @@ pagedown = PageDown(application)
|
||||||
|
|
||||||
application.debug = config.FLASK_DEBUG
|
application.debug = config.FLASK_DEBUG
|
||||||
application.secret_key = config.FLASK_SECRET_KEY
|
application.secret_key = config.FLASK_SECRET_KEY
|
||||||
application.config["FLASK_ADMIN_SWATCH"] = "lux"
|
application.config["FLASK_ADMIN_SWATCH"] = "darkly"
|
||||||
|
|
||||||
|
|
||||||
# Initializes the login manager used for the admin
|
# Initializes the login manager used for the admin
|
||||||
|
@ -62,7 +62,14 @@ from afpy.models.JobPost import JobPost, JobPost_Admin
|
||||||
from afpy.models.Slug import Slug, SlugAdmin
|
from afpy.models.Slug import Slug, SlugAdmin
|
||||||
|
|
||||||
|
|
||||||
from afpy.routes.admin import AdminIndexView, NewAdminView, ChangePasswordView, ModerateView, CustomFileAdmin
|
from afpy.routes.admin import (
|
||||||
|
AdminIndexView,
|
||||||
|
NewAdminView,
|
||||||
|
ChangePasswordView,
|
||||||
|
JobsModerateView,
|
||||||
|
NewsModerateView,
|
||||||
|
CustomFileAdmin,
|
||||||
|
)
|
||||||
|
|
||||||
# Creates the Admin manager
|
# Creates the Admin manager
|
||||||
admin = Admin(
|
admin = Admin(
|
||||||
|
@ -74,14 +81,15 @@ admin = Admin(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Registers the views for each table
|
# Registers the views for each table
|
||||||
admin.add_view(AdminUser_Admin(AdminUser, category="Models"))
|
admin.add_view(JobsModerateView(name="Moderate Jobs", endpoint="jobs_moderation", category="Moderate"))
|
||||||
admin.add_view(NewsEntry_Admin(NewsEntry, category="Models"))
|
admin.add_view(NewsModerateView(name="Moderate News", endpoint="news_moderation", category="Moderate"))
|
||||||
admin.add_view(JobPost_Admin(JobPost, category="Models"))
|
admin.add_view(NewsEntry_Admin(NewsEntry))
|
||||||
admin.add_view(SlugAdmin(Slug, category="Models"))
|
admin.add_view(JobPost_Admin(JobPost))
|
||||||
|
admin.add_view(SlugAdmin(Slug))
|
||||||
admin.add_view(CustomFileAdmin(config.IMAGES_PATH, "/images/", name="Images Files"))
|
admin.add_view(CustomFileAdmin(config.IMAGES_PATH, "/images/", name="Images Files"))
|
||||||
admin.add_view(NewAdminView(name="New Admin", endpoint="register_admin"))
|
admin.add_view(NewAdminView(name="New Admin", endpoint="register_admin", category="Admin"))
|
||||||
admin.add_view(ChangePasswordView(name="Change password", endpoint="change_password"))
|
admin.add_view(ChangePasswordView(name="Change password", endpoint="change_password", category="Admin"))
|
||||||
admin.add_view(ModerateView(name="Moderate", endpoint="moderation"))
|
admin.add_view(AdminUser_Admin(AdminUser, category="Admin"))
|
||||||
|
|
||||||
|
|
||||||
@application.template_filter("rfc822_datetime")
|
@application.template_filter("rfc822_datetime")
|
||||||
|
|
|
@ -100,6 +100,8 @@ class JobPost(BaseModel):
|
||||||
|
|
||||||
class JobPost_Admin(ModelView):
|
class JobPost_Admin(ModelView):
|
||||||
model_class = JobPost
|
model_class = JobPost
|
||||||
|
column_list = ("state", "title", "dt_published")
|
||||||
|
column_default_sort = ("id", True)
|
||||||
|
|
||||||
def is_accessible(self):
|
def is_accessible(self):
|
||||||
return current_user.is_authenticated
|
return current_user.is_authenticated
|
||||||
|
|
|
@ -86,6 +86,8 @@ class NewsEntry(BaseModel):
|
||||||
|
|
||||||
class NewsEntry_Admin(ModelView):
|
class NewsEntry_Admin(ModelView):
|
||||||
model_class = NewsEntry
|
model_class = NewsEntry
|
||||||
|
column_list = ("state", "title", "dt_published")
|
||||||
|
column_default_sort = ("id", True)
|
||||||
|
|
||||||
def is_accessible(self):
|
def is_accessible(self):
|
||||||
return current_user.is_authenticated
|
return current_user.is_authenticated
|
||||||
|
|
|
@ -92,52 +92,28 @@ class ChangePasswordView(admin.BaseView):
|
||||||
return self.render("admin/change_password.html", form=form)
|
return self.render("admin/change_password.html", form=form)
|
||||||
|
|
||||||
|
|
||||||
class ModerateView(admin.BaseView):
|
class _ModerateView(admin.BaseView):
|
||||||
|
model = None
|
||||||
|
|
||||||
@expose("/", methods=["GET"])
|
@expose("/", methods=["GET"])
|
||||||
def home_moderation(self):
|
def moderate_view(self):
|
||||||
if not current_user.is_authenticated:
|
if not current_user.is_authenticated:
|
||||||
return redirect(url_for("admin.index"))
|
return redirect(url_for("admin.index"))
|
||||||
return self.render("admin/moderation_home.html")
|
items = self.model.select().where(self.model.state == "waiting").order_by(self.model.dt_submitted.desc())
|
||||||
|
return self.render("admin/moderate_view.html", items=items, edit_view=self.edit_view)
|
||||||
|
|
||||||
@expose("/<type>", methods=["GET"])
|
@expose("/preview/<id>", methods=["GET"])
|
||||||
def moderate_view(self, type):
|
def preview_item(self, id):
|
||||||
if not current_user.is_authenticated:
|
if not current_user.is_authenticated:
|
||||||
return redirect(url_for("admin.index"))
|
return redirect(url_for("admin.index"))
|
||||||
if type == "jobs":
|
item = self.model.get_by_id(id)
|
||||||
jobs = JobPost.select().where(JobPost.state == "waiting").order_by(JobPost.dt_submitted.desc())
|
return self.render("pages/post.html", post=item, preview=True)
|
||||||
return self.render("admin/moderate_view.html", items=jobs, type=type)
|
|
||||||
elif type == "news":
|
|
||||||
news = NewsEntry.select().where(NewsEntry.state == "waiting").order_by(NewsEntry.dt_submitted.desc())
|
|
||||||
return self.render("admin/moderate_view.html", items=news, type=type)
|
|
||||||
else:
|
|
||||||
flash("Wrong type")
|
|
||||||
return redirect(url_for("admin.index"))
|
|
||||||
|
|
||||||
@expose("/preview/<type>/<id>", methods=["GET"])
|
@expose("/moderate/action/<id>/<action>", methods=["GET"])
|
||||||
def preview_item(self, type, id):
|
def moderate_action(self, id, action):
|
||||||
if not current_user.is_authenticated:
|
if not current_user.is_authenticated:
|
||||||
return redirect(url_for("admin.index"))
|
return redirect(url_for("admin.index"))
|
||||||
if type == "jobs":
|
item = self.model.get_by_id(id)
|
||||||
job = JobPost.get_by_id(id)
|
|
||||||
return self.render("pages/job.html", job=job, preview=True)
|
|
||||||
elif type == "news":
|
|
||||||
news = NewsEntry.get_by_id(id)
|
|
||||||
return self.render("pages/post.html", post=news, preview=True)
|
|
||||||
else:
|
|
||||||
flash("Wrong type")
|
|
||||||
return redirect(url_for("admin.index"))
|
|
||||||
|
|
||||||
@expose("/moderate/action/<id>/<type>/<action>", methods=["GET"])
|
|
||||||
def moderate_action(self, id, type, action):
|
|
||||||
if not current_user.is_authenticated:
|
|
||||||
return redirect(url_for("admin.index"))
|
|
||||||
if type == "jobs":
|
|
||||||
item = JobPost.get_by_id(id)
|
|
||||||
elif type == "news":
|
|
||||||
item = NewsEntry.get_by_id(id)
|
|
||||||
else:
|
|
||||||
flash("Wrong type")
|
|
||||||
return redirect(url_for("admin.index"))
|
|
||||||
if action == "approve":
|
if action == "approve":
|
||||||
item.state = "published"
|
item.state = "published"
|
||||||
item.approved_by = current_user.id
|
item.approved_by = current_user.id
|
||||||
|
@ -150,7 +126,17 @@ class ModerateView(admin.BaseView):
|
||||||
else:
|
else:
|
||||||
flash("Wrong action type")
|
flash("Wrong action type")
|
||||||
return redirect(url_for("admin.index"))
|
return redirect(url_for("admin.index"))
|
||||||
return redirect(url_for(".moderate_view", type=type))
|
return redirect(url_for(".moderate_view"))
|
||||||
|
|
||||||
|
|
||||||
|
class JobsModerateView(_ModerateView):
|
||||||
|
model = JobPost
|
||||||
|
edit_view = "jobpost.edit_view"
|
||||||
|
|
||||||
|
|
||||||
|
class NewsModerateView(_ModerateView):
|
||||||
|
model = NewsEntry
|
||||||
|
edit_view = "newsentry.edit_view"
|
||||||
|
|
||||||
|
|
||||||
class CustomFileAdmin(FileAdmin):
|
class CustomFileAdmin(FileAdmin):
|
||||||
|
|
|
@ -18,15 +18,12 @@
|
||||||
{% if item.summary %}
|
{% if item.summary %}
|
||||||
<p>{{ item.summary }}</p>
|
<p>{{ item.summary }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if type == "jobs" %}
|
<p><a class="btn btn-secondary" href="{{ url_for(".preview_item", id=item.id) }}" role="button">Preview</a></p>
|
||||||
<p><a class="btn btn-secondary" href="{{ url_for("moderation.preview_item", type="jobs", id=item.id) }}" role="button">Preview</a></p>
|
<p>
|
||||||
<p><a class="btn btn-warning" href="{{ url_for("jobpost.edit_view", id=item.id) }}" role="button">Edit</a></p>
|
<a class="btn btn-warning" href="{{ url_for(edit_view, id=item.id) }}" role="button">Edit</a>
|
||||||
<p><a class="btn btn-success" href="{{ url_for("moderation.moderate_action", id=item.id, type="jobs", action="approve") }}" role="button">Approve</a> <a class="btn btn-danger" href="{{ url_for("moderation.moderate_action", id=item.id, type="jobs", action="reject") }}" role="button">Reject</a></p>
|
<a class="btn btn-success" href="{{ url_for(".moderate_action", id=item.id, action="approve") }}" role="button">Approve</a>
|
||||||
{% else %}
|
<a class="btn btn-danger" href="{{ url_for(".moderate_action", id=item.id, action="reject") }}" role="button">Reject</a>
|
||||||
<p><a class="btn btn-secondary" href="{{ url_for("moderation.preview_item", type="news", id=item.id) }}" role="button">Preview</a></p>
|
</p>
|
||||||
<p><a class="btn btn-warning" href="{{ url_for("newsentry.edit_view", id=item.id) }}" role="button">Edit</a></p>
|
|
||||||
<p><a class="btn btn-success" href="{{ url_for("moderation.moderate_action", id=item.id, type="news", action="approve") }}" role="button">Approve</a> <a class="btn btn-danger" href="{{ url_for("moderation.moderate_action", id=item.id, type="news", action="reject") }}" role="button">Reject</a></p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
{% extends 'admin/master.html' %}
|
|
||||||
{% block body %}
|
|
||||||
{{ super() }}
|
|
||||||
<div class="row-fluid">
|
|
||||||
{% include "_parts/flashes.jinja2" %}
|
|
||||||
<div>
|
|
||||||
{% if current_user.is_authenticated %}
|
|
||||||
<div class="col-md-4 text-center mx-3">
|
|
||||||
<a class="btn btn-primary" href="{{ url_for("moderation.moderate_view", type="jobs") }}"><i class="icon-arrow-left icon-white"></i>Moderate Jobs</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-xs-12 col-md-4 text-center mx-3">
|
|
||||||
<a class="btn btn-primary" href="{{ url_for("moderation.moderate_view", type="news") }}"><i class="icon-arrow-left icon-white"></i>Moderate News</a>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
{% endblock body %}
|
|
|
@ -7,7 +7,7 @@
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
{% if preview %}
|
{% if preview %}
|
||||||
<a href="{{ url_for("moderation.moderate_view", type="jobs") }}">Retour à l'interface d'administration</a>
|
<a href="{{ url_for("jobs_moderation.moderate_view") }}">Retour à l'interface d'administration</a>
|
||||||
{# <p><a class="btn btn-warning" href="http://127.0.0.1:5000/admin/jobpost/edit/?id={{ job.id }}" role="button">Edit</a></p>#}
|
{# <p><a class="btn btn-warning" href="http://127.0.0.1:5000/admin/jobpost/edit/?id={{ job.id }}" role="button">Edit</a></p>#}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
{% if preview %}
|
{% if preview %}
|
||||||
<a href="{{ url_for("moderation.moderate_view", type="news") }}">Retour à l'interface d'administration</a>
|
<a href="{{ url_for("news_moderation.moderate_view") }}">Retour à l'interface d'administration</a>
|
||||||
{# <p><a class="btn btn-warning" href="http://127.0.0.1:5000/admin/jobpost/edit/?id={{ post.id }}" role="button">Edit</a></p>#}
|
{# <p><a class="btn btn-warning" href="http://127.0.0.1:5000/admin/jobpost/edit/?id={{ post.id }}" role="button">Edit</a></p>#}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user