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
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>')
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
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
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
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>')
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>')