def logout_dealer(request): try: view_logger = log_rotator.view_logger() if request.method == 'POST': view_logger.debug("Logout request for %s through POST method"%request.user) logout(request) result = {"status": "success", "msg": "User is valid, active and authenticated"} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json") elif request.method == 'GET': view_logger.debug("Logout request for %s through GET method"%request.user) logout(request) return redirect('/dealer/login/') else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def fetch_scheduled_maintenance(request): try: view_logger = log_rotator.view_logger() if request.method == 'POST': data = request.POST brand = data.get('brand', 'NA') model = data.get('model', 'NA') fuel_type = data.get('fuel_type', 'NA') km_ticked = int(data.get('km_ticked', '0')) view_logger.debug("JOBCARD VIEW : Fetch sch maint Request - brand: %s, model: %s, fuel_type: %s, km_ticked: %s"%(brand, model, fuel_type, km_ticked)) result = util.fetchScheduledServices(brand, model, fuel_type, km_ticked) else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} view_logger.debug("JOBCARD VIEW : Fetch sch maint Response - %s"%str(result)) return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def estimate_parts(request): try: view_logger = log_rotator.view_logger() if request.method == 'POST': if not request.user.is_authenticated(): result = {"status": "failure", "msg" : "Invalid session"} else: data = request.POST parts = data.get('parts', 'NA') dealerid = request.user view_logger.debug("JOBCARD VIEW : Estimate parts request - parts: %s, dealerid: %s"%(str(parts), dealerid)) result = util.getEstimate(parts, dealerid) else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} view_logger.debug("JOBCARD VIEW : Estimate parts response - %s"%str(result)) return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def get_jobcards_list(request): try: view_logger = log_rotator.view_logger() view_logger.debug("JOBCARD VIEW : Get Job card request detail %s"%str(request.session.get('user'))) view_logger.debug("JOBCARD VIEW : Get Job card request detail %s"%str(request)) if request.method == 'POST': view_logger.debug("JOBCARD VIEW : Get Job card list request for %s"%str(request.user)) view_logger.debug("JOBCARD VIEW : Get Job card list request for %s"%str(request.user.is_authenticated())) if request.user.is_authenticated(): result = {"status": "success", "data": util.getJobCardsList(request.user)} else: result = {"status": "unauthorized", "msg": "Not authorized."} else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} view_logger.debug("JOBCARD VIEW : Get Job card list response - %s"%str(result)) return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def fetch_job_card(request): try: view_logger = log_rotator.view_logger() view_logger.debug("JOBCARD GET REQQ : Fetch job card request details: %s :"%(request)) if request.method == 'POST': if request.user.is_authenticated(): data = request.POST jc_id = data.get('jc_id', 'NA') dealerid = request.user view_logger.debug("JOBCARD VIEW : Fetch job card request for jobcard: %s dealerid : %s"%(jc_id, dealerid)) result = util.getJobCard(jc_id, dealerid) else: result = {"status": "failure", "msg" : "Invalid session"} else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} view_logger.debug("JOBCARD VIEW : Fetch job card response - %s"%str(result)) return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def generate_invoice(request): try: view_logger = log_rotator.view_logger() if request.method == 'GET': view_logger.debug("DEALER VIEW : Invoice page request for %s through GET method"%request.user) if not request.user.is_authenticated(): view_logger.debug("DEALER VIEW : Redirected %s to login from Invoice page"%request.user) return redirect('/dealer/login/') t = get_template('generateinvoice.html') context_dictionary = {'jobcards' : util.getJobCardsList(request.user, for_invoice=True)} context_dictionary['user'] = request.user html = t.render(context_dictionary) view_logger.debug("DEALER VIEW : Rendered Invoice page for : %s with context : %s"%(request.user, str(context_dictionary))) return HttpResponse(html) else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def update_inventory(request): try: view_logger = log_rotator.view_logger() if request.method == 'GET': view_logger.debug("DEALER VIEW : Update inventory request for %s through GET method"%request.user) if not request.user.is_authenticated(): view_logger.debug("DEALER VIEW : Redirected %s to login from update inventory"%request.user) return redirect('/dealer/login/') t = get_template('updateinventory.html') identifier = request.GET['identifier'] context_dictionary = util.getInventoryData(identifier, request.user) context_dictionary['user'] = request.user html = t.render(context_dictionary) view_logger.debug("DEALER VIEW : Rendered Update Inventory page for : %s with context : %s"%(request.user, str(context_dictionary))) return HttpResponse(html) else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def get_service_history(request): try: view_logger = log_rotator.view_logger() view_logger.debug("SERVICE HISTORY details: %s :"%(request)) if request.method == 'GET': view_logger.debug("DEALER VIEW : Service history request for %s"%request.user) if not request.user.is_authenticated(): view_logger.debug("DEALER VIEW : Redirected %s to login from service history"%request.user) return redirect('/dealer/login/') t = get_template('servicehistory.html') #util.fetchServiceHistory(veh_num, c_num) #context_dictionary['user'] = request.user html = t.render({'user': request.user}) view_logger.debug("DEALER VIEW : Rendered service history for : %s"%request.user) return HttpResponse(html) else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def jobcard_edit(request): try: view_logger = log_rotator.view_logger() if request.method == 'GET': view_logger.debug("DEALER VIEW : Edit job card request for %s through GET method"%request.user) if not request.user.is_authenticated(): view_logger.debug("DEALER VIEW : Redirected %s to login from Edit job card"%request.user) return redirect('/dealer/login/') t = get_template('editjobcard.html') jc_id = request.GET['jc'] view_logger.debug("DEALER VIEW : Dealer id: %s Job card id: %s"%(request.user, jc_id)) user_agent = "all" user_agent=request.META.get("HTTP_USER_AGENT") view_logger.debug("USER AGENT : %s"%user_agent) if "Android" in user_agent: user_agent = "android" context_dictionary_data = util.getJobCard(jc_id, request.user) context_dictionary = context_dictionary_data['jobcard_details'] context_dictionary['user'] = request.user context_dictionary['user_agent'] = user_agent context_dictionary['serviceTypes'] = global_constants.service_types_dropdown service_type = context_dictionary['service_type'] context_dictionary['service_type_list'] = (service_type.split(' - ')) print(context_dictionary) html = t.render(context_dictionary) view_logger.debug("DEALER VIEW : Rendered Edit Job card page for : %s with context : %s"%(request.user, str(context_dictionary))) return HttpResponse(html) else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def jobcard_home(request): try: view_logger = log_rotator.view_logger() if request.method == 'GET': view_logger.debug("DEALER VIEW : Job card home request for %s through GET method"%request.user) if not request.user.is_authenticated(): view_logger.debug("DEALER VIEW : Redirected %s to login from Job card home"%request.user) return redirect('/dealer/login/') user_agent = "all" user_agent=request.META.get("HTTP_USER_AGENT") view_logger.debug("USER AGENT : %s"%user_agent) if "Android" in user_agent: user_agent = "android" t = get_template('jobcardhome.html') html = t.render({'user': request.user,'user_agent': user_agent}) view_logger.debug("DEALER VIEW : Rendered Get Job card page for : %s"%request.user) return HttpResponse(html) else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def login_dealer(request): """ @summary: View method to check the server status. @param request: HttpRequest. @rtype: HttpResponse @return: HttpResponse containing server status. """ try: view_logger = log_rotator.view_logger() if request.method == 'POST': data = request.POST username = data.get('user', 'NA') passwd = data.get('passwd', 'NA') view_logger.debug("Dealer login request for : %s"%username) # check if user is valid and activated. try: user_obj = User.objects.get(username=username) if user_obj.is_active != 1: return HttpResponse(json.dumps( {"status": "failure", "msg": global_constants.ResponseMessages.LOGIN_VERIFICATION}, default=json_default ), content_type="application/json" ) except User.DoesNotExist: return HttpResponse(json.dumps( {"status": "failure", "msg": "The username and password were incorrect."}, default=json_default ), content_type="application/json" ) user = authenticate(username=username, password=passwd) if user is not None: # the password verified for the user if user.is_active: login(request, user) request.session.__setitem__('user', username) result = {"status": "success", "url": "/dealer/home/"} else: result = {"status": "failure", "msg": "The password is valid, but the account has been disabled!"} else: # the authentication system was unable to verify the username and password result = {"status": "failure", "msg": "The username and password were incorrect."} view_logger.debug("Dealer login response for %s : %s"%(username, str(result))) # save ServiceCenterID to session try: sc_obj = ServiceCenterInfo.objects.get(USER=user_obj) request.session['service_center_id'] = sc_obj.ServiceCenterID except ServiceCenterInfo.DoesNotExist: request.session['service_center_id'] = None return HttpResponse(json.dumps(result, default=json_default), content_type="application/json") elif request.method == 'GET': view_logger.debug("Dealer login GET request for : %s"%request.user) if request.user.is_authenticated(): view_logger.debug("%s already logged in. Redirecting to home page."%request.user) return redirect('/dealer/home/') t = get_template('dealerlogin.html') html = t.render({}) view_logger.debug("Rendered login page.") return HttpResponse(html) else: result = {'status': 'error', 'msg': 'Invalid Request method.'} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json") except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {'status': 'error', 'msg': 'Something went wrong.'} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")
def save_job_card(request): # if not request.user.is_authenticated(): # return Response({"status": "failure", "msg" : "Invalid session"}, status=status_code.HTTP_423_LOCKED) # view_logger = log_rotator.view_logger() # jc_form = forms.SaveJcForm(request.data) # if not jc_form.is_valid(): # return Response({'status': "failure", 'errors': jc_form.errors, "msg": "Parameters Missing."}, status=status_code.HTTP_400_BAD_REQUEST) # is_valid, message = util.vehicle_number_check(jc_form.cleaned_data['veh_num']) # if not is_valid: # return Response({'status': "failure", "msg": message}, # status=status_code.HTTP_400_BAD_REQUEST # ) # try: # result = util.saveJobCard( # { # 'jc_id': jc_form.cleaned_data['jc_id'], # 'veh_num': jc_form.cleaned_data['veh_num'], # 'brand': jc_form.cleaned_data['brand'], # 'model': jc_form.cleaned_data['model'], # 'fuel_type': jc_form.cleaned_data['fuel_type'], # 'c_num': jc_form.cleaned_data['c_num'], # 'cust_name': jc_form.cleaned_data['cust_name'], # 'cont_num': jc_form.cleaned_data['cont_num'], # 'cont_address': jc_form.cleaned_data['cont_address'], # 'km_ticked': jc_form.cleaned_data['km_ticked'], # 'service_reminder_time': jc_form.cleaned_data['service_reminder_time'], # 'del_time': jc_form.cleaned_data['del_time'], # 'status': jc_form.cleaned_data['status'], # 'reason': jc_form.cleaned_data['reason'], # 'mechanic_name': jc_form.cleaned_data['mechanic_name'], # 'services': jc_form.cleaned_data['services'], # 'spares': jc_form.cleaned_data['spares'], # 'otherparts_desc': jc_form.cleaned_data['otherparts_desc'], # 'otherparts_cost': jc_form.cleaned_data['otherparts_cost'], # 'recommendedservices': jc_form.cleaned_data['recommendedservices'], # 'labour_cost': jc_form.cleaned_data['labour_cost'], # 'service_type_id': jc_form.cleaned_data['service_type_id'] # }, # request.user # ) # result['url'] = '/jobcard/' # except: # view_logger.exception("JOBCARD VIEW : Create job card response - %s" % str(result)) # return Response(result) try: view_logger = log_rotator.view_logger() if request.method == 'POST': if request.user.is_authenticated(): dealerid = request.user details = {} data = json.loads(request.body.decode('utf-8'))['data'] print(data) view_logger.debug("JOBCARD VIEW : Save job card request - %s"%str(data)) details['jc_id'] = data.get('jc_id', 'NA') details['veh_num'] = data['veh_num'] details['brand'] = data['brand'] details['model'] = data['model'] details['fuel_type'] = data['fuel_type'] details['c_num'] = data['c_num'] details['cust_name'] = data['cust_name'] details['cont_num'] = data['cont_num'] details['cont_address'] = data['cont_address'] details['km_ticked'] = data['km_ticked'] details['service_reminder_time'] = data['service_reminder_time'] details['del_time'] = data['del_time'] details['status'] = data['status'] details['reason'] = data['reason'] details['otherparts_desc'] = data['otherparts_desc'] details['otherparts_cost'] = data['otherparts_cost'] details['services'] = data['services'] details['spares'] = data['spares'] details['recommendedservices'] = data['recommendedservices'] details['labour_cost'] = data['labour_cost'] if 'vehicle_images' in data: if type(data['vehicle_images']) == list: details['vehicle_images'] = data['vehicle_images'] else: result = {"status": "failure", "msg": "Invalid vehicle_images format."} return HttpResponse(json.dumps(result, default=json_default), content_type="application/json") else: details['vehicle_images'] = [] if 'mechanic_name' in details: details['mechanic_name'] = data['mechanic_name'] else: details['mechanic_name'] = "" if 'service_type_id' in details: details['ServiceTypeId'] = data['service_type_id'] else: # General service by default details['ServiceTypeId'] = "5s5d5f5g" result = util.saveJobCard(details, dealerid, details['jc_id']) result['url'] = '/jobcard/' else: result = {"status": "failure", "msg" : "Invalid session"} else: result = {"status": "failure", "msg": "Invalid request method"} except: error_logger = log_rotator.error_logger() error_logger.debug("Exception::", exc_info=True) result = {"status": "failure", "msg": "something went wrong"} view_logger.debug("JOBCARD VIEW : Save job card response - %s"%str(result)) return HttpResponse(json.dumps(result, default=json_default), content_type="application/json")