Esempio n. 1
0
    def post(self, request):
        form = AddRestaurantForm(request.POST, request.FILES)
        data = dict(form=form)
        if form.is_valid():
            data = form.cleaned_data

            restaurant = Restaurant()
            manager = Manager()

            restaurant.name = data['name']
            restaurant.description = data['description']
            restaurant.profile_image = request.FILES['profile_image']

            manager.email = data['manager_email']
            chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"

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

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

            restaurant.manager = manager
            restaurant.category = data['category']

            restaurant.save()

        return render(request, self.template_name, dict(form=form))
Esempio n. 2
0
    def seed(self):
        for i in range(10):
            first_name = names.get_first_name()
            last_name = names.get_full_name()

            guest = Manager()
            guest.role = "GUEST"
            guest.email = "*****@*****.**" % str(i)
            guest.set_password('password')
            guest.first_name = first_name
            guest.last_name = last_name
            guest.is_active = True
            guest.is_confirmed = True
            guest.is_staff = False
            guest.is_superuser = False

            guest.save()