Exemplo n.º 1
0
def register(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data

            new_customer = Customer()

            # Stock django User model fields
            new_customer.username = data['id_number']
            new_customer.set_password(data['password'])
            new_customer.first_name = data['first_name']
            new_customer.last_name = data['last_name']
            new_customer.email = data['email']

            # Our custom properties
            new_customer.phone_number = data['phone_number']
            new_customer.address = data['address']

            new_customer.save()

            return HttpResponseRedirect(reverse("register_thanks"))
    else:
        form = RegistrationForm()

    return render(request, "users/register.html", {"form": form})
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
def register_customer(request):
    if request.method == 'POST':
        new_customer = Customer(
            first_name=request.POST['first_name'],
            last_name=request.POST['last_name'],
            phone=request.POST['phone'],
            email=request.POST['email'],
            address=request.POST['address'],
            password=request.POST['password'],
        )
        new_customer.save()
        return HttpResponseRedirect(reverse('users:login'))
    elif request.method == 'GET':
        template = 'users/register.html'
        return render(request, template)
    return HttpResponse('Error: No se puede Guardar!')
Exemplo n.º 4
0
def get_session(request, user=None):
    '''get or create anonymous customer through request.session_key'''
    if not request.session.session_key:
        request.session.save()

    session_key = request.session.session_key
    customer_session, created = Customer.objects.get_or_create(
        session_id=session_key)

    if created:
        print('NEW ANONYMOUS USER WAS CREATED')
        print('ANONYMOUS SESSION_ID:', customer_session.session_id)
    else:
        print('ANONYMOUS EXiSTS')
        print('ANONYMOUS SESSION_ID:', customer_session.session_id)
        if user and customer_session.user:
            customer_session = Customer(user=user)
            customer_session.save()
    return customer_session
Exemplo n.º 5
0
    def create(self, validated_data):
        user = User.objects.create_user(**self.initial_data)
        user.save()

        # person = Person(user=user, **person_data)
        person = Person(user=user)
        person.save()

        is_user = self.initial_data['is_user']

        if is_user == 'customer':
            customer = Customer(person_info=person)
            customer.save()
        elif is_user == 'vendor':
            vendor = Vendor(person_info=person)
            vendor.save()
        else:
            '''Here goes Partner'''

        return user
Exemplo n.º 6
0
    def save(self, commit=True):
        cleaned_data = self.cleaned_data
        instance = super().save(commit=False)
        instance.set_password(self.cleaned_data.get('password'))
        instance.save()
        client = Customer(user=instance)
        address = cleaned_data.get('address')
        if address:
            client.address = address
        avatar = cleaned_data.get('avatar')
        if avatar:
            file = Image(file=avatar,
                         owner=instance,
                         name=avatar.name,
                         original_filename=avatar.name)
            file.save()
            instance.image = file
        client.save()
        instance.save()

        return instance
Exemplo n.º 7
0
def post_customer(request):
    if not is_authenticated(request): return redirect('login')
    user_id = request.session['user_id']
    page = 'register'
    if request.method == 'POST':
        if 'cancel' in request.POST: return redirect('dashboard')
        instance = Customer(user=User.objects.get(id=user_id))
        form_basic = CustomerForm(data=request.POST, instance=instance)
        form_status = CustomerStatusForm(request.POST)
        if form_basic.is_valid() and form_status.is_valid():
            post_customer_save(form_basic, request)
            return redirect('dashboard')
    else:
        form_basic = CustomerForm()
        form_status = CustomerStatusForm()
    return render(
        request, 'customer_register.html', {
            'form_basic': form_basic,
            'form_status': form_status,
            'page': page,
            'user': get_user_data(request)
        })
Exemplo n.º 8
0
from users.models import Customer  # 2. App이름.models
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
User = get_user_model()

bulk_list = []
with open(CSV_PATH, encoding='UTF-8') as csvfile:  # 4. newline =''
    data_reader = csv.reader(csvfile)
    next(data_reader, None)
    for row in data_reader:
        bulk_list.append(
            Customer(  # 5. class명.objects.create
                user=User.objects.get(username=row[0]),
                name=row[1],
                email=row[2],
                phone_num=row[3],
                team_state=row[4],
                study_state=row[5],
                intro=row[6],
            ))

Customer.objects.bulk_create(bulk_list)

# 3. Domain 데이터 업로드

CSV_PATH = 'users/domain.csv'  # 3. csv 파일 경로
# CSV_PATH = 'C:/Users/leeso/OneDrive/바탕 화면/data/domain_index.csv'
import csv
from users.models import Domain, Customer  # 2. App이름.models
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
Exemplo n.º 9
0
def checkout(request):
    try:
        if request.user.customer.membership:
            return redirect('users:settings')
    except Customer.DoesNotExist:
        pass
    coupons = {'haloween': 31, 'welcome': 10}
    if request.method == 'POST':
        stripe_customer = stripe.Customer.create(
            email=request.user.email, source=request.POST['stripeToken'])
        plan = os.getenv('MONTHLY', None)
        if request.POST['plan'] == 'yearly':
            plan = os.getenv('YEARLY', None)
        if request.POST['coupon'] in coupons:
            percentage = coupons[request.POST['coupon'].lower()]
            try:
                coupon = stripe.Coupon.create(
                    duration='once',
                    id=request.POST['coupon'].lower(),
                    percent_off=percentage)
            except Exception:
                pass
            subscriprion = stripe.Subscription.create(
                customer=stripe_customer.id,
                items=[{
                    'plan': plan
                }],
                coupon=request.POST['coupon'].lower())
        else:
            subscriprion = stripe.Subscription.create(
                customer=stripe_customer.id, items=[{
                    'plan': plan
                }])
        customer = Customer()
        customer.user = request.user
        customer.stripe_id = stripe.customer.id
        customer.membership = True
        customer.cancel_at_period_end = False
        customer.stripe_subscription_id = subscriprion.id
        customer.save()
        return redirect('website:home')
    else:
        plan = 'monthly'
        coupon = 'none'
        price = 1000
        og_dollar = 10
        coupon_dollar = 0
        final_dollar = 10
        if request.method == 'GET' and 'plan' in request.GET:
            if request.GET['plan'] == 'yearly':
                plan = 'yearly'
                price = 10000
                og_dollar = 100
                final_dollar = 100
        if request.method == 'GET' and 'coupon' in request.GET:
            if request.GET['coupon'].lower() in coupons:
                coupon = request.GET['coupon'].lower()
                percentage = coupons[coupons]
                coupons_price = int(percentage / 100) * price
                price = price - coupons_price
                coupon_dollar = (str(coupons_price[:-2]) + '.' +
                                 str(coupons_price[-2:]))
                final_dollar = str(price[:-2]) + '.' + str(price[-2:])
        return render(
            request, 'plans/checkout.html', {
                'plan': plan,
                'coupon': coupon,
                'price': price,
                'og_dollar': og_dollar,
                'coupon_dollar': coupon_dollar,
                'final_dollar': final_dollar
            })