Beispiel #1
0
def add_event(request):
    data = {"success": False, "appointment": {}}
    if request.is_ajax() and request.method == 'POST':
        form = SimpleAppointmentForm(request.POST)
        form.fields['venue'].queryset = Venue.objects.filter(
            customer=request.user.userprofile.customer)
        if form.is_valid():
            appointment = form.add_new(request.user)
            data['success'] = True
            data['appointment'] = {
                'id': appointment.pk,
                'title': appointment.display_name,
                'userId': [appointment.venue.pk],
                'start': appointment.event.start.isoformat(),
                'end': appointment.event.end.isoformat(),
                'clientId': appointment.clientId,
                'status': appointment.status,
                'tag': getattr(appointment.tag, 'html_name', ""),
                'body': appointment.event.description
            }
    return HttpResponse(json.dumps(data), content_type="application/json")
Beispiel #2
0
def add_event(request):
    data = {
        "success": False,
        "appointment": {}
    }
    if request.is_ajax() and request.method == 'POST':
        form = SimpleAppointmentForm(request.POST)
        form.fields['venue'].queryset = Venue.objects.filter(customer=request.user.userprofile.customer)
        if form.is_valid():
            appointment = form.add_new(request.user)
            data['success'] = True
            data['appointment'] = {
                'id': appointment.pk,
                'title': appointment.display_name,
                'userId': [appointment.venue.pk],
                'start': appointment.event.start.isoformat(),
                'end': appointment.event.end.isoformat(),
                'clientId': appointment.clientId,
                'status': appointment.status,
                'tag': getattr(appointment.tag, 'html_name', ""),
                'body': appointment.event.description
            }
    return HttpResponse(json.dumps(data), content_type="application/json")
Beispiel #3
0
 def get_context_data(self, **kwargs):
     context = super(AddAppointmentSnippetView, self).get_context_data(**kwargs)
     client_form = SelectClientForm()
     client_form.fields['client'].queryset = Client.objects.filter(
         customer=self.request.user.userprofile.customer)
     context['SelectClientForm'] = client_form
     context['AddClientForm'] = AddClientForm()
     context['add_client_helper'] = add_client_helper
     context['GenericEventForm'] = GenericEventForm()
     appointment_form = SimpleAppointmentForm()
     context['AppointmentForm'] = appointment_form
     # set initial data based on GET parameters to facilitate new advert creation
     appointment_form.fields['start_datetime'].initial = self.request.GET.get('start', "")
     appointment_form.fields['end_datetime'].initial = self.request.GET.get('end', "")
     appointment_form.fields['venue_id'].initial = self.request.GET.get('venue_id', "")
     context['AppointmentFormHelper'] = hidden_appointment_form_helper
     return context
Beispiel #4
0
def edit_event(request, pk):
    appointment = get_object_or_404(Appointment, pk=pk)
    success = False
    if request.user.userprofile.customer != appointment.customer:
        return False
    if request.is_ajax() and request.method == 'POST':
        if request.POST.get('client'):
            form = SimpleAppointmentForm(request.POST)
            form.fields['venue'].queryset = Venue.objects.filter(
                customer=request.user.userprofile.customer)
            if form.is_valid():
                success = form.save_edit()
        else:
            form = SimpleGenericEventForm(request.POST or None)
            if form.is_valid():
                success = form.save_edit()
    return HttpResponse(json.dumps(success), content_type="application/json")
Beispiel #5
0
def edit_event(request, pk):
    appointment = get_object_or_404(Appointment, pk=pk)
    success = False
    if request.user.userprofile.customer != appointment.customer:
        return False
    if request.is_ajax() and request.method == 'POST':
        if request.POST.get('client'):
            form = SimpleAppointmentForm(request.POST)
            form.fields['venue'].queryset = Venue.objects.filter(customer=request.user.userprofile.customer)
            if form.is_valid():
                success = form.save_edit()
        else:
            form = SimpleGenericEventForm(request.POST or None)
            if form.is_valid():
                success = form.save_edit()
    return HttpResponse(json.dumps(success), content_type="application/json")