Exemplo n.º 1
0
def ryhmat_menneet_muokkaa(kokous_id):
    kokous = Kokous.query.get(kokous_id)
    if not ryhma_autorisaatio(kokous.ryhmaid):
        return login_manager.unauthorized()
    return render_template("ryhmat/lasnalista.html",
                           kokous=kokous,
                           ryhma=kokous.ryhma)
Exemplo n.º 2
0
def ryhmat_kokoukset_uusisarja(ryhma_id: int):
    """Lomake toistuvien kokousten sarjan lisäämiseksi"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()
    ryhma = Ryhma.query.get(ryhma_id)
    form = KokousSarjaForm()
    return render_template("ryhmat/uusisarja.html", ryhma=ryhma, form=form)
Exemplo n.º 3
0
def ryhmat_kokoukset_uusi(ryhma_id: int):
    """Lomake uuden kokouksen lisäämiseen"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()
    ryhma = Ryhma.query.get(ryhma_id)
    form = KokousTiedotForm()
    return render_template("ryhmat/uusikokous.html", ryhma=ryhma, form=form)
Exemplo n.º 4
0
def ryhmat_jasenet(ryhma_id: int):
    """Ryhmän jäsenluettelon näyttäminen"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()

    ryhma = Ryhma.query.get(ryhma_id)
    jasenet = ryhma.jasenet()

    ryhmassaidt = []
    for jasen in jasenet:
        ryhmassaidt.append(jasen["henkiloId"])

    # Uusien jäsenten lisäämistoimintoa (chosen-select) varten haetaan kaikkien
    # niiden henkilöiden nimet, jotka eivät ole ryhmässä,
    # Näin ylläpitäjä voi lisätä sellaisenkin jäsnen, joka ei täytä ikävaatimusta,
    # tai jäsenen ryhmään, joka on jo täysi.
    kaikkijasenet = Henkilo.query.filter(
        Henkilo.jasenyysalkoi.isnot(None),
        Henkilo.jasenyyspaattyi == None).order_by(Henkilo.sukunimi)
    eiryhmassa = []
    for henkilo in kaikkijasenet:
        if henkilo.id not in ryhmassaidt:
            eiryhmassa.append(henkilo)

    return render_template("ryhmat/jasenet.html",
                           ryhma=ryhma,
                           eiryhmassa=eiryhmassa,
                           jasenet=jasenet)
Exemplo n.º 5
0
def ryhmat_luo_kokoussarja(ryhma_id: int):
    """Toistuvien kokousten sarjan lisääminen tietokantaan"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()

    form = KokousSarjaForm(request.form)
    ryhma = Ryhma.query.get(ryhma_id)

    if not form.validate():
        return render_template("ryhmat/uusisarja.html", ryhma=ryhma, form=form)

    paiva = form.alkaa.data
    kokoukset = 0
    while paiva < form.paattyy.data:
        if paiva.weekday() == int(form.viikonpaiva.data):

            kokous = Kokous(ryhma.id)
            kokous.alkaa = datetime.combine(paiva, form.alkaaklo.data)
            kokous.paattyy = datetime.combine(paiva, form.paattyyklo.data)
            kokous.sijainti = form.sijainti.data
            kokous.kuvaus = form.kuvaus.data
            db.session.add(kokous)
            kokoukset += 1

        paiva = paiva + timedelta(days=1)

    db.session.commit()
    flash("Lisätty {}  kokousta".format(kokoukset), "success")

    return redirect(url_for("ryhmat_kokoukset", ryhma_id=ryhma_id))
Exemplo n.º 6
0
def ryhmat_tiedot(ryhma_id: int):
    """Ryhmän tietojen näyttäminen"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()
    ryhma = Ryhma.query.get(ryhma_id)
    form = RyhmaTiedotForm()
    form.lataa(ryhma)

    return render_template("ryhmat/tiedot.html", ryhma=ryhma, form=form)
Exemplo n.º 7
0
def ryhmat_jasen_tiedot(ryhmassa_id: int):
    """Näyttää yksittäisen jäsenen tiedot.
       Alaikäiselle näytetään myös huoltajien yhteystiedot."""
    ryhmassa = Ryhmassa.query.get(ryhmassa_id)
    if not ryhma_autorisaatio(ryhmassa.ryhmaid):
        return login_manager.unauthorized()
    return render_template("ryhmat/jasentiedot.html",
                           jasenyys=ryhmassa,
                           ryhma=ryhmassa.ryhma)
Exemplo n.º 8
0
def ryhmat_poista_kokous(kokous_id: int):
    """Yksittäisen kokouksen poistaminen tietokannasta"""
    kokous = Kokous.query.get(kokous_id)
    if not ryhma_autorisaatio(kokous.ryhmaid):
        return login_manager.unauthorized()
    flash("Kokous {:%d.%m.%y klo %H.%M} poistettiin".format(kokous.alkaa),
          "danger")
    db.session.delete(kokous)
    db.session.commit()
    return redirect(url_for("ryhmat_kokoukset", ryhma_id=kokous.ryhmaid))
Exemplo n.º 9
0
def ryhmat_erota_jasen(ryhmassa_id: int):
    """Merkitsee ryhmän jäsenneen eronneeksi.
       Jotta tilastoinnit yms. onnistuvat, ei jäsenyyttä tuhota, vaan siihen
       merkitään loppumspäivä,"""
    ryhmassa = Ryhmassa.query.get(ryhmassa_id)
    if not ryhma_autorisaatio(ryhmassa.ryhmaid):
        return login_manager.unauthorized()
    ryhmassa.paattyen = datetime.today()
    db.session.commit()
    return redirect(url_for("ryhmat_jasenet", ryhma_id=ryhmassa.ryhmaid))
Exemplo n.º 10
0
def ryhmat_linkita_jasen(ryhma_id: int):
    """Lisää ryhmään jäsenen"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()
    ryhmassa = Ryhmassa(ryhmaId=ryhma_id,
                        jasenId=request.form.get("linkita"),
                        ohjaaja=False)
    ryhmassa.alkaen = datetime.today()
    db.session.add(ryhmassa)
    db.session.commit()
    return redirect(url_for("ryhmat_jasenet", ryhma_id=ryhma_id))
Exemplo n.º 11
0
def ryhmat_menneet(ryhma_id: int):
    """Näyttää luettelon ryhmän menneistä kokouksista läsnäolomäärien kanssa"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()
    ryhma = Ryhma.query.get(ryhma_id)
    menneet = ryhma.menneetKokoukset()
    sivutus = Sivutus(len(menneet),
                      request.args.get("sivu", type=int, default=1), 20)

    return render_template("ryhmat/menneet.html",
                           ryhma=ryhma,
                           menneet=menneet[sivutus.alku():sivutus.loppu()],
                           linkit=sivutus.linkit())
Exemplo n.º 12
0
def ryhmat_muokkaa_mennyt(kokous_id):
    kokous = Kokous.query.get(kokous_id)
    if not ryhma_autorisaatio(kokous.ryhmaid):
        return login_manager.unauthorized()
    kokous.memo = request.form.get("memo")
    kokous.lasna = []

    for key in request.form.keys():
        if key.isdigit():
            ryhmassa = Ryhmassa.query.get(int(key))
            kokous.lasna.append(ryhmassa)

    db.session.commit()
    return redirect(url_for("ryhmat_menneet", ryhma_id=kokous.ryhmaid))
Exemplo n.º 13
0
def ryhmat_tilasto(ryhma_id: int):
    """Näyttää ryhmän tilaston ja jäsenten aktiivisuuden"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()

    ryhma = Ryhma.query.get(ryhma_id)

    mista = parse(request.args.get("mista", date.today().strftime("%Y-01-01")))
    mihin = parse(request.args.get("mihin", date.today().strftime("%Y-%m-%d")))

    return render_template("ryhmat/tilasto.html",
                           ryhma=ryhma,
                           mista=mista,
                           mihin=mihin,
                           tiedot=ryhma.ryhmantilasto(mista, mihin))
Exemplo n.º 14
0
def ryhmat_muokkaa_kokous(kokous_id: int):
    """Kokouksen muutosten tallentaminen tietokantaan"""
    kokous = Kokous.query.get(kokous_id)
    if not ryhma_autorisaatio(kokous.ryhmaid):
        return login_manager.unauthorized()
    form = KokousTiedotForm(request.form)
    if not form.validate():
        flash("Ole hyvä ja tarkista syöttämäsi tiedot", "danger")
        return render_template("ryhmat/muokkaakokous.html",
                               kokous=kokous,
                               ryhma=kokous.ryhma,
                               form=form)
    form.tallenna(kokous)
    db.session.commit()
    return redirect(url_for("ryhmat_kokoukset", ryhma_id=kokous.ryhma.id))
Exemplo n.º 15
0
def ryhmat_paivita(ryhma_id: int):
    """Ryhmän tietojen päivittäminen tietokantaan"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()
    form = RyhmaTiedotForm(request.form)
    ryhma = Ryhma.query.get(ryhma_id)

    if not form.validate():
        flash("Ole hyvä ja tarkista syöttämäsi tiedot", "danger")
        return render_template("ryhmat/tiedot.html", ryhma=ryhma, form=form)

    form.tallenna(ryhma)
    db.session.commit()

    flash("Ryhmä " + ryhma.nimi + " tallennettu", "success")
    return redirect(url_for("ryhmat_tiedot", ryhma_id=ryhma_id))
Exemplo n.º 16
0
def ryhmat_kokoukset_muokkaa(kokous_id: int):
    """Yksittäisen kokouksen muokkausnäkymän näyttäminen.

      Jos kokouksen alkamiseen on aikaa vähemmän kuin 15 minuuttia, ohjataan lomakkeeseen,
      jolla merkitään kokouksen läsnäolijat.
    """
    kokous = Kokous.query.get(kokous_id)
    if not ryhma_autorisaatio(kokous.ryhmaid):
        return login_manager.unauthorized()

    if kokous.alkaa < datetime.today() + timedelta(minutes=15):
        return redirect(url_for("ryhmat_menneet_muokkaa", kokous_id=kokous_id))

    form = KokousTiedotForm()
    form.lataa(kokous)
    return render_template("ryhmat/muokkaakokous.html",
                           kokous=kokous,
                           ryhma=kokous.ryhma,
                           form=form)
Exemplo n.º 17
0
def ryhmat_luo_kokous(ryhma_id: int):
    """Yksittäisen kokouksen lisääminen tietokantaan"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()

    form = KokousTiedotForm(request.form)
    ryhma = Ryhma.query.get(ryhma_id)

    if not form.validate():
        return render_template("ryhmat/uusikokous.html",
                               ryhma=ryhma,
                               form=form)

    kokous = Kokous(ryhma.id)
    form.tallenna(kokous)
    db.session.add(kokous)
    db.session.commit()

    return redirect(url_for("ryhmat_kokoukset", ryhma_id=ryhma_id))
Exemplo n.º 18
0
def ryhmat_kokoukset(ryhma_id: int):
    """Luettelon ryhmän tulevista kokouksista (ei vielä päättyneistä)"""
    if not ryhma_autorisaatio(ryhma_id):
        return login_manager.unauthorized()

    ryhma = Ryhma.query.get(ryhma_id)
    kokoukset = Kokous.query.filter(
        Kokous.ryhmaid == ryhma.id,
        Kokous.paattyy > datetime.now()).order_by("alkaa").paginate(
            request.args.get("sivu", type=int, default=1),
            20,
        )

    # Sivutuksen navigointikomponentti toteutetaan omalla Sivutus-apuluokalla
    # katso /application/helpers/sivutus.py

    sivutus = Sivutus(kokoukset.total, kokoukset.page, kokoukset.per_page)

    return render_template("ryhmat/kokoukset.html",
                           ryhma=ryhma,
                           kokoukset=kokoukset.items,
                           linkit=sivutus.linkit())