Exemple #1
0
def edit_championships():
    with client.context():
        me = auth.user()
        if not me or not me.HasAnyRole(Roles.AdminRoles()):
            abort(403)

        all_us_competitions = (Competition.query(
            Competition.country == ndb.Key(Country, 'USA')).order(
                Competition.name).fetch())

        national_championships = (Championship.query(
            Championship.national_championship == True).order(
                -Championship.year).fetch())
        regional_championships = (Championship.query(
            Championship.region != None).order(
                Championship.region).order(-Championship.year).fetch())
        state_championships = (Championship.query(
            Championship.state != None).order(
                Championship.state).order(-Championship.year).fetch())

        states = State.query().fetch()
        regions = Region.query().fetch()

        return render_template('admin/edit_championships.html',
                               c=common.Common(),
                               all_us_competitions=all_us_competitions,
                               national_championships=national_championships,
                               regional_championships=regional_championships,
                               state_championships=state_championships,
                               states=states,
                               regions=regions)
Exemple #2
0
def add_championship(competition_id, championship_type):
    with client.context():
        me = auth.user()
        if not me or not me.HasAnyRole(Roles.AdminRoles()):
            abort(403)
        competition = Competition.get_by_id(competition_id)
        if championship_type == 'national':
            championship_id = Championship.NationalsId(competition.year)
        elif championship_type == 'regional':
            championship_id = Championship.RegionalsId(
                competition.year,
                competition.state.get().region.get())
        elif championship_type == 'state':
            championship_id = Championship.StateChampionshipId(
                competition.year, competition.state.get())
        championship = (Championship.get_by_id(championship_id)
                        or Championship(id=championship_id))

        if championship_type == 'national':
            championship.national_championship = True
        elif championship_type == 'regional':
            championship.region = competition.state.get().region
        elif championship_type == 'state':
            championship.state = competition.state
        championship.competition = competition.key
        championship.put()
        # TODO: if we changed a championship we should update champions and eligibilities.
        return redirect('/admin/edit_championships')
Exemple #3
0
def delete_championship(championship_id):
    with client.context():
        me = auth.user()
        if not me or not me.HasAnyRole(Roles.AdminRoles()):
            abort(403)
        championship = Championship.get_by_id(championship_id)
        championship.key.delete()
        # TODO: if we changed a championship we should update champions and eligibilities.
        return redirect('/admin/edit_championships')
Exemple #4
0
    def __init__(self, wca_disclaimer=False):
        self.uri = request.path
        self.len = len
        self.formatters = formatters
        self.year = datetime.date.today().year
        self.user = auth.user()
        self.wca_disclaimer = wca_disclaimer

        if self.user:
            time_since_login = datetime.datetime.now() - self.user.last_login
            if time_since_login < datetime.timedelta(seconds=1):
                self.just_logged_in = True
Exemple #5
0
def edit_users_table(filter_text=''):
    with client.context():
        me = auth.user()
        if not me or not me.HasAnyRole(Roles.AdminRoles()):
            abort(403)

        if filter_text:
            users_to_show = User.query(ndb.OR(
                User.name == filter_text, User.city == filter_text,
                User.wca_person == ndb.Key(Person, filter_text)),
                                       order_by=[User.name]).fetch(30)
        else:
            users_to_show = User.query(order_by=[User.name]).fetch(30)

        return render_template('admin/edit_users_table.html',
                               c=Common(),
                               users=users_to_show)
Exemple #6
0
def update_states():
    with client.context():
        me = auth.user()
        if not me or not me.HasAnyRole([Roles.GLOBAL_ADMIN, Roles.WEBMASTER]):
            abort(403)

        futures = []
        all_regions = {}
        NORTHEAST = MakeRegion('ne', 'Northeast', 'Northeastern', all_regions,
                               futures)
        SOUTHEAST = MakeRegion('se', 'Southeast', 'Southeastern', all_regions,
                               futures)
        GREAT_LAKES = MakeRegion('gl', 'Great Lakes', 'Great Lakes',
                                 all_regions, futures)
        HEARTLAND = MakeRegion('hl', 'Heartland', 'Heartland', all_regions,
                               futures)
        SOUTH = MakeRegion('s', 'South', 'Southern', all_regions, futures)
        NORTHWEST = MakeRegion('nw', 'Northwest', 'Northwestern', all_regions,
                               futures)
        WEST = MakeRegion('w', 'West', 'Western', all_regions, futures)

        for future in futures:
            future.wait()
        del futures[:]

        all_states = {}
        for state_id, state_name, region in (
            ('al', 'Alabama', SOUTHEAST), ('ak', 'Alaska', NORTHWEST),
            ('az', 'Arizona', WEST), ('ar', 'Arkansas',
                                      SOUTH), ('ca', 'California', WEST),
            ('co', 'Colorado', WEST), ('ct', 'Connecticut', NORTHEAST),
            ('de', 'Delaware', NORTHEAST), ('fl', 'Florida', SOUTHEAST),
            ('ga', 'Georgia', SOUTHEAST), ('hi', 'Hawaii',
                                           WEST), ('id', 'Idaho', NORTHWEST),
            ('il', 'Illinois', GREAT_LAKES), ('in', 'Indiana', GREAT_LAKES),
            ('ia', 'Iowa', HEARTLAND), ('ks', 'Kansas', HEARTLAND),
            ('ky', 'Kentucky', GREAT_LAKES), ('la', 'Louisiana', SOUTH),
            ('me', 'Maine', NORTHEAST), ('md', 'Maryland',
                                         NORTHEAST), ('ma', 'Massachusetts',
                                                      NORTHEAST),
            ('mi', 'Michigan',
             GREAT_LAKES), ('mn', 'Minnesota',
                            HEARTLAND), ('ms', 'Mississippi',
                                         SOUTH), ('mo', 'Missouri', HEARTLAND),
            ('mt', 'Montana', NORTHWEST), ('ne', 'Nebraska',
                                           HEARTLAND), ('nv', 'Nevada', WEST),
            ('nh', 'New Hampshire',
             NORTHEAST), ('nj', 'New Jersey',
                          NORTHEAST), ('nm', 'New Mexico',
                                       WEST), ('ny', 'New York', NORTHEAST),
            ('nc', 'North Carolina',
             SOUTHEAST), ('nd', 'North Dakota',
                          HEARTLAND), ('oh', 'Ohio',
                                       GREAT_LAKES), ('ok', 'Oklahoma', SOUTH),
            ('or', 'Oregon', NORTHWEST), ('pa', 'Pennsylvania', NORTHEAST),
            ('ri', 'Rhode Island',
             NORTHEAST), ('sc', 'South Carolina',
                          SOUTHEAST), ('sd', 'South Dakota',
                                       HEARTLAND), ('tn', 'Tennessee',
                                                    SOUTHEAST), ('tx', 'Texas',
                                                                 SOUTH),
            ('ut', 'Utah', WEST), ('vt', 'Vermont',
                                   NORTHEAST), ('va', 'Virginia', SOUTHEAST),
            ('wa', 'Washington',
             NORTHWEST), ('wv', 'West Virginia',
                          NORTHEAST), ('wi', 'Wisconsin',
                                       GREAT_LAKES), ('wy', 'Wyoming',
                                                      NORTHWEST)):
            MakeState(state_id, state_name, region, True, all_states, futures)

        for territory_id, territory_name, region in (
            ('dc', 'D. C.', NORTHEAST), ('pr', 'Puerto Rico', SOUTHEAST),
            ('gu', 'Guam', WEST), ('mp', 'Northern Mariana Islands', WEST),
            ('as', 'American Samoa', WEST), ('vi', 'U.S. Virgin Islands',
                                             SOUTHEAST)):
            MakeState(territory_id, territory_name, region, False, all_states,
                      futures)

        for future in futures:
            future.wait()
        del futures[:]

        for region in Region.query().iter():
            if region.key.id() not in all_regions:
                region.delete()
        for state in State.query().iter():
            if state.key.id() not in all_states:
                state.delete()
        return 'ok'
Exemple #7
0
def edit_user(user_id=-1):
    with client.context():
        me = auth.user()
        if not me:
            return redirect('/')
        if user_id == -1:
            user = me
        else:
            user = User.get_by_id(user_id)
        if not user:
            return error('Unrecognized user ID %d' % user_id)
        if not permissions.CanViewUser(user, me):
            return error('You\'re not authorized to view this user.')

        if request.method == 'GET':
            return render_template(
                'edit_user.html',
                c=Common(),
                user=user,
                all_roles=Roles.AllRoles(),
                editing_location_enabled=permissions.CanEditLocation(user, me),
                can_view_roles=permissions.CanViewRoles(user, me),
                editable_roles=permissions.EditableRoles(user, me),
                successful=request.args.get('successful', 0))

        city = request.form['city']
        state_id = request.form['state']
        if state_id == 'empty':
            state_id = ''

        if request.form['lat'] and request.form['lng']:
            lat = int(request.form['lat'])
            lng = int(request.form['lng'])
        else:
            lat = 0
            lng = 0
        template_dict = {}

        old_state_id = user.state.id() if user.state else ''
        changed_location = user.city != city or old_state_id != state_id
        user_modified = False
        if permissions.CanEditLocation(user, me) and changed_location:
            if city:
                user.city = city
            else:
                del user.city
            if state_id:
                user.state = ndb.Key(State, state_id)
            else:
                del user.state
            if user.wca_person and old_state_id != state_id:
                wca_person = user.wca_person.get()
                if wca_person:
                    wca_person.state = user.state
                    wca_person.put()
                RewriteRanks(wca_person)
            user.latitude = lat
            user.longitude = lng
            user_modified = True

            if changed_location:
                # Also save the Update.
                update = UserLocationUpdate()
                update.updater = me.key
                if city:
                    update.city = city
                update.update_time = datetime.datetime.now()
                if state_id:
                    update.state = ndb.Key(State, state_id)
                user.updates.append(update)

        elif changed_location:
            return error('You\'re not authorized to edit user locations.')

        for role in permissions.EditableRoles(user, me):
            if role in request.form and role not in user.roles:
                user.roles.append(role)
                user_modified = True
            elif role not in request.form and role in user.roles:
                user.roles.remove(role)
                user_modified = True

        if user_modified:
            user.put()

        return redirect(request.path + '?successful=1')
Exemple #8
0
def edit_users():
    with client.context():
        me = auth.user()
        if not me or not me.HasAnyRole(Roles.AdminRoles()):
            abort(403)
        return render_template('admin/edit_users.html', c=Common())