def get_cart(request,dealer_code,profile,appointment): try: if appointment: customer_factory = CustomerServicesFactory() dealer_factory = DealerShipServicesFactory() dealer_service = dealer_factory.get_instance("dealership") dealer = dealer_service.get_dealer_by(dealer_code) userservice = customer_factory.get_instance("user") appointmentservice = dealer_factory.get_instance("appointment") repairservice = dealer_factory.get_instance("repair") services = repairservice.get_service_for(appointment.id,'s') repairs = repairservice.get_service_for(appointment.id,'r') print services print repairs context = { "mainurl":settings.MEDIA_ROOT, "appointment":appointment, "dealer_code":dealer_code, "services":services,"repairs":repairs, "cart_count":len(repairs)+len(services) } return render(request, "customer/cart/main.html",context) else: # return "" return render(request, "customer/cart/main.html",{}) except Exception,e: print e
def appointment_book_ajax_view(request): appointment = {} template = 'appointment/partials/confirmation_modal_content.html' dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") if request.method == 'POST': aptservice = AppointmentService() #try: data = {} for key, value in request.POST.iteritems(): if key == "start_time": #value = datetime.datetime.strptime(value, '%b. %d, %Y, %I:%M %p') value = datetime.datetime.strptime(value, '%Y-%m-%d %H:%M') value = timezone.make_aware(value) data[key] = value aptservice = AppointmentService() context = aptservice.create_update_appointment(data) aptservice.book_appointment_with_id(request.POST.get('id'), request.session["dealer_id"]) appointment = aptservice.get_appointment_by_id(request.POST.get('id')) print appointment #except Exception, ex: #pass return render(request, template, appointment)
def get_all_advisor(request, dealer_code): customer_factory = CustomerServicesFactory() dealer_factory = DealerShipServicesFactory() service_layer = customer_factory.get_instance("user") #CUserService() media_url = settings.MEDIA_URL dealer_service = dealer_factory.get_instance( "dealership") #DealerShipService() dealership = dealer_service.get_dealer_by( request.session.get("dealer_code")) selected_advisor_id = None appointment = None rtype = request.GET.get("type", "appointment") profile_id = request.GET.get("profile_id") """when saving for appointment""" if rtype == "appointment": appointment_id = request.GET.get("appointment_id") service = dealer_factory.get_instance( "appointment") #AppointmentService() appointment = service.get_appointment(appointment_id) if appointment and appointment.advisor: selected_advisor_id = appointment.advisor.id if selected_advisor_id == None and appointment: try: customer_advisor = CustomerAdvisor.objects.get( customer_id=appointment.customer.id) selected_advisor_id = customer_advisor.advisor.id except Exception, e: print e customer_advisor = None
def appointment(request): searchform = SearchCustomerForm() custform = CustomerGuestAccountForm() vehicleform = CustomerVehichleForm() apptform = GuestAppointmentForm() guestform = GuestAccountForm() aptservice = AppointmentService() dealer_factory = DealerShipServicesFactory() dealer_service = dealer_factory.get_instance("dealership") vehicle_service = dealer_factory.get_instance("vehicle") dealer = dealer_service.get_dealer_by(request.session.get("dealer_code")) vehichles = vehicle_service.get_vehichles_dealer(dealer) vehicles = list(vehichles) breadcrumb = BreadCrumb() breadcrumb = breadcrumb.create_breadcrumb(["appointment"]) status = aptservice.get_appointments_status() wayaway = aptservice.get_wayaway() advisors = aptservice.get_appointments_advisor( request.session["dealer_id"]) wallboard = aptservice.get_appointments_wallboard_data( request.session["dealer_id"]) template = 'appointment/index.html' qstring = {} for key, value in request.GET.iteritems(): qstring[key] = value dealer_service = dealer_factory.get_instance("dealership") favorites = dealer_service.get_dealer_favorites( request.session["dealer_id"]) config = { "username": request.user, "dealer_code": request.session["dealer_code"], "dealer_name": request.session["dealer_name"], "dealer_id": request.session["dealer_id"], "group": request.session["group"], "tab": "appointment", "CENTRIFUGE_URL": settings.CENTRIFUGE_URL, "CENTRIFUGE_SECRET": settings.CENTRIFUGE_SECRET } return render( request, template, { 'config': config, "favorites": favorites, 'breadcrumb': breadcrumb, 'wallboard': wallboard, 'searchform': searchform, 'qstring': qstring, 'searchform': searchform, 'custform': custform, 'guestform': guestform, 'vehicleform': vehicleform, 'apptform': apptform, 'vehicles': mainjson.dumps(vehicles), 'status': status['data'], 'wayaway': wayaway['data'], 'advisors': advisors, 'qstring': qstring })
def service_history(request, vehicle_id): template_name = 'customer/vehicle_services.html' user = request.user # user = User.objects.get(id=user.id) profile = UserProfile.objects.get(user_id=user.id) dealer_code = request.session["dealer_code"] customer_factory = CustomerServicesFactory() dealer_factory = DealerShipServicesFactory() dealer_service = dealer_factory.get_instance( "dealership") #DealerShipService() appt_service = dealer_factory.get_instance( "appointment") #DealerShipService() dealership = dealer_service.get_dealer_by( request.session.get("dealer_code")) appts_list = appt_service.get_old_appointments_by(vehicle_id, dealership) paginator = Paginator(appts_list, 10) page = request.GET.get('page', 1) try: appts = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. appts = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. appts = paginator.page(paginator.num_pages) context = { "appts": appts, "dealer_code": dealer_code, "vehicle_id": int(vehicle_id) } return render(request, template_name, context)
def appointment_wayaway_ajax_view(request): dealer_factory = DealerShipServicesFactory() appointment_service = dealer_factory.get_instance("appointment") dealership_service = dealer_factory.get_instance("dealership") template = 'appointment/wayaway.html' wayaway = WayAwayService() cuser = CUserService() selected_wayaway = None appointment = None user_id = None profile = None dealer = None if request.method == 'POST': # selected_wayaway = wayaway.get_apt_wayaway() if request.POST.get("user_id") != 0: profile = cuser.get_user_profile(request.POST.get("user_id")) if request.POST.get("dealer_code") != 0: dealer = dealership_service.get_dealer_by( request.POST.get("dealer_code")) appointment = appointment_service.get_valid_appointment( request.POST.get('appt_id')) wyay = wayaway.get_all_wayaway(dealer) states = wayaway.get_all_states() return render( request, template, { 'appointment': appointment, 'wayaway': wyay, 'states': states, "profile": profile })
def index(request, dealer_code, profile): """ this method is the index view for the chat session. Its just a test page currently for advisors """ customer_factory = CustomerServicesFactory() dealer_factory = DealerShipServicesFactory() dealer_service = dealer_factory.get_instance( "dealership") #DealerShipService() dealership = dealer_service.get_dealer_by(dealer_code) userservice = customer_factory.get_instance("user") #CUserService() # userservice = UserService() advisor = userservice.get_advisor_for_chat(dealership, profile) img = UploadForm() template_name = 'livechat/advisorchat.html' chat_username = getUserName(request) chat_nick = getChatNick(request) return render( request, template_name, { "CENTRIFUGE_URL": settings.CENTRIFUGE_URL, "CENTRIFUGE_SECRET": settings.CENTRIFUGE_SECRET, "advisor": advisor, "chat_username": chat_username, "chat_nick": chat_nick, 'form': img })
def save_advisor(request, dealer_code): customer_factory = CustomerServicesFactory() dealer_factory = DealerShipServicesFactory() resp = True user = None dealer_service = dealer_factory.get_instance( "dealership") #DealerShipService() dealership = dealer_service.get_dealer_by( request.session.get("dealer_code")) rtype = request.GET.get("type", "appointment") if rtype == "appointment": # if request.GET.get("advisor_id"): try: appointment_id = request.GET.get("appointment_id") service = AppointmentService() appointment = service.get_appointment(appointment_id) advisor_id = request.GET.get("advisor_id", appointment.advisor_id) save_advisor = service.save_advisor(appointment, advisor_id) cservice = customer_factory.get_instance("user") #CUserService() if save_advisor: resp = True print appointment.customer.id print dealership.id print advisor_id save = cservice.save_my_advisor(appointment.customer.id, dealership.id, advisor_id) if save == False: resp = False except Exception, e: print e
def rservices(request): dealer_factory = DealerShipServicesFactory() breadcrumb = BreadCrumb() #form = AddServiceRepairForm() breadcrumb = breadcrumb.create_breadcrumb(["rservices"]) template = 'rservices/index.html' qstring = {} for key, value in request.GET.iteritems(): qstring[key] = value dealer_service = dealer_factory.get_instance("dealership") favorites = dealer_service.get_dealer_favorites( request.session["dealer_id"]) config = { "username": request.user, "dealer_code": request.session["dealer_code"], "dealer_name": request.session["dealer_name"], "dealer_id": request.session["dealer_id"], "group": request.session["group"], "tab": "rservices", "CENTRIFUGE_URL": settings.CENTRIFUGE_URL, "CENTRIFUGE_SECRET": settings.CENTRIFUGE_SECRET } return render( request, template, { 'config': config, "favorites": favorites, 'breadcrumb': breadcrumb, 'qstring': qstring })
def appointment_remove_service(request): status = False dealer_factory = DealerShipServicesFactory() repair_service = dealer_factory.get_instance("repair") if request.method == 'POST': status = repair_service.remove_service(request.POST.get('id')) return JsonResponse({"status": status}) return JsonResponse({"status": status})
def wallboard_ajax_view(request): dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") wallboard = aptservice.get_appointments_wallboard_data(request.session["dealer_id"], request.POST.get('date')) template = 'dealership/app/wallboard.html' return render(request, template, {'wallboard':wallboard})
def dealer_title(dealer_code): service_factory = DealerShipServicesFactory() dealerservice = service_factory.get_instance("dealership") dealer = dealerservice.get_dealer_by(dealer_code) if dealer: return dealer.name else: return ""
def time_daily_search_appt_ajax_view(request): template = 'overview/time_daily_multi_slab.html' context = {} if request.method == 'POST': dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") context = aptservice.get_appointments_by_time_id(request.POST.get('appt_id'), request.session["dealer_id"]) return render(request, template, context)
def appointment_row_ajax_view(request): template = 'overview/time_daily_row.html' context = {} if request.method == 'POST': dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") context = {'row':aptservice.get_appointment_by_id(request.POST.get('id'))} print context return render(request, template, context)
def handle(self, *args, **options): dealer_factory = DealerShipServicesFactory() capacityservice = dealer_factory.get_instance("capacity") dealers = Dealer.objects.all() now = datetime.datetime.now() start_date = now.date() end_date = start_date + timedelta(7) for dealer in dealers: capacityservice.save_tech_count_for_date_range( start_date, end_date, dealer)
def time_weekly_slab_ajax_view(request): template = 'overview/time_weekly_slab.html' context = {} if request.method == 'POST': dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") context = aptservice.get_appoiontments_by_time(request.POST.get('datetime'), request.session["dealer_id"]) context["id"] = request.POST.get('id') return render(request, template, context)
def wayaway_ajax_view(request): """ wayaway_ajax_view *get list of all the wayaway options from along with calculated capacity """ context = {} if request.method == 'POST': dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") context = aptservice.get_wayaway() return JsonResponse(context)
def advisor_weekly_slab_ajax_view(request): template = 'overview/time_weekly_slab.html' context = {} if request.method == 'POST': dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") context = aptservice.get_appointments_by_advisor(request.POST.get('date'), request.session["dealer_id"], request.POST.get('id')) context["id"] = "%s_%s" % (request.POST.get('date').replace("-", "_"),request.POST.get('id')) return render(request, template, context)
def time_daily_search_ajax_view(request): #template = 'overview/time_daily_multi_slab.html' context = {} if request.method == 'POST': dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") context = aptservice.get_appointments_by_time_criteria(request.POST.get('date'), request.session["dealer_id"], request.POST.get('search'), request.POST.get('criteria')) return JsonResponse(context)
def dealer_detail(dealer_code): service_factory = DealerShipServicesFactory() dealerservice = service_factory.get_instance("dealership") dealer = dealerservice.get_dealer_by(dealer_code) if dealer: if dealer.logo: return "<img width='60' src='%s'/> %s" % ( dealer.logo.url, dealer.name) else: return "%s" % dealer.name else: return ""
def status_daily_slab_ajax_view(request): template = 'overview/time_daily_slab.html' context = {} print "new function " if request.method == 'POST': dealer_factory = DealerShipServicesFactory() aptservice = dealer_factory.get_instance("appointment") context = aptservice.get_appointments_by_status(request.POST.get('date'), request.session["dealer_id"], request.POST.get('id')) print context return render(request, template, context)
def appointment_update_vehicle(request): dealer_factory = DealerShipServicesFactory() vehicleservice = dealer_factory.get_instance("vehicle") if request.method == 'POST': vehicle_instance = vehicleservice.get_customer_vehicle(request.POST.get('id')) vehicle_form = CustomerVehichleForm(request.POST, instance = vehicle_instance) if vehicle_form.is_valid(): result = vehicle_form.save() #return JsonResponse({"status":"success", "id":result.pk}) return JsonResponse({"status":"success", "message":"Vehicle Information Updated Successfully"}) else: return JsonResponse({"status":"error", "message":"Vehicle Data is not Valid"}) return JsonResponse({"status":"error"})
def dealer_detail_dealer(dealer_code): service_factory = DealerShipServicesFactory() dealerservice = service_factory.get_instance("dealership") dealer = dealerservice.get_dealer_by(dealer_code) main_url = reverse("dealership:index") + "?dealer_code=" + dealer_code if dealer: if dealer.logo: return "<a href='%s' class='logo'><img width='60' src='%s'/> %s DEALERSHIP APPLICATION</a>" % ( main_url, dealer.logo.url, dealer.name) else: return "%s" % dealer.name else: return ""
def ov_time_weekly(request): dealer_factory = DealerShipServicesFactory() template = 'overview/time_weekly.html' dealer_service = dealer_factory.get_instance("dealership") breadcrumb = BreadCrumb() if request.method == 'GET' and 'q' in request.GET: filter = "_%s" % (request.GET['q']) date = datetime.datetime.now() if request.method == 'GET' and 'date' in request.GET: date = datetime.datetime.strptime(request.GET['date'], '%Y-%m-%d %H:%M') timings = dealer_service.get_dealer_shop_time(date, request.session["dealer_id"]) breadcrumb = breadcrumb.create_breadcrumb(["overview", "ov_time_weekly%s" % (filter)]) return render(request, template, {'breadcrumb':breadcrumb, 'timings':timings})
def dealer_ico(dealer_code): service_factory = DealerShipServicesFactory() dealerservice = service_factory.get_instance("dealership") dealer = dealerservice.get_dealer_by(dealer_code) if dealer: if dealer.ico_logo: return "<link rel='shortcut icon' href='%s'/>" % ( dealer.ico_logo.url, ) else: return "<link rel='shortcut icon' href='%s' />" % ( dealer.ico_logo, ) else: return ""
def setservices(self): from dealership.factories import DealerShipServicesFactory self.dealer_service_factory = DealerShipServicesFactory() self.userservice = self.dealer_service_factory.get_instance("user") self.vehicle_service = self.dealer_service_factory.get_instance( "vehicle") self.repair_service = self.dealer_service_factory.get_instance( "repair") self.dealership_service = self.dealer_service_factory.get_instance( "dealership") self.capacity_service = self.dealer_service_factory.get_instance( "capacity") self.email_service = self.dealer_service_factory.get_instance("email") self.dealership_service = self
def setservices(self): from customer.factories import CustomerServicesFactory from dealership.factories import DealerShipServicesFactory self.customer_service_factory = CustomerServicesFactory() self.dealer_service_factory = DealerShipServicesFactory() self.cuserservice = self.customer_service_factory.get_instance("user") self.userservice = self.dealer_service_factory.get_instance("user") self.appointment_service = self.dealer_service_factory.get_instance( "appointment") self.vehicle_service = self self.repair_service = self.dealer_service_factory.get_instance( "repair") self.dealership_service = self.dealer_service_factory.get_instance( "dealership")
def sync_gcalendar(request): gcalservice = GoogleService() if request.GET.get("appointment_id"): if request.GET.get("refferrer"): request.session["refferrer"] = request.GET.get("refferrer") customer_factory = CustomerServicesFactory() dealer_factory = DealerShipServicesFactory() dealer_service = dealer_factory.get_instance("dealership") # dealer = dealer_service.get_dealer_by(dealer_code) uservice = customer_factory.get_instance("user") #CUserService() appt_service = dealer_factory.get_instance( "appointment") #AppointmentService() appointment = appt_service.get_appointment( request.GET.get("appointment_id")) #,dealer) # REDIRECT_URI = 'http://127.0.0.1:8000/customer/oauth2callback/'#?appointment_id='+request.GET.get("appointment_id") request.session["oauth_appointment"] = request.GET.get( "appointment_id") #REDIRECT_URI = "https://%s%s" % ( # get_current_site(request).domain, reverse("customer:return")) REDIRECT_URI = settings.SITE_MAIN_URL + reverse("customer:return") CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), gcalservice.CLIENT_SECRET_FILE) FLOW = flow_from_clientsecrets(CLIENT_SECRETS, scope=gcalservice.SCOPES, redirect_uri=REDIRECT_URI) storage = Storage(CredentialsModel, 'id', appointment, 'credential') credential = storage.get() if credential is None or credential.invalid is True: FLOW.params['state'] = xsrfutil.generate_token( settings.SECRET_KEY, appointment) authorize_url = FLOW.step1_get_authorize_url() f = FlowModel(id=appointment, flow=FLOW) f.save() return HttpResponseRedirect(authorize_url) else: resp = gcalservice.create_event(appointment, credential) messages.success( request, "Your appointment has been added to Google Calendars") if request.session.get("refferrer"): refferrer = request.session["refferrer"] del request.session["refferrer"] return HttpResponseRedirect(refferrer) else: return JsonResponse({"success": resp}, safe=False)
def flag_changed(sender, **kwargs): import json from django.utils import timezone from django.core.urlresolvers import reverse from dealership.services.emailservice import EmailService from dealership.factories import DealerShipServicesFactory from dealership.services import userservices dealer_factory = DealerShipServicesFactory() notificationservice = dealer_factory.get_instance("notification") appointmentservice = dealer_factory.get_instance("appointment") instance = kwargs["instance"] try: service = userservices.UserService() if instance.id == None: old_instance = None else: old_instance = RO.objects.get(id=instance.id) if old_instance.flag3_id != instance.flag3_id and instance.flag3_id !=None and instance.flag3.customer_facing==1: app = Appointment.objects.get(ro=instance.id) advisor = app.advisor.userprofile main_url = settings.SITE_MAIN_URL send_text = True if advisor: notification_settings = notificationservice.get_flagging_settings(advisor) if notification_settings.get("text",True) == False: send_text=False if advisor: context = {"name":app.customer.first_name+" "+app.customer.last_name,"flag_name":instance.flag3.name,"notes":instance.shop_notes, "main_url":main_url+reverse('customer:status_alert_index',kwargs={'appointment_id': app.id})} param = json.dumps(context) if instance.flag3_id == app.dealer.approval_needed_flag_id and app.dealer.approval_needed_flag_id!=0: notificationservice.send_dealer_based_notification(app.dealer,advisor,param,"approval_required",send_email=True,send_text=send_text) notificationservice.send_dealer_based_notification(app.dealer,app.customer,param,"approval_required",send_email=True,send_text=send_text) # elif instance.flag3_id == app.dealer.carwash_flag_id and app.dealer.carwash_flag_id!=0: notificationservice.send_dealer_based_notification(app.dealer,advisor,param,"car_wash",send_email=True,send_text=send_text) notificationservice.send_dealer_based_notification(app.dealer,app.customer,param,"car_wash",send_email=True,send_text=send_text) else: notificationservice.send_dealer_based_notification(app.dealer,advisor,param,"flags_change",send_email=True,send_text=send_text) notificationservice.send_dealer_based_notification(app.dealer,app.customer,param,"flags_change",send_email=True,send_text=send_text) except Exception,e: print "failed sending email" print e
def notificationssettings(request,dealer_code,profile): """ This is the notification screen. This is used to save settings """ customer_factory = CustomerServicesFactory() dealer_factory= DealerShipServicesFactory() user_service = customer_factory.get_instance("user") profile = user_service.get_userprofile(request.user) notificationservice = dealer_factory.get_instance("notification") remindersettings = notificationservice.get_user_remindersettings(profile,True) phone_numbers = user_service.get_profile_numbers(profile) emails = user_service.get_profile_emails(profile) carrier_choices = ( ("Verizon"), ("AT & T"), ) tab = "notification" if request.method == "POST": special_offer_notify = False if request.POST.get("special_offer_notify"): special_offer_notify = True ids = request.POST.getlist("settings_id") for id in ids: textset = False phoneset=False emailset = False if request.POST.get("setting_email_"+id): emailset = True if request.POST.get("setting_text_"+id): textset=True if request.POST.get("setting_phone_"+id): phoneset=True notificationservice.save_reminder_settings(id,emailset,textset,phoneset) # user_service.save_active_phone(profile,request.POST.get("active_phone_number")) user_service.save_active_email(profile,request.POST.get("active_email")) user_service.save_special_offer_notify(profile,special_offer_notify) messages.success(request, "Reminder settings saved successfully") return HttpResponseRedirect(reverse("customer:notifications")) else: context = {"dealer_code":dealer_code,"tab":tab,"page_title":"Customer Profile", "remindersettings":remindersettings, "phonenumbers":phone_numbers, "emails":emails,"profile":profile,"carrier_choices":carrier_choices} user_service.set_centrifuge_context(request, dealer_code,profile,context,chatposition="top") return render(request, "customer/notifications.html",context )