Beispiel #1
0
def save_calendar():  # jwt):
    try:
        form = CalendarForm()
        if form.validate():
            calendar = {
                'name': form.name.data,
                'description': form.description.data,
                'min_year': int(form.min_year.data),
                'max_year': int(form.max_year.data),
                'time_zone': form.time_zone.data,
                'week_starting_day': int(form.week_starting_day.data),
                'emojis_enabled': form.emojis_enabled.data,
                'show_view_past_btn': form.show_view_past_btn.data
            }
            ret, response = api_request('POST', '/calendars/',
                                        json.dumps(calendar))
            if ret is True:
                flash('Calendar ' + form.name.data +
                      ' was successfully created!')
                return redirect("/calendar/%d" % (response['calendar_id']),
                                code=302)
        else:
            error_msg = ''
            if form.errors:
                for key, value in form.errors.items():
                    error_msg += ' -' + key + ': ' + value[0]
            if len(error_msg):
                flash('Error! Calendar ' + form.name.data +
                      ' contains invalid data!' + error_msg)
            return render_template("calendar/calendar_form.html", form=form)
    except Exception:
        print("Unexpected error:", sys.exc_info()[0])
        return unprocessable_entity_error('Calendar not created')
Beispiel #2
0
def save_calendar_form(calendar_id):
    form = CalendarForm()
    if not form.validate():
        error_msg = ''
        if form.errors:
            for key, value in form.errors.items():
                error_msg += ' -' + key + ': ' + value[0]
        if len(error_msg):
            flash('Error! Calendar ' + form.name.data +
                  ' contains invalid data!' + error_msg)
        return render_template("calendar/calendar_form.html",
                               calendar=vars(calendar_query),
                               form=form)

    calendar = {}
    calendar['id'] = int(form.calendar_id.data)
    calendar['name'] = form.name.data
    calendar['description'] = form.description.data
    calendar['min_year'] = int(form.min_year.data)
    calendar['max_year'] = int(form.max_year.data)
    calendar['time_zone'] = form.time_zone.data
    calendar['week_starting_day'] = int(form.week_starting_day.data)
    calendar['emojis_enabled'] = form.emojis_enabled.data
    calendar['show_view_past_btn'] = form.show_view_past_btn.data

    ret, response = api_request('PATCH', '/calendars/%d/' % calendar_id,
                                json.dumps(calendar))
    if ret is False:
        flash('Calendar %s not updated' % calendar_id)
        return response

    flash('Calendar ' + form.name.data + ' was successfully saved!')
    return redirect("/calendar/%d" % (calendar_id), code=302)
Beispiel #3
0
def save_calendar_form(jwt, calendar_id):
    calendar_query = Calendar.query.get(calendar_id)
    if calendar_query is None:
        return not_found_error('Calendar %s not found' % calendar_id)
    try:
        form = CalendarForm()
        if form.validate():
            calendar_query.id = int(form.calendar_id.data)
            calendar_query.name = form.name.data
            calendar_query.description = form.description.data
            calendar_query.min_year = int(form.min_year.data)
            calendar_query.max_year = int(form.max_year.data)
            calendar_query.time_zone = form.time_zone.data
            calendar_query.week_starting_day = int(form.week_starting_day.data)
            calendar_query.emojis_enabled = form.emojis_enabled.data
            calendar_query.show_view_past_btn = form.show_view_past_btn.data
            calendar_query.update()
        else:
            error_msg = ''
            if form.errors:
                for key, value in form.errors.items():
                    error_msg += ' -' + key + ': ' + value[0]
            if len(error_msg):
                flash('Error! Calendar ' + form.name.data +
                      ' contains invalid data!' + error_msg)
            return render_template("calendar/calendar_form.html",
                                   calendar=vars(calendar_query),
                                   form=form)
    except:
        print("Unexpected error:", sys.exc_info()[0])
        return unprocessable_entity_error('Calendar %s not saved' %
                                          calendar_id)

    flash('Calendar ' + form.name.data + ' was successfully saved!')
    return redirect("/calendar/%d" % (calendar_id), code=302)
Beispiel #4
0
def save_calendar(jwt):
    try:
        form = CalendarForm()
        if form.validate():
            calendar = Calendar(
                name=form.name.data,
                description=form.description.data,
                min_year=int(form.min_year.data),
                max_year=int(form.max_year.data),
                time_zone=form.time_zone.data,
                week_starting_day=int(form.week_starting_day.data),
                emojis_enabled=form.emojis_enabled.data,
                show_view_past_btn=form.show_view_past_btn.data)
            calendar.insert()
        else:
            error_msg = ''
            if form.errors:
                for key, value in form.errors.items():
                    error_msg += ' -' + key + ': ' + value[0]
            if len(error_msg):
                flash('Error! Calendar ' + form.name.data +
                      ' contains invalid data!' + error_msg)
            return render_template("calendar/calendar_form.html", form=form)
    except:
        print("Unexpected error:", sys.exc_info()[0])
        return unprocessable_entity_error('Calendar not created')

    flash('Calendar ' + form.name.data + ' was successfully created!')
    return redirect("/calendar/%d" % (calendar.id), code=302)
Beispiel #5
0
def new_calendar(jwt):
    form = CalendarForm()
    form.calendar_id.default = 0
    form.process()
    calendar = Calendar()
    calendar.id = 0
    return render_template("calendar/calendar_form.html", form=form)
Beispiel #6
0
def edit_calendar_form(jwt, calendar_id):
    calendar_query = Calendar.query.get(calendar_id)
    if calendar_query is None:
        return not_found_error('Calendar %s not found' % calendar_id)

    form = CalendarForm()
    form.calendar_id.default = calendar_query.id
    form.name.default = calendar_query.name
    form.description.default = calendar_query.description
    form.min_year.default = calendar_query.min_year
    form.max_year.default = calendar_query.max_year
    form.time_zone.default = calendar_query.time_zone
    form.week_starting_day.default = calendar_query.week_starting_day
    form.time_zone.default = calendar_query.time_zone
    form.emojis_enabled.default = calendar_query.emojis_enabled
    form.show_view_past_btn.default = calendar_query.show_view_past_btn
    form.process()

    return render_template("calendar/calendar_form.html", form=form)
Beispiel #7
0
def edit_calendar_form(calendar_id):
    ret, response = api_request('GET', '/calendars/%d/' % calendar_id)
    if ret is False:
        flash('Calendar %s not found' % calendar_id)
        return response
    calendar = response['calendar']

    form = CalendarForm()
    form.calendar_id.default = calendar['id']
    form.name.default = calendar['name']
    form.description.default = calendar['description']
    form.min_year.default = calendar['min_year']
    form.max_year.default = calendar['max_year']
    form.time_zone.default = calendar['time_zone']
    form.week_starting_day.default = calendar['week_starting_day']
    form.time_zone.default = calendar['time_zone']
    form.emojis_enabled.default = calendar['emojis_enabled']
    form.show_view_past_btn.default = calendar['show_view_past_btn']
    form.process()

    return render_template("calendar/calendar_form.html", form=form)