def get(self, request, store_name): store = StoreManagement.check_store_by_name(store_name) if store is None: raise Http404() service = self.service_class(request, store) data_report = service.get_data_aggregations() return JsonResponse(data=data_report, status=200)
def check_store_name(request, store_name): if StoreManagement.check_store_by_name(store_name): response = { "status": "success", "url": reverse("core:login"), "store_name": store_name } else: response = {"status": "failed", "msg": "Cửa hàng không tồn tại"} return JsonResponse(data=response, status=200)
def get(self, request): """ Show login view. Change action in core/login.html rely on 'next' context """ redirect_to = request.GET.get('next', '') try: store_name = redirect_to.split('/')[1] except IndexError: raise Http404("Cửa hàng không xác dịnh") if StoreManagement.check_store_by_name(store_name): redirect_to = request.GET.get('next', '') context = {'next': redirect_to, 'store_name': store_name} return render(request, template_name='core/login.html', context=context) else: raise Http404("Không tìm thấy trang")
def post(self, request): """ Authenticate username and password. Redirect to other view if url has <QueryDict: {'next': ['...']}> """ store_name = request.POST['storeName'] store = StoreManagement.check_store_by_name(store_name) if store is None: raise Http404("Không tin thấy trang") error_msg = '' redirect_to = '' try: username = request.POST['username'] password = request.POST['password'] user = user_authentication(username=username, password=password, store=store) login(request, user) if request.GET: redirect_to = request.GET.get('next', '') if redirect_to: return HttpResponseRedirect(redirect_to=redirect_to) else: return HttpResponseRedirect( reverse("core:dashboard", args=[store_name])) except MultiValueDictKeyError as e: error_msg = str(e) except AccountNotExistsError as e: error_msg = str(e) except AccountIsBlockedError as e: error_msg = str(e) context = { 'error_msg': error_msg, 'username': username, 'next': redirect_to, 'store_name': store_name } return render(request, template_name='core/login.html', context=context)