Exemplo n.º 1
0
def daily_table(context, day, width, width_slot, height, start=8, end=20, increment=30):
    """
      Display a nice table with occurrences and action buttons.
      Arguments:
      width - width of the table (px)
      width_slot - width of the slot column (px)
      height - height of the table
      start - hour at which the day starts
      end - hour at which the day ends
      increment - size of a time slot (in minutes)
    """
    user = context['request'].user
    addable = CHECK_EVENT_PERM_FUNC(None, user)
    CHECK_EVENT_PERM_FUNC(None, user)
    if 'calendar' in context:
        addable &= CHECK_CALENDAR_PERM_FUNC(context['calendar'], user)
    context['addable'] = addable

    width_occ = width - width_slot
    day_part = day.get_time_slot(day.start + datetime.timedelta(hours=start), day.start + datetime.timedelta(hours=end))
    occurrences = day_part.get_occurrences()
    occurrences = _cook_occurrences(day_part, occurrences, width_occ, height)
    # get slots to display on the left
    slots = _cook_slots(day_part, increment, width, height)
    context['occurrences'] = occurrences
    context['slots'] = slots
    context['width'] = width
    context['width_slot'] = width_slot
    context['width_occ'] = width_occ
    context['height'] = height
    return context
Exemplo n.º 2
0
def api_move_or_resize_by_code(request):
    if request.method == 'POST':
        id = request.POST.get('id')
        existed = (request.POST.get('existed') == 'true')
        dt = datetime.timedelta(minutes=int(request.POST.get('delta')))
        resize = bool(request.POST.get('resize', False))
        resp = {}
        resp['status'] = "PERMISSION DENIED"

        if existed:
            occurrence = Occurrence.objects.get(id=id)
            occurrence.end += dt
            if not resize:
                occurrence.start += dt
            if CHECK_OCCURRENCE_PERM_FUNC(occurrence, request.user):
                occurrence.save()
                resp['status'] = "OK"
        else:
            event_id = request.POST.get('event_id')
            event = Event.objects.get(id=event_id)
            dts = 0
            dte = dt
            if not resize:
                event.start += dt
                dts = dt
            event.end = event.end + dt
            if CHECK_EVENT_PERM_FUNC(event, request.user):
                event.save()
                event.occurrence_set.all().update(
                    original_start=F('original_start') + dts,
                    original_end=F('original_end') + dte,
                )
                resp['status'] = "OK"
    return HttpResponse(json.dumps(resp))
Exemplo n.º 3
0
def options(context, occurrence):
    context.update({
        'occurrence': occurrence,
        'MEDIA_URL': getattr(settings, "MEDIA_URL"),
    })
    context['view_occurrence'] = occurrence.get_absolute_url()
    user = context['request'].user
    if CHECK_EVENT_PERM_FUNC(occurrence.event, user) and CHECK_EVENT_PERM_FUNC(occurrence.event.calendar, user):
        context['edit_occurrence'] = occurrence.get_edit_url()
        print context['edit_occurrence']
        context['cancel_occurrence'] = occurrence.get_cancel_url()
        context['delete_event'] = reverse('delete_event', args=(occurrence.event.id,))
        context['edit_event'] = reverse('edit_event', args=(occurrence.event.calendar.slug, occurrence.event.id,))
    else:
        context['edit_event'] = context['delete_event'] = ''
    return context
Exemplo n.º 4
0
def laundryapp_daily_table(context, day, start=6, end=23, increment=60):
    user = context['request'].user
    addable = CHECK_EVENT_PERM_FUNC(None, user)
    if 'calendar' in context:
        addable &= CHECK_CALENDAR_PERM_FUNC(context['calendar'], user)
    context['addable'] = addable

    day_part = day.get_time_slot(day.start + datetime.timedelta(hours=start), day.start + datetime.timedelta(hours=end))
    # get slots to display on the left
    slots = _cook_slots(day_part, increment)
    context['slots'] = slots
    return context
Exemplo n.º 5
0
 def decorator(request, *args, **kwargs):
     from schedule.models import Event, Calendar, Occurrence
     user = request.user
     if not user:
         return HttpResponseRedirect(settings.LOGIN_URL)
     occurrence, event, calendar = get_objects(request, *args, **kwargs)
     if calendar:
         allowed = (CHECK_EVENT_PERM_FUNC(event, user) and \
             CHECK_CALENDAR_PERM_FUNC(calendar, user))
         if not allowed:
             return HttpResponseRedirect(settings.LOGIN_URL)
         # all checks passed
         return function(request, *args, **kwargs)
     return HttpResponseNotFound('<h1>Page not found</h1>')
Exemplo n.º 6
0
def daily_table(context, day, start=0, end=24, increment=30):
    """
      Display a nice table with occurrences and action buttons.
      Arguments:
      start - hour at which the day starts
      end - hour at which the day ends
      increment - size of a time slot (in minutes)
    """
    user = context['request'].user
    addable = CHECK_EVENT_PERM_FUNC(None, user)
    if 'calendar' in context:
        addable &= CHECK_CALENDAR_PERM_FUNC(context['calendar'], user)
    context['addable'] = addable

    day_part = day.get_time_slot(day.start + datetime.timedelta(hours=start), day.start + datetime.timedelta(hours=end))
    # get slots to display on the left
    slots = _cook_slots(day_part, increment)
    context['slots'] = slots
    return context
Exemplo n.º 7
0
    def decorator(request, *args, **kwargs):
        from schedule.models import Event, Calendar
        user = request.user
        # check event permission
        event = get_object_or_None(Event, pk=kwargs.get('event_id', None))
        allowed = CHECK_EVENT_PERM_FUNC(event, user)
        if not allowed:
            return HttpResponseRedirect(settings.LOGIN_URL)

        # check calendar permissions
        calendar = None
        if event:
            calendar = event.calendar
        elif 'calendar_slug' in kwargs:
            calendar = Calendar.objects.get(slug=kwargs['calendar_slug'])
        allowed = CHECK_CALENDAR_PERM_FUNC(calendar, user)
        if not allowed:
            return HttpResponseRedirect(settings.LOGIN_URL)

        # all checks passed
        return function(request, *args, **kwargs)