Example #1
0
def team_form_parking_card(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members'] or \
            g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        return render_template('./form_parking_card.html', project=project, team=team)

    elif request.method == 'POST':
        post_data = request.get_json()

        if post_data['casename'] == 'get':
            data = Form.get_parking_card(pid=team['pid'], uid=g.user['account']['_id'])
            if not data:
                return jsonify({'data': {'carno': '', 'dates': []}})

            return jsonify({'data': data['data']})

        elif post_data['casename'] == 'post':
            if 'data' in post_data and post_data['data']:
                carno = post_data['data']['carno'].strip().upper()
                if not carno:
                    return jsonify({})

                dates = post_data['data']['dates']

                Form.update_parking_card(pid=team['pid'], uid=g.user['account']['_id'],
                        data={'carno': carno, 'dates': dates})

                return jsonify({})
Example #2
0
def team_form_parking_card(pid, tid):
    ''' Team form parking card '''
    # pylint: disable=too-many-return-statements
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members']
            or g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        return render_template('./form_parking_card.html',
                               project=project,
                               team=team)

    if request.method == 'POST':
        post_data = request.get_json()

        if post_data['casename'] == 'get':
            data = Form.get_parking_card(pid=team['pid'],
                                         uid=g.user['account']['_id'])

            parking_card_options = []
            if 'parking_card' in project:
                parking_card_options = project['parking_card']

            if not data:
                return jsonify({
                    'data': {
                        'carno': '',
                        'dates': []
                    },
                    'parking_card_options': parking_card_options
                })

            return jsonify({
                'data': data['data'],
                'parking_card_options': parking_card_options
            })

        if post_data['casename'] == 'post':
            if 'data' in post_data and post_data['data']:
                carno = post_data['data']['carno'].strip().upper()
                if not carno:
                    return jsonify({})

                dates = post_data['data']['dates']

                Form.update_parking_card(pid=team['pid'],
                                         uid=g.user['account']['_id'],
                                         data={
                                             'carno': carno,
                                             'dates': dates
                                         })

                return jsonify({})

    return jsonify({}), 404