Exemplo n.º 1
0
def show_student(email=None):
    """Summary

    Args:
        email (None, optional): Description

    Returns:
        function: Description
    """

    # if no email
    if not email:
        return redirect(url_for('student_list'))

    # if student is being updated
    if request.method == 'POST':
        student = students.update_student(data_storage_file, email, request.form)
        return render_template("student.html", student=student)

    list_of_students = data.load_json(data_storage_file)

    # if student available
    if list_of_students.get(email):
        student = list_of_students[email]
        return render_template("student.html", student=student)
    else:
        return render_template("students.html")
Exemplo n.º 2
0
def delete_item(box_id=None, item_id=None):
    """
    Route to delete an existing item
        (1): handle post request to delete item when clicked on yes on the 'are you sure you want to delete this item' page
        (2): show the 'are you sure you want to delete this item' page

    Args:
        box_id (str): ID of the box in which the item to delete is
        item_id (str): ID of the item to delete

    Returns:
        (1) redirect: redirect to box detail page with the overview of all items of the box
        (2) render_template: render delete_item.html template to ask if they are sure to delete the item (with all the item informations to display)
    """
    boxes = data_lib.load_json(data_storage_file)

    # (1): handle post request to delete item when clicked on yes on the 'are you sure you want to delete this item' page
    if request.method == 'POST':
        boxes = item_lib.delete_item(boxes, box_id, item_id)

        data_lib.save_json(data_storage_file, boxes)

        return redirect(url_for('box', box_id=box_id))

    # (2): show the 'are you sure you want to delete this item' page
    if box_id and item_id:
        item = boxes[box_id]['box_items'][item_id]
        return render_template('delete_item.html',
                               box_id=box_id,
                               item_id=item_id,
                               item=item)

    return render_template('index.html')
Exemplo n.º 3
0
def todo_speichern(was_machen, wann_deadline, zeitlich):
    """
    Summary:
        Hier wird angegeben wie, dass die eingegeben To Do's in die json-File gespeicherten werden.

    Argumente:
        was_machen(string): Was muss gemacht werden
        wann_deadline(date): Bis zu welchem Datum muss es erledigt werden
        zeitlich(time): Bis zu welcher Uhrzeit soll es erledigt werden?

    Returns:
        Dictionary: Alle To Do-Daten werden aus json-File wiedergegeben.

    """
    json_daten = data.load_json()
    alle_todos = json_daten.get("todos", {})

    todo = {
        "was_machen": was_machen,
        "wann_deadline": wann_deadline,
        "zeitlich": zeitlich
    }

    alle_todos['open'][was_machen] = todo

    json_daten["todos"] = alle_todos

    data.save_to_json(json_daten)
    return json_daten
Exemplo n.º 4
0
def clear_database():
    data.clear_json()
    person_daten = data.load_json()

    # keine daten gefunden, falls keine vorhanden

    return render_template("all.html", daten=person_daten)
Exemplo n.º 5
0
def search(email=None):

    # wenn email ausgefüllt, dann wird auf eigene seite geleitet mit dem eigenen get-parameter
    # if wenn gerade aufgefüllt, in gleicher session

    if request.method == 'POST':
        destiny_email = request.form['destiny_email']
        return redirect(url_for('search', email=destiny_email))

    # versuchen alle daten laden und matching entsprechend der eingegeben mail-adresse (primary-key)
    # verweis destiny.py

    try:
        alle_personen = data.load_json()
        match_daten = destiny.get_matching(email, alle_personen)

    except:
        match_daten = None
        alle_personen = None

    # match_daten = data.load_json()
    # destiny wird geladen aus matchprozess

    return render_template("destiny.html",
                           match_emails=match_daten,
                           daten=alle_personen,
                           person_email=email)
Exemplo n.º 6
0
def termin_speichern(category, subject, where, date, time):
    """Summary
    Gibt an, wie die eingegebenen Daten in das json-File gespeichert wird.
    Argumente:
        category(string): Terminkategorie
        subject(string): Was für ein Termin ist es, Beschreibung
        where(string): Wo wird Termin stattfinden
        date(date): An welchem Datum Termin stattfinden wird
        time(time): Um welche Uhrzeit Termin beginnt

    Returns:
        Dictionary: Alle Termindaten werden aus json-File wiedergegeben.
    """
    json_daten = data.load_json()
    alle_termine = json_daten.get("termine", {})

    termin = {
        "category": category,
        "subjects": subject,
        "where": where,
        "date": date,
        "time": time
    }

    alle_termine[category][str(
        datetime.datetime.now()
    )] = termin  #In Verschachtlung: In der Kategorie, bsp. Work, wird der Termin mit einem Timestamp erfasst, damit mehrere Termine des Kategorie Work erfasst werden können.

    json_daten["termine"] = alle_termine

    data.save_to_json(json_daten)
    return json_daten
Exemplo n.º 7
0
def monatsplananzeige(categoryfilter=None):
    """
    Summary:
        Hier werden alle Events angezeigt.
        Die url/route ist '/monatsplananzeige' oder wenn categoryfilter gesetzt: '/monatsplananzeige/<categoryfilter>'.
    
    Argumente:
        categoryfilter: wenn vorhanden, wird er mitgegeben, sonst nicht. --> für filtern von Events.

    Returns:
        if:
            template: Das HTML 'monatsplan' wird mit dem categoryfilter gerendert. Es werden nur Termine der Zukunft angezeigt
        else:
            template: Das HTML 'monatsplan' wird ohne categoryfilter gerendert. Es werden alle erfassten Termine angezeigt
    """
    termin_daten = data.load_json()

    if categoryfilter:
        termine_from_now = speichern_termine.get_events_from_now(
            termin_daten['termine'][categoryfilter])
        return render_template("monatsplan.html",
                               daten=termine_from_now,
                               categoryfilter=categoryfilter)
    else:
        return render_template("monatsplan.html", daten=termin_daten)
Exemplo n.º 8
0
def home():
    """
    Show the home page when the url/route is '/' or '/home'.
    On the home page all todos will be shown which are open.

    Returns:
        template: The template index.html will be rendered with all open todos and the statistics.
    """
    error_message = None
    todolist = data.load_json(data_storage_file)

    if request.method == 'POST':
        new_todo = request.form['todo_text']

        if new_todo in todolist['open']:
            error_message = "ToDo already exists!"
        else:
            todolist['open'].append(new_todo)
            data.save_json(data_storage_file, todolist)

    count_open = statistics.get_count_open(todolist)
    count_done = statistics.get_count_done(todolist)
    count_total = int(count_open+count_done)
    percent_open = statistics.get_percent_open(count_open, count_total)
    percent_done = statistics.get_percent_done(count_done, count_total)

    return render_template('index.html', open_todos=todolist["open"], error=error_message, count_total=count_total, count_open=count_open, count_done=count_done, percent_open=percent_open, percent_done=percent_done)
Exemplo n.º 9
0
def delete_box(box_id=None):
    """
    Route to delete an existing box
        (1): handle post request to delete box when clicked on yes on the 'are you sure you want to delete this box' page
        (2): show the 'are you sure you want to delete this box' page

    Args:
        box_id (str): ID of the box to delete

    Returns:
        (1) redirect: redirect to home page with the overview of boxes after box is deleted
        (2) render_template: render delete_box.html template to ask if they are sure to delete the box with all the items (with all the box informations to display)
    """
    boxes = data_lib.load_json(data_storage_file)

    # (1): handle post request to delete box when clicked on yes on the 'are you sure you want to delete this box' page
    if request.method == 'POST':
        boxes = box_lib.delete_box(boxes, box_id)

        data_lib.save_json(data_storage_file, boxes)

        return redirect(url_for('home'))

    # (2): show the 'are you sure you want to delete this box' page
    if box_id:
        box = boxes[box_id]
        return render_template('delete_box.html', box_id=box_id, box=box)

    return render_template('index.html')
Exemplo n.º 10
0
def box(box_id=None, edit_box=None):
    """
    Route for the box page which handles anything about boxes, following situations
        (1): handling post request from adding or edit a box
        (2): handling the edit box reuest
        (3): showing box details
        (4): showing form to add new box

    Args:
        box_id (str): box_id for edit or show details
        edit_box (str): to know if edit button pressed

    Returns:
        (1) render_template: renders box.html template with box data to show details
        (2) render_template/redirect: renders box.html template with details or redirects to home if a wrong param (box_id is given) 
        (3) render_template/redirect: renders box.html template with details or redirects to home if a wrong param (box_id is given) 
        (4) render_template: renders box.html template without any data - empty form is shown
    """
    boxes = data_lib.load_json(data_storage_file)

    # (1): handling post request from adding a new box or edit
    if request.method == 'POST':
        box_name = request.form['box_name']
        box_description = request.form['box_description']

        # when editbox set box_id otherwise create new from timestamp in ms
        if 'box_id' in request.form:
            box_id = request.form['box_id']
            boxes = box_lib.update_box(boxes, box_id, box_name,
                                       box_description)
        else:
            box_id = str(int(round(time.time() * 1000)))
            boxes = box_lib.add_new_box(boxes, box_id, box_name,
                                        box_description)

        data_lib.save_json(data_storage_file, boxes)

        box = boxes[box_id]
        return render_template('box.html', box_id=box_id, box=box)

    # (2): handling the edit box reuest
    if edit_box == "edit":
        try:
            box = boxes[box_id]
            return render_template('box.html', edit_box_id=box_id, box=box)
        except ():
            return redirect(url_for('home'))

    # (3): showing box details
    if box_id:
        try:
            box = boxes[box_id]
            return render_template('box.html', box_id=box_id, box=box)
        except ():
            return redirect(url_for('home'))

    # (4): showing form to add new box
    return render_template('box.html')
Exemplo n.º 11
0
def student_list():
    """Summary

    Returns:
        function: Description
    """
    students = data.load_json(data_storage_file)

    return render_template("students.html", students=students)
Exemplo n.º 12
0
def home():
    """
    Route for the home page where the box overview and statistics are shown

    Returns:
        render_template: renders the index.html template with the boxes and statistics
    """
    boxes = data_lib.load_json(data_storage_file)
    statistics = stats_lib.calc_stats(boxes)
    return render_template('index.html', boxes=boxes, statistics=statistics)
Exemplo n.º 13
0
def todosanzeige():
    """
    Summary:
        Hier werden alle To Do's angezeigt.
        Die url/route ist '/todosanzeige'.
    
    Returns:
        template: Das HTML 'todosanzeige.html' wird gerendert.
    """
    todo_daten = data.load_json()
    return render_template("todosanzeige.html", daten=todo_daten)
Exemplo n.º 14
0
def summary_turkey():
    """
    Route und Funktion für die Anzeige aller türkischen Gerichte
    Entweder werden alle Rezepte angezeigt (GET) oder ein Rezept wird gelöscht (POST)

    Returns:
        render_template: Das template summary_turkey.html wird gerendert (Anzeige aller türkischen Rezepte)
    """
    rezepte = data.load_json(data_storage_file)

    if request.method == 'POST':
        rezept_titel = request.form['rezept_titel']
        rezepte['turkey'].pop(rezept_titel, None)
        data.save_json(data_storage_file, rezepte)

    return render_template('summary_turkey.html', rezepte=rezepte['turkey'])
Exemplo n.º 15
0
def done_todos():
    """
    Show the done page when the url/route is '/done'.
    On the done page all todos will be shown which are done.

    Returns:
        template: The template done_todos.html will be rendered with all done todos and the statistics.
    """
    todolist = data.load_json(data_storage_file)

    count_open = statistics.get_count_open(todolist)
    count_done = statistics.get_count_done(todolist)
    count_total = int(count_open+count_done)
    percent_open = statistics.get_percent_open(count_open, count_total)
    percent_done = statistics.get_percent_done(count_done, count_total)

    return render_template('done_todos.html', done_todos=todolist["done"], count_total=count_total, count_open=count_open, count_done=count_done, percent_open=percent_open, percent_done=percent_done)
Exemplo n.º 16
0
def mark_as_open(todo_as_open=None):
    """
    Marks a done todo item as open.

    Args:
        todo_as_open: name of the done todo item

    Returns:
        redirect: The user will be redirected to the done_todos page.
    """
    todolist = data.load_json(data_storage_file)

    if todo_as_open:
        if todo_as_open in todolist['done']:
            todolist['done'].remove(todo_as_open)
            todolist['open'].append(todo_as_open)
            data.save_json(data_storage_file, todolist)
    
    return redirect(url_for('done_todos'))
Exemplo n.º 17
0
def mark_as_done(todo_as_done=None):
    """
    Marks an open todo item as done.

    Args:
        todo_as_done: name of the open todo item

    Returns:
        redirect: The user will be redirected to the home page.
    """
    todolist = data.load_json(data_storage_file)

    if todo_as_done:
        if todo_as_done in todolist['open']:
            todolist['open'].remove(todo_as_done)
            todolist['done'].append(todo_as_done)
            data.save_json(data_storage_file, todolist)
    
    return redirect(url_for('home'))
Exemplo n.º 18
0
def todoasdone(todoId=None):
    """
    Summary:
        Hier wird ein To do als done gekennzeichnet,
        beziehungsweise in das dictionary 'done' kopiert 
        und aus dem dictionar 'open' rausgelöscht
    Argumente:
        todoId: Key des To Do's welches als Done markiert werden soll.
    Returns:
        redirect: es wird auf die 'todosanzeige' weitergeleitet.
    """
    daten = data.load_json()

    todo = daten['todos']['open'][todoId]
    daten['todos']['done'][todoId] = todo
    daten['todos']['open'].pop(todoId, None)

    data.save_to_json(daten)

    return redirect(url_for('todosanzeige'))
Exemplo n.º 19
0
def all(email=None):
    person_daten = data.load_json()

    #wenn im gleicher session, dann wird begrüssungssatz formuliert: Hallo willi oberhänsli! Hier geht's zu deinen Matches.

    if email:
        try:
            neue_person_daten = person_daten['personen']['person'][email]
        except:
            neue_person_daten = None

    # keine email im zwischenspeicher, dann kein begrüssungssatz

    else:
        neue_person_daten = None

    # ALL aufrufen mit personendaten und NEUER Person

    return render_template("all.html",
                           daten=person_daten,
                           neue_person=neue_person_daten)
Exemplo n.º 20
0
def add_italy():
    """
    Route und Funktion für das Erstellen eines neuen italienischen Rezeptes
    Entweder wird das Formualr zur Eingabe angezeigt (GET) oder der Eintrag wird gespeichert (POST)

    Returns:
        render_template: Das template add_italy.html wird gerendert (Anzeige Formular zur Eingabe)
        redirect: Wenn ein Eintrag gespeichert wurde (POST), wird auf die Anzeige aller italienischen Rezepte weitergeleitet
    """
    rezepte = data.load_json(data_storage_file)

    if request.method == 'POST':
        rezept_titel = request.form['rezept_titel']
        rezept_beschreibung = request.form['rezept_beschreibung']
        if not 'italy' in rezepte:
            rezepte['italy'] = {}
        rezepte['italy'][rezept_titel] = rezept_beschreibung
        data.save_json(data_storage_file, rezepte)
        return redirect(url_for('summary_italy'))

    return render_template('add_italy.html')
Exemplo n.º 21
0
def home():
    """
    Route und Funktion für die Startseite
    Daten werden geladen und Statistiken, welche auf der Startseite angezeigt werden, werden berechnet und mitgeschickt

    Returns:
        render_template: Das template index.html wird mit allen nötigen Daten gerendert
    """
    rezepte = data.load_json(data_storage_file)

    # calculating some statistic facts
    count_italy = int(len(rezepte['italy']))
    count_franz = int(len(rezepte['franz']))
    count_turkey = int(len(rezepte['turkey']))
    count_total = count_italy + count_franz + count_turkey

    percent_italy = round(count_italy / count_total * 100, 1)
    percent_franz = round(count_franz / count_total * 100, 1)
    percent_turkey = round(count_turkey / count_total * 100, 1)

    return render_template("index.html", count_total=count_total, count_italy=count_italy, count_franz=count_franz, count_turkey=count_turkey, percent_italy=percent_italy, percent_franz=percent_franz, percent_turkey=percent_turkey)
Exemplo n.º 22
0
def eintrag_speichern(vorname, nachname, email, telefon, tag, monat, jahr,
                      stunde, minute, stadt):
    json_daten = data.load_json()
    alle_personen = json_daten.get('personen', {})
    person = {
        "vorname": vorname,
        "nachname": nachname,
        "email": email,
        "telefon": telefon,
        "tag": tag,
        "monat": monat,
        "jahr": jahr,
        "stunde": stunde,
        "minute": minute,
        "stadt": stadt
    }
    alle_personen['person'][email] = person
    json_daten["personen"] = alle_personen

    data.save_to_json(json_daten)
    return json_daten
Exemplo n.º 23
0
def item(box_id=None, item_id=None, edit_item=None):
    """
    Route for the box page which handles anything about items, following situations
        (1): handling post request from adding or edit a item
        (2): handling the edit item reuest
        (3): showing item details
        (4): showing form to add new item

    Args:
        box_id (str): box_id in which the item is
        item_id (str): id of the item
        edit_item (str): to know if edit button pressed

    Returns:
        (1) redirect: redirects to specific box overview in which the new or updated item is
        (2) render_template/redirect: renders item.html template with details or redirects to home if a wrong param (box_id or item_id) 
        (3) render_template: renders item.html template with details of item
        (4) render_template: renders item.html template without any data - empty form is shown
    """
    boxes = data_lib.load_json(data_storage_file)

    # (1): handling post request from adding or edit a item
    if request.method == 'POST':
        item_name = request.form['item_name']
        item_description = request.form['item_description']
        item_quantity = request.form['item_quantity']

        # when edit
        if 'item_id' in request.form:
            item_id = request.form['item_id']
            boxes = item_lib.update_item(boxes, box_id, item_id, item_name,
                                         item_description, item_quantity)

        # else new item
        else:
            boxes = item_lib.add_item(boxes, box_id, item_name,
                                      item_description, item_quantity)

        data_lib.save_json(data_storage_file, boxes)

        return redirect(url_for('box', box_id=box_id))

    # (2): handling the edit item reuest
    if edit_item == "edit":
        try:
            item = boxes[box_id]['box_items'][item_id]
            return render_template('item.html',
                                   box_id=box_id,
                                   edit_item_id=item_id,
                                   item=item)
        except ():
            return redirect(url_for('home'))

    # (3): showing item details
    if item_id:
        item = boxes[box_id]['box_items'][item_id]

        return render_template('item.html',
                               box_id=box_id,
                               item_id=item_id,
                               item=item)

    # (4): showing form to add new item
    return render_template('item.html', box_id=box_id)