Esempio n. 1
0
def project_form(action='add', project_id=None):
    form = ProjectForm()
    form.set_choices()
    title = 'Add Project'
    if action.lower() == 'add':
        pass
    elif action.lower() == 'edit':
        if project_id is None:
            flash("project id should not be empty")
            return redirect(url_for('404'))
        title = 'Edit Project'
        the_project = Project.query.get(project_id)
        form.name.data = the_project.name
        form.description.data = the_project.description
        form.facility.default = the_project.id
        if the_project.start_time is not None:
            form.start_time.data = the_project.start_time
        if the_project.end_time is not None:
            form.end_time.data = the_project.end_time
    else:
        flash("Action not foundL %s" % action)
        return redirect(url_for('index'))
    return render_template('edit/project.html',
                           form=form,
                           title=title,
                           projects=helper.getProjects())
Esempio n. 2
0
def project_submit(action='add', project_id=None):
    form = ProjectForm(request.form)
    form.set_choices()
    title = 'Add Project Request Submitted'
    project = Project()
    if action.lower() == 'add':
        pass
    elif action.lower() == 'edit':
        if project_id is None:
            flash("project id should not be empty")
            return redirect(url_for('404'))
        title = 'Edit Project Request Submitted'
        project = Project.query.get(project_id)
    else:
        flash("Action not found: %s" % action)
        return redirect(url_for('index'))
    if form.validate_on_submit():
        project.name = form.name.data
        project.description = form.description.data
        project.start_time = form.start_time.data
        project.end_time = form.end_time.data
        project.facility = form.facility.data
        db.session.add(project)
        db.session.commit()
        flash('Your change is saved to project %s with id %d' %
              (project.name, project.id))
        return redirect(url_for('project', project_id=project.id))
    else:
        flash('Your change is not saved to project %s with id %d' %
              (project.name, project.id))

    return render_template('edit/project.html',
                           form=form,
                           title=title,
                           projects=helper.getProjects())
Esempio n. 3
0
def reward_submit(action='add', reward_id=None):
    form = RewardForm(request.form)
    the_object = Reward()
    title = 'Add Reward Submitted'
    if action.lower() == 'add':
        pass
    elif action.lower() == 'edit':
        if reward_id is None:
            flash("reward id should not be empty")
            return redirect(url_for('404'))
        the_object = Reward.query.get(reward_id)
        title = 'Edit Reward Submitted'
    else:
        flash("Action not found: %s" % action)
        return redirect(url_for('index'))
    if form.validate_on_submit():
        the_object.name = form.name.data
        the_object.description = form.description.data
        db.session.add(the_object)
        db.session.commit()
        flash('Your change is saved to reward %s with id %d' %
              (the_object.name, the_object.id))
        return redirect(url_for('index'))
    else:
        flash('Your change is not saved to reward %s with id %d' %
              (the_object.name, the_object.id))
    return render_template('edit/reward.html',
                           form=form,
                           title=title,
                           projects=helper.getProjects())
Esempio n. 4
0
def facility_submit(action='add', facility_id=None):
    form = FacilityForm(request.form)
    facility = Facility()
    if action.lower() == 'add':
        pass
    elif action.lower() == 'edit':
        if facility_id is None:
            flash("facility id should not be empty")
            return redirect(url_for('404'))
        facility = Facility.query.get(facility_id)
    else:
        flash("Action not found: %s" % action)
        return redirect(url_for('index'))
    if form.validate_on_submit():
        facility.name = form.name.data
        facility.start_time = form.start_time.data
        facility.end_time = form.end_time.data
        facility.location = form.location.data
        facility.position = form.position.data
        facility.type = 'school' if form.type.data == 1 else 'company'
        db.session.add(facility)
        db.session.commit()
        flash('Your change is saved to facility %s with id %d' %
              (facility.name, facility.id))
        return redirect(url_for('index'))
    else:
        flash('Your change is not saved to facility %s with id %d' %
              (facility.name, facility.id))
    return render_template('edit/facility.html',
                           form=form,
                           projects=helper.getProjects())
Esempio n. 5
0
def facility_form(action='add', facility_id=None):
    form = FacilityForm()
    form.set_projects_choices()
    form.type.data = '8'
    title = 'Add Facility'
    if action.lower() == 'add':
        pass
    elif action.lower() == 'edit':
        if facility_id is None:
            flash("facility id should not be empty")
            return redirect(url_for('404'))
        title = 'Edit Facility'
        the_facility = Facility.query.get(facility_id)
        form.name.data = the_facility.name
        form.position.data = the_facility.position
        form.location.data = the_facility.location
        if the_facility.start_time is not None:
            form.start_time.data = the_facility.start_time
        if the_facility.end_time is not None:
            form.end_time.data = the_facility.end_time
    else:
        flash("Action not found: %s" % action)
        return redirect(url_for('index'))
    return render_template('edit/facility.html',
                           title=title,
                           form=form,
                           projects=helper.getProjects())
Esempio n. 6
0
def project(project_id):
    project = Project.query.get(project_id)
    if project:
        return render_template('display/project.html',
                               project=project,
                               projects=helper.getProjects())
    else:
        flash("Project not found")
        return redirect(url_for('index'))
Esempio n. 7
0
def index():
    the_companies = Facility.query.filter_by(type='company').order_by(
        Facility.start_time.desc()).all()
    the_schools = Facility.query.filter_by(type='school').order_by(
        Facility.start_time.desc()).all()
    the_user = User.query.order_by(User.id).first()
    the_rewards = Reward.query.all()
    the_skills = Skill.query.order_by(Skill.scale.desc()).all()
    the_publications = Publication.query.all()
    return render_template('index.html',
                           title='Home',
                           projects=helper.getProjects(),
                           companies=the_companies,
                           schools=the_schools,
                           user=the_user,
                           rewards=the_rewards,
                           skills=the_skills,
                           publications=the_publications)
Esempio n. 8
0
def reward_form(action='add', reward_id=None):
    form = RewardForm()
    title = 'Add Reward'
    if action.lower() == 'add':
        pass
    elif action.lower() == 'edit':
        if reward_id is None:
            flash("reward id should not be empty")
            return redirect(url_for('404'))
        title = 'Edit Reward'
        the_object = Reward.query.get(reward_id)
        form.name.data = the_object.name
        form.description.data = the_object.description
        form.scale.data = the_object.scale
    else:
        flash("Action not found: %s" % action)
        return redirect(url_for('index'))
    return render_template('edit/reward.html',
                           title=title,
                           form=form,
                           projects=helper.getProjects())
Esempio n. 9
0
def skill_form(action='add', skill_id=None):
    form = SkillForm()
    title = 'Add Skill'
    if action.lower() == 'add':
        pass
    elif action.lower() == 'edit':
        if skill_id is None:
            flash("skill id should not be empty")
            return redirect(url_for('404'))
        title = 'Edit Skill'
        the_object = Skill.query.get(skill_id)
        form.name.data = the_object.name
        form.description.data = the_object.description
        form.scale.data = the_object.scale
    else:
        flash("Action not found: %s" % action)
        return redirect(url_for('index'))
    return render_template('edit/skill.html',
                           title=title,
                           form=form,
                           projects=helper.getProjects())