예제 #1
0
파일: main.py 프로젝트: JaySuter/prog2
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)
예제 #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')
예제 #3
0
def overview():
    """
    Summary: 
    Shows table of all activites entered (saved in json file) including current amount of entrys in json-file. 
    If non existing file or emtpy file = empty table.

    Input:
    Possibility to delete an entry --> will flash a message, update number of current entrys in json-file, update table.
            
    Returns:
    Overview.  
    """
    if request.method == 'POST':
        flash('Die Aktivität wurde erfolgreich gelöscht.')
        jahresplan = data.load_overview()
        result = request.form['eintrag']
        del jahresplan[result]
        data.save_json(jahresplan)
        anzahl = data.count_entrys()
        return render_template('overview_termine.html',
                               jahresplan=jahresplan,
                               anzahl=anzahl)
    else:
        jahresplan = data.load_overview()
        anzahl = data.count_entrys()
        return render_template('overview_termine.html',
                               jahresplan=jahresplan,
                               anzahl=anzahl)
예제 #4
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')
예제 #5
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')
예제 #6
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'])
예제 #7
0
파일: main.py 프로젝트: JaySuter/prog2
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'))
예제 #8
0
파일: main.py 프로젝트: JaySuter/prog2
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'))
예제 #9
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')
예제 #10
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)