Beispiel #1
0
def hide_repetition_task_instance_action(calendar_id: str, year: str, month: str, day: str, task_id: str) -> Response:
    calendar_data = CalendarData(config.DATA_FOLTER)
    calendar_data.hide_repetition_task_instance(calendar_id=calendar_id,
                                                year_str=year,
                                                month_str=month,
                                                day_str=day,
                                                task_id_str=task_id)
    export_to_icalendar(calendar_data, calendar_id)

    return jsonify({})
Beispiel #2
0
def delete_task_action(calendar_id: str, year: str, month: str, day: str, task_id: str) -> Response:
    calendar_data = CalendarData(config.DATA_FOLTER)
    calendar_data.delete_task(calendar_id=calendar_id,
                              year_str=year,
                              month_str=month,
                              day_str=day,
                              task_id=int(task_id))
    export_to_icalendar(calendar_data, calendar_id)

    return jsonify({})
Beispiel #3
0
def update_task_action(calendar_id: str, year: str, month: str, day: str,
                       task_id: str) -> Response:
    # Logic is same as save + delete, could refactor but can wait until need to change any save/delete logic

    calendar_data = CalendarData(config.DATA_FOLTER)

    # For creation of "updated" task use only form data
    title = request.form["title"].strip()
    date = request.form.get("date", "")
    if len(date) > 0:
        fragments = re.split("-", date)
        updated_year = int(fragments[0])  # type: Optional[int]
        updated_month = int(fragments[1])  # type: Optional[int]
        updated_day = int(fragments[2])  # type: Optional[int]
    else:
        updated_year = updated_month = updated_day = None
    is_all_day = request.form.get("is_all_day", "0") == "1"
    due_time = request.form["due_time"]
    details = request.form["details"].replace("\r", "").replace("\n", "<br>")
    color = request.form["color"]
    has_repetition = request.form.get("repeats", "0") == "1"
    repetition_type = request.form.get("repetition_type", "")
    repetition_subtype = request.form.get("repetition_subtype", "")
    repetition_value = int(request.form["repetition_value"])  # type: int

    calendar_data.create_task(calendar_id=calendar_id,
                              year=updated_year,
                              month=updated_month,
                              day=updated_day,
                              title=title,
                              is_all_day=is_all_day,
                              due_time=due_time,
                              details=details,
                              color=color,
                              has_repetition=has_repetition,
                              repetition_type=repetition_type,
                              repetition_subtype=repetition_subtype,
                              repetition_value=repetition_value)
    # For deletion of old task data use only url data
    calendar_data.delete_task(calendar_id=calendar_id,
                              year_str=year,
                              month_str=month,
                              day_str=day,
                              task_id=int(task_id))
    export_to_icalendar(calendar_data, calendar_id)

    if updated_year is None:
        return redirect("{}/{}/".format(config.BASE_URL, calendar_id),
                        code=302)
    else:
        return redirect("{}/{}/?y={}&m={}".format(config.BASE_URL, calendar_id,
                                                  updated_year, updated_month),
                        code=302)
Beispiel #4
0
def update_task_day_action(calendar_id: str, year: str, month: str, day: str, task_id: str) -> Response:
    new_day = request.data.decode("utf-8")

    calendar_data = CalendarData(config.DATA_FOLTER)
    calendar_data.update_task_day(calendar_id=calendar_id,
                                  year_str=year,
                                  month_str=month,
                                  day_str=day,
                                  task_id=int(task_id),
                                  new_day_str=new_day)
    export_to_icalendar(calendar_data, calendar_id)

    return jsonify({})
Beispiel #5
0
def save_task_action(calendar_id: str) -> Response:
    title = request.form["title"].strip()
    date = request.form.get("date", "")
    if len(date) > 0:
        date_fragments = re.split("-", date)
        year = int(date_fragments[0])  # type: Optional[int]
        month = int(date_fragments[1])  # type: Optional[int]
        day = int(date_fragments[2])  # type: Optional[int]
    else:
        year = month = day = None
    is_all_day = request.form.get("is_all_day", "0") == "1"
    due_time = request.form["due_time"]
    details = request.form["details"].replace("\r", "").replace("\n", "<br>")
    color = request.form["color"]
    
    
    username = get_session_username(session_id=str(request.cookies.get(SESSION_ID)))
    user_data = authentication.user_data(username=username)
    color = user_data['color']
    has_repetition = request.form.get("repeats", "0") == "1"
    repetition_type = request.form.get("repetition_type")
    repetition_subtype = request.form.get("repetition_subtype")
    repetition_value = int(request.form["repetition_value"])

    calendar_data = CalendarData(config.DATA_FOLTER)
    calendar_data.create_task(calendar_id=calendar_id,
                              year=year,
                              month=month,
                              day=day,
                              title=title,
                              is_all_day=is_all_day,
                              due_time=due_time,
                              details=details,
                              color=color,
                              has_repetition=has_repetition,
                              repetition_type=repetition_type,
                              repetition_subtype=repetition_subtype,
                              repetition_value=repetition_value)
    export_to_icalendar(calendar_data, calendar_id)

    if year is None:
        return redirect("{}/{}/".format(config.BASE_URL, calendar_id), code=302)
    else:
        return redirect("{}/{}/?y={}&m={}".format(config.BASE_URL, calendar_id, year, month), code=302)