示例#1
0
def create(request, template_name=None, next=None, action=None):
    """ create an event """
    if request.method == 'POST':
        request_user = request.user
        f = EventForm(request.POST)
        if f.is_valid():
            title = f.cleaned_data['title']
            start = f.cleaned_data['start_time']
            end = f.cleaned_data['end_time']
            allDay = f.cleaned_data['check_whole_day']
            category = f.cleaned_data['category']
            priority = f.cleaned_data['priority']
            end_recurring_period = f.cleaned_data['end_recurring_period']
            recursion_frequency = f.cleaned_data['recursion_frequency']
            recursion_count = f.cleaned_data['recursion_count']
            recursion_byweekday = f.cleaned_data['recursion_byweekday']
            recursion_bymonthday = f.cleaned_data['recursion_bymonthday']
            close = f.cleaned_data['close']
            invite = f.cleaned_data['invite']
            min_number_guests = f.cleaned_data['min_number_guests']
            max_number_guests = f.cleaned_data['max_number_guests']
            slug = slugify(title)
            if Event.objects.filter(slug=slug).count() > 0:
                slug = slug + str(Event.objects.filter(slug__contains=slug).count())
            event = Event(author=request_user, slug=slug, title=title, start=start,
                                 end=end, category=category, allDay=allDay,
                                 priority=priority, end_recurring_period=end_recurring_period)

            #first we have to check if the current event is recurring, if so we:
            #the recursion parameters are required
            if f.cleaned_data['add_recursion']:
                recursion_params = recursion_count + recursion_byweekday + recursion_bymonthday
                recursion = Recursion(frequency=recursion_frequency, params=recursion_params)
                recursion.save()
                event.recursion = recursion
            event.save()
            stats = Stat(event=event,
                              min_number_guests=min_number_guests,
                              max_number_guests=max_number_guests,
                              close=close)
            stats.save()

            Calendar(event=event, user=request_user, stats=stats, is_guest=True).save()
            #@todo uncomment the code below to set the notification
            #set the notification object
            #ToNotify(user=request_user, basecal=eventCal).save()
            if invite:
                for user in invite:
                    Calendar(event=event, user=user,
                                 stats=stats, is_guest=True).save()
                    #send notification
                    #notification.send([user], "cal_invitation", {'cal': eventCal,})
                    #set the notification object
                    #ToNotify(user=user, basecal=eventCal).save()

            if not request.is_ajax():
                return HttpResponseRedirect(reverse(next, args=(event.get_url(),)))
            else:
                response = {'success':True, 'id':event.id, 'color': EVENT_COLOR[int(event.category)],
                            'url' : event.get_absolute_url(),'start': event.start.strftime('%Y-%m-%dT%H:%M:%S'), 'end': event.end.strftime('%Y-%m-%dT%H:%M:%S'),}
                json = simplejson.dumps(response, ensure_ascii=False)
                return HttpResponse(json, mimetype="application/json")
        else:
            response = errors_as_json(f)
            if request.is_ajax():
                json = simplejson.dumps(response, ensure_ascii=False)
                return HttpResponse(json, mimetype="application/json")
    else:
        f = EventForm()

    c = RequestContext(request, {'form': f,
                                 'action':reverse(action),
                                 })

    return render_to_response(template_name, c)
示例#2
0
def create(request, template_name=None, next=None, action=None):
    """ create an event """
    if request.method == 'POST':
        request_user = request.user
        f = EventForm(request.POST)
        if f.is_valid():
            title = f.cleaned_data['title']
            start = f.cleaned_data['start_time']
            end = f.cleaned_data['end_time']
            allDay = f.cleaned_data['check_whole_day']
            category = f.cleaned_data['category']
            priority = f.cleaned_data['priority']
            end_recurring_period = f.cleaned_data['end_recurring_period']
            recursion_frequency = f.cleaned_data['recursion_frequency']
            recursion_count = f.cleaned_data['recursion_count']
            recursion_byweekday = f.cleaned_data['recursion_byweekday']
            recursion_bymonthday = f.cleaned_data['recursion_bymonthday']
            close = f.cleaned_data['close']
            invite = f.cleaned_data['invite']
            min_number_guests = f.cleaned_data['min_number_guests']
            max_number_guests = f.cleaned_data['max_number_guests']
            slug = slugify(title)
            if Event.objects.filter(slug=slug).count() > 0:
                slug = slug + str(
                    Event.objects.filter(slug__contains=slug).count())
            event = Event(author=request_user,
                          slug=slug,
                          title=title,
                          start=start,
                          end=end,
                          category=category,
                          allDay=allDay,
                          priority=priority,
                          end_recurring_period=end_recurring_period)

            #first we have to check if the current event is recurring, if so we:
            #the recursion parameters are required
            if f.cleaned_data['add_recursion']:
                recursion_params = recursion_count + recursion_byweekday + recursion_bymonthday
                recursion = Recursion(frequency=recursion_frequency,
                                      params=recursion_params)
                recursion.save()
                event.recursion = recursion
            event.save()
            stats = Stat(event=event,
                         min_number_guests=min_number_guests,
                         max_number_guests=max_number_guests,
                         close=close)
            stats.save()

            Calendar(event=event,
                     user=request_user,
                     stats=stats,
                     is_guest=True).save()
            #@todo uncomment the code below to set the notification
            #set the notification object
            #ToNotify(user=request_user, basecal=eventCal).save()
            if invite:
                for user in invite:
                    Calendar(event=event,
                             user=user,
                             stats=stats,
                             is_guest=True).save()
                    #send notification
                    #notification.send([user], "cal_invitation", {'cal': eventCal,})
                    #set the notification object
                    #ToNotify(user=user, basecal=eventCal).save()

            if not request.is_ajax():
                return HttpResponseRedirect(
                    reverse(next, args=(event.get_url(), )))
            else:
                response = {
                    'success': True,
                    'id': event.id,
                    'color': EVENT_COLOR[int(event.category)],
                    'url': event.get_absolute_url(),
                    'start': event.start.strftime('%Y-%m-%dT%H:%M:%S'),
                    'end': event.end.strftime('%Y-%m-%dT%H:%M:%S'),
                }
                json = simplejson.dumps(response, ensure_ascii=False)
                return HttpResponse(json, mimetype="application/json")
        else:
            response = errors_as_json(f)
            if request.is_ajax():
                json = simplejson.dumps(response, ensure_ascii=False)
                return HttpResponse(json, mimetype="application/json")
    else:
        f = EventForm()

    c = RequestContext(request, {
        'form': f,
        'action': reverse(action),
    })

    return render_to_response(template_name, c)
示例#3
0
def edit(request, event_slug, cal_type="5", template_name=None, next=None):
    """ edit a withcal """
    (event, err) = fetch_from_url(request, event_slug)
    if err:
        return err
    request_user = request.user
    if request.method == 'POST':
        f = BaseEventForm(request.POST)
        if f.is_valid():
            event.start = f.cleaned_data['start_time']
            event.end = f.cleaned_data['end_time']
            event.allDay = f.cleaned_data['check_whole_day']
            event.category = f.cleaned_data['category']
            event.priority = f.cleaned_data['priority']
            event.end_recurring_period = f.cleaned_data['end_recurring_period']
            recursion_frequency = f.cleaned_data['recursion_frequency']
            recursion_count = f.cleaned_data['recursion_count']
            recursion_byweekday = f.cleaned_data['recursion_byweekday']
            recursion_bymonthday = f.cleaned_data['recursion_bymonthday']

            #first we have to check if the current event is recurring, if so we:
            #the recursion parameters are required
            if f.cleaned_data['add_recursion']:
                recursion_params = recursion_count + recursion_byweekday + recursion_bymonthday
                if event.recursion is None:
                    recursion = Recursion(frequency=recursion_frequency, params=recursion_params)
                    recursion.save()
                    event.recursion = recursion
                else :
                    recursion = event.recursion
                    recursion.frequency = recursion_frequency
                    recursion.params = recursion_params
                    recursion.save()
            else :
                if event.recursion is not None:
                    recursion = event.recursion
                    event.recursion = None
                    event.save()
                    recursion.delete()

            event.save()
            #notify all concerned users by the object by the new comment
            #users_tonotify = ToNotify.objects.filter(event=event).exclude(user=request_user)
            #for user_tonotify in users_tonotify:
                #user = user_tonotify.user
                #notification.send([user], "cal_updated", {'event': event, 'user':request_user,})

            if not request.is_ajax():
                return HttpResponseRedirect(reverse(next, args=(event.get_url(),)))
            response = ({'success':'True'})
        else:
            response = errors_as_json(f)
        if request.is_ajax():
            json = simplejson.dumps(response, ensure_ascii=False)
            return HttpResponse(json, mimetype="application/json")
    else:

        if event.recursion:
            params = event.recursion.get_params()
            count = ''
            byweekday = ''
            bymonthday = ''
            if 'count' in params:
                count = params['count']
            if 'byweekday' in params:
                try:
                    byweekday = [int(params['byweekday'])]
                except:
                    byweekday = params['byweekday']
            if 'bymonthday' in params:
                try:
                    bymonthday = [int(params['bymonthday'])]
                except:
                    bymonthday = params['bymonthday']
            f = BaseEventForm({'start_date': event.start.date(),
                      'start_time': event.start.time().strftime("%I:%M %p"),
                      'end_date': event.end.date(),
                      'end_time': event.end.time().strftime("%I:%M %p"),
                      'category': event.cal_category,
                      'priority': event.priority,
                      'check_whole_day': event.allDay,
                      'end_recurring_period': event.end_recurring_period,
                      'recursion_frequency' : event.recursion.frequency,
                      'add_recursion': True,
                      'recursion_count': count,
                      'recursion_byweekday':byweekday,
                      'recursion_bymonthday':bymonthday,
                      })
        else :
            f = BaseEventForm({'start_date': event.start.date(),
                      'start_time': event.start.time().strftime("%I:%M %p"),
                      'end_date': event.end.date(),
                      'end_time': event.end.time().strftime("%I:%M %p"),
                      'check_whole_day': event.allDay,
                      'category': event.category,
                      'priority': event.priority,
                      'end_recurring_period': event.end_recurring_period,
                      })
    c = RequestContext(request, {'form': f,
                                 'action': event.get_edit_url(),
                                 'event': event,
                                 })

    return render_to_response(template_name, c)
示例#4
0
def edit(request, event_slug, cal_type="5", template_name=None, next=None):
    """ edit a withcal """
    (event, err) = fetch_from_url(request, event_slug)
    if err:
        return err
    request_user = request.user
    if request.method == 'POST':
        f = BaseEventForm(request.POST)
        if f.is_valid():
            event.start = f.cleaned_data['start_time']
            event.end = f.cleaned_data['end_time']
            event.allDay = f.cleaned_data['check_whole_day']
            event.category = f.cleaned_data['category']
            event.priority = f.cleaned_data['priority']
            event.end_recurring_period = f.cleaned_data['end_recurring_period']
            recursion_frequency = f.cleaned_data['recursion_frequency']
            recursion_count = f.cleaned_data['recursion_count']
            recursion_byweekday = f.cleaned_data['recursion_byweekday']
            recursion_bymonthday = f.cleaned_data['recursion_bymonthday']

            #first we have to check if the current event is recurring, if so we:
            #the recursion parameters are required
            if f.cleaned_data['add_recursion']:
                recursion_params = recursion_count + recursion_byweekday + recursion_bymonthday
                if event.recursion is None:
                    recursion = Recursion(frequency=recursion_frequency,
                                          params=recursion_params)
                    recursion.save()
                    event.recursion = recursion
                else:
                    recursion = event.recursion
                    recursion.frequency = recursion_frequency
                    recursion.params = recursion_params
                    recursion.save()
            else:
                if event.recursion is not None:
                    recursion = event.recursion
                    event.recursion = None
                    event.save()
                    recursion.delete()

            event.save()
            #notify all concerned users by the object by the new comment
            #users_tonotify = ToNotify.objects.filter(event=event).exclude(user=request_user)
            #for user_tonotify in users_tonotify:
            #user = user_tonotify.user
            #notification.send([user], "cal_updated", {'event': event, 'user':request_user,})

            if not request.is_ajax():
                return HttpResponseRedirect(
                    reverse(next, args=(event.get_url(), )))
            response = ({'success': 'True'})
        else:
            response = errors_as_json(f)
        if request.is_ajax():
            json = simplejson.dumps(response, ensure_ascii=False)
            return HttpResponse(json, mimetype="application/json")
    else:

        if event.recursion:
            params = event.recursion.get_params()
            count = ''
            byweekday = ''
            bymonthday = ''
            if 'count' in params:
                count = params['count']
            if 'byweekday' in params:
                try:
                    byweekday = [int(params['byweekday'])]
                except:
                    byweekday = params['byweekday']
            if 'bymonthday' in params:
                try:
                    bymonthday = [int(params['bymonthday'])]
                except:
                    bymonthday = params['bymonthday']
            f = BaseEventForm({
                'start_date':
                event.start.date(),
                'start_time':
                event.start.time().strftime("%I:%M %p"),
                'end_date':
                event.end.date(),
                'end_time':
                event.end.time().strftime("%I:%M %p"),
                'category':
                event.cal_category,
                'priority':
                event.priority,
                'check_whole_day':
                event.allDay,
                'end_recurring_period':
                event.end_recurring_period,
                'recursion_frequency':
                event.recursion.frequency,
                'add_recursion':
                True,
                'recursion_count':
                count,
                'recursion_byweekday':
                byweekday,
                'recursion_bymonthday':
                bymonthday,
            })
        else:
            f = BaseEventForm({
                'start_date':
                event.start.date(),
                'start_time':
                event.start.time().strftime("%I:%M %p"),
                'end_date':
                event.end.date(),
                'end_time':
                event.end.time().strftime("%I:%M %p"),
                'check_whole_day':
                event.allDay,
                'category':
                event.category,
                'priority':
                event.priority,
                'end_recurring_period':
                event.end_recurring_period,
            })
    c = RequestContext(request, {
        'form': f,
        'action': event.get_edit_url(),
        'event': event,
    })

    return render_to_response(template_name, c)