Browse Source

admin page without functionality

current_wdka_release
crunk 3 years ago
parent
commit
847f4b234d
  1. 35
      verse/adminpage.py
  2. 12
      verse/forms/admindistribusiform.py
  3. 13
      verse/forms/adminuserform.py
  4. 2
      verse/forms/themeform.py
  5. 12
      verse/start.py
  6. 53
      verse/templates/admin.html
  7. 7
      verse/templates/index.html

35
verse/adminpage.py

@ -0,0 +1,35 @@
import os
import bleach
import shutil
from flask import render_template
from werkzeug.utils import secure_filename
from sqlalchemy.exc import (
DataError,
DatabaseError,
InterfaceError,
InvalidRequestError,
)
from app import db
from statuspengguna.helper import (
IsZipUploaded,
CurrentDistribusi,
IsDistribusiLive,
)
from distribusimodel import Distribusis
from distribusisinfo import DistribusisInfo
from forms.adminuserform import AdminUserForm
from forms.admindistribusiform import AdminDistribusiForm
def AdminPage():
adminuserform = AdminUserForm()
admindistribusiform = AdminDistribusiForm()
template = render_template(
"admin.html",
adminuserform=adminuserform,
admindistribusiform=admindistribusiform,
)
return template

12
verse/forms/admindistribusiform.py

@ -0,0 +1,12 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from wtforms import (
RadioField,
SubmitField,
)
class AdminDistribusiForm(FlaskForm):
"""Admin Distribusi form."""
delete = SubmitField("Delete")

13
verse/forms/adminuserform.py

@ -0,0 +1,13 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from wtforms import (
RadioField,
SubmitField,
)
class AdminUserForm(FlaskForm):
"""Admin Userform form."""
update = SubmitField("update")
delete = SubmitField("Delete")

2
verse/forms/themeform.py

@ -7,7 +7,7 @@ from wtforms import (
class ThemeForm(FlaskForm): class ThemeForm(FlaskForm):
"""Publication upload form.""" """Basic theme selection form."""
theme = RadioField( theme = RadioField(
"Select your theme:", "Select your theme:",

12
verse/start.py

@ -41,6 +41,7 @@ from distribusiselector import (
from editor import Editor from editor import Editor
from themeselector import ThemeSelector from themeselector import ThemeSelector
from upload import UploadNewDistribusi, UploadUpdatedFiles from upload import UploadNewDistribusi, UploadUpdatedFiles
from adminpage import AdminPage
# UserPengguna # UserPengguna
from statuspengguna.helper import ( from statuspengguna.helper import (
@ -90,12 +91,14 @@ def index():
terms = uploadform.term.choices terms = uploadform.term.choices
courses = uploadform.course.choices courses = uploadform.course.choices
adminuser = isadminuser()
template = render_template( template = render_template(
"index.html", "index.html",
distribusies=distribusies, distribusies=distribusies,
years=years, years=years,
terms=terms, terms=terms,
courses=courses, courses=courses,
adminuser=adminuser,
) )
return template return template
@ -275,7 +278,7 @@ def distribusistash(path):
@APP.route("/admin") @APP.route("/admin")
@login_required @login_required
def admin(): def admin():
return "admin" return AdminPage()
@APP.route("/logout") @APP.route("/logout")
@ -307,6 +310,13 @@ def load_user(user_id):
return User.query.get(int(user_id)) return User.query.get(int(user_id))
def isadminuser():
if not current_user.is_authenticated:
return False
user = User.query.filter_by(email=current_user.email).first()
return user.admin
if __name__ == "__main__": if __name__ == "__main__":
APP.debug = True APP.debug = True
APP.run(port=5000) APP.run(port=5000)

53
verse/templates/admin.html

@ -0,0 +1,53 @@
{% extends "base.html" %}
{% block main %}
<div id="buttons">
{% if not current_user.is_authenticated %}
<div class="signin">
<a href="/login">
<input type="button" name="button" value="Sign in"></input>
</a>
</div>
<div class="signin">
<a href="/register">
<input type="button" name="button" value="Register"></input>
</a>
</div>
{% else %}
<div class="distribusi">
<a href="/distribusi">
<input type="button" name="button" value="Distribusi"></input>
</a>
</div>
<div class="logout">
<a href="/logout">
<input type="button" name="button" value="Logout"></input>
</a>
</div>
{% endif %}
</div>
<div class="maincontent">
<!-- a div with all the distribusis listed in the distribusiverse -->
<div id="distribusiverse" class="maincontent">
<h2>List of distribusis</h2>
<form method="POST" enctype="multipart/form-data" action="{{ url_for('theme') }}">
{{ admindistribusiform.csrf_token }}
<fieldset class="button required multiselect delete">
{{ admindistribusiform.delete }}
</fieldset>
</form>
</div>
<div id="distribusiverse" class="maincontent">
<h2>List of users</h2>
<form method="POST" enctype="multipart/form-data" action="{{ url_for('theme') }}">
{{ adminuserform.csrf_token }}
<fieldset class="button required multiselect update">
{{ adminuserform.update }}
</fieldset>
<fieldset class="button required multiselect delete">
{{ adminuserform.delete }}
</fieldset>
</form>
</div>
{% endblock %}

7
verse/templates/index.html

@ -24,6 +24,13 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
{% if adminuser %}
<div class="admin">
<a href="/admin">
<input type="button" name="button" value="Admin"></input>
</a>
</div>
{% endif %}
</div> </div>
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<h2 id="fancyboi"> Hi {{ current_user.email }}!</h2> <h2 id="fancyboi"> Hi {{ current_user.email }}!</h2>

Loading…
Cancel
Save