Esempio n. 1
0
    def create_default_depts(silent=False):
        """ creates default departments and categories. """

        for d in depart_categories:

            department = d['department']
            categories = d['category']

            query = FlicketDepartment.query.filter_by(department=department).first()
            if not query:
                add_department = FlicketDepartment(
                    department=department
                )
                db.session.add(add_department)

                if not silent:
                    print("department {} added.".format(department))

                for c in categories:
                    query = FlicketCategory.query.filter_by(category=c).first()
                    if not query:
                        add_category = FlicketCategory(
                            category=c,
                            department=add_department
                        )
                        db.session.add(add_category)

                        if silent is False:
                            print("category {} added.".format(c))
Esempio n. 2
0
def departments(page=1):

    form = DepartmentForm()

    query = FlicketDepartment.query.order_by(
        FlicketDepartment.department.asc())

    if form.validate_on_submit():
        add_department = FlicketDepartment(department=form.department.data)
        db.session.add(add_department)
        db.session.commit()
        flash(
            gettext('New department "%(value)s" added.',
                    value=form.department.data))
        return redirect(url_for('flicket_bp.departments'))

    _departments = query.paginate(page, app.config['posts_per_page'])

    title = gettext('Flicket - Departments')

    return render_template('flicket_departments.html',
                           title=title,
                           form=form,
                           page=page,
                           departments=_departments)
Esempio n. 3
0
def get_departments():
    page = request.args.get('page', 1, type=int)
    per_page = min(
        request.args.get('per_page', app.config['posts_per_page'], type=int),
        100)
    data = FlicketDepartment.to_collection_dict(
        FlicketDepartment.query.order_by(FlicketDepartment.department.asc()),
        page, per_page, 'bp_api.get_departments')
    return jsonify(data)
Esempio n. 4
0
def create_department():

    # todo add authentication. only those in the admin or super_user groups should be allowed to create.

    data = request.get_json() or {}

    if 'department' not in data:
        return bad_request('Must include department name.')

    if FlicketDepartment.query.filter_by(
            department=data['department']).first():
        return bad_request('Department already created.')

    department = FlicketDepartment(data['department'])
    db.session.add(department)
    db.session.commit()

    response = jsonify(department.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('bp_api.get_department',
                                           id=department.id)

    return response
Esempio n. 5
0
def departments(page=1):

    form = DepartmentForm()

    query = FlicketDepartment.query

    if form.validate_on_submit():
        add_department = FlicketDepartment(department=form.department.data)
        db.session.add(add_department)
        db.session.commit()
        flash('New department {} added.'.format(form.department.data))
        return redirect(url_for('flicket_bp.departments'))

    _departments = query.paginate(page, app.config['posts_per_page'])

    return render_template('flicket_departments.html',
                           title='Flicket - Departments',
                           form=form,
                           page=page,
                           departments=_departments)
Esempio n. 6
0
 def before_create_object(self, data, view_kwargs):
     if view_kwargs.get('id') is not None:
         department = FlicketDepartment.filter_by(id=view_kwargs['id']).one()
         data['department_id'] = department.id