def handle(self, *args, **options):

        URL = 'https://www.whattoexpect.com/baby-names/list/top-baby-names-for-boys/'
        page = requests.get(URL)
        soup = BeautifulSoup(page.content, 'html.parser')

        results = soup.select('ol > li')
        names = []

        for item in results:
            names.append(item.text)

        accounts_array = []
        array = []

        for accounts in range(options['a']):
            accounts_array.append(Account(email=(random.choice(names) + '.' + random.choice(names) + '@gmail.com'), date_of_birth='1994-01-26'))

        Account.objects.bulk_create(accounts_array)

        for objects in Account.objects.all():
            array.append(objects)

        for staff in range(options['s']):
            account = random.choice(array)
            Staff.objects.bulk_create([Staff(user=account)])
            array.remove(account)

        staff_objects = Staff.objects.all()

        for customers in range(options['c']):
            account = random.choice(array)
            Customer.objects.bulk_create([Customer(user=account, staff=random.choice(staff_objects))])
            array.remove(account)
Beispiel #2
0
 def save(self):
     account = Account(
         email=self.validated_data['email'],
         username=self.validated_data['username'],
     )
     password = self.validated_data['password']
     account.address = self.validated_data['address']
     account.name = self.validated_data['name']
     account.set_password(password)
     account.save()
     return account
Beispiel #3
0
    def save(self):
        account = Account(
            email=self.validated_data['email'],
            username=self.validated_data['username'],
        )
        password = self.validated_data['password']
        password2 = self.validated_data['password2']

        if password != password2:
            raise serializers.ValidationError(
                {'password': '******'})
        account.set_password(password)
        account.save()
        return account
Beispiel #4
0
    def save(self, *args, **kwargs):
        email = self.validated_data["email"]
        account = Account(
            username=self.validated_data["username"],
            email=email,
        )
        password = self.validated_data["password"]
        confirm_password = self.validated_data["confirm_password"]

        if password != confirm_password:
            raise serializers.ValidationError({"password": "******"})
        account.set_password(password)
        account.save()
        return account
Beispiel #5
0
    def save(self, *args, **kwargs):
        user = Account(
            email=self.validated_data["email"],
            user_name=self.validated_data["user_name"],
        )

        password = self.validated_data["password"]
        password2 = self.validated_data["password2"]
        if password != password2:
            raise serializers.ValidationError({"password": "******"})

        user.set_password(password)
        user.save()
        return user
Beispiel #6
0
def register_view(request):
    # Authentication check. Users logged in cannot view this page.
    if request.user.is_authenticated:
        return HttpResponseRedirect('/profile/')
    # Get the template data from the session
    template_data = parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = AccountRegisterForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                form.cleaned_data['email'].lower(
                ),  # Username, make sure it's lowercase
                form.cleaned_data['email'],  # Email
                form.cleaned_data['password_first']  # Password
            )
            profile = Profile(
                firstname=form.cleaned_data['firstname'],
                lastname=form.cleaned_data['lastname'],
                insurance=form.cleaned_data['insurance'],
            )
            profile.save()
            account = Account(role=Account.ACCOUNT_PATIENT,
                              profile=profile,
                              user=user)
            account.save()
            medicalinfo = MedicalInfo(patient=account.user,
                                      alzheimer=False,
                                      asthma=False,
                                      diabetes=False,
                                      stroke=False)
            medicalinfo.save()
            user = authenticate(
                username=form.cleaned_data['email'].lower(
                ),  # Make sure it's lowercase
                password=form.cleaned_data['password_first'])
            logger.log(Action.ACTION_ACCOUNT, "Account registered", user)
            logger.log(Action.ACTION_ACCOUNT, "Account login", user)
            login(request, user)
            request.session[
                'alert_success'] = "Successfully registered with OTS"
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'page/register.html', template_data)
Beispiel #7
0
    def save(self, request):
        # create and save account
        new_account = Account(
            email=request.data['email'],
            first_name=request.data['first_name'],
            last_name=request.data['last_name'],
            type_user=request.data['type_user'],
        )
        new_account.set_password(request.data['password1'])
        new_account.save()

        # create a new profile
        new_profile = GraduateProfile(
            enrollment=request.data['enrollment'],
            career=request.data['career'],
            gender=request.data['gender'],
        )

        # make a default documents properties
        documents = dict()
        documents["acta"] = self.attrsDocs('Acta de Nacimimento')
        documents["curp"] = self.attrsDocs('C.U.R.P.')
        documents["titulo_bach"] = self.attrsDocs('Título de bachillerato')
        documents["ingles"] = self.attrsDocs('Constancia de inglés')
        documents["cni"] = self.attrsDocs('Constancia de no inconvenientes')

        # save documents and account on new profile
        new_profile.documents = documents
        new_profile.account = new_account
        new_profile.save()

        # adapter = get_adapter()
        # user = adapter.new_user(request)
        # self.cleaned_data = self.get_cleaned_data()
        # adapter.save_user(request, user, self)
        # setup_user_email(request, user, [])
        # #user.save()
        return new_account
Beispiel #8
0
def signup_view(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password1']
        password_verify = request.POST['password2']
        try:
            user = User.objects.get(username=username)
            return JsonResponse(
                {
                    "status": "failure",
                    "message": "username already taken"
                },
                status=409)
        except User.DoesNotExist:
            if password == password_verify:
                user = User.objects.create_user(username=username,
                                                password=password)
                account = Account(user=user, certificate="None")
                if 'email' in request.POST:
                    account.email = request.POST['email']
                account.save()
                login(request, user)
                return JsonResponse(
                    {
                        "status": "success",
                        "message": "account created"
                    },
                    status=201)
            else:
                return JsonResponse(
                    {
                        "status": "failure",
                        "message": "password does not match"
                    },
                    status=406)
    else:
        return render(request, 'users/signupd.html')
Beispiel #9
0
def participate(request, id_account=None):

    if id_account is None:
        account = Account()
        PhotoInlineFormSet = inlineformset_factory(Account,
                                                   Photo,
                                                   form=PhotoCreationForm,
                                                   max_num=5,
                                                   validate_max=True,
                                                   min_num=1,
                                                   validate_min=True,
                                                   extra=5,
                                                   can_delete=False)
    else:
        account = Account.objects.get(pk=id_account)
        PhotoInlineFormSet = inlineformset_factory(Account,
                                                   Photo,
                                                   form=PhotoCreationForm,
                                                   max_num=5,
                                                   validate_max=True,
                                                   min_num=1,
                                                   validate_min=True,
                                                   extra=5,
                                                   can_delete=True)

    all_tags = Tag.objects.all()
    hot_tags = Tag.objects.order_by('-tag_count')[:5]
    recent_tags = Tag.objects.order_by('-update_time')[:5]
    if request.method == "POST":
        form = AccountCreationFrom(request.POST,
                                   request.FILES,
                                   instance=account,
                                   prefix="main")
        formset = PhotoInlineFormSet(request.POST,
                                     request.FILES,
                                     instance=account,
                                     prefix="nested")

        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']

            if formset.is_valid():
                messages.add_message(request, messages.SUCCESS,
                                     'Photos are uploading...')
                form.save()
                photoList = formset.save(commit=False)
                for photo in photoList:
                    photo.rank = len(
                        photo.content) + len(photo.tags.split(' ')) * 5
                    photo.save()
                    #uploadPhoto(photo)

                user = authenticate(email=email, password=password)
                user.updatePhotosRank()
                if user:
                    auth_login(request, user)
                else:
                    print 'login failed'

                return redirect(reverse('users:profile'))
            else:
                messages.add_message(request, messages.ERROR,
                                     'At least upload one photo!')

        return render(
            request, "index/participate.html", {
                "form": form,
                "formset": formset,
                "marker_list": Marker.objects.all(),
                "all_tags": [x.tag_name for x in all_tags],
                "hot_tags": [x.tag_name for x in hot_tags],
                "recent_tags": [x.tag_name for x in recent_tags],
            })
    else:

        form = AccountCreationFrom(instance=account, prefix="main")
        formset = PhotoInlineFormSet(instance=account, prefix="nested")
        return render(
            request, "index/participate.html", {
                "form": form,
                "formset": formset,
                "marker_list": Marker.objects.all(),
                "all_tags": [x.tag_name for x in all_tags],
                "hot_tags": [x.tag_name for x in hot_tags],
                "recent_tags": [x.tag_name for x in recent_tags],
            })