示例#1
0
def calendar_week_spec(year, week):
    if week < 1:
        week = 1
    sunday = datetime.datetime.strptime("%s %s 0" % (year, week - 1), "%Y %W %w")
    monday = sunday - datetime.timedelta(days=6)
    begin = to_utc(monday + datetime.timedelta(hours=8))
    days = {}

    for wd in range(0, 7):
        days[wd] = _get_shows(begin, begin + datetime.timedelta(hours=24))
        begin = begin + datetime.timedelta(hours=24)

    #app.logger.warn(days)
    next_week = (sunday + datetime.timedelta(days=1))
    prev_week = (sunday + datetime.timedelta(days=-7))
    return render_template('shows/calendar/week.html',
                           TITLE=gettext('Schedule :: Week'),
                           shows=days,
                           year=year,
                           week=week,
                           monday=monday.date(),
                           sunday=sunday.date(),
                           next_week=url_for('.calendar_week_spec', year=next_week.strftime('%Y'),
                                             week=int(next_week.strftime('%W')) + 1),
                           prev_week=url_for('.calendar_week_spec', year=prev_week.strftime('%Y'),
                                             week=int(prev_week.strftime('%W')) + 1)
    )
示例#2
0
def show_edit(show):
    if 'begin' in request.form and \
                    'description' in request.form and \
                    'duration' in request.form and \
                    'title' in request.form:
        if int(request.form['duration']) < 30:
            return emit_error(6, 'Duration too short')
        if int(request.form['duration']) > 1440:
            return emit_error(5, 'Duration too long')
        if len(request.form['title']) < 3:
            return emit_error(4, 'Title too short')
        if len(request.form['description']) == 0:
            return emit_error(3, 'Description is empty')
        show = Show.query.get(show)
        if show is None:
            return emit_error(7, 'Whoop, invalid show!')
        if show.get_usershow(current_user) is None:
            return emit_error(8, 'Trying to edit another user\'s show, eh?!')
        begin = to_utc(datetime.fromtimestamp(int(request.form['begin'])))
        begin = begin.replace(second=0)
        if begin < now():
            return jsonify({'success': False, 'error': 'You cannot enter a past date!'})
        end = begin + timedelta(minutes=int(request.form['duration']))
        if Show.query.filter(Show.end > begin, Show.begin < end, Show.show != show.show).count() > 0:
            return emit_error(1, 'Your show collides with other shows')
        show.begin = begin
        show.end = end
        _set_show_info(show, request.form)
        rfk.database.session.commit()
    else:
        return emit_error(0, 'Wait a second, are you trying to trick me again?!')
    return jsonify({'success': True, 'data': None})
示例#3
0
def show_edit(show):
    if 'begin' in request.form and \
                    'description' in request.form and \
                    'duration' in request.form and \
                    'title' in request.form:
        if int(request.form['duration']) < 30:
            return emit_error(6, 'Duration too short')
        if int(request.form['duration']) > 1440:
            return emit_error(5, 'Duration too long')
        if len(request.form['title']) < 3:
            return emit_error(4, 'Title too short')
        if len(request.form['description']) == 0:
            return emit_error(3, 'Description is empty')
        show = Show.query.get(show)
        if show is None:
            return emit_error(7, 'Whoop, invalid show!')
        if show.get_usershow(current_user) is None:
            return emit_error(8, 'Trying to edit another user\'s show, eh?!')
        begin = to_utc(get_timezone().localize(datetime.utcfromtimestamp(int(request.form['begin']))))
        begin = begin.replace(second=0)
        if begin < now():
            return jsonify({'success': False, 'error': 'You cannot enter a past date!'})
        end = begin + timedelta(minutes=int(request.form['duration']))
        if Show.query.filter(Show.end > begin, Show.begin < end, Show.show != show.show).count() > 0:
            return emit_error(1, 'Your show collides with other shows')
        show.begin = begin
        show.end = end
        _set_show_info(show, request.form)
        rfk.database.session.commit()
    else:
        return emit_error(0, 'Wait a second, are you trying to trick me again?!')
    return jsonify({'success': True, 'data': None})
示例#4
0
def show_add():
    try:
        if 'begin' in request.form and \
                        'description' in request.form and \
                        'duration' in request.form and \
                        'title' in request.form:
            if int(request.form['duration']) < 30:
                return emit_error(6, 'Duration too short')
            if int(request.form['duration']) > 1440:
                return emit_error(5, 'Duration too long')
            if len(request.form['title']) < 3:
                return emit_error(4, 'Title too short')
            if len(request.form['description']) == 0:
                return emit_error(3, 'Description is empty')

            begin = to_utc(get_timezone().localize(
                datetime.utcfromtimestamp(int(request.form['begin']))))
            begin = begin.replace(second=0)
            end = begin + timedelta(minutes=int(request.form['duration']))
            if begin < now():
                return emit_error(2, 'You cannot enter a past date!')
            if Show.query.filter(Show.end > begin,
                                 Show.begin < end).count() > 0:
                return emit_error(1, 'Your show collides with other shows')
            show = Show(begin=begin,
                        end=end,
                        name=request.form['title'],
                        description=request.form['description'],
                        flags=Show.FLAGS.PLANNED)
            rfk.database.session.add(show)
            show.add_user(current_user)
            _set_show_info(show, request.form)
            rfk.database.session.commit()
            return jsonify({'success': True, 'data': None})
        else:
            return emit_error(
                0, 'Wait a second, are you trying to trick me again?!')
    except Exception as e:
        from rfk.site import app

        app.logger.error(e)
        return emit_error(0, 'something went horribly wrong')
示例#5
0
def show_add():
    try:
        if 'begin' in request.form and \
                        'description' in request.form and \
                        'duration' in request.form and \
                        'title' in request.form:
            if int(request.form['duration']) < 30:
                return emit_error(6, 'Duration too short')
            if int(request.form['duration']) > 1440:
                return emit_error(5, 'Duration too long')
            if len(request.form['title']) < 3:
                return emit_error(4, 'Title too short')
            if len(request.form['description']) == 0:
                return emit_error(3, 'Description is empty')

            begin = to_utc(datetime.fromtimestamp(int(request.form['begin'])))
            begin = begin.replace(second=0)
            end = begin + timedelta(minutes=int(request.form['duration']))
            if begin < now():
                return emit_error(2, 'You cannot enter a past date!')
            if Show.query.filter(Show.end > begin, Show.begin < end).count() > 0:
                return emit_error(1, 'Your show collides with other shows')
            show = Show(begin=begin,
                        end=end,
                        name=request.form['title'],
                        description=request.form['description'],
                        flags=Show.FLAGS.PLANNED)
            rfk.database.session.add(show)
            show.add_user(current_user)
            _set_show_info(show, request.form)
            rfk.database.session.commit()
            return jsonify({'success': True, 'data': None})
        else:
            return emit_error(0, 'Wait a second, are you trying to trick me again?!')
    except Exception as e:
        from rfk.site import app

        app.logger.error(e)
        return emit_error(0, 'something went horribly wrong')
示例#6
0
 def pre_validate(self, form):
     if self.data:
         self.data = to_utc(self.data)