def add(request): if request.method == 'POST': # set current user as employer implicitly form = EmployeeForm(request.POST) form_valid = form.is_valid() if form_valid: employee = form.save(commit=False) employee.employer = request.user.service_provider employee.save() h = EmployeeWorkingHours() h.employee = employee spwh = WorkingHours.objects.filter( service_provider=request.user.service_provider.id)[0] if spwh: h.time_from = spwh.time_from h.time_to = spwh.time_to h.week_days = [1, 2, 3, 4, 5] else: h.time_from = datetime.time(9, 0) h.time_to = datetime.time(21, 0) h.week_days = [1, 2, 3, 4, 5] h.save() return HttpResponseRedirect(reverse(myemployees)) else: form = EmployeeForm() # render form - new (get request) or invalid with error messages (post request) return render_to_response('employees/add.html', locals(), context_instance=RequestContext(request))
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()