Пример #1
0
    def post(self, request):
        form = AddEmployeeForm(request.POST)
        data = dict(form=form)
        if form.is_valid():
            data = form.cleaned_data

            employee = Employee()
            employee.email = data['email']
            employee.first_name = data['first_name']
            employee.last_name = data['last_name']
            employee.shoe_size = data['shoe_size']
            employee.clothes_size = data['clothes_size']
            employee.role = data['role']

            chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"

            password = "".join([chars[ord(c) % len(chars)] for c in urandom(8)])
            employee.set_password(password)
            employee.is_confirmed = True

            restaurant = Restaurant.objects.filter(manager=request.user)[0]

            employee.works_in = restaurant

            employee.save()

            employee.send_email("Login details - Restaurant booking online",
                                "Your login details :\n E-mail : " + employee.email +
                                "\n Password : "******"\n You can login now " +
                                get_current_site(request).domain + "\n Restaurant booking online")

            employee.save()

        return render(request, self.template_name, dict(form=form))
Пример #2
0
 def seed(self):
     waiter = Employee()
     waiter.employee_role = "WAITER"
     waiter.email = "*****@*****.**"
     waiter.set_password("gazerocker")
     waiter.first_name = "Kristina"
     waiter.last_name = "Grujic"
     waiter.is_staff = False
     waiter.is_superuser = False
     waiter.is_confirmed = True
     waiter.works_in = Restaurant.objects.get(id=1)
     waiter.save()