コード例 #1
0
ファイル: team.py プロジェクト: susutw/COSCUP-Volunteer
def team_form_drink(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_drink.html', project=project, team=team)

    elif request.method == 'POST':
        post_data = request.get_json()
        if post_data['casename'] == 'get':
            data = Form.get_drink(pid=team['pid'], uid=g.user['account']['_id'])
            if not data:
                data = {'data': {'y18': False}}

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

        elif post_data['casename'] == 'post':
            if 'y18' in post_data:
                data = {'y18': bool(post_data['y18'])}
                Form.update_drink(pid=team['pid'], uid=g.user['account']['_id'], data=data)

        return jsonify({'data': post_data})
コード例 #2
0
ファイル: team.py プロジェクト: susutw/COSCUP-Volunteer
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({})
コード例 #3
0
 def post(self, request):
     self.__form = Form(data=request.data)
     if self.__form.is_valid():
         user = self.__form.save()
         return redirect('users', userId=user.pk)
     else:
         return render(request, 'form.html', {"form": self.__form})
コード例 #4
0
ファイル: team.py プロジェクト: COSCUP/COSCUP-Volunteer
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
コード例 #5
0
ファイル: team.py プロジェクト: COSCUP/COSCUP-Volunteer
def team_form_clothes(pid, tid):
    ''' Team form clothes '''
    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_clothes.html',
                               project=project,
                               team=team)

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

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

            in_action = False
            htg = ''
            if not data:
                data = {
                    'data': {
                        'clothes': '',
                        'htg': htg,
                        'in_action': in_action
                    }
                }

            if project['action_date'] + 86400 * 10 >= arrow.now().timestamp():
                in_action = True

            if 'htg' in data['data']:
                htg = data['data']['htg']

            return jsonify({
                'clothes': data['data']['clothes'],
                'htg': htg,
                'in_action': in_action,
            })

        if post_data['casename'] == 'post':
            if 'clothes' in post_data and post_data['clothes']:
                Form.update_clothes(pid=team['pid'],
                                    uid=g.user['account']['_id'],
                                    data={
                                        'clothes': post_data['clothes'],
                                        'htg': post_data['htg'],
                                    })
                return jsonify({})

    return jsonify({})
コード例 #6
0
ファイル: team.py プロジェクト: susutw/COSCUP-Volunteer
def team_form_appreciation(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':
        names = {
            'oauth': g.user['data']['name'],
        }

        if 'profile' in g.user['account'] and \
           'badge_name' in g.user['account']['profile'] and \
           g.user['account']['profile']['badge_name']:
            names['badge_name'] = g.user['account']['profile']['badge_name']

        if 'profile_real' in g.user['account'] and \
           'name' in g.user['account']['profile_real'] and \
           g.user['account']['profile_real']['name']:
            names['real_name'] = g.user['account']['profile_real']['name']

        select_value = 'no'
        form_data = Form.get_appreciation(pid=pid, uid=g.user['account']['_id'])
        if form_data and 'data' in form_data and 'key' in form_data['data']:
            if 'available' in form_data['data'] and form_data['data']['available']:
                select_value = form_data['data']['key']

        return render_template('./form_appreciation.html',
            project=project, team=team, names=names.items(), select_value=select_value)

    elif request.method == 'POST':
        if request.form['appreciation'] not in ('oauth', 'badge_name', 'real_name', 'no'):
            return u'', 406

        if request.form['appreciation'] == 'no':
            data = {'available': False}

        else:
            if request.form['appreciation'] == 'oauth':
                name = g.user['data']['name']
            elif request.form['appreciation'] == 'badge_name':
                name = g.user['account']['profile']['badge_name']
            elif request.form['appreciation'] == 'real_name':
                name = g.user['account']['profile_real']['name']

            data = {
                'available': True,
                'key': request.form['appreciation'],
                'value': name,
            }

        Form().update_appreciation(pid=team['pid'], uid=g.user['account']['_id'], data=data)
        return redirect(url_for('team.team_form_appreciation', pid=team['pid'], tid=team['tid'], _scheme='https', _external=True))
コード例 #7
0
ファイル: team.py プロジェクト: COSCUP/COSCUP-Volunteer
def team_form_volunteer_certificate(pid, tid):
    ''' Team form volunteer certificate '''
    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('/')

    is_ok_submit = False
    user = g.user['account']
    if 'profile_real' in user:
        _check = []
        for k in ('name', 'roc_id', 'birthday', 'company'):
            if k in user['profile_real'] and user['profile_real'][k]:
                _check.append(True)
            else:
                _check.append(False)

        is_ok_submit = all(_check)

    if request.method == 'GET':
        form_data = Form.get_volunteer_certificate(
            pid=pid, uid=g.user['account']['_id'])
        if form_data and 'data' in form_data and 'value' in form_data['data']:
            select_value = 'yes' if form_data['data']['value'] else 'no'
        else:
            select_value = 'no'

        return render_template('./form_volunteer_certificate.html',
                               project=project,
                               team=team,
                               is_ok_submit=is_ok_submit,
                               select_value=select_value)

    if request.method == 'POST':
        if not is_ok_submit:
            return '', 406

        data = {'value': request.form['volunteer_certificate'] == 'yes'}
        Form.update_volunteer_certificate(pid=team['pid'],
                                          uid=g.user['account']['_id'],
                                          data=data)

        return redirect(
            url_for('team.team_form_volunteer_certificate',
                    pid=team['pid'],
                    tid=team['tid'],
                    _scheme='https',
                    _external=True))

    return jsonify({}), 404
コード例 #8
0
class MakeUserController(BaseController):
    __form = Form()

    def get(self, request):
        return render(request, 'form.html', {"form": self.__form})

    def post(self, request):
        self.__form = Form(data=request.data)
        if self.__form.is_valid():
            user = self.__form.save()
            return redirect('users', userId=user.pk)
        else:
            return render(request, 'form.html', {"form": self.__form})
コード例 #9
0
ファイル: team.py プロジェクト: susutw/COSCUP-Volunteer
def team_form_traffic_fee(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('/')

    is_ok_submit = False
    user = g.user['account']
    feemapping = FormTrafficFeeMapping.get(pid=pid)

    if 'traffic_fee_doc' in project and project['traffic_fee_doc'] and feemapping and 'data' in feemapping and feemapping['data']:
        if 'profile_real' in user and 'bank' in user['profile_real']:
            _short_check = []
            for k in ('name', 'branch', 'no', 'code'):
                if k in user['profile_real']['bank'] and user['profile_real']['bank'][k]:
                    _short_check.append(True)
                else:
                    _short_check.append(False)

            if all(_short_check):
                is_ok_submit = True

    if request.method == 'GET':
        form_data = Form.get_traffic_fee(pid=pid, uid=g.user['account']['_id'])
        data = ''
        if form_data:
            data = json.dumps({
                'apply': 'yes' if form_data['data']['apply'] else 'no',
                'fromwhere': form_data['data']['fromwhere'],
                'howto': form_data['data']['howto'],
                'fee': form_data['data']['fee'],
            })
        return render_template('./form_traffic_fee.html', project=project, team=team,
                data=data, is_ok_submit=is_ok_submit)

    elif request.method == 'POST':
        if is_ok_submit and request.form['fromwhere'] in feemapping['data']:
            data = {
                'fee': int(request.form['fee']),
                'howto': request.form['howto'].strip(),
                'apply': True if request.form['apply'].strip() == 'yes' else False,
                'fromwhere': request.form['fromwhere'],
            }
            Form.update_traffic_fee(pid=pid, uid=g.user['account']['_id'], data=data)
            return redirect(url_for('team.team_form_traffic_fee',
                    pid=team['pid'], tid=team['tid'], _scheme='https', _external=True))

        return u'', 406
コード例 #10
0
 def post(self, request):
     self.__usersInfoList = self._databaseObject.getAllUsersByName(
         request.data['name'])
     return render(request, 'findform.html', {
         'form': Form(data=request.data),
         'resultList': self.__usersInfoList
     })
コード例 #11
0
 def get(self, request):
     return render(request, 'findform.html', {'form': Form()})
コード例 #12
0
ファイル: team.py プロジェクト: susutw/COSCUP-Volunteer
def team_form_accommodation(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('/')

    is_ok_submit = False
    user = g.user['account']
    if 'profile_real' in user and 'name' in user['profile_real'] and 'roc_id' in user['profile_real'] and 'phone' in user['profile_real']:
        if user['profile_real']['name'] and user['profile_real']['roc_id'] and user['profile_real']['phone']:
            is_ok_submit = True

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

    elif request.method == 'POST':
        if not is_ok_submit:
            return u'', 406

        post_data = request.get_json()

        if post_data['casename'] == 'get':
            raw = {'selected': 'no'}
            room = {}

            form_data = Form.get_accommodation(pid=pid, uid=g.user['account']['_id'])
            if form_data:
                raw['selected'] = form_data['data']['key']

                if 'room' in form_data['data'] and form_data['data']['room']:
                    room['no'] = form_data['data']['room']
                    room['key'] = form_data['data']['room_key']
                    room['exkey'] = form_data['data'].get('room_exkey', '')

                    room['mate'] = {}
                    _user_room, mate_room = FormAccommodation.get_room_mate(pid=pid, uid=g.user['account']['_id'])
                    if mate_room:
                        user_info = User.get_info(uids=[mate_room['uid'], ])[mate_room['uid']]
                        room['mate'] = {
                            'uid': mate_room['uid'],
                            'name': user_info['profile']['badge_name'],
                            'tid': '',
                            'picture': user_info['oauth']['picture'],
                        }

            return jsonify({'data': raw, 'room': room})

        elif post_data['casename'] == 'update':
            if post_data['selected'] not in ('no', 'yes', 'yes-longtraffic'):
                return u'', 406

            data = {
                'status': True if post_data['selected'] in ('yes', 'yes-longtraffic') else False,
                'key': post_data['selected'],
            }

            Form.update_accommodation(pid=pid, uid=g.user['account']['_id'], data=data)

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

        elif post_data['casename'] == 'makechange':
            msg = FormAccommodation.make_exchange(pid=pid, uid=g.user['account']['_id'], exkey=post_data['key'].strip())
            return jsonify({'data': post_data, 'msg': msg})
コード例 #13
0
ファイル: project.py プロジェクト: COSCUP/COSCUP-Volunteer
def project_form_api(pid):
    ''' Project form API '''
    # pylint: disable=too-many-return-statements,too-many-branches,too-many-statements
    project = Project.get(pid)
    if g.user['account']['_id'] not in project['owners']:
        return redirect(
            url_for('project.team_page',
                    pid=pid,
                    _scheme='https',
                    _external=True))

    if request.method == 'POST':
        data = request.get_json()
        if 'case' not in data:
            return redirect(
                url_for('project.team_page',
                        pid=pid,
                        _scheme='https',
                        _external=True))

        if data['case'] == 'volunteer_certificate':
            fieldnames = ('uid', 'picture', 'value', 'name', 'roc_id',
                          'birthday', 'company')
            with io.StringIO() as str_io:
                csv_writer = csv.DictWriter(str_io, fieldnames=fieldnames)
                csv_writer.writeheader()

                for raw in Form.all_volunteer_certificate(pid):
                    user_info = UsersDB().find_one({'_id': raw['uid']})
                    oauth = OAuthDB().find_one({'owner': raw['uid']},
                                               {'data.picture': 1})

                    data = {
                        'uid': raw['uid'],
                        'picture': oauth['data']['picture'],
                        'value': raw['data']['value'],
                        'name': user_info['profile_real']['name'],
                        'roc_id': user_info['profile_real']['roc_id'],
                        'birthday': user_info['profile_real']['birthday'],
                        'company': user_info['profile_real']['company'],
                    }

                    csv_writer.writerow(data)

                result = []
                for raw in csv.reader(io.StringIO(str_io.getvalue())):
                    result.append(raw)

                return jsonify({'result': result})

        elif data['case'] == 'traffic_fee':
            fieldnames = ('uid', 'picture', 'name', 'apply', 'fee',
                          'fromwhere', 'howto')
            with io.StringIO() as str_io:
                csv_writer = csv.DictWriter(str_io, fieldnames=fieldnames)
                csv_writer.writeheader()

                for raw in Form.all_traffic_fee(pid):
                    user_info = User.get_info(uids=[
                        raw['uid'],
                    ])[raw['uid']]

                    data = {
                        'uid': raw['uid'],
                        'picture': user_info['oauth']['picture'],
                        'name': user_info['profile']['badge_name'],
                        'apply': raw['data']['apply'],
                        'fee': raw['data']['fee'],
                        'fromwhere': raw['data']['fromwhere'],
                        'howto': raw['data']['howto'],
                    }

                    csv_writer.writerow(data)

                result = []
                for raw in csv.reader(io.StringIO(str_io.getvalue())):
                    result.append(raw)

                return jsonify({'result': result})

        elif data['case'] == 'accommodation':
            fieldnames = ('uid', 'picture', 'name', 'key', 'status')
            with io.StringIO() as str_io:
                csv_writer = csv.DictWriter(str_io, fieldnames=fieldnames)
                csv_writer.writeheader()

                for raw in Form.all_accommodation(pid):
                    user_info = User.get_info(uids=[
                        raw['uid'],
                    ])[raw['uid']]

                    data = {
                        'uid': raw['uid'],
                        'picture': user_info['oauth']['picture'],
                        'name': user_info['profile']['badge_name'],
                        'key': raw['data']['key'],
                        'status': raw['data']['status'],
                    }

                    csv_writer.writerow(data)

                result = []
                for raw in csv.reader(io.StringIO(str_io.getvalue())):
                    result.append(raw)

                return jsonify({'result': result})

        elif data['case'] == 'appreciation':
            fieldnames = ('uid', 'picture', 'name', 'available', 'key',
                          'value')
            with io.StringIO() as str_io:
                csv_writer = csv.DictWriter(str_io, fieldnames=fieldnames)
                csv_writer.writeheader()

                for raw in Form.all_appreciation(pid):
                    if not raw['data']['available']:
                        continue

                    user_info = User.get_info(uids=[
                        raw['uid'],
                    ])[raw['uid']]

                    data = {
                        'uid': raw['uid'],
                        'picture': user_info['oauth']['picture'],
                        'name': user_info['profile']['badge_name'],
                        'available': raw['data']['available'],
                        'key': raw['data']['key'],
                        'value': raw['data']['value'],
                    }
                    csv_writer.writerow(data)

                result = []
                for raw in csv.reader(io.StringIO(str_io.getvalue())):
                    result.append(raw)

                return jsonify({'result': result})

        elif data['case'] == 'clothes':
            all_users = {}
            for team in Team.list_by_pid(pid=pid):
                for uid in team['chiefs'] + team['members']:
                    all_users[uid] = {'tid': team['tid']}

            user_info = User.get_info(uids=list(all_users.keys()))

            fieldnames = ('uid', 'picture', 'name', '_has_data', 'tid',
                          'clothes', 'htg')
            with io.StringIO() as str_io:
                csv_writer = csv.DictWriter(str_io, fieldnames=fieldnames)
                csv_writer.writeheader()

                for raw in Form.all_clothes(pid):
                    if raw['uid'] not in all_users:
                        continue

                    all_users[raw['uid']]['clothes'] = raw['data']['clothes']

                    if 'htg' in raw['data']:
                        all_users[raw['uid']]['htg'] = raw['data']['htg']

                for uid, value in all_users.items():
                    data = {
                        'uid': uid,
                        'picture': user_info[uid]['oauth']['picture'],
                        'name': user_info[uid]['profile']['badge_name'],
                        '_has_data': bool(value.get('clothes', False)),
                        'tid': value['tid'],
                        'clothes': value.get('clothes'),
                        'htg': value.get('htg'),
                    }
                    csv_writer.writerow(data)

                result = []
                for raw in csv.reader(io.StringIO(str_io.getvalue())):
                    result.append(raw)

                return jsonify({'result': result})

        elif data['case'] == 'parking_card':
            fieldnames = ('uid', 'picture', 'name', 'carno', 'dates')
            with io.StringIO() as str_io:
                csv_writer = csv.DictWriter(str_io, fieldnames=fieldnames)
                csv_writer.writeheader()

                for raw in Form.all_parking_card(pid):
                    if not raw['data']['dates']:
                        continue

                    user_info = User.get_info(uids=[
                        raw['uid'],
                    ])[raw['uid']]

                    data = {
                        'uid': raw['uid'],
                        'picture': user_info['oauth']['picture'],
                        'name': user_info['profile']['badge_name'],
                        'carno': raw['data']['carno'],
                        'dates': ', '.join(raw['data']['dates']),
                    }
                    csv_writer.writerow(data)

                result = []
                for raw in csv.reader(io.StringIO(str_io.getvalue())):
                    result.append(raw)

                return jsonify({'result': result})

        elif data['case'] == 'drink':
            all_users = {}
            for team in Team.list_by_pid(pid=pid):
                for uid in team['chiefs'] + team['members']:
                    all_users[uid] = {'tid': team['tid']}

            user_info = User.get_info(uids=list(all_users.keys()))

            fieldnames = ('uid', 'picture', 'name', '_has_data', 'tid', 'y18')
            with io.StringIO() as str_io:
                csv_writer = csv.DictWriter(str_io, fieldnames=fieldnames)
                csv_writer.writeheader()

                for raw in Form.all_drink(pid):
                    if raw['uid'] not in all_users:
                        continue

                    all_users[raw['uid']]['y18'] = raw['data']['y18']

                for uid, value in all_users.items():
                    data = {
                        'uid': uid,
                        'picture': user_info[uid]['oauth']['picture'],
                        'name': user_info[uid]['profile']['badge_name'],
                        '_has_data': bool(value.get('y18')),
                        'tid': value['tid'],
                        'y18': value.get('y18'),
                    }
                    csv_writer.writerow(data)

                result = []
                for raw in csv.reader(io.StringIO(str_io.getvalue())):
                    result.append(raw)

                return jsonify({'result': result})

    return jsonify({}), 404