예제 #1
0
파일: models.py 프로젝트: JonNatanael/TPO
def customer_handler(sender, instance, created, **kwargs):
    date = datetime.datetime.combine(instance.date, instance.time)
    c = None
    if instance.user:
        c = Customer.objects.filter(user_id=instance.user.id)
    if not c:
        c = Customer.objects.filter(service_id=instance.service_provider.id, email=instance.user_email)
    if not c:
        c_obj = Customer(service_id=instance.service_provider.id, email=instance.user_email)
        c_obj.provider = instance.service_provider
        c_obj.email = instance.user_email
        c_obj.name = instance.user_fullname
        c_obj.phone = instance.user_phone
        c = [c_obj]

    c = c[0]

    if instance.user and not c.user:
        c.user = instance.user

    if created:
        c.last_reservation = date
        c.num_reservations += 1

    c.save()
예제 #2
0
파일: models.py 프로젝트: mfrlin/TPO
def customer_handler(sender, instance, created, **kwargs):
    date = datetime.datetime.combine(instance.date, instance.time)
    c = None
    if instance.user:
        c = Customer.objects.filter(user_id=instance.user.id)
    if not c:
        c = Customer.objects.filter(service_id=instance.service_provider.id,
                                    email=instance.user_email)
    if not c:
        c_obj = Customer(service_id=instance.service_provider.id,
                         email=instance.user_email)
        c_obj.provider = instance.service_provider
        c_obj.email = instance.user_email
        c_obj.name = instance.user_fullname
        c_obj.phone = instance.user_phone
        c = [c_obj]

    c = c[0]

    if instance.user and not c.user:
        c.user = instance.user

    if created:
        c.last_reservation = date
        c.num_reservations += 1

    c.save()
예제 #3
0
파일: views.py 프로젝트: km4054/eNarocanje
def reservation(request, id, employee_id):
    service = get_object_or_404(Service, id=id)
    #Klemen: dobi zaposlenega za to storitev, ce je bil dolocen


    if employee_id > 0:
        service_provider_employee_obj = get_object_or_404(ServiceProviderEmployee, id=employee_id)
    else:
        service_provider_employee_obj = None

    if not service.is_active():
        raise Http404



    minTime, maxTime = getMinMaxTime(service.service_provider)



    if request.method != 'POST':
        # ce je zaposleni dolocen, ga daj kot initial
        if service_provider_employee_obj:
            form = ReservationForm(request, workingHours=None, service=service, serviceProviderEmployee=service_provider_employee_obj, initial={"service_provider_employee":service_provider_employee_obj})
        else:
            #ce se ni bil izbran
            form = ReservationForm(request, workingHours=None, service=service, serviceProviderEmployee=service_provider_employee_obj)
        service_provider = service.service_provider
        data = {'service_provider_id': service.service_provider_id} # 'service_provider_employee_id': service_provider_employee_obj.id }
        return render_to_response('reservations/reservation.html', locals(), context_instance=RequestContext(request))

    # POST
    step = request.POST.get('step', '1')

    try:
        data = pickle.loads(base64.b64decode(request.POST.get('data')))  # Serializes an object from request
    except:
        raise Http404

    if service_provider_employee_obj:
        workingHours = WorkingHours.objects.filter(service_provider_id=service.service_provider_id)
    else:
        workingHours = EmployeeWorkingHours.objects.filter(service=service, service_provider_employee=service_provider_employee_obj)




    formNonRegisteredUser = NonRegisteredUserForm()

    if step == '1':
        # Service, date, time
        # form = ReservationForm(request.POST, workingHours='gergerre')
        #service_provider_employee_choice = request.POST.get['service_provider_employee']
        #print service_provider_employee_choice
        form = ReservationForm(request, request.POST, workingHours=workingHours, service=service, serviceProviderEmployee=service_provider_employee_obj)

        if form.is_valid():
            data['date'] = form.cleaned_data['date']
            data['time'] = form.cleaned_data['time']
            data['number'] = form.cleaned_data['number']
            service_provider_employee_obj = form.cleaned_data['service_provider_employee']
            # ce je bil izbran zaposleni, shrani njegov id in ga prenesi v naslednje step-e

            if service_provider_employee_obj:
                data['service_provider_employee'] = form.cleaned_data['service_provider_employee'].id

            if request.user.is_authenticated():
                data['user_id'] = request.user.id
                data['name'] = request.user.get_full_name()
                data['phone'] = request.user.phone
                data['email'] = request.user.email
                data['service_notifications'] = request.user.service_notifications
                return render_to_response('reservations/confirmation.html', locals(), context_instance=RequestContext(request))

            return render_to_response('reservations/userinfo.html', locals(), context_instance=RequestContext(request))
        if service_provider_employee_obj:
            form = ReservationForm(request, workingHours=None, service=service, serviceProviderEmployee=service_provider_employee_obj, initial={"service_provider_employee":service_provider_employee_obj})
        else:
            #ce se ni bil izbran
            form = ReservationForm(request, workingHours=None, service=service, serviceProviderEmployee=service_provider_employee_obj)
        service_provider = service.service_provider
        data = {'service_provider_id': service.service_provider_id} # 'service_provider_employee_id': service_provider_employee_obj.id }

        return render_to_response('reservations/reservation.html', locals(), context_instance=RequestContext(request))

    if step == '2':
        # User info
        if data.get('date') is None or data.get('time') is None:
            raise Http404
        formNonRegisteredUser = NonRegisteredUserForm(request.POST)
        if formNonRegisteredUser.is_valid():
            data['name'] = formNonRegisteredUser.cleaned_data['name']
            data['phone'] = formNonRegisteredUser.cleaned_data['phone']
            data['email'] = formNonRegisteredUser.cleaned_data['email']
            data['service_notifications'] = formNonRegisteredUser.cleaned_data['service_notifications']
            return render_to_response('reservations/confirmation.html', locals(), context_instance=RequestContext(request))

        return render_to_response('reservations/userinfo.html', locals(), context_instance=RequestContext(request))

    if step == '3':
        # Confirmation

        #inicializiraj objekt zaposlenega glede na to, kateri je bil prej izbran
        if data.get('service_provider_employee'):
            service_provider_employee_obj = get_object_or_404(ServiceProviderEmployee, id=data.get('service_provider_employee'))
        else:
            service_provider_employee_obj = None
        if data.get('date') is None or data.get('time') is None:  # or data.get('user_id') is None:
            raise Http404
        if data.get('user_id') is not None:
            ruser = get_object_or_404(User, id=data.get('user_id'))
        else:
            ruser = None

        sync(service.service_provider)

        # Checking again if form for reservation is valid
        form = ReservationForm(request, {'date': data.get('date'), 'time': data.get('time')}, workingHours=workingHours, service=service, serviceProviderEmployee=service_provider_employee_obj)
        #form.fields['service_provider_employee']=service_provider_employee_obj

        if form.is_valid():
            # Add a customer
            user_mail = None
            if ruser is None:
            # If an unregistered customer performs reservation
                customer_name = data.get('name').split()
                customer = Customer(name=customer_name[0], last_name=customer_name[len(customer_name)-1], phone=data.get('phone'), email=data.get('email'), full_name=data.get('name'))
                user_mail = data.get('email')
            else:
                # If a registered customer performs reservation
                customer = Customer(name=ruser.first_name, last_name=ruser.last_name, phone=ruser.phone, email=ruser.email, full_name=ruser.first_name+' '+ruser.last_name)
                user_mail = ruser.email
            try:
                Customer.objects.get(email=data.get('email'))

            except:
                # Save a customer if they are not already in
                customer.save()
            # Save a reservation
            customer = Customer.objects.get(email=user_mail)
            customer.last_reservation=datetime.datetime.today()
            customer.save(update_fields=['last_reservation'])
            reserve = Reservation(user=ruser, service=service, date=data['date'], time=data['time'], customer=customer, service_notifications=data['service_notifications'])
            # Add backup fields
            reserve.user_fullname = data.get('name')
            reserve.user_phone = data.get('phone')
            reserve.user_email = data.get('email')
            reserve.service_provider = service.service_provider
            reserve.service_name = service.name
            reserve.service_duration = service.duration
            reserve.service_price = service.discounted_price()
            reserve.service_provider_employee = service_provider_employee_obj
            # Save
            reserve.save()

            #Creating scheduler reminder
            if data.get('service_notifications'):
                datetime_reminder = datetime.datetime.combine(reserve.date, reserve.time) - datetime.timedelta(hours=4)
                if service.service_provider.send_sms_reminder:
                    send_reminder_sms.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)
                if service.service_provider.send_email_reminder:
                    send_reminder_email.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)

            elif request.user.send_reminders:
                datetime_reminder = datetime.datetime.combine(reserve.date, reserve.time) - datetime.timedelta(hours=4)
                if service.service_provider.send_sms_reminder:
                    send_reminder_sms.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)
                if service.service_provider.send_email_reminder:
                    send_reminder_email.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)

            # saving coupon is_valid
            coupons = Coupon.objects.filter(service=service.id)
            for coup in coupons:
                if(data['number'] == coup.number):
                    coup.is_used = True
                    coup.save()
                    # Validation checking in form

            email_to1 = data.get('email')
            email_to2 = service.service_provider.user.email
            if(service.service_provider.reservation_confirmation_needed == False):
                subject = _('Confirmation of service reservation')
                renderedToCustomer = render_to_string('emails/reservation_customer.html', {'reservation': reserve})
                renderedToProvider = render_to_string('emails/reservation_provider.html', {'reservation': reserve})
                message1 = (subject, renderedToCustomer, None, [email_to1])
                message2 = (subject, renderedToProvider, None, [email_to2])
                send_mass_mail((message1, message2), fail_silently=True)
            else:
                subject = _('Confirmation of service reservation')
                renderedToProvider = render_to_string('emails/reservation_provider.html', {'reservation': reserve})
                send_mail(subject, renderedToProvider, None, [email_to2], fail_silently=False)

            start = datetime.datetime.combine(reserve.date, reserve.time)
            gcal_params = urllib.urlencode({
                'action': 'TEMPLATE',
                'text': reserve.service_name.encode('utf8'),
                'dates': '%s/%s' % (datetime_to_url_format(start), datetime_to_url_format(start + datetime.timedelta(minutes=reserve.service_duration))),
                'details': reserve.service.description.encode('utf8'),
                'location': reserve.service_provider.full_address().encode('utf8'),
                'trp': 'true',
                'sprop': 'E-Narocanje',
                'sprop': 'name:%s' % settings.BASE_URL,
            })
            if service_provider_employee_obj <> None:
                url_service = settings.BASE_URL + reverse('service', args=(service.id,service_provider_employee_obj.id,))
            else:
                url_service = settings.BASE_URL + reverse('service2', args=(service.id,))

            sync(service.service_provider)

            return render_to_response('reservations/done.html', locals(), context_instance=RequestContext(request))

        # Someone else has made a reservation in the meantime
        return render_to_response('reservations/alreadyreserved.html', locals(), context_instance=RequestContext(request))
    raise Http404
예제 #4
0
def reservation(request, id, employee_id):
    service = get_object_or_404(Service, id=id)
    #Klemen: dobi zaposlenega za to storitev, ce je bil dolocen


    if employee_id > 0:
        service_provider_employee_obj = get_object_or_404(ServiceProviderEmployee, id=employee_id)
    else:
        service_provider_employee_obj = None

    if not service.is_active():
        raise Http404
    if service_provider_employee_obj:
        workingHoursEmployee = EmployeeWorkingHours.objects.get(service=service, service_provider_employee=service_provider_employee_obj)
        minTime = workingHoursEmployee.time_from
        maxTime = workingHoursEmployee.time_to
    else:
        minTime, maxTime = getMinMaxTime(service.service_provider)


    if request.POST.get('action', None) == 'employeechanged':
        workingHoursEmployee = EmployeeWorkingHours.objects.get(service=service, service_provider_employee_id=request.POST.get('service_provider_employee', None))
        minTime = workingHoursEmployee.time_from
        maxTime = workingHoursEmployee.time_to
        form = ReservationForm(request, workingHours=None, service=service, serviceProviderEmployee=service_provider_employee_obj, initial={"service_provider_employee": request.POST.get('service_provider_employee', None),})
        service_provider_employee_obj = ServiceProviderEmployee.objects.get(pk=request.POST.get('service_provider_employee', None))
        data = {'service_provider_id': service.service_provider_id} # 'service_provider_employee_id': service_provider_employee_obj.id }
        return render_to_response('reservations/reservation.html', locals(), context_instance=RequestContext(request))


    if request.method != 'POST':
        # ce je zaposleni dolocen, ga daj kot initial
        if service_provider_employee_obj:
            form = ReservationForm(request, workingHours=None, service=service, serviceProviderEmployee=service_provider_employee_obj, initial={"service_provider_employee":service_provider_employee_obj})
        else:
            #ce se ni bil izbran
            form = ReservationForm(request, workingHours=None, service=service, serviceProviderEmployee=service_provider_employee_obj)

        data = {'service_provider_id': service.service_provider_id} # 'service_provider_employee_id': service_provider_employee_obj.id }
        return render_to_response('reservations/reservation.html', locals(), context_instance=RequestContext(request))

    # POST
    step = request.POST.get('step', '1')

    try:
        data = pickle.loads(base64.b64decode(request.POST.get('data')))  # Serializes an object from request
    except:
        raise Http404

    if service_provider_employee_obj:
        workingHours = WorkingHours.objects.filter(service_provider_id=service.service_provider_id)
    else:
        workingHours = EmployeeWorkingHours.objects.filter(service=service, service_provider_employee=service_provider_employee_obj)




    formNonRegisteredUser = NonRegisteredUserForm()

    if step == '1':
        # Service, date, time
        # form = ReservationForm(request.POST, workingHours='gergerre')
        #service_provider_employee_choice = request.POST.get['service_provider_employee']
        #print service_provider_employee_choice
        form = ReservationForm(request, request.POST, workingHours=workingHours, service=service, serviceProviderEmployee=service_provider_employee_obj)

        if form.is_valid():
            data['date'] = form.cleaned_data['date']
            data['time'] = form.cleaned_data['time']
            data['number'] = form.cleaned_data['number']
            service_provider_employee_obj = form.cleaned_data['service_provider_employee']
            # ce je bil izbran zaposleni, shrani njegov id in ga prenesi v naslednje step-e

            if service_provider_employee_obj:
                data['service_provider_employee'] = form.cleaned_data['service_provider_employee'].id

            if request.user.is_authenticated():
                data['user_id'] = request.user.id
                data['name'] = request.user.get_full_name()
                data['phone'] = request.user.phone
                data['email'] = request.user.email
                data['service_notifications'] = request.user.service_notifications
                return render_to_response('reservations/confirmation.html', locals(), context_instance=RequestContext(request))

            return render_to_response('reservations/userinfo.html', locals(), context_instance=RequestContext(request))

        return render_to_response('reservations/reservation.html', locals(), context_instance=RequestContext(request))

    if step == '2':
        # User info
        if data.get('date') is None or data.get('time') is None:
            raise Http404
        formNonRegisteredUser = NonRegisteredUserForm(request.POST)
        if formNonRegisteredUser.is_valid():
            data['name'] = formNonRegisteredUser.cleaned_data['name']
            data['phone'] = formNonRegisteredUser.cleaned_data['phone']
            data['email'] = formNonRegisteredUser.cleaned_data['email']
            data['service_notifications'] = formNonRegisteredUser.cleaned_data['service_notifications']
            return render_to_response('reservations/confirmation.html', locals(), context_instance=RequestContext(request))

        return render_to_response('reservations/userinfo.html', locals(), context_instance=RequestContext(request))

    if step == '3':
        # Confirmation

        #inicializiraj objekt zaposlenega glede na to, kateri je bil prej izbran
        if data.get('service_provider_employee'):
            service_provider_employee_obj = get_object_or_404(ServiceProviderEmployee, id=data.get('service_provider_employee'))
        else:
            service_provider_employee_obj = None
        if data.get('date') is None or data.get('time') is None:  # or data.get('user_id') is None:
            raise Http404
        if data.get('user_id') is not None:
            ruser = get_object_or_404(User, id=data.get('user_id'))
        else:
            ruser = None

        sync(service.service_provider)

        # Checking again if form for reservation is valid
        form = ReservationForm(request, {'date': data.get('date'), 'time': data.get('time')}, workingHours=workingHours, service=service, serviceProviderEmployee=service_provider_employee_obj)
        #form.fields['service_provider_employee']=service_provider_employee_obj

        if form.is_valid():
            # Add a customer
            user_mail = None
            if ruser is None:
            # If an unregistered customer performs reservation
                customer_name = data.get('name').split()
                customer = Customer(name=customer_name[0], last_name=customer_name[len(customer_name)-1], phone=data.get('phone'), email=data.get('email'), full_name=data.get('name'))
                user_mail = data.get('email')
            else:
                # If a registered customer performs reservation
                customer = Customer(name=ruser.first_name, last_name=ruser.last_name, phone=ruser.phone, email=ruser.email, full_name=ruser.first_name+' '+ruser.last_name)
                user_mail = ruser.email
            try:
                Customer.objects.get(email=data.get('email'))

            except:
                # Save a customer if they are not already in
                customer.save()
            # Save a reservation
            customer = Customer.objects.get(email=user_mail)
            customer.last_reservation=datetime.datetime.today()
            customer.save(update_fields=['last_reservation'])
            reserve = Reservation(user=ruser, service=service, date=data['date'], time=data['time'], customer=customer, service_notifications=data['service_notifications'])
            # Add backup fields
            reserve.user_fullname = data.get('name')
            reserve.user_phone = data.get('phone')
            reserve.user_email = data.get('email')
            reserve.service_provider = service.service_provider
            reserve.service_name = service.name
            reserve.service_duration = service.duration
            reserve.service_price = service.discounted_price()
            reserve.service_provider_employee = service_provider_employee_obj
            # Save
            reserve.save()

            #Creating scheduler reminder
            if data.get('service_notifications'):
                datetime_reminder = datetime.datetime.combine(reserve.date, reserve.time) - datetime.timedelta(hours=4)
                if service.service_provider.send_sms_reminder:
                    send_reminder_sms.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)
                if service.service_provider.send_email_reminder:
                    send_reminder_email.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)

            elif request.user.send_reminders:
                datetime_reminder = datetime.datetime.combine(reserve.date, reserve.time) - datetime.timedelta(hours=4)
                if service.service_provider.send_sms_reminder:
                    send_reminder_sms.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)
                if service.service_provider.send_email_reminder:
                    send_reminder_email.apply_async((data.get('time'), service.service_provider.name, service.name), eta=datetime_reminder)

            # saving coupon is_valid
            coupons = Coupon.objects.filter(service=service.id)
            for coup in coupons:
                if(data['number'] == coup.number):
                    coup.is_used = True
                    coup.save()
                    # Validation checking in form

            email_to1 = data.get('email')
            email_to2 = service.service_provider.user.email
            if(service.service_provider.reservation_confirmation_needed == False):
                subject = _('Confirmation of service reservation')
                renderedToCustomer = render_to_string('emails/reservation_customer.html', {'reservation': reserve})
                renderedToProvider = render_to_string('emails/reservation_provider.html', {'reservation': reserve})
                message1 = (subject, renderedToCustomer, None, [email_to1])
                message2 = (subject, renderedToProvider, None, [email_to2])
                send_mass_mail((message1, message2), fail_silently=True)
            else:
                subject = _('Confirmation of service reservation')
                renderedToProvider = render_to_string('emails/reservation_provider.html', {'reservation': reserve})
                send_mail(subject, renderedToProvider, None, [email_to2], fail_silently=False)

            start = datetime.datetime.combine(reserve.date, reserve.time)
            gcal_params = urllib.urlencode({
                'action': 'TEMPLATE',
                'text': reserve.service_name.encode('utf8'),
                'dates': '%s/%s' % (datetime_to_url_format(start), datetime_to_url_format(start + datetime.timedelta(minutes=reserve.service_duration))),
                'details': reserve.service.description.encode('utf8'),
                'location': reserve.service_provider.full_address().encode('utf8'),
                'trp': 'true',
                'sprop': 'E-Narocanje',
                'sprop': 'name:%s' % settings.BASE_URL,
            })
            if service_provider_employee_obj <> None:
                url_service = settings.BASE_URL + reverse('service', args=(service.id,service_provider_employee_obj.id,))
            else:
                url_service = settings.BASE_URL + reverse('service2', args=(service.id,))

            sync(service.service_provider)

            return render_to_response('reservations/done.html', locals(), context_instance=RequestContext(request))

        # Someone else has made a reservation in the meantime
        return render_to_response('reservations/alreadyreserved.html', locals(), context_instance=RequestContext(request))
    raise Http404
예제 #5
0
def fillDatabase():
    # Users
    # Password is defined as: admin

    password = '******'
    name = 'admin'
    obj = User(id=666, password=password, is_superuser=1, username=name, first_name='Admin',
               email=name + '@gmail.com', is_staff=1, is_active=1,
               phone='435345', language='en')
    obj.save()

    password = '******'
    name = 'user'
    for i in range(1, 11):
        obj = User(id=i, password=password, is_superuser=0, username=name + str(i), first_name='John',
                   last_name='Doe ' + str(i), email=name + str(i) + '@gmail.com', is_staff=0, is_active=1,
                   phone='435345', language='en', notification_type=1)
        obj.save()

    # Provider categories
    cat = ["Nega telesa", "Frizerski salon", "Kozmetični salon"]
    generic = ["massage_salon", "hairdresser_salon", "cosmetic_salon"]
    for i in range(1, len(cat) + 1):
        obj = ProvCat(id=i, name=cat[i - 1], generic_gallery=generic[i - 1])
        obj.save()

    # Service categories
    cat = ["Negovalni salon", "Masažni salon", "Manikura, nega rok", "Pedikura, nega nog", "Depilacija", "Solarij",
           "Ličenje", "Masaža", "Frizerske storitve", "Fotografske storitve"]
    for i in range(1, len(cat) + 1):
        obj = Category(id=i, name=cat[i - 1], show_in_gallery=False)
        if obj.name == "Fotografske storitve":
            obj.show_in_gallery = True
        obj.save()

    # Service Providers
    int_list = "1,2,3,4,5"
    for i in range(2, 10):
        obj = ServiceProvider(id=i, name="Provider" + str(i - 1), street="Strasse" + str(i - 1),
                              zipcode='100' + str(i - 1),
                              city="City" + str(i - 1), country="Country" + str(i - 1),
                              category_id=random.randint(1, len(ProvCat.objects.all())), subscription_mail_sent=0,
                              reservation_confirmation_needed=0, display_generic_gallery=True,
                              userpage_link="Provider" + str(i - 1))
        obj.save()
        user = User.objects.get(id=i)
        user.service_provider_id = i
        user.save()

        #Add working hours on weekdays (9h-21h)
        h = WorkingHours()
        h.service_provider = obj
        h.time_from = datetime.time(9)
        h.time_to = datetime.time(21)
        h.week_days = int_list
        h.save()

    # Services
    # 10 services for each provider
    durations = [15, 30, 45, 60, 75, 90, 105, 120]
    discounts = [10, 15, 30, 50, 70, 90, 100]
    gender = ['m', 'f']
    id = 1
    for p in ServiceProvider.objects.all():
        for s in range(1, 11):
            obj = Service(id=id, service_provider_id=p.id, name="Service" + str(s),
                          duration=durations[random.randint(0, len(durations) - 1)],
                          price=round(random.uniform(10, 250), 2), sex=gender[random.randint(0, len(gender) - 1)],
                          category_id=random.randint(1, len(Category.objects.all())))
            obj.description = str(Category.objects.get(id=obj.category_id))
            if random.uniform(1, 100):
                disc = Discount(discount=discounts[random.randint(0, len(discounts) - 1)], service=obj,
                                valid_from=datetime.date.today(),
                                valid_to=datetime.date.today() + relativedelta(months=1))
                disc.save()
            obj.save()
            id += 1

    #some employees
    for p in ServiceProvider.objects.all():
        for s in range(1, 11):
            e = Employee(name="Name" + str(s), surname="Surname" + str(s), phone=random.randint(100000, 999999),
                         employer=p)
            e.save()
            h = EmployeeWorkingHours()
            h.employee = e
            h.time_from = datetime.time(9)
            h.time_to = datetime.time(21)
            h.week_days = "1,2,3,4,5"
            h.save()
            name = "Customer_" + str(s)
            c = Customer(name=name, service=p,
                         phone=random.randint(100000, 999999), email=name + '@gmail.com',
                         last_reservation=datetime.datetime.now())
            c.save()
예제 #6
0
def fillDatabase():
    # Users
    # Password is defined as: admin

    password = '******'
    name = 'admin'
    obj = User(id=666,
               password=password,
               is_superuser=1,
               username=name,
               first_name='Admin',
               email=name + '@gmail.com',
               is_staff=1,
               is_active=1,
               phone='435345',
               language='en')
    obj.save()

    password = '******'
    name = 'user'
    for i in range(1, 11):
        obj = User(id=i,
                   password=password,
                   is_superuser=0,
                   username=name + str(i),
                   first_name='John',
                   last_name='Doe ' + str(i),
                   email=name + str(i) + '@gmail.com',
                   is_staff=0,
                   is_active=1,
                   phone='435345',
                   language='en',
                   notification_type=1)
        obj.save()

    # Provider categories
    cat = ["Nega telesa", "Frizerski salon", "Kozmetični salon"]
    generic = ["massage_salon", "hairdresser_salon", "cosmetic_salon"]
    for i in range(1, len(cat) + 1):
        obj = ProvCat(id=i, name=cat[i - 1], generic_gallery=generic[i - 1])
        obj.save()

    # Service categories
    cat = [
        "Negovalni salon", "Masažni salon", "Manikura, nega rok",
        "Pedikura, nega nog", "Depilacija", "Solarij", "Ličenje", "Masaža",
        "Frizerske storitve", "Fotografske storitve"
    ]
    for i in range(1, len(cat) + 1):
        obj = Category(id=i, name=cat[i - 1], show_in_gallery=False)
        if obj.name == "Fotografske storitve":
            obj.show_in_gallery = True
        obj.save()

    # Service Providers
    int_list = "1,2,3,4,5"
    for i in range(2, 10):
        obj = ServiceProvider(id=i,
                              name="Provider" + str(i - 1),
                              street="Strasse" + str(i - 1),
                              zipcode='100' + str(i - 1),
                              city="City" + str(i - 1),
                              country="Country" + str(i - 1),
                              category_id=random.randint(
                                  1, len(ProvCat.objects.all())),
                              subscription_mail_sent=0,
                              reservation_confirmation_needed=0,
                              display_generic_gallery=True,
                              userpage_link="Provider" + str(i - 1))
        obj.save()
        user = User.objects.get(id=i)
        user.service_provider_id = i
        user.save()

        #Add working hours on weekdays (9h-21h)
        h = WorkingHours()
        h.service_provider = obj
        h.time_from = datetime.time(9)
        h.time_to = datetime.time(21)
        h.week_days = int_list
        h.save()

    # Services
    # 10 services for each provider
    durations = [15, 30, 45, 60, 75, 90, 105, 120]
    discounts = [10, 15, 30, 50, 70, 90, 100]
    gender = ['m', 'f']
    id = 1
    for p in ServiceProvider.objects.all():
        for s in range(1, 11):
            obj = Service(
                id=id,
                service_provider_id=p.id,
                name="Service" + str(s),
                duration=durations[random.randint(0,
                                                  len(durations) - 1)],
                price=round(random.uniform(10, 250), 2),
                sex=gender[random.randint(0,
                                          len(gender) - 1)],
                category_id=random.randint(1, len(Category.objects.all())))
            obj.description = str(Category.objects.get(id=obj.category_id))
            if random.uniform(1, 100):
                disc = Discount(
                    discount=discounts[random.randint(0,
                                                      len(discounts) - 1)],
                    service=obj,
                    valid_from=datetime.date.today(),
                    valid_to=datetime.date.today() + relativedelta(months=1))
                disc.save()
            obj.save()
            id += 1

    #some employees
    for p in ServiceProvider.objects.all():
        for s in range(1, 11):
            e = Employee(name="Name" + str(s),
                         surname="Surname" + str(s),
                         phone=random.randint(100000, 999999),
                         employer=p)
            e.save()
            h = EmployeeWorkingHours()
            h.employee = e
            h.time_from = datetime.time(9)
            h.time_to = datetime.time(21)
            h.week_days = "1,2,3,4,5"
            h.save()
            name = "Customer_" + str(s)
            c = Customer(name=name,
                         service=p,
                         phone=random.randint(100000, 999999),
                         email=name + '@gmail.com',
                         last_reservation=datetime.datetime.now())
            c.save()