Exemplo n.º 1
0
def _parameters ():

    if is_admin():
        sel = ParameterSearchForm()

        if request.method == 'POST':
            sel.param_groups.default = request.form["param_groups"]
            sel.process()
            session["group"] = sel.param_groups.default # save group into session variable for reference.
            # params = Parameter.query.filter(Parameter.param_group == sel.param_groups.default).paginate(1, app.config["PAGINATION_SIZE"], False) # get the currently chosen option from the select list and use to control which parameters are shown
            params = Parameter.query.filter(Parameter.param_group == sel.param_groups.default).all()
        else:
            session["group"] = request.args.get('group', 0, type=int)

            if session["group"] > 0:
                page = request.args.get('page', 1, type=int)
                # set the session variable to the arg GROUP from the URL and then choose the params from that group id.
                sel.param_groups.default = session["group"]
                sel.process()
                # params = Parameter.query.filter(Parameter.param_group == Parameter.query.filter(Parameter.id == session["group"]).first().id).paginate(page, app.config["PAGINATION_SIZE"], False)
                params = Parameter.query.filter(Parameter.param_group == Parameter.query.filter(Parameter.id == session["group"]).first().id).all()
            else:
                # Just get the first in the list as the chosen option, then get the params for that id.
                session["group"] = Parameter.query.filter(Parameter.param_group==0).order_by(Parameter.param_name.asc()).first().id
                # params = Parameter.query.filter(Parameter.param_group == session["group"]).paginate(1, app.config["PAGINATION_SIZE"], False)
                params = Parameter.query.filter(Parameter.param_group == session["group"]).all()
                sel.param_groups.default = session["group"]
                sel.process()

        print (params)
        return render_template("parameters.html", data=params, sel=sel)
    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 2
0
def _editcomplex (id):
    if is_admin():

        complex = Complex.query.filter_by(id=id).first()
        form = ComplexForm(obj=complex)

        if request.method == "GET":
            return render_template("editcomplex.html", data=complex, form=form)

        if form.validate_on_submit():
            if not complex:
                complex = Complex()
                db.session.add(complex)

            form.populate_obj(complex)
            complex.complex_updated = datetime.now()
            db.session.commit()
            flash ('Complex saved successfully', 'success')
            return redirect(url_for('gui_blueprint._complexes'))
        else:
            flash_errors(form)

        return render_template("editcomplex.html", data=complex, form=form)

    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 3
0
    def get(self):
        if is_admin():
            # get query from database
            users_ = db.session.query(User.id,User.forename,User.surname,User.comment,User.email,Role.role_name,Parameter.param_value)\
            .join(Role).outerjoin(Parameter).order_by(User.id.asc()).all()

            # create list of a map for query
            result = list(map(lambda x: x._asdict(), users_))
            #result = json.dumps(result, indent=4, sort_keys=True, default=json_fmt_default)
            return result
Exemplo n.º 4
0
    def get(self):
        if is_admin():
            # get query from database
            roles_ = db.session.query(Role.id, Role.role_name, Role.role_admin,
                                      Role.created_date, Role.enabled).all()

            # create list of a map for query
            result = list(map(lambda x: x._asdict(), roles_))
            return result

        else:
            return not_admin()
Exemplo n.º 5
0
    def get(self):
        if is_admin():
            # get query from database
            doi_ = db.session.query(DateOfInterest).all()

            result = []
            for subl in doi_:
                d = model_as_dict(subl)
                result.append(d)

            return result

        else:
            return not_admin()
Exemplo n.º 6
0
def _dates ():
    if is_admin():
        a = aliased(Parameter)
        b = aliased(Parameter)
        c = aliased(Parameter)
        d = aliased(DateOfInterest)

        dates = db.session.query(d.id, d.doi_name, d.doi_regions, d.doi_start_dt, d.doi_end_dt, a.param_value, \
        b.param_name, c.param_name).join(a, d.doi_priority==a.id).\
        join(b, d.doi_hap==b.id).join(c, d.doi_locked==c.id).order_by(d.doi_start_dt.asc()).all()

        return render_template("dates.html", data=dates)
    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 7
0
    def get(self, id):
        if is_admin():
            # get query from database
            users_ = db.session.query(User.id, User.login_id, User.forename, User.surname, User.comment,\
                    User.email, Role.role_name, Parameter.param_value, User.enabled, User.created_date,
                    User.last_login, User.last_modified, User.modified_by)\
                    .join(Role).outerjoin(Parameter).filter(User.id==id).all()

            # create list of a map for query
            result = list(map(lambda x: x._asdict(), users_))
            #result = json.dumps(users_, indent=4, sort_keys=True, default=json_fmt_default)
            return result

        else:
            return not_admin()
Exemplo n.º 8
0
def _editdate (id):

    if is_admin():

        doi = DateOfInterest.query.filter_by(id=id).first()
        form = DOIForm(obj=doi)

        if request.method == "GET":
            if doi:
                form.doi_start_dt.data = datetime.strftime(datetime.strptime(doi.doi_start_dt, '%Y-%m-%d %H:%M:%S'), '%d/%m/%Y %H:%M')
                form.doi_end_dt.data = datetime.strftime(datetime.strptime(doi.doi_end_dt, '%Y-%m-%d %H:%M:%S'), '%d/%m/%Y %H:%M')
            return render_template("editdate.html", form=form, data=doi)

        if form.deletebtn.data:
            doi = DateOfInterest.query.filter_by(id=id).first()
            db.session.delete(doi)
            flash ('Date removed successfully', 'success')
            db.session.commit()
            return redirect(url_for('gui_blueprint._dates'))

        if form.validate_on_submit():

            start_dt = datetime.strptime(form.doi_start_dt.data, '%d/%m/%Y %H:%M')
            end_dt = datetime.strptime(form.doi_end_dt.data, '%d/%m/%Y %H:%M')

            if form.savebtn.data:
                if not doi:
                    doi = DateOfInterest(form.doi_name.data, form.doi_priority.data, form.doi_comment.data, \
                    start_dt, end_dt, form.doi_regions, form.doi_locked, form.doi_hap)
                    db.session.add(doi)

                form.populate_obj(doi)
                doi.doi_start_dt = start_dt
                doi.doi_end_dt = end_dt
                db.session.commit()

                flash ('Date saved successfully', 'success')
                return redirect(url_for('gui_blueprint._dates'))

        else:
            flash_errors(form)
            return render_template("editdate.html", form=form, data=doi)

        return redirect(url_for('gui_blueprint._dates'))


    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 9
0
def _comms ():

    if is_admin():
        form = CommsOptionsSelectForm()

        if request.method == 'GET':
            form.date_picker.data = datetime.now().strftime("%d/%m%Y")
            return render_template("comms.html", form=form)

        if request.method == 'POST':
            type_ = request.form.get("type_select", 0)
            emails = Parameter.query.filter(Parameter.param_name.like("OPERATIONS_EMAILS")).first()
            content = Parameter.query.filter(Parameter.param_parent==type_).first()
            return render_template("comms.html", form=form, emails=emails, content=content)

    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 10
0
def _complexes ():
    if is_admin():

        a = aliased(Parameter)
        b = aliased(Parameter)
        c = aliased(Parameter)
        d = aliased(Parameter)

        complexes = db.session.query(Complex, a, b, c, d).\
        filter(Complex.complex_manager==a.id).\
        filter(Complex.complex_type==b.id).\
        filter(Complex.complex_country==c.id).\
        filter(Complex.complex_active==d.id).all()

        return render_template("complexes.html", data = complexes)
    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 11
0
def _approvebooking (id):

    if is_admin():
        booking = Booking.query.filter_by(id=id).first()
        if booking.approved_date:
            booking.approved_date = None
            booking.approved_by = None
            booking.approval_reason = "Manually set to not approved by " + get_user()
        else:
            booking.approved_date = datetime.now()
            booking.approved_by = get_user()
            booking.approval_reason = "Approved by " + get_user()
        flash("Toggled approval date for booking <{}>".format(booking.title))
        db.session.commit()
    else:
        flash ("Cannot toggle booking approval unless an administrator")

    return redirect(url_for('gui_blueprint._index'))
Exemplo n.º 12
0
def _edituser (id):
    if is_admin():

        user = User.query.filter_by(id=id).first()
        form = UserForm(obj=user)

        if request.method == "GET":
            return render_template("edituser.html", data=user, form=form)

        if form.validate_on_submit():

            if form.savebtn.data:
                if not user:
                    user = User(form.login_id.data, form.forename.data, form.surname.data, form.comment.data, form.password.data, form.email.data, form.role.data, form.vendor.data)
                    user.last_login = None
                    db.session.add(user)

                form.populate_obj(user)
                user.last_modified = datetime.now()
                user.modified_by = session["login_id"]

                if not form.created_date.data:
                    user.created_date = datetime.now()

                db.session.commit()
                flash ('User saved successfully', 'success')
                return redirect(url_for('gui_blueprint._users'))

            if form.deletebtn.data:
                user = User.query.filter_by(id=id).first()
                db.session.delete(user)
                flash ('User removed successfully', 'success')
                db.session.commit()
                return redirect(url_for('gui_blueprint._users'))

        else:
            flash_errors (form)

        return render_template("edituser.html", data=user, form=form)

    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 13
0
    def get(self):
        if is_admin():

            # get query from database
            a = aliased(Parameter)
            b = aliased(Parameter)
            c = aliased(Parameter)
            d = aliased(Parameter)

            complexes_ = db.session.query(Complex.id, Complex.complex_name, Complex.complex_push_days, \
            Complex.complex_push_start, Complex.complex_push_end, a.param_value.label("complex_manager"), \
            b.param_value.label("complex_type"), \
            c.param_value.label("complex_country"), d.param_name.label("complex_active")).\
            join(a,Complex.complex_manager==a.id).join(b,Complex.complex_type==b.id).\
            join(c,Complex.complex_country==c.id).join(d,Complex.complex_active==d.id).all()

            result = list(map(lambda x: x._asdict(), complexes_))

            return result

        else:
            return not_admin()
Exemplo n.º 14
0
def _editparameter (id):
    if is_admin():

        param = Parameter.query.filter_by(id=id).first()
        form = ParameterForm(obj=param)

        if request.method == "GET":
            return render_template("editparameter.html", data=param, form=form)

        if form.validate_on_submit():
            if form.savebtn.data:
                if not param:
                    param = Parameter(form.id.data, form.param_name.data, form.param_value.data, form.param_group.data, form.param_parent.data, form.param_disabled.data, form.param_critical.data)
                    db.session.add(param)

                form.populate_obj(param)
                db.session.commit()
                return redirect(url_for('gui_blueprint._parameters', group=session["group"]))

            if form.deletebtn.data:
                param = Parameter.query.filter_by(id=id).first()
                capacity = Parameter.query.filter(Parameter.param_group==param.id).count()
                if capacity == 0:
                    db.session.delete(param)
                    db.session.commit()
                else:
                    flash("Cannot delete non-empty Parameter Group: " + param.param_name, "warning")

                return redirect(url_for('gui_blueprint._parameters', group=0))

        else:
            for fieldName, errorMessages in form.errors.items():
                for err in errorMessages:
                    print (fieldName + " " + err + " value:(" + str(form.param_group.data) + ")")
            return render_template("400.html", error = form.errors)

    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 15
0
def _editrole (id):

    if is_admin():

        role = Role.query.filter_by(id=id).first()
        form = RoleForm(obj=role)

        if request.method == "GET":
            return render_template("editrole.html", form=form, data=role)

        if form.validate_on_submit():

            if form.savebtn.data:
                if not role:
                    role = Role(form.role_name.data, form.role_admin.data, form.role_app_sections.data, form.enabled.data)
                    db.session.add(role)

                form.populate_obj(role)
                role.created_date = datetime.now()
                db.session.commit()
                flash ('Role saved successfully', 'success')
                return redirect(url_for('gui_blueprint._roles'))

            if form.deletebtn.data:
                role = Role.query.filter_by(id=id).first()
                counter = User.query.filter_by(role=role.id).count()
                if counter == 0:  # there are no user accounts using this role
                    db.session.delete(role)
                    flash ('Role removed successfully', 'success')
                    db.session.commit()
                else:
                    flash ('Cannot delete role as it is in use', 'warning')

        else:
            flash_errors (form)
            return render_template("editrole.html", form=form, data=role)

        return redirect(url_for('gui_blueprint._roles'))
Exemplo n.º 16
0
def _logs ():
    if is_admin():

        form = LogForm()

        # Prevent the rec # counter from breaking the app - default to 10
        try:
            records = int(request.args.get('log_records'))
        except:
            records = 5

        # Prevent the log name from breaking the app - default to LOG_FILE variable
        try:
            rec_t = request.args.get('log_options')
            log_t   = app.config[rec_t]
        except:
            log_t = app.config["LOG_FILE"]

        form.log_records.data = str(records)
        form.log_options.data = rec_t
        data = FileReadBackwards(log_t, encoding="utf-8")
        return render_template("logs.html", data=data, form=form, counter=records)
    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 17
0
def _users ():
    if is_admin():
        users = db.session.query(User,Role,Parameter).join(Role).outerjoin(Parameter).order_by(User.id.asc())
        return render_template("users.html", data = users)
    else:
        return render_template("403.html", error = "You are not an administrator")
Exemplo n.º 18
0
def _roles ():
    if is_admin():
        roles = Role.query.order_by(Role.id.asc())
        return render_template("roles.html", data = roles)
    else:
        return render_template("403.html", error = "You are not an administrator")