Пример #1
0
def settings():
    if request.method == "POST":
        if 'cancel' in request.form:
            flash(escape("Ændringer annulleret"))
            return redirect(url_for('usermanager.overview'))

        username = session["username"]

        b = data.Bucket(request.form)
        b.name
        b.email
        b.phone
        b.address
        b.zipcode
        b.city
        b.birthday = nonify(b.birthday)
        b.driverslicence = "driverslicence" in request.form
        b.diku_age
        b.about_me  # = request.form["about_me"]
        b >> ("UPDATE Users $ WHERE username = ?", username)

        return redirect(url_for('usermanager.user', username=username))

    else:
        user = data.execute("SELECT * FROM Users WHERE username = ?",
                            session["username"])
        user = user[0]
        user = unnonify(user)

        birthday = user["birthday"]
        if birthday == None:
            birthday = ""
        elif isinstance(birthday, datetime.date):
            birthday = birthday.isoformat()

        w = html.WebBuilder()
        w.form()
        w.formtable()
        w.textfield("name", "Fulde navn")
        w.textfield("email", "Email")
        w.textfield("phone", "Telefonnummer")
        w.textfield("address", "Adresse")
        w.textfield("zipcode", "Postnummer")
        w.textfield("city", "By")
        w.calendar("birthday", "Fødselsdag")
        w.checkbox("driverslicence", "Har du kørekort?")
        w.textfield("diku_age", "Hvornår startede du på DIKU?")
        w.textarea("about_me", "Lidt om mig")

        form = w.create(user)
        return render_template("form.html", form=form)
Пример #2
0
def settings():
    if request.method == "POST":
        if 'cancel' in request.form:
            flash(escape("Ændringer annulleret"))
            return redirect(url_for('usermanager.overview'))

        username = session["username"]

        b = data.Bucket(request.form)
        b.name
        b.email
        b.phone
        b.address
        b.zipcode
        b.city
        b.birthday = nonify(b.birthday)
        b.driverslicence = "driverslicence" in request.form
        b.diku_age
        b.about_me# = request.form["about_me"]
        b >> ("UPDATE Users $ WHERE username = ?", username)

        return redirect(url_for('usermanager.user', username=username))

    else:
        user = data.execute("SELECT * FROM Users WHERE username = ?", session["username"])
        user = user[0]
        user = unnonify(user)

        birthday = user["birthday"]
        if birthday == None:
            birthday = ""
        elif isinstance(birthday, datetime.date):
            birthday = birthday.isoformat()

        w = html.WebBuilder()
        w.form()
        w.formtable()
        w.textfield("name", "Fulde navn")
        w.textfield("email", "Email")
        w.textfield("phone", "Telefonnummer")
        w.textfield("address", "Adresse")
        w.textfield("zipcode", "Postnummer")
        w.textfield("city", "By")
        w.calendar("birthday", "Fødselsdag")
        w.checkbox("driverslicence", "Har du kørekort?")
        w.textfield("diku_age", "Hvornår startede du på DIKU?")
        w.textarea("about_me", "Lidt om mig")

        form = w.create(user)
        return render_template("form.html", form=form)
Пример #3
0
def rus(r_id):
    if request.method == "POST":
        if 'cancel' in request.form:
            flash(escape("Ændringer anulleret"))
            return redirect(url_for('rusmanager.overview'))

        b = data.Bucket(request.form)
        b.filled_by = session["username"]
        b.can_contact = True if "can_contact" in request.form else False
        b.called = "called" in request.form
        b.name
        b.gender
        b.birthday = nonify(b.birthday)
        b.co
        b.address
        b.zipcode
        b.city
        b.move_time
        b.new_address
        b.new_zipcode
        b.new_city
        b.phone
        b.email
        b.vacation
        b.priority
        b.gymnasium
        b.since_gymnasium
        b.supplementary_exams
        b.merit
        b.code_experience
        b.special_needs
        b.plays_instrument
        b.other
        b.tshirt
        b.paid = "paid" in request.form
        b.attending_uniday = "attending_uniday" in request.form
        b.attending_campus = "attending_campus" in request.form
        b.attending_rustour = "attending_rustour" in request.form

        b.mentor = nonify(b.mentor)
        b.rustour = nonify(b.rustour)
        b.dutyteam = nonify(b.dutyteam)
        if b.dutyteam is not None:
            t_id = data.execute("SELECT t_id FROM Dutyteams WHERE d_id = ?", b.dutyteam)
            t_id = str(t_id[0]['t_id'])
            if b.rustour != t_id:
                b.dutyteam = None
        b >> ("UPDATE Russer SET $ WHERE r_id = ?", r_id)

        # Friends:
        friends = request.form['friends']
        friends = friends.replace('"', '')
        friends = friends.replace('"', '')
        friend_ids = [name.split()[0] for name in re.split(';\s', friends) if name != ""]

        for friend in friend_ids:
            try:
                b = data.Bucket()
                b.r_id1, b.r_id2 = sorted((int(friend), int(r_id)))
                b >= "Friends"
            except psycopg2.IntegrityError as e:
                pass

        # Friends of us:
        user_friends = request.form['user_friends']
        user_friends = user_friends.replace('"', '')
        user_friends = user_friends.replace('"', '')
        user_friends = [name.split()[0] for name in re.split(';\s', user_friends) if name != ""]

        for friend in user_friends:
            try:
                b = data.Bucket()
                b.r_id = r_id
                b.username = friend
                b >= "Friends_of_us"
            except psycopg2.IntegrityError as e:
                pass

        flash("Rus opdateret")

        if "next" in request.form:
            russer = data.execute("SELECT r_id FROM Russer ORDER BY name ASC")
            russer = [str(rus['r_id']) for rus in russer]
            try:
                next = russer[russer.index(r_id) + 1]
                return redirect(url_for('rusmanager.rus', r_id=next))
            except (ValueError, IndexError):
                pass

        if "previous" in request.form:
            russer = data.execute("SELECT r_id FROM Russer ORDER BY name ASC")
            russer = [str(rus['r_id']) for rus in russer]
            try:
                index = russer.index(r_id) - 1
                if index < 0:
                    raise IndexError()
                previous = russer[index]
                return redirect(url_for('rusmanager.rus', r_id=previous))
            except (ValueError, IndexError):
                pass


        return redirect(url_for('rusmanager.overview'))
    else:
        rus = data.execute("SELECT * FROM Russer WHERE r_id = ?", r_id)
        if len(rus) == 0:
            return "Den rus findes ikke din spasser!"
        else:
            rus = rus[0]

        year = rkgyear()
        tours = data.execute("SELECT * FROM Tours WHERE year = ?", year)
        tours = [(tour['t_id'], tour['tour_name']) for tour in tours]
        tours = [(None, "None")] + tours

        birthday = rus["birthday"]
        if birthday == None:
            birthday = ""
        elif isinstance(birthday, datetime.date):
            birthday = birthday.isoformat()

        dutyteams = data.execute("SELECT * FROM Dutyteams WHERE t_id = ?", rus["rustour"])
        dutyteams = [(dutyteam['d_id'], dutyteam['name']) for dutyteam in dutyteams]
        dutyteams = [(None, "None")] + dutyteams

        mentors = data.execute("SELECT * FROM Mentorteams WHERE year = ?", year)
        mentors = [(mentor['m_id'], mentor['mentor_names']) for mentor in mentors]
        mentors = [(None, "None")] + mentors


        # Friends:
        russer = data.execute("SELECT r_id, name FROM Russer WHERE r_id != ?", r_id)
        russer = ['\\"{0}\\" {1}'.format(rus['r_id'], rus['name']) for rus in russer]
        friends = data.execute("SELECT * FROM ((SELECT r_id2 as r_id FROM Friends WHERE r_id1 = ?) UNION (SELECT r_id1 as r_id FROM Friends where r_id2 = ?)) as a INNER JOIN Russer USING (r_id) ORDER BY Name", r_id, r_id)
        friends = ['&quot;{0}&quot; {1}; '.format(friend['r_id'], friend['name']) for friend in friends]
        friends = "".join(friends)

        # Friends of us:
        users = data.execute("SELECT username, name FROM Users WHERE deleted = ?", False)
        users = ['\\"{0}\\" {1}'.format(user['username'], user['name']) for user in users]
        user_friends = data.execute("SELECT username, name FROM Friends_of_us INNER JOIN USERS Using (username) WHERE r_id = ?", r_id)
        user_friends = ['&quot;{0}&quot; {1}; '.format(friend['username'], friend['name']) for friend in user_friends]
        user_friends = "".join(user_friends)

        gender = [("male", "Mand"), ("female", "Kvinde"), ("other", "andet")]

        wb = html.WebBuilder()
        wb.form()
        wb.formtable()
        wb.html(rus_icons(rus))
        wb.checkbox("can_contact", "Må kontaktes")
        wb.checkbox("called", "Opringet")
        wb.textfield("name", "Navn")
        wb.select("gender", "Køn", gender)
        wb.calendar("birthday", "Fødselsdag")
        wb.textfield("phone", "Tlf")
        wb.textfield("email", "email")
        wb.textfield("co", "co")
        wb.textfield("address", "Adresse")
        wb.textfield("zipcode", "Postnummer")
        wb.textfield("city", "By")
        wb.textfield("move_time", "Flyttedato")
        wb.textfield("new_address", "Ny adresse")
        wb.textfield("new_zipcode", "Nyt postnummer")
        wb.textfield("new_city", "Ny by")
        wb.textfield("vacation", "Ferie")
        wb.textfield("priority", "DIKU prioritet")
        wb.textfield("gymnasium", "Adgangsgivende eksamen (inkl. år)")
        wb.textfield("since_gymnasium", "Lavet efterfølgende")
        wb.textfield("supplementary_exams", "Tager du supplerende eksamener")
        wb.textfield("merit", "Merit")
        wb.textfield("code_experience", "Kode erfaring")
        wb.textfield("special_needs", "Specielle behov")
        wb.textfield("plays_instrument", "Spiller instrument")
        wb.textarea("other", "Andet")
        #wb.textfield("Friends", "Kender")
        wb.checkbox("attending_uniday", "Deltager unidag")
        wb.checkbox("attending_campus", "Deltager campus")
        wb.checkbox("attending_rustour", "Deltager rustur")
        wb.select("mentor", "Mentorhold:", mentors)
        wb.select("rustour", "Skal på:", tours)
#        wb.textfield("dutyteam", "Tjansehold")
        wb.select("dutyteam", "Tjansehold:", dutyteams)
        wb.textfield("tshirt", "Tshirt størrelse")
        wb.checkbox("paid", "Betalt")
        wb.html(html.autocomplete_multiple(russer, "friends", default=friends), description="Tilføj bekendte russer")
        wb.html(html.autocomplete_multiple(users, "user_friends", default=user_friends), description="Tilføj bekendte vejledere")
        wb.html('<button type="submit" name="next" value="next">Gem og gå videre</button>')
        wb.html('<button type="submit" name="previous" value="previous">Gem og gå til forige</button>')

        form = wb.create(rus)

        return render_template("rusmanager/rus.html", form=form, name=rus['name'])