예제 #1
0
파일: views.py 프로젝트: mamakancha/lfs-1
def _api_move_or_resize_by_code(user, id, existed, delta, resize, event_id):
    response_data = {}
    response_data['status'] = "PERMISSION DENIED"

    if existed:
        occurrence = Occurrence.objects.get(id=id)
        occurrence.end += delta
        if not resize:
            occurrence.start += delta
        if CHECK_OCCURRENCE_PERM_FUNC(occurrence, user):
            occurrence.save()
            response_data['status'] = "OK"
    else:
        event = Event.objects.get(id=event_id)
        dts = 0
        dte = delta
        if not resize:
            event.start += delta
            dts = delta
        event.end = event.end + delta
        if CHECK_EVENT_PERM_FUNC(event, user):
            event.save()
            event.occurrence_set.all().update(
                original_start=F('original_start') + dts,
                original_end=F('original_end') + dte,
            )
            response_data['status'] = "OK"
    return response_data
예제 #2
0
 def decorator(request, *args, **kwargs):
     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>')
예제 #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_CALENDAR_PERM_FUNC(occurrence.event.calendar, user):
        context['edit_occurrence'] = occurrence.get_edit_url()
        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
예제 #4
0
def daily_table(context, day, start=8, end=20, 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
예제 #5
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_CALENDAR_PERM_FUNC(
                                 occurrence.event.calendar, user):
        context["edit_occurrence"] = occurrence.get_edit_url()
        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
예제 #6
0
 def decorator(request, *args, **kwargs):
     user = request.user
     if not user:
         return HttpResponseRedirect(settings.LOGIN_URL)
     occurrence, event, calendar = get_objects(request, *args, **kwargs)
     if calendar:
         #____________________IN THE WORKS FOR PERMISSIONS CHECKING_____
         strUserLowered = str(user).lower()
         if calendar.name == strUserLowered:
             #____________________IN THE WORKS FOR PERMISSIONS CHECKING_____
             allowed = (CHECK_EVENT_PERM_FUNC(event, user)
                        and CHECK_CALENDAR_PERM_FUNC(calendar, user))
         else:
             return HttpResponseRedirect('/')
     #____________________IN THE WORKS FOR PERMISSIONS CHECKING_____
         if not allowed:
             return HttpResponseRedirect(settings.LOGIN_URL)
         # all checks passed
         return function(request, *args, **kwargs)
     return HttpResponseNotFound('<h1>Page not found</h1>')
예제 #7
0
 def decorator(request, *args, **kwargs):
     user = request.user
     if not user:
         return HttpResponseRedirect(settings.LOGIN_URL)
     occurrence, event, calendar = get_objects(request, *args, **kwargs)
     if calendar and event:
         #____________________IN THE WORKS FOR PERMISSIONS CHECKING_____
         if event.creator == user:
             #____________________IN THE WORKS FOR PERMISSIONS CHECKING_____
             allowed = (CHECK_EVENT_PERM_FUNC(event, user)
                        and CHECK_CALENDAR_PERM_FUNC(calendar, user)
                        and CHECK_OCCURRENCE_PERM_FUNC(occurrence, user))
         #____________________IN THE WORKS FOR PERMISSIONS CHECKING_____
         else:
             # return HttpResponseRedirect('<h1 style="text-align:center">You do not have permission to edit this guides schedule</h1>')
             return HttpResponseRedirect('/')
         #____________________IN THE WORKS FOR PERMISSIONS CHECKING_____
         if not allowed:
             return HttpResponseRedirect(settings.LOGIN_URL)
         # all checks passed
         return function(request, *args, **kwargs)
     return HttpResponseNotFound('<h1>Page not found</h1>')