Esempio n. 1
0
def tracker_edit(id):
    tracker = Tracker.get_tracker(id)
    if tracker is None:
        flash('tracker with id {} does not exist'.format(id))
        return redirect(
            url_for('trackerapp.trackerlist', filter_tracker='open'))
    form = EditTrackerForm(obj=tracker)
    form.project.choices = [(p.id, p.name) for p in TrkProject.get_all()]
    form.user_assigned.choices = [(u.username, u.username)
                                  for u in User.get_list_enabled_users()]
    if not form.project.choices:
        flash('No Projects exist!')
        return redirect(url_for('projects.projectlist'))
    if form.validate_on_submit():
        tracker.title = form.title.data
        tracker.description = form.description.data
        tracker.priority = int(form.priority.data)
        tracker.status = int(form.status.data)
        tracker.project = form.project.data
        tracker.user_assigned = form.user_assigned.data
        tracker.prefix = TrkProject.get_project(tracker.project).prefix
        tracker.categories = form.categories.data
        files = form.images.data
        action = 'EDITED'
        for f in files:
            if f is not None and not f == '':
                filename = secure_filename(f.filename)
                if allowed_file(filename):
                    if filename not in tracker.filenames:
                        tracker.filenames.append(filename)
                    if not os.path.exists(
                            os.path.join(current_app.config['UPLOAD_FOLDER'],
                                         tracker.id)):
                        os.mkdir(
                            os.path.join(current_app.config['UPLOAD_FOLDER'],
                                         tracker.id))
                    f.save(
                        os.path.join(current_app.config['UPLOAD_FOLDER'],
                                     tracker.id, filename))
                    action = 'ADDED IMAGES'
                    tracker.user_assigned = current_user.username
                    if tracker.status == 0:
                        tracker.status = 1  #working
                else:
                    flash('File {} skipped because not image'.format(filename))
        tracker.update_tracker_by_form()
        flash('Tracker  {} updated'.format(tracker.number))
        TrkChanges.create_change(current_user.username, tracker,
                                 tracker.project, action)
        return redirect(
            url_for('trackerapp.trackerlist', filter_tracker='open'))
    else:
        return render_template('trackerapp/tracker_edit.html',
                               form=form,
                               tracker=tracker,
                               title=Tracker.title)
Esempio n. 2
0
def add_session_project_processor():
    project_choices = [('ALL', '')]
    project_choices += ([(p.id, p.name) for p in TrkProject.get_all()])
    val = ''
    if 'sessionproject' in session:
        val = session['sessionproject']
    return {'project_choices': project_choices, 'sessionproject': val}
Esempio n. 3
0
def projectlist():
    if not current_user.admin:
        return redirect(url_for('trackerapp.index'))
    page = request.args.get('page', 1, type=int)
    projects = TrkProject.get_list_projects(page, int(current_app.config['PROJECTS_PER_PAGE']))
    prev_url = url_for('projects.projectlist', page=projects.prev) if projects.has_prev else None
    next_url = url_for('projects.projectlist', page=projects.next) if projects.has_next else None
    return render_template('projects/projectlist.html', title='projects',
                       prev_url=prev_url, next_url=next_url, projects=projects.projects )
Esempio n. 4
0
def add_tracker():
    form = AddTrackerForm()
    form.project.choices = [(p.id, p.name) for p in TrkProject.get_all()]
    form.user_assigned.choices = [(u.username, u.username)
                                  for u in User.get_list_enabled_users()]
    form.user_assigned.data = current_user.username
    if 'sessionproject' in session and session['sessionproject'] != 'ALL':
        form.project.data = session['sessionproject']
    if not form.project.choices:
        flash('No Projects exist!')
        return redirect(url_for('projects.projectlist', filter_tracker='open'))
    if form.validate_on_submit():
        tracker = Tracker.add_tracker(form.title.data, form.project.data)
        tracker.description = form.description.data
        tracker.priority = int(form.priority.data)
        tracker.project = form.project.data
        tracker.prefix = TrkProject.get_project(tracker.project).prefix
        tracker.categories = form.categories.data
        tracker.user_assigned = form.user_assigned.data
        files = form.images.data

        for f in files:
            if f is not None and not f == '':
                filename = secure_filename(f.filename)
                if allowed_file(filename):
                    tracker.filenames.append(filename)
                    if not os.path.exists(
                            os.path.join(current_app.config['UPLOAD_FOLDER'],
                                         tracker.id)):
                        os.mkdir(
                            os.path.join(current_app.config['UPLOAD_FOLDER'],
                                         tracker.id))
                    f.save(
                        os.path.join(current_app.config['UPLOAD_FOLDER'],
                                     tracker.id, filename))
                else:
                    flash('File {} skipped because not image'.format(filename))
        tracker.update_tracker_by_form()
        TrkChanges.create_change(current_user.username, tracker,
                                 tracker.project, 'CREATED')
        return redirect(url_for('trackerapp.tracker_info', id=tracker.id))
    return render_template('trackerapp/add_tracker.html',
                           form=form,
                           title='Add tracker')
Esempio n. 5
0
def project_edit(id):
    project = TrkProject.get_project(id)
    
    if project is None:
        flash('project with id {} does not exist'.format(id))
        return redirect(url_for('projects.projectlist'))
    form = AddEditProjectForm(obj=project)
    if form.validate_on_submit():
        project.name = form.name.data
        project.description = form.description.data
        project.prefix = form.prefix.data
        project.update_project()
        flash('Project  {} updated'.format(project.name))
        return redirect(url_for('projects.projectlist'))
    else:
        return render_template('projects/project_edit.html', form=form,project=project, title=project.name)
Esempio n. 6
0
def project_info(id):
    
    project = TrkProject.get_project(id)
    
    if project is None:
        flash('project with id {} does not exist'.format(id))
        return redirect(url_for('projects.projectlist'))
    if request.method == 'POST':
        if request.form['action'] == 'edit':
            return redirect(url_for('projects.project_edit', id=project.id))
        elif request.form['action'] == 'back': 
            return redirect(url_for('projects.projectlist'))
        else:
            flash('Something strange happened here')
            return redirect(url_for('projects.projectlist'))
    else:
        return render_template('projects/project_info.html', project=project, title=project.name)
Esempio n. 7
0
def add_project():
    form = AddEditProjectForm()
    if form.validate_on_submit():
        project=TrkProject.create_project(form.name.data, form.description.data,form.prefix.data)
        return redirect(url_for('projects.project_info', id= project.id))
    return render_template('projects/add_project.html', form=form, title='Add project')