def remove_temp_applications_for_user(user): if is_customer(user): Application.objects.filter(applicant=user, customer_status='temp').delete() elif is_officer(user): Application.objects.filter(proxy_applicant=user, customer_status='temp').delete()
def get_context_data(self, **kwargs): try: application = utils.get_session_application(self.request.session) except Exception as e: messages.error(self.request, e.message) return redirect("wl_applications:new_application") kwargs["is_payment_required"] = ( not is_licence_free(generate_product_code(application)) and not application.invoice_reference and is_customer(self.request.user) ) if application.data: utils.convert_documents_to_url(application.data, application.documents.all(), "") if application.hard_copy is not None: application.licence_type.application_schema, application.data = utils.append_app_document_to_schema_data( application.licence_type.application_schema, application.data, application.hard_copy.file.url ) else: kwargs["data"] = application.data kwargs["application"] = application return super(PreviewView, self).get_context_data(**kwargs)
def setUp(self): self.customer = helpers.get_or_create_default_customer() self.assertTrue(is_customer(self.customer)) self.officer = helpers.get_or_create_default_officer() self.assertTrue(is_officer(self.officer)) self.assessor = helpers.get_or_create_default_assessor() self.assertTrue(is_assessor(self.assessor)) self.client = helpers.SocialClient()
def create_random_customer(self): user = create_random_customer() self.assertIsNotNone(user) self.assertTrue(isinstance(user, EmailUser)) self.assertEqual(TestData.DEFAULT_CUSTOMER['email'], user.email) self.assertTrue(accounts_helpers.is_customer(user)) # test that we can login self.client.login(user.email) is_client_authenticated(self.client)
def get(self, request, *args, **kwargs): delete_app_session_data(request.session) set_app_session_data(request.session, 'temp_files_dir', tempfile.mkdtemp(dir=settings.MEDIA_ROOT)) if is_customer(request.user): set_app_session_data(request.session, 'customer_pk', request.user.pk) return redirect('applications:select_licence_type', *args, **kwargs) else: return redirect('applications:create_select_customer')
def test_func(self): """ implementation of the UserPassesTestMixin test_func """ user = self.request.user if not user.is_authenticated(): self.raise_exception = False return False self.raise_exception = True if is_customer(user) or is_officer(user): return False assessment = self.get_assessment() return assessment is not None and assessment.assessor_group in get_user_assessor_groups(user)
def test_func(self): """ implementation of the UserPassesTestMixin test_func """ user = self.request.user if not user.is_authenticated(): self.raise_exception = False return False self.raise_exception = True if is_customer(user) or is_officer(user): return False assessment = self.get_assessment() return assessment is not None and assessment.assessor_group in get_user_assessor_groups( user)
def get(self, request, *args, **kwargs): try: utils.delete_app_session_data(request.session) except Exception as e: messages.warning(request, 'There was a problem deleting session data: %s' % e) utils.set_app_session_data(request.session, 'temp_files_dir', tempfile.mkdtemp(dir=settings.MEDIA_ROOT)) if is_customer(request.user): utils.set_app_session_data(request.session, 'customer_pk', request.user.pk) return redirect('wl_applications:select_licence_type', *args, **kwargs) else: return redirect('wl_applications:create_select_customer')
def get(self, request, *args, **kwargs): utils.remove_temp_applications_for_user(request.user) application = Application.objects.create() utils.set_session_application(request.session, application) if is_customer(request.user): application.applicant = request.user application.save() return redirect('wl_applications:select_licence_type', *args, **kwargs) else: application.proxy_applicant = request.user application.save() return redirect('wl_applications:create_select_customer')
def get_context_data(self, **kwargs): application = utils.get_session_application(self.request.session) kwargs['is_payment_required'] = not is_licence_free(generate_product_title(application)) and \ not application.invoice_reference and is_customer(self.request.user) if application.data: utils.convert_documents_to_url(application.data, application.documents.all(), '') if application.hard_copy is not None: application.licence_type.application_schema, application.data = utils.\ append_app_document_to_schema_data(application.licence_type.application_schema, application.data, application.hard_copy.file.url) else: kwargs['data'] = application.data kwargs['application'] = application return super(PreviewView, self).get_context_data(**kwargs)
def test_func(self): return is_customer(self.request.user)
def is_customer(user): return helpers.is_customer(user)
def test_func(self): user = self.request.user return is_officer(user) or is_customer(user)
def remove_temp_applications_for_user(user): if is_customer(user): Application.objects.filter(applicant=user, customer_status="temp").delete() elif is_officer(user): Application.objects.filter(proxy_applicant=user, customer_status="temp").delete()