Esempio n. 1
0
 def post(self, request, *args, **kwargs):
     form = EventGuestForm(self.request.POST, user=self.request.user)
     if form.is_valid():
         obj = form.save(commit=False)
         obj.status = 1
         cleaned_data = form.cleaned_data
         if not self.request.user in cleaned_data['event'].guests.all() and not cleaned_data['event'].eventguest_set.filter(status=0).first():
             EventGuest.objects.create(event=cleaned_data['event'],status=0, guest=self.request.user)
         obj.save()
         send_invitation_to_guest(obj)
         if self.request.is_ajax():
             delete_form = render_to_string(
                 "partial/delete_form.html",
                 {'delete_url': form.instance.delete_url()}
             )
             data = {
                 'guest': form.instance.guest.username,
                 'get_status_display' : form.instance.get_status_display(),
                 'delete_form': delete_form
             }
             return HttpResponse(
                 json.dumps(data),
                 content_type="application/json"
             )
         else:
             return HttpResponseRedirect('/calendar/%s/detail/' % form.instance.event.id)
     else:
         if request.is_ajax():
             return render(request,
                 'partial/guest_form.html',
                 { 'event': form.instance.event, 'form': form}
             )
         else:
             return render(request, 'event/detail.html', {'event': form.instance.event, 'form': form})
Esempio n. 2
0
 def post(self, request, *args, **kwargs):
     form = EventGuestForm(self.request.POST)
     if form.is_valid():
         form.save()
         if self.request.is_ajax():
             delete_form = render_to_string(
                 "partial/delete_form.html",
                 {'delete_url': form.instance.delete_url()})
             data = {
                 'guest': form.instance.guest.username,
                 'get_status_display': form.instance.get_status_display(),
                 'delete_form': delete_form
             }
             return HttpResponse(json.dumps(data),
                                 content_type="application/json")
         else:
             return HttpResponseRedirect('/calendar/%s/detail/' %
                                         form.instance.event.id)
     else:
         if request.is_ajax():
             return render(request, 'partial/guest_form.html', {
                 'event': form.instance.event,
                 'form': form
             })
         else:
             return render(request, 'event/detail.html', {
                 'event': form.instance.event,
                 'form': form
             })
Esempio n. 3
0
def detail_event(request, id):
    event = Event.objects.get(pk=id)
    if request.method == "POST":
        form = EventGuestForm(request.POST, user=self.request.user)
        if form.is_valid():
            form.save()
            if request.is_ajax():
                delete_form = render_to_string(
                    "partial/delete_form.html",
                    {'delete_url': form.instance.delete_url()}
                )
                data = {
                    'guest': form.instance.guest.username,
                    'get_status_display' : form.instance.get_status_display(),
                    'delete_form': delete_form
                }
                return HttpResponse(
                    json.dumps(data),
                    content_type="application/json"
                )
            return HttpResponseRedirect('/calendar/%s/detail/' % id)
    else:
        form = EventGuestForm(initial={'event': event},user=self.request.user)
        guests = [user.pk for user in event.guests.all()]
        form.fields['guest'].queryset=User.objects.exclude(pk__in=guests)
        form.fields['event'].widget = HiddenInput()
    if request.is_ajax():
        render_to_response(
            'partial/guest_form.html',
            { 'event': event, 'form': form}
        )
    return render(request, 'event/detail.html', {'event': event, 'form': form})
Esempio n. 4
0
def detail_event(request, id):
    event = Event.objects.get(pk=id)
    if request.method == "POST":
        form = EventGuestForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/calendar/%s/detail/' % id)
    else:
        form = EventGuestForm(initial={'event': event})
        guests = [user.pk for user in event.guests.all()]
        form.fields['guest'].queryset = User.objects.exclude(pk__in=guests)
        form.fields['event'].widget = HiddenInput()
    return render(request, 'event/detail.html', {'event': event, 'form': form})