def get(request, qry_type): resp = Response() contents = get_contents(request) if contents: qry_id = contents.get('id', None) qry_email = contents.get('email', None) try: accnt = None if qry_type == 'id': accnt = AccountProfile.objects.get(id=qry_id) elif qry_type == 'email': accnt = AccountProfile.objects.get(company_email__icontains=qry_email) a_obj = {'id': accnt.id, 'name': accnt.name, 'email': accnt.company_email, 'mobile': str(accnt.company_phone), 'address_info': accnt.company_address.address_info, 'country': accnt.company_address.country.name, 'city': accnt.company_address.city.name} resp.passed() resp.add_param('result', a_obj) except AccountProfile.DoesNotExist: resp.failed() resp.add_message('AccountProfile with ID/Email does not exist') except AccountProfile.MultipleObjectsReturned: resp.failed() resp.add_message('Multiple AccountProfiles matches the Id/Email') return HttpResponse(resp.get_response(), content_type="application/json")
def get(request): resp = Response() contents = get_contents(request) if contents: acct_id = contents.get('id', None) acct_email = contents.get('email', None) try: if acct_id: AccountProfile.objects.get(id=acct_id) resp.passed() resp.add_param('result', True) elif acct_email: AccountProfile.objects.get(company_email__icontains=acct_email) resp.passed() resp.add_param('result', True) except AccountProfile.DoesNotExist: resp.passed() resp.add_param('result', False) except AccountProfile.MultipleObjectsReturned: resp.passed() resp.add_param('result', False) else: resp.failed() resp.add_message('Missing parameters!') return HttpResponse(resp.get_response(), content_type="application/json")
def get(request): resp = Response() country_code = request.GET.get('country_id', None) try: fetch_country_cities(country_code, resp) resp.passed() except Exception as err: resp.failed() resp.add_message(str(err)) return HttpResponse(resp.get_response(), content_type="application/json")
def post(request): resp = Response() contents = get_contents(request) enquiry_form = SiteEnquiryForm(contents) if enquiry_form.is_valid(): enquiry_form.save() resp.passed() resp.add_message("Thank you. We received your enquiry and we'll get in touch soonest.") else: resp.failed() resp.add_param('errors', compile_form_errors(enquiry_form)) return HttpResponse(resp.get_response(), content_type="application/json")
def post(self, request, **kwargs): customer_type = kwargs.get('account_type', None) contents = get_contents(request) resp = Response() if contents: _pageSize = contents.get('pageSize', 10) _pageIndex = contents.get('pageIndex', 1) _filter = contents.get('filters', []) _sort = contents.get('sort', None) kwargs = build_query_filter(_filter) pager = build_pagination_markers(_pageIndex, _pageSize) # Run Query accounts = None if customer_type == 'pod': kwargs['account_type__name__iexact'] = 'pod' elif customer_type == 'streamz': kwargs['account_type__name__iexact'] = 'streamz' result_size = AccountProfile.objects.filter(**kwargs).count() results = AccountProfile.objects.filter(**kwargs)[pager['lm']:pager['um']] try: accounts = [{'id': x.id, 'name': x.name, 'account_code': x.account_code, 'company_email': x.company_email, 'account_officer': {'id': x.account_officer.id, 'label': x.account_officer.name} if x.account_officer is not None else {'id': "",'label': ""}, 'industry': {'id': x.industry.id, 'label': x.industry.name}, 'company_address': {'address_info': x.company_address.address_info, 'city': {'id': x.company_address.city.id, 'label': x.company_address.city.name}, 'country': {'id': x.company_address.country.id, 'label': x.company_address.country.name} }, 'company_phone': {'country_code': x.company_phone.country_code, 'phone_number': x.company_phone.phone_number}, 'contact_person': {'first_name': x.contact_person.first_name, 'last_name': x.contact_person.last_name}} for x in results] resp.passed() resp.add_param('result', accounts) resp.add_param('result_size', result_size) except Exception as err: resp.failed() resp.add_message(str(err)) return HttpResponse(resp.get_response(), content_type="application/json")
def get(request): resp = Response() country_code = request.GET.get('location', None) if not country_code: ip_addr = request.META.get('REMOTE_ADDR') locale_data = fetch_locale_data(ip_addr) country_code = locale_data.get('country') try: compose_account_creation_params(country_code, resp) resp.passed() except Exception as err: resp.failed() resp.add_message(str(err)) return HttpResponse(resp.get_response(), content_type="application/json")
def get(request): resp = Response() contents = get_contents(request) if contents: search_string = contents.get('pattern', None) if search_string: try: results = AccountProfile.objects.filter(name__icontains=search_string, active=True).order_by('id')\ .values('id', 'name', 'account_code', 'account_address') matches = [x for x in results] resp.passed() resp.add_param('matches', matches) except Exception as err: resp.failed() resp.add_message(str(err)) else: resp.failed() resp.add_message('Missing request parameters.') return HttpResponse(resp.get_response(), content_type="application/json")
def post(self, request): resp = Response() email = request.data.get('email', None) valid_email = SubscriberInput(data={'email': email}) if valid_email.is_valid(): try: subscriber = NewsLetterSubscribers.objects.create(email=email) serializer = SubscriberSerializer(instance=subscriber) resp.data = serializer.data resp.add_message('Successs') resp.passed() return HttpResponse(resp.get_response(), content_type='application/json') except Exception as err: resp.add_message('Email already exists') resp.failed() return HttpResponse(resp.get_response(), content_type='application/json') else: resp.add_message('Invalid Email') resp.failed() return HttpResponse(resp.get_response(), content_type='application/json')