Пример #1
0
def update_styf():
    users = get_users()
    events = get_events()
    places_left = events.find_one({'name': 'styf'}).get('places_left')

    user = current_user
    if user.profile.get('first_name') and user.profile.get(
            'name') and user.profile.get('tel') and user.profile.get(
                'school') and user.profile.get('year'):
        if places_left > 0 or current_user.events['styf'].get('registered'):
            users.update_one({'id': current_user.id},
                             {'$set': {
                                 'events.styf': request.form
                             }})
            users.update_one({'id': current_user.id},
                             {'$set': {
                                 'events.styf.registered': True
                             }})
            if not current_user.events['styf'].get('registered'):
                events.update_one({'name': 'styf'},
                                  {'$inc': {
                                      'places_left': -1
                                  }})
            return 'success'
        else:
            return 'full_event'
    else:
        return 'incomplete_profile'
Пример #2
0
def update_profile():
    users = get_users()
    form = request.form.to_dict()
    if form.get('school_'):
        form['school'] = form.get('school_')
    form.pop('school_', None)
    for k, v in form.items():
        users.update_one({'id': current_user.id},
                         {'$set': {
                             'profile.{}'.format(k): v
                         }})
    flash('profile_completed')
    return redirect(url_for('users.dashboard', page='profile'))
Пример #3
0
def update_master_class():
    registered = request.form.get('registered')
    registered = True if registered == 'true' else False
    users = get_users()
    user = current_user
    if user.profile.get('first_name') and user.profile.get(
            'name') and user.profile.get('tel') and user.profile.get(
                'school') and user.profile.get('year'):
        users.update_one(
            {'id': current_user.id},
            {'$set': {
                'events.master_class.registered': registered
            }})
        return 'success'
    else:
        return 'incomplete_profile'
Пример #4
0
def update_event():
    mevent = request.form.get('event')
    if mevent != 'fra':
        name = request.form.get('name')
        mtype = request.form.get('type')
        time = request.form.get('time')

        events = get_events()
        users = get_users()

        event = events.find_one({'name': name, 'type': mtype})
        places_left = event['places_left']
        if mtype == 'table_ronde':
            places_left = event['places_left'][time]

        if places_left > 0:
            old_event = users.find_one({'id': current_user.id})
            old_name = old_event['events']['joi'].get(mtype)
            old_name = old_name['name'] if old_name else None
            doc = {'name': name, 'registered': True}
            if mtype == 'table_ronde':
                doc = {'name': name, 'registered': True, 'time': time}
                events.update_one({
                    'name': old_name,
                    'type': mtype
                }, {'$inc': {
                    'places_left.{}'.format(time): 1
                }}) if old_name else None
                events.update_one({
                    'name': name,
                    'type': mtype
                }, {'$inc': {
                    'places_left.{}'.format(time): -1
                }})
            else:
                doc = {'name': name, 'registered': True}
                events.update_one({
                    'name': old_name,
                    'type': mtype
                }, {'$inc': {
                    'places_left': 1
                }}) if old_name else None
                events.update_one({
                    'name': name,
                    'type': mtype
                }, {'$inc': {
                    'places_left': -1
                }})
            users.update_one({'id': current_user.id},
                             {'$set': {
                                 'events.joi.{}'.format(mtype): doc
                             }})
            return 'success'
        else:
            return 'error'
    else:
        users = get_users()
        user = current_user
        if user.profile.get('first_name') and user.profile.get(
                'name') and user.profile.get('school') and user.profile.get(
                    'year') and user.profile.get('specialty'):
            users.update_one({'id': current_user.id},
                             {'$set': {
                                 'events.fra.registered': True
                             }})
            return 'success'
        else:
            return 'incomplete_profile'