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
    context['addable'] = CHECK_PERMISSION_FUNC(None, user)
    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
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_PERMISSION_FUNC(occurrence.event, user):
        context['edit_occurrence'] = occurrence.get_edit_url()
示例#3
0
 def __call__(self, request, *args, **kwargs):
     user = request.user
     object_id = kwargs.get('event_id', None)
     try:
         obj = self.contenttype.get_object_for_this_type(pk=object_id)
     except self.contenttype.model_class().DoesNotExist:
         obj = None
     allowed = CHECK_PERMISSION_FUNC(obj, user)
     if not allowed:
         return HttpResponseRedirect(settings.LOGIN_URL)
     return self.f(request, *args, **kwargs)
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_PERMISSION_FUNC(occurrence.event, 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
示例#5
0
def serialize_occurrences(request, occurrences, user):
    occ_list = []
    for occ in occurrences:
        original_id = occ.id
        occ.id = encode_occurrence(occ)
        occ.start = occ.start.ctime()
        occ.end = occ.end.ctime()
        occ.read_only = not CHECK_PERMISSION_FUNC(occ, user)
        occ.recurring = bool(occ.event.rule)
        occ.persisted = bool(original_id)
        # these attributes are very important from UI point of view
        # if occ is recurreing and not persisted then a user can edit either event or occurrence
        # once an occ has been edited it is persisted so he can edit only occurrence
        # if occ represents non-recurring event then he always edits the event
        occ.description = occ.description.replace('\n', '\\n') # this can be multiline
        occ_list.append(occ)
    rnd = loader.get_template('schedule/occurrences_json.html')
    resp = rnd.render(Context({'occurrences':occ_list}))
    return resp