def process_add_client_form(request): form = AddClientForm(request.POST or None) if form.is_valid(): client = form.create_client(request.user) return {'success': True, 'client_id': client.id} form_html = render_crispy_form(form, helper=add_client_form_modal_helper) return {'success': False, 'form_html': form_html}
def process_edit_client_form(request, pk): client = get_object_or_404(Client, pk=pk) form = AddClientForm(request.POST or None, instance=client) if form.is_valid( ) and request.user.userprofile.customer == client.customer: form.save() return {'success': True, 'client_id': client.id} form_html = render_crispy_form(form, helper=edit_client_form_modal_helper) return {'success': False, 'form_html': form_html}
def process_add_client_form(request): form = AddClientForm(request.POST or None) if form.is_valid(): client = form.create_client(request.user) return { 'success': True, 'client_id': client.id } form_html = render_crispy_form(form, helper=add_client_form_modal_helper) return {'success': False, 'form_html': form_html}
def process_edit_client_form(request, pk): client = get_object_or_404(Client, pk=pk) form = AddClientForm(request.POST or None, instance=client) if form.is_valid() and request.user.userprofile.customer == client.customer: form.save() return { 'success': True, 'client_id': client.id } form_html = render_crispy_form(form, helper=edit_client_form_modal_helper) return {'success': False, 'form_html': form_html}
def get_context_data(self, **kwargs): context = super(AddEventView, 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() appointment_form = AppointmentForm() appointment_form.fields['venue'].queryset = Venue.objects.filter( customer=self.request.user.userprofile.customer) context['AppointmentForm'] = appointment_form return context
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
def get_context_data(self, **kwargs): context = super(AppointmentSnippetView, self).get_context_data(**kwargs) edit_client_form = AddClientForm(instance=self.get_object().client) context['edit_client_form'] = edit_client_form context['edit_client_helper'] = edit_client_helper event_info_form = EventInfoForm(instance=self.get_object().event) if event_info_form.fields.get('tag'): event_info_form.fields['tag'].queryset = Tag.objects.filter( customer=self.request.user.userprofile.customer) if self.object.customer.use_tags: event_info_form.fields['tag'].initial = self.object.tag else: del event_info_form.fields['tag'] context['event_info_form'] = event_info_form # generic event generic_event_form = GenericEventForm(instance=self.get_object().event) generic_event_form.fields['start_datetime'].initial = self.get_object().event.start generic_event_form.fields['end_datetime'].initial = self.get_object().event.end generic_event_form.fields['venue_id'].initial = self.get_object().venue.id generic_event_form.fields['appointment_id'].initial = self.get_object().id context['generic_event_form'] = generic_event_form context['edit_generic_event_form_helper'] = edit_generic_event_form_helper context['object'] = self.object return context