예제 #1
0
파일: common.py 프로젝트: danfossi/FQM
def fill_tasks(entry_number=10):
    for _ in range(entry_number):
        name = f'TEST{randint(10000, 99999999)}'
        offices = []
        # First task will be uncommon task
        number_of_offices = 1 if _ == 0 else choice(range(1, 5))

        while number_of_offices > len(offices):
            office = choice(Office.query.all())

            if office not in offices:
                offices.append(office)
        
        task = Task(name)
        db.session.add(task)
        db.session.commit()
        task.offices = offices
        db.session.commit()


# TODO: get refactor the helper to fit the testing process
# def fill_tickets(entery_number=10, s_task=None):
#     for i in range(entery_number):
#         forin = Task.query if s_task is None else Task.query.filter_by(
#             id=s_task)
#         for task in forin:
#             num = Serial.query.order_by(Serial.timestamp.desc()).first()
#             num = num.number if num is not None else None
#             name = choice(names)
#             t_id = task.id
#             f_id = choice(task.offices).id
#             # if i >= 11: WTF ?!
#             db.session.add(Serial(number=num + 1,
#                                     office_id=f_id,
#                                     task_id=t_id, name=name, n=True))
#     for a in range(Waiting.query.count(), 11):
#         for b in Serial.query.filter_by(p=False).order_by(Serial.timestamp):
#             if Waiting.query.filter_by(office_id=b.office_id,
#                                        number=b.number,
#                                        task_id=b.task_id).first() is None:
#                 db.session.add(Waiting(b.number, b.office_id,
#                                        b.task_id, b.name, b.n))
#     db.session.commit()
예제 #2
0
def fill_tasks(entry_number=ENTRY_NUMBER):
    for _ in range(entry_number):
        name = f'TEST{randint(10000, 99999999)}'
        offices = []
        # First task will be uncommon task and the second is common
        number_of_offices = 1 if _ == 0 else 2 if _ == 1 else choice(range(1, 5))

        while number_of_offices > len(offices):
            office = choice(Office.query.all())

            if office not in offices:
                offices.append(office)

        task = Task(name)
        db.session.add(task)
        db.session.commit()
        task.offices = offices
        # Add tasks initial tickets
        db.session.add(Serial(number=100, office_id=office.id, task_id=task.id))
        db.session.commit()
예제 #3
0
def add_task(task):
    db = connect_db(app.config.get('DB'))
    Task.set_db(db)
    Project.set_db(db)
    #
    db_task = Task()
    #
    db_project = list(Project.view('projects/by_title',
                                   key=task['project']))[0]

    db_task.author = task['author']
    db_task.assigned = task['assigned']
    db_task.priority = task['priority']
    db_task.title = task['title']
    db_task.text = task['text']
    db_task.status = task['status']
    db_task.project = db_project.title
    db_task.create_date = datetime.datetime.utcnow()
    db_task.update_date = datetime.datetime.utcnow()
    db_task.due_date = datetime.date.today()
    #
    db.save_doc(db_task)
예제 #4
0
def edit(id):
    errors = []
    form = EditTaskForm(request.form)
    task = None

    possible_assigned = [
        elem.username for elem in list(User.view('users/by_username'))
    ]
    possible_project = [
        elem.title for elem in list(Project.view('projects/by_title'))
    ]

    if id == NEW_TASK_ID:
        task = Task()
    else:
        if not g.db.doc_exist(id):
            abort(404)
        task = Task.get(id)
        if request.method == 'GET':
            form = EditTaskForm(obj=task)

    form.assigned.choices = zip(possible_assigned, possible_assigned)
    form.project.choices = zip(possible_project, possible_project)
    # dirty hack here: we use referrer to determine from which
    # project we came from and set correct value to select field
    if PROJECT_ROUTE in request.referrer:
        project = request.referrer.split('/')[-1]
        project = Project.get(project_id)
        form.project.default = project.title
        form.process()

    if request.method == 'POST' and form.validate():
        form.populate_obj(task)
        task.author = session['username']
        task.update_date = datetime.datetime.utcnow()
        task.tags = ' '.join(set(task.tags.split()))

        if id == NEW_TASK_ID:
            task.create_date = task.update_date

        task.save()
        for ff in request.files.keys():
            f = request.files[ff]
            if f:
                fname = secure_filename(f.filename)
                fld = os.path.join(UPLOADED_FILES, task._id)
                if not os.path.exists(fld):
                    os.mkdir(fld)

                target_path = os.path.join(fld, fname)
                while os.path.exists(target_path):
                    filename, ext = os.path.splitext(target_path)
                    r = ''.join(
                        random.choice('0123456789abcdef') for i in range(8))
                    target_path = os.path.join(fld, filename + '-' + r + ext)
                f.save(target_path)
                flash('Successfully uploaded %s' % fname)

        flash('Task was successfully %s' %
              ('created' if id == NEW_TASK_ID else 'updated'))
        return redirect(url_for('tasks.show', id=task._id))

    errors.extend(format_form_errors(form.errors.items()))
    return render_template('task_edit.html', id=id, form=form, errors=errors)