def get_context_data(self, **kwargs): form_config = FORMS_BY_SLUG.get(self.object.version_verbose) kwargs.update({ 'form_config': form_config, }) return super().get_context_data(**kwargs)
def get_context_data(self, **kwargs): kwargs.update(self.kwargs) form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) if not form_config: raise Http404 kwargs.update(form_config) federation_type = form_config.get('federation_type') federation = self.get_federation() recipient_list = self.get_recipient_list() kwargs.update({ 'federation_type': federation_type, 'form_config': form_config, 'federation': federation, 'recipient_list': recipient_list, 'object': self.object, 'document_list': Document.objects.filter( case=self.object, forms__contains=self.kwargs.get('form_config_slug')), })
def form_organization_type_abbreviation(form): organization = Organization.objects.filter( federation_type=FORMS_BY_SLUG.get( form, {}).get('federation_type'), ).first() if organization: return organization.abbreviation return None
def get_federation(self): form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) federation_type = form_config.get('federation_type') federation = Federation.objects.filter( organization__federation_type=federation_type).first() if federation_type == FEDERATION_TYPE_WONINGCORPORATIE and self.object.woningcorporatie: federation = self.object.woningcorporatie return federation
def clean_form(self): form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) form_fields = get_sections_fields(form_config.get('sections', {})) for f in form_fields: if hasattr(self.object, f): setattr(self.object, f, None) self.object.save() return True
def get_success_url(self): form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug'), {}) if not form_config.get('enable_ajax', False): return reverse('case', kwargs={'pk': self.object.id}) return reverse('update_case', kwargs={ 'pk': self.object.id, 'form_config_slug': self.kwargs.get('form_config_slug') })
def get_recipient_list(self): form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) federation_type = form_config.get('federation_type') recipient_list = get_zorginstelling_medewerkers_email_list(self.object) if federation_type == FEDERATION_TYPE_ADW: recipient_list += get_wonen_medewerkers_email_list() elif federation_type == FEDERATION_TYPE_WONINGCORPORATIE: recipient_list += get_woningcorporatie_medewerkers_email_list( self.object) recipient_list = list(set(recipient_list)) return recipient_list
def get_context_data(self, **kwargs): kwargs = super().get_context_data(**kwargs) kwargs.update({ 'form_config': FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')), 'case_status': CaseStatus.objects.filter( case=self.object, form=self.kwargs.get( 'form_config_slug')).order_by('-created').first(), }) return kwargs
def get(self, request, *args, **kwargs): response = super().get(request, *args, **kwargs) if FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')).get( 'options', {}).get('addres_required') and not self.object.address_complete: return redirect('%s%s' % ( reverse('create_case_address', args=[self.object.id]), '?next=%s' % reverse( 'update_case', args=[self.object.id, self.kwargs.get('form_config_slug')]), )) return response
def get_context_data(self, **kwargs): kwargs.update(self.kwargs) form_context = FORMS_BY_SLUG.get(self.kwargs.get('slug')) if not form_context: raise Http404 kwargs.update(form_context) kwargs.update({ 'organization_list': Organization.objects.filter(main_email__isnull=False), 'object': self.object, }) return super().get_context_data(**kwargs)
def create(self, request, *args, **kwargs): data = {'profile': request.user.profile.id} data.update(request.data) if data.get('status') != CASE_STATUS_INGEDIEND: data.update({ 'case_version': Case.objects.get(id=data.get('case')).create_version( data.get('form')).id, }) serializer = self.get_serializer(data=data) serializer.is_valid(raise_exception=True) self.perform_create(serializer) if serializer.instance.status != CASE_STATUS_INGEDIEND: current_site = get_current_site(request) form_config = FORMS_BY_SLUG.get(serializer.instance.form) body = render_to_string( 'cases/mail/case_status_to_pb.txt', { 'case_status': serializer.instance, 'form_name': form_config.get('title'), 'case_form_url': 'https://%s%s' % (current_site.domain, reverse('update_case', kwargs={ 'pk': serializer.instance.case.id, 'form_config_slug': serializer.instance.form, })), }) email_adresses = get_zorginstelling_medewerkers_email_list( serializer.instance.case) if settings.SENDGRID_KEY and email_adresses: sg = sendgrid.SendGridAPIClient(settings.SENDGRID_KEY) email = Mail( from_email='noreply@%s' % current_site.domain, to_emails=email_adresses, subject='Omslagroute - %s, status: %s' % ( form_config.get('title'), CASE_STATUS_DICT.get( serializer.instance.status).get('current'), ), plain_text_content=body) sg.send(email) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def get_context_data(self, **kwargs): kwargs = super().get_context_data(**kwargs) form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) kwargs.update({ 'case_versions': self.object.get_history(form_config), 'case_status_list': CaseStatus.objects.filter( case=self.object, form=self.kwargs.get('form_config_slug')).order_by('-created') }) return kwargs
def form_valid(self, form): form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) version = self.object.create_version( self.kwargs.get('form_config_slug')) case_status_dict = { 'form': self.kwargs.get('form_config_slug'), 'case': self.object, 'case_version': version, 'profile': self.request.user.profile, } case_status = CaseStatus(**case_status_dict) case_status.save() recipient_list = self.get_recipient_list() federation = self.get_federation() if recipient_list: current_site = get_current_site(self.request) body = render_to_string( 'cases/mail/case_link.txt', { 'form_name': form_config.get('title'), 'case_url': 'https://%s%s' % (current_site.domain, reverse('case_version_form', kwargs={ 'pk': self.object.id, 'form_config_slug': self.kwargs.get('form_config_slug'), })), 'user': self.request.user, }) if settings.SENDGRID_KEY: sg = sendgrid.SendGridAPIClient(settings.SENDGRID_KEY) email = Mail(from_email='noreply@%s' % current_site.domain, to_emails=recipient_list, subject='Omslagroute - %s' % form_config.get('title'), plain_text_content=body) sg.send(email) messages.add_message( self.request, messages.INFO, "De aanvraag is ingediend bij en vanaf nu zichtbaar voor medewerkers van '%s'." % (federation.name, )) return super().form_valid(form)
class Organization(models.Model): name = models.CharField( verbose_name=_('Naam'), max_length=100 ) name_abbreviation = models.CharField( verbose_name=_('Naam afkorting'), max_length=4, blank=True, null=True, ) federation_type = models.PositiveIntegerField( verbose_name=('Federatie type'), choices=FEDERATION_TYPE_CHOICES, blank=True, null=True, ) main_email = models.EmailField( verbose_name=('Standaard e-mailadres'), max_length=100, blank=True, null=True, ) field_restrictions = MultiSelectField( verbose_name=_('Cliƫnt gegevens velden'), help_text=_('De inhoud van een geselecteerd veld wordt zichtbaar voor deze organisatie.'), choices=get_fields(), blank=True, null=True, ) rol_restrictions = MultiSelectField( verbose_name=_('Rol opties voor federatie beheerder'), choices=User.user_types, blank=True, null=True, ) def get_case_data(self, case): return case.to_dict(self.field_restrictions) def get_case_form_data(self, case, form): if self.federation_type == FEDERATION_TYPE_ZORGINSTELLING: return case.to_dict() form_sections = FORMS_BY_SLUG.get(form, {}).get('sections', []) fields = [f for f in self.field_restrictions if f in get_sections_fields(form_sections)] return case.to_dict(fields)
def get_success_url(self): next = self.request.POST.get('next') default_url = reverse('update_case', kwargs={ 'pk': self.object.id, 'form_config_slug': self.kwargs.get('form_config_slug') }) percentage = self.object.status( FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug'), {}).get('sections')).get('percentage') if percentage < 100 and next: return '%s?control=1' % default_url if next: return next return default_url
def get_context_data(self, **kwargs): form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) kwargs.update({ 'form_fields': get_sections_fields(form_config.get('sections')), 'form_config': form_config, 'user_list': ', '.join(get_zorginstelling_medewerkers_email_list(self.object)), 'document_list': self.object.document_set.filter( forms__contains=self.kwargs.get('form_config_slug')), 'status_options': json.dumps( dict((k, v) for k, v in CASE_STATUS_DICT.items() if k in CASE_STATUS_CHOICES_BY_FEDEATION_TYPE.get( self.request.user.federation.organization. federation_type))), }) return super().get_context_data(**kwargs)
def get_redirect_url(self, *args, **kwargs): self.object = get_object_or_404(self.model, pk=kwargs['pk']) form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) redirect_url = reverse('case', args=[ self.object.id, ]) recipient_list = self.request.user.federation.main_email_list current_site = get_current_site(self.request) body = render_to_string( 'cases/mail/validate_case.txt', { 'form_name': form_config.get('title'), 'case_url': 'https://%s%s' % ( current_site.domain, reverse('update_case', args=[ self.object.id, self.kwargs.get('form_config_slug'), ]), ), 'user': self.request.user, }) if settings.SENDGRID_KEY and recipient_list: sg = sendgrid.SendGridAPIClient(settings.SENDGRID_KEY) email = Mail(from_email='noreply@%s' % current_site.domain, to_emails=recipient_list, subject='Omslagroute - %s controleren' % form_config.get('title'), plain_text_content=body) sg.send(email) messages.add_message( self.request, messages.INFO, "De aanvraag is ter controle gestuurd naar '%s'." % (self.request.user.federation.name_form_validation_team if self.request.user.federation.name_form_validation_team else self.request.user.federation.name, )) return redirect_url
def client_status(client, form_key, *args, **kwargs): if not FORMS_BY_SLUG.get(form_key): return {} return client.status(FORMS_BY_SLUG.get(form_key).get('sections', []))
def form_verbose(form): return FORMS_BY_SLUG.get(form, {}).get('title')
def form_federation_type(form): return FORMS_BY_SLUG.get(form, {}).get('federation_type')
def form_list_versions(form): return FORMS_BY_SLUG.get(form, {}).get('list_versions')
def get_fields(self): form_config = FORMS_BY_SLUG.get(self.kwargs.get('form_config_slug')) return get_sections_fields(form_config.get('sections')),
return FORMS_BY_SLUG.get(form, {}).get('list_versions') @register.filter() def form_organization_type_abbreviation(form): organization = Organization.objects.filter( federation_type=FORMS_BY_SLUG.get( form, {}).get('federation_type'), ).first() if organization: return organization.abbreviation return None @register.simple_tag() def woningcorporatie_federation(case, form): ft = FORMS_BY_SLUG.get(form, {}).get('federation_type') if ft == FEDERATION_TYPE_WONINGCORPORATIE and case.woningcorporatie: return case.woningcorporatie return None @register.simple_tag() def form_federation(case, form): ft = FORMS_BY_SLUG.get(form, {}).get('federation_type') federation = Federation.objects.filter( organization__federation_type=ft, ).first() if ft == FEDERATION_TYPE_WONINGCORPORATIE and case.woningcorporatie: return case.woningcorporatie elif ft == FEDERATION_TYPE_ADW and federation: return federation return None