Beispiel #1
0
    def find_teacher(cls, emailaddress):
        try:
            return cls(
                database.fetch_oneentry(
                    'user', 'user_id', {
                        'user_email': emailaddress,
                        'user_type': UserType.TEACHER.value
                    }))
        except NoRow:
            # Dynamically create a new teacher
            from oclubs.objs import Upload

            ret = cls.new()
            ret.studentid = emailaddress
            ret.passportname = 'Teacher'
            ret.password = None
            ret.nickname = 'Teacher'
            ret.email = emailaddress
            ret.phone = None
            ret.picture = Upload(-101)
            ret.type = UserType.TEACHER
            ret.grade = None
            ret.currentclass = None

            return ret.create()
Beispiel #2
0
def changeclubinfo_submit(club):
    '''Change club's info'''
    intro = request.form['intro']
    if len(intro) > 90:
        fail('Your intro is too long.', 'clubinfo')
        return redirect(url_for('.changeclubinfo', club=club.callsign))
    elif request.form['intro'] != '':
        club.intro = request.form['intro']

    desc = request.form['description'].strip()
    if desc and desc != club.description.raw:
        club.description = FormattedText.handle(current_user, club,
                                                request.form['description'])
    if request.files['picture'].filename != '':
        try:
            club.picture = Upload.handle(current_user, club,
                                         request.files['picture'])
        except UploadNotSupported:
            fail('Please upload the correct file type.', 'clubinfo')
            return redirect(url_for('.changeclubinfo', club=club.callsign))
    teacher_email = request.form['email']
    if teacher_email != club.teacher.studentid:
        club.teacher = User.find_teacher(teacher_email)
    location = request.form['location']
    if location != club.location and location != '':
        club.location = location
    for member in club.teacher_and_members:
        parameters = {'user': member, 'club': club}
        contents = render_email_template('changeclubinfo', parameters)
        member.email_user('Change Club Info - ' + club.name, contents)
        member.notify_user(club.name + '\'s information has been changed.')
    flash('The information about club has been successfully submitted.',
          'clubinfo')
    return redirect(url_for('.changeclubinfo', club=club.callsign))
Beispiel #3
0
def gen_blockpic_css():
    css = "#blockpic-img%d{background-image:url(%s)}"
    ret = ''
    for key, value in request.args.iteritems():
        if key.startswith('img'):
            ret += css % (int(key[3:]), Upload(int(value)).location_external)

    return Response(ret, mimetype='text/css')
Beispiel #4
0
def clubactivities(club, page):
    '''One Club's Activities'''
    act_num = 20
    count, acts = club.activities(limit=((page-1)*act_num, act_num))
    pagination = Pagination(page, act_num, count)
    club_pic = []
    club_pic.extend([item['upload'] for item in club.allactphotos(limit=3)[1]])
    club_pic.extend([Upload(-101) for _ in range(3 - len(club_pic))])
    return render_template('club/clubact.jinja2',
                           club_pic=club_pic,
                           acts=acts,
                           pagination=pagination)
Beispiel #5
0
def changeactpost_submit(activity):
    '''Input info into database'''
    for pic in request.files.getlist('picture'):
        if pic.filename != '':
            try:
                activity.add_picture(
                    Upload.handle(current_user, activity.club, pic))
            except UploadNotSupported:
                fail('Please upload a correct file type.', 'actpost')
                return redirect(
                    url_for('.changeactpost', activity=activity.callsign))
    activity.post = FormattedText.handle(current_user, activity.club,
                                         request.form['post'])
    flash('Activity post has been successfully modified.', 'actpost')
    return redirect(url_for('.changeactpost', activity=activity.callsign))
Beispiel #6
0
    def allactphotos(self, pager=None):
        from oclubs.objs import Activity, Upload

        pager_fetch, pager_return = pager
        tempdata = pager_fetch(database.fetch_multirow, 'act_pic', {
            'actpic_upload': 'upload',
            'act_id': 'activity',
        }, {
            'join': [('inner', 'activity', [('actpic_act', 'act_id')])],
            'where': [('=', 'act_club', self.id)],
        })

        for item in tempdata:
            item['upload'] = Upload(item['upload'])
            item['activity'] = Activity(item['activity'])

        return pager_return(tempdata)
Beispiel #7
0
def personal():
    '''Student Personal Page'''
    pictures = [Upload(-num) for num in range(1, 21)]
    allow_club_creation = siteconfig.get_config('allow_club_creation')
    receive_email = current_user.get_preference('receive_email')
    if current_user.type == UserType.STUDENT:
        clubs = current_user.clubs
        attendances = current_user.attendance

        # CAS calculation
        # add all attended activities
        cas = defaultdict(float)
        for attendance in attendances:
            cas[attendance.club] += attendance.cas
        # And all currently attending clubs
        for club in clubs:
            if club.is_active:
                cas[club]

        meetings_obj = current_user.activities_reminder(
            [ActivityTime.NOON, ActivityTime.AFTERSCHOOL])
        meetings = []
        meetings.extend([meeting for meeting in meetings_obj])
        acts_obj = current_user.activities_reminder(
            [ActivityTime.UNKNOWN, ActivityTime.HONGMEI, ActivityTime.OTHERS])
        activities = []
        activities.extend([act for act in acts_obj])
        leader_club = filter(lambda club_obj: current_user == club_obj.leader,
                             clubs)
        return render_template('user/student.jinja2',
                               pictures=pictures,
                               clubs=clubs,
                               cas=cas,
                               meetings=meetings,
                               activities=activities,
                               leader_club=leader_club,
                               allow_club_creation=allow_club_creation,
                               receive_email=receive_email)
    else:
        years = (lambda m: map(lambda n: m + n, range(2)))(date.today().year)
        return render_template('user/admin.jinja2',
                               pictures=pictures,
                               years=years,
                               receive_email=receive_email)
Beispiel #8
0
def newclub_submit():
    '''Upload excel file to create new clubs'''
    if not siteconfig.get_config('allow_club_creation'):
        abort(403)
    clubname = request.form['clubname']
    email = request.form['email']
    clubtype = int(request.form['clubtype'])
    location = request.form['location']
    intro = request.form['intro']
    description = request.form['description'].strip()
    true_or_fail(clubname, 'Please input club name.', 'newclub')
    true_or_fail(email, 'Please input teacher\'s email address.', 'newclub')
    true_or_fail(location, 'Please input club\'s meeting location.', 'newclub')
    true_or_fail(intro, 'Please input club\'s one-sentence introduction.',
                        'newclub')
    true_or_fail(len(intro) <= 90, 'Your one sentence intro is too long.',
                                   'newclub')

    true_or_fail(description, 'Please input club\'s paragraph description.',
                              'newclub')
    if form_is_valid():
        c = Club.new()
        c.name = clubname
        teacher = User.find_teacher(email)
        if teacher is not None:
            c.teacher = teacher
        else:
            fail('There is no teacher with this email address.', 'newclub')
            return redirect(url_for('.newclub'))
        c.leader = current_user
        c.description = FormattedText.emptytext()
        c.location = location
        c.is_active = False
        c.intro = intro
        c.picture = Upload(-101)
        c.type = ClubType(clubtype)
        c.joinmode = ClubJoinMode.FREE_JOIN
        c.reactivate = True
        c.create()
        c.add_member(current_user)
        c.description = FormattedText.handle(current_user, c,
                                             request.form['description'])
        return redirect(url_for('.clubintro', club=c.callsign))
    return redirect(url_for('.newclub'))
Beispiel #9
0
def _create_account(authority, _type='STUDENT', haspassword=True):
    u = User.new()
    u.studentid = ''
    u.passportname = ''
    u.email = ''
    u.phone = None
    u.grade = None
    u.currentclass = None
    _user_refresh(u, authority)
    password = User.generate_password() if haspassword else None
    u.password = password
    u.nickname = u.passportname
    u.picture = Upload(-1)
    u.type = UserType[_type]
    u.create(True)

    if haspassword:
        redis.RedisCache('tempuserpw:' + str(u.id), 3600 * 48).set(password)

    print 'CREATED USER ID %d' % u.id
Beispiel #10
0
def homepage():
    '''Homepage'''
    top_pic = []
    sizes = [3, 6, 3, 6, 3, 3]
    acts = Activity.get_activities_conditions(require_photos=True,
                                              limit=len(sizes))[1]

    top_pic.extend([{
        'picture':
        act.pictures[0],
        'actname':
        act.name,
        'content':
        act.description.formatted,
        'link':
        url_for('actblueprint.actintro', activity=act.callsign)
    } for act in acts])

    top_pic.extend([{
        'picture': Upload(-101),
        'actname': 'Default',
        'content': 'Oops, we don\'t have much picture',
        'link': '#'
    } for _ in range(len(sizes) - len(top_pic))])

    for num, (pic, size) in enumerate(zip(top_pic, sizes)):
        pic['id'] = 'img' + str(num)
        pic['size'] = size

    blockpiccss = url_for('gen_blockpic_css',
                          **{pic['id']: pic['picture'].id
                             for pic in top_pic})

    ex_clubs = Club.excellentclubs(3)
    pic_acts = top_pic[0:3]
    return render_template('static/homepage.jinja2',
                           is_home=True,
                           top_pic=top_pic,
                           blockpiccss=blockpiccss,
                           ex_clubs=ex_clubs,
                           pic_acts=pic_acts)
Beispiel #11
0
def personalsubmitinfo():
    '''Change user's information in database'''
    if request.form['name']:
        current_user.nickname = request.form['name']
    current_user.email = request.form['email']

    phone = request.form['phone']
    try:
        phone = int(phone)
    except ValueError:
        phone = None
    current_user.phone = phone
    if 'picture' in request.form:
        pic = int(request.form['picture'])
        if -pic in range(1, 21):
            current_user.picture = Upload(pic)
    if 'receive_email' in request.form:
        current_user.set_preference('receive_email', True)
    else:
        current_user.set_preference('receive_email', False)
    flash('Your information has been successfully changed.', 'status_info')
    return redirect(url_for('.personal'))