Exemplo n.º 1
0
def create():

    # Login-less logic
    if not 'access_token' in session:
        if not 'tasks' in session:
            session['tasks'] = []
        elif len(session['tasks']) == 5:
            flash(
                "Wanna create more? Login with your Github Account first, will Ya?",
                'info')
            return redirect(url_for('home.index'))

        if request.form['task-desc']:
            task_id = len(session['tasks'])  # To be used for temporary task_id
            task = {}
            task['id'] = task_id
            task['create_date'] = date.today()
            task['description'] = request.form['task-desc']
            session['tasks'].append(task)
            # Session won't be written in the response unless modified is set to True when modifying nested objects
            session.modified = True
            return redirect(url_for('home.index'))
        else:
            flash('A task can\'t be blank, boss!', 'info')
            return redirect(url_for('home.index'))

    # Logged in logic
    if request.form['task-desc']:
        task_desc = request.form['task-desc']
        user_id = g.user.id
        Task.add_task(task_desc, user_id)
        return redirect(url_for('home.index'))
    else:
        flash('A task can\'t be blank, boss!', 'info')
        return redirect(url_for('home.index'))
Exemplo n.º 2
0
def upload():
    file = request.files['file']
    ALLOWED_EXTENSIONS = set(['xls', 'xlsx'])
    if file:
        if '.' in file.filename and file.filename.rsplit(
                '.', 1)[1] not in ALLOWED_EXTENSIONS:
            raise FileTypeError()
        else:
            dirpath = os.path.join(current_app.root_path, 'upload')
            dirpath = dirpath.replace('\\', '/')
            now = datetime.datetime.now().strftime('%Y-%m-%d')
            path = dirpath + r'/task' + now + '.xls'
            file.save(path)
            #解析excel
            deal_excel = dealBatchExcel(path)
            task_name, task_url, task_description = deal_excel.get_task()
            task = Task.query.filter_by(name=task_name).all()
            #如果上传文件中的task不存在,则新增一个task
            if not task:
                task = Task()
                task.add_task(task_name, task_description, task_url)
            task = Task.query.filter_by(name=task_name).first_or_404()
            deal_excel.add_task_case(task.id)

    return jsonify(task)
Exemplo n.º 3
0
def githubCallback():
    if 'code' not in request.args:
        return '', 500

    # Fetch user from GitHub OAuth and store in session
    github = GitHub(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET)
    access_token = github.get_token(request.args['code'])

    if access_token is None:
        flash('Could not authorize your request. Please try again.', 'danger')
        return '', 404

    user = User.find_or_create_from_token(access_token)

    session['access_token'] = access_token
    session['user_id'] = user.id

    # Transfer tasks in session to user database
    if 'tasks' in session:
        for task in session['tasks']:
            user_id = session['user_id']
            task_desc = task['description']
            Task.add_task(task_desc, user_id)

        session.pop('tasks', None)

    return redirect(url_for('home.index'))
Exemplo n.º 4
0
def add_Task():
    form = TaskForm().validate_for_api()
    if Task.is_name_exist(form.name.data):
        raise RepeatFailed()
    else:
        task = Task()
        task.add_task(form.name.data,form.description.data,form.request_header.data)

    return Success()