Esempio n. 1
0
def review():
    gid = 1
    fid = session['form_id']
    if fid is None:
        return redirect("/")

    form = FormQueries.get(fid)

    files = FormToFileQueries.get_form_files(fid)

    show_next = False
    show_previous = False
    if FormQueries.exists(fid + 1):
        show_next = True
    if FormQueries.exists(fid - 1):
        show_previous = True

    cfg = get_cfg()

    return render_template('views/public/review.html',
                           form=form,
                           files=files,
                           allowed_extensions=cfg['allowed_extensions'],
                           document_extensions=cfg['document_extensions'],
                           show_next=show_next,
                           show_previous=show_previous)
Esempio n. 2
0
def upload(upload_type):
    fid = session['form_id']
    username = session['username']
    message = "Complete"
    status = 200

    if fid is None or username is None:
        return abort(404)
    try:
        cfg = get_cfg()
        form = Forms.get(Forms.fid == fid)
        staticPath = form.gallery.folder_name + "/" + secure_filename(username) + "-" + str(fid)
        if form.folder_path is None:
            form.folder_path = staticPath
            form.save()
        file_count = FormToFileQueries.file_count(fid)
        print(file_count)
        for i, f in enumerate(request.files):
            file_count += 1
            file = request.files[f]
            file_ext = get_file_extension(file.filename)
            date = str(datetime.today().__format__("%m-%d-%y"))
            if upload_type == "cv":
                new_file_name = date + "-" + username + "-CV"
            elif upload_type == "statement":
                new_file_name = date + "-" + username + "-Statement"
            else:
                new_file_name = date + "-" + username + \
                    "-Image" + "-" + str(file_count)
            new_file_name += "." + file_ext
            new_file_name = secure_filename(new_file_name)

            file_upload_path = getAbsolutePath(
                cfg['paths']['app'] + staticPath, new_file_name, True)

            if allowed_file(file.filename):
                if upload_type == "cv":
                    FormQueries.insert_attachment_file(
                        "cv", fid, new_file_name,
                        staticPath + '/' + new_file_name, file_ext)
                    file.save(file_upload_path)
                elif upload_type == "statement":
                    FormQueries.insert_attachment_file(
                        "statement", fid, new_file_name,
                        staticPath + '/' + new_file_name, file_ext)
                    file.save(file_upload_path)
                else:
                    file_id, created = FilesQueries.insert(
                        staticPath + '/' + new_file_name, new_file_name,
                        file_ext)
                    if created:
                        FormToFileQueries.insert(fid, file_id)
                        file.save(file_upload_path)
                    else:
                        message = "File already exists"
                        status = 501
        return message, status

    except Exception as e:
        return "We were unable to upload the file, please try again", 501
Esempio n. 3
0
def application_image():
    gid = 1
    if "form_id" not in session or session['form_id'] is None:
        return redirect("/")
    fid = session["form_id"]
    gallery = Galleries.get(Galleries.gid == gid)
    accepted_files = get_cfg()["allowed_extensions"]
    accepted_files = "." + ",.".join(accepted_files)

    new_files_message = "Please upload your images along with a list describing them."
    existing_files_message = "You previously uploaded the following images"
    form = Forms.get(Forms.fid == fid)
    pre_exist = False
    files = FormToFileQueries.get_form_files(fid)

    if files is not None:
        pre_exist = True

    action = "/upload/image/"
    next_href = "/application/review/"
    prev_href = "/application/statement/"
    maxFiles = 40
    step = 4

    allowed_extensions = get_cfg()['allowed_extensions']
    document_extensions = get_cfg()['document_extensions']
    next_button = "Review Application"

    return render_template('views/public/file_uploads.html',
                           next_href=next_href,
                           prev_href=prev_href,
                           step=step,
                           new_files_message=new_files_message,
                           existing_files_message=existing_files_message,
                           pre_exist=pre_exist,
                           maxFiles=maxFiles,
                           action=action,
                           accepted_files=accepted_files,
                           gallery=gallery,
                           files=files,
                           allowed_extensions=allowed_extensions,
                           document_extensions=document_extensions,
                           next_button=next_button)
Esempio n. 4
0
def create_app(config_filename):
    from app.models.Role import Role
    from app.models.Users import Users
    from app.models.UserRoles import UserRoles
    from app.models.util import getDB
    from app.config import loadConfig
    from app.logic.validation import doesUserHaveRole

    from app.controllers.admin import admin
    from app.controllers.public import public

    app = Flask(__name__)

    secret_cfg = loadConfig.get_secret_cfg()
    cfg = loadConfig.get_cfg()
    app.secret_key = os.environ["APP_SECRET_KEY"]

    app.register_blueprint(admin)
    app.register_blueprint(public)
    mainDB = getDB()
    user_datastore = PeeweeUserDatastore(mainDB, Users, Role, UserRoles)

    # app.config["SECURITY_SEND_REGISTER_EMAIL"] = False
    app.config["SECURITY_PASSWORD_SALT"] = os.environ["SECURITY_PASSWORD_SALT"]
    security = Security(app, user_datastore)
    app.jinja_env.globals.update(doesUserHaveRole=doesUserHaveRole)

    # @app.before_first_request
    # def create_user():
    #     user = user_datastore.create_user(email='*****@*****.**',password=utils.encrypt_password('password'),role='admin')
    #     role =  user_datastore.create_role(name='admin')
    #     user_datastore.add_role_to_user(user, role)

    @app.errorhandler(403)
    def access_denied(e):
        return render_template('views/403.html', cfg=cfg), 403

    @app.errorhandler(404)
    def pageNotFound(e):
        return render_template('views/404.html', cfg=cfg), 404

    return app
Esempio n. 5
0
def application_cv():
    gid = 1
    if "form_id" not in session or session['form_id'] is None:
        return redirect("/")
    fid = session["form_id"]
    gallery = Galleries.get(Galleries.gid == gid)
    accepted_files = get_cfg()["document_extensions"]
    accepted_files = "." + ",.".join(accepted_files)

    new_files_message = "Please upload your curriculum vitae"
    existing_files_message = "You previously uploaded the following curriculum vitae"
    form = Forms.get(Forms.fid == fid)
    pre_exist = False
    if form.cv is not None:
        pre_exist = True

    button_text = "Your Curriculum Vitae"
    filepath = "/download/cv/"
    action = "/upload/cv/"
    next_href = "/application/statement/"
    prev_href = "/?active_session='true'"
    maxFiles = 1
    remove_url = "/delete/cv"
    step = 2
    return render_template('views/public/file_uploads.html',
                           next_href=next_href,
                           prev_href=prev_href,
                           step=step,
                           new_files_message=new_files_message,
                           existing_files_message=existing_files_message,
                           pre_exist=pre_exist,
                           maxFiles=maxFiles,
                           action=action,
                           accepted_files=accepted_files,
                           gallery=gallery,
                           button_text=button_text,
                           filepath=filepath,
                           remove_url=remove_url)
Esempio n. 6
0
def application_statement():
    gid = 1
    if "form_id" not in session or session['form_id'] is None:
        return redirect("/")
    gallery = Galleries.get(Galleries.gid == gid)
    fid = session["form_id"]
    accepted_files = get_cfg()["document_extensions"]
    accepted_files = "." + ",.".join(accepted_files)
    new_files_message = "Please upload your artist statement"
    existing_files_message = "You previously uploaded the following artist statement"
    form = Forms.get(Forms.fid == fid)
    pre_exist = False
    if form.personal_statement is not None:
        pre_exist = True

    button_text = "Your Artistic Statement"
    filepath = "/download/statement"
    action = "/upload/statement/"
    next_href = "/application/image/"
    prev_href = "/application/cv/"
    maxFiles = 1
    remove_url = "/delete/statement"
    step = 3
    return render_template('views/public/file_uploads.html',
                           next_href=next_href,
                           prev_href=prev_href,
                           step=step,
                           new_files_message=new_files_message,
                           existing_files_message=existing_files_message,
                           pre_exist=pre_exist,
                           maxFiles=maxFiles,
                           action=action,
                           accepted_files=accepted_files,
                           gallery=gallery,
                           button_text=button_text,
                           filepath=filepath,
                           remove_url=remove_url)
def contributors():
    return render_template("snips/contributors.html", cfg=get_cfg())
Esempio n. 8
0
from flask import redirect
from flask import request
from flask import g
from flask import url_for
from flask import flash
from flask import abort
from flask_admin import Admin
from app.config import *
from app.models import *
from app.config import loadConfig
from app.models.util import *

import pprint
import sys

cfg = loadConfig.get_cfg()
secret_cfg = loadConfig.get_secret_cfg()
sys.dont_write_bytecode = True
mainDB = getDB()
''' Creates an Flask object; @app will be used for all decorators.
from: http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/
"A decorator is just a callable that takes a function as an argument and 
returns a replacement function. See start.py for an example"
'''
app = Flask(__name__)
app.secret_key = secret_cfg['secret_key']
#from app import app
admin = Admin(app)


# Builds all the database connections on app run
def get_static_absolute_path(relaitivePath, filename=None, makeDirs=True):
    return getAbsolutePath(
        loadConfig.get_cfg()['paths']['app'] + relaitivePath, filename,
        makeDirs)