Пример #1
0
def prepacks(request, id):
    p = PrePack.objects.first()
    if len(PrePack.objects.filter(facepack__id=id)) == 1:
        p = PrePack.objects.get(facepack__id=id)
    data = { 'valid_user': get_valid_user_data(request),
             'cart_size' : cart_size(request),
             'p'         : p,
             'ing'       : [{'img': i.ingredient.image.url,
                             'name': i.ingredient.name} \
                           for i in p.prepackingredients_set.all()],
             'prepacks'  : [{
                             'facepack' : i.facepack,
                             'cart_type': request.user.cart_set.get(item=i.facepack).type \
                                 if hasattr(request.user, 'cart_set') and \
                                 request.user.cart_set.filter(item=i.facepack).count() > 0 \
                                 else None
                           } for i in PrePack.objects.all() if i != p],
    }
    if cart_size(request) > 0:
        for fp in FacePack.objects.filter(pk=id):
            if request.user.cart_set.filter(item=fp).count() > 0:
                cart_type = request.user.cart_set.get(item=fp).type
                data['fp'] = fp.id
                data['fp_type'] = cart_type
    return render(request, "prepacks.html", data)
Пример #2
0
def view_cart(request):
    data = {}
    #init_user_login(request)
    cart_items = []
    shipping_id = int(request.GET.get('shipping')) if request.GET.get('shipping') else 4
    shipping = Shipping.objects.get(pk=shipping_id)
    subtotal = Decimal('0.00');
    total = Decimal('0.00');
    user = request.user
    if cart_size(request) > 0:
        for c in user.cart_set.all():
            mandatory = []
            optional = None
            for cfp in CustomFacePack.objects.filter(facepack=c.item):
                mandatory.append({
                    'name'   : cfp.recipe.mandatory_ingredient.name,
                    'id'     : cfp.recipe.mandatory_ingredient.id,
                    'r_id'   : cfp.recipe.id,
                    'image'  : cfp.recipe.mandatory_ingredient.image,  
                })
                optional = cfp.optional_ingredient
            fp = FacePack.objects.get(pk=c.item_id)
            cart_items.append({
                'id'           : c.id,
                'type'         : c.type,
                'subtype'      : c.subtype,
                'item_id'      : c.item_id,
                'name'         : fp.name,
                'mandatory'    : mandatory,
                'base'         : fp.base.name,
                'mixing_agent' : fp.mixing_agent.name,
                'optional'     : { 
                                   'name'  : optional.name,
                                   'image' : optional.image,
                                 } if optional else "" ,
                'quantity'     : c.quantity,
                'price'        : '$'+str(c.item.price*c.quantity) if c.type == "buy" else '$'+str(c.item.price)
            })
            subtotal += c.item.price*c.quantity
    promo_discount = sum([p.discount for p in Promo.objects.filter(active=True)])
    data = {
        'cart_size' : cart_size(request),
        'cart_items': cart_items,
        'shipping_items'  : [{ 'type': s.type,
                               'id': s.id } for s in Shipping.objects.all()],
        'shipping_id'     : shipping.id,
        'shipping_cost'   : '$'+str(shipping.cost),
        'shipping_helper' : shipping.helper,
        'subtotal'        : '$'+str(subtotal),
        'total'           : '$'+str(subtotal+shipping.cost-promo_discount) ,
        'total_cents'     : (subtotal+shipping.cost-promo_discount)*100,
        'valid_user'      : get_valid_user_data(request),
        'is_anonymous'    : user.username.startswith("anon_"),
        'promo'           : Promo.objects.filter(active=True),
    }
    return render(request, "cart.html", data)
Пример #3
0
def show_story(request):
    data = {
        'cart_size': cart_size(request),
        'valid_user': get_valid_user_data(request),
        'title': Story.objects.get(pk=1),
        'section_1': Story.objects.get(pk=2),
        'section_2': Story.objects.get(pk=3),
        'section_3': Story.objects.get(pk=4),
        'section_4': Story.objects.get(pk=5),
        'section_5': Story.objects.get(pk=6),
        'section_6': Story.objects.get(pk=7),
    }
    return render(request, "story.html", data)
Пример #4
0
def wizard(request):
    data = []
    for q in Question.objects.all():
        data.append({
            'id'       : q.id,
            'name'     : q.name,
            'why'      : q.why,
            'multiple' : 'multiple' if q.id == 8 else '',
            'options'  : [{
                            'name':    o['option__name'],
                            'id':      o['option__id'],
                            'helper':  o['option__helper']
                          } for o in Questionnaire.objects.filter(question=q).\
                          values('option__name','option__id',
                          'option__helper')]
        })
    return render(
        request, "wizard.html", {
            'questions': data,
            'cart_size': cart_size(request),
            'valid_user': get_valid_user_data(request)
        })
Пример #5
0
def review_page(request, skin_type=""):
    reviews = []
    review_ids = []
    skin = skin_type
    if skin and SkinType.objects.filter(name=skin).count() > 0:
        cmd_str = "Q(question__id=7, option__name='%s')" % skin
        for qe in QuestionnaireEntry.objects.filter(eval(cmd_str)):
            for c in qe.wizard.customfacepack_set.all():
                review_set = c.facepack.review_set
                if not skin_type:
                    skin_type = c.recipe.skin_type.name
                if review_set.count() > 0:
                    for r in review_set.all():
                        if r.id not in review_ids:
                            user = r.ph.user
                            reviews.append({
                                'review':
                                r,
                                'rating':
                                range(r.rating),
                                'rating_neg':
                                range(5 - r.rating),
                                'user_pic':
                                user.profile.picture
                                if hasattr(user, 'profile')
                                and user.profile.picture else
                                'images/profile/default.png',
                                'fp':
                                r.fp,
                                'pics': [{
                                    'url': ri.image.url,
                                    'id': ri.id
                                } for ri in r.reviewimage_set.all()],
                                'is_cfp':
                                True,
                            })
                            review_ids.append(r.id)
    review_count = len(reviews)
    rating_avg = float(sum([int(r['review'].rating) for r in reviews
                            ])) / review_count if review_count > 0 else 0
    rating_avg_full = int(rating_avg)
    rating_avg_half = 0.0
    rating_avg_empty = 5 - int(rating_avg)
    if int(rating_avg) < rating_avg:
        rating_avg_half = round(rating_avg - rating_avg_full, 1)
        rating_avg_empty -= 1
    data = {
        'reviews': reviews,
        'count': review_count,
        'rating_avg_full': range(rating_avg_full),
        'rating_avg_half': rating_avg_half,
        'rating_avg_half_dec': "".join(str(rating_avg_half).split('.')[1:]),
        'rating_avg_empty': range(rating_avg_empty),
        'skin_type': skin if skin else skin_type,
        'type': type,
        'cart_size': cart_size(request),
        'valid_user': get_valid_user_data(request),
    }
    if not skin_type:
        skin_list = [i.name for i in SkinType.objects.all()]
        random.shuffle(skin_list)
        for skin in skin_list:
            cmd_str = "Q(question__id=7, option__name='%s')" % skin
            for qe in QuestionnaireEntry.objects.filter(eval(cmd_str)):
                for c in qe.wizard.customfacepack_set.all():
                    review_set = c.facepack.review_set
                    if review_set.count() > 0:
                        return redirect('/reviews/%s' % skin)
        return redirect('/reviews/Normal')
    return render(request, "review_page.html", data)
Пример #6
0
def results(request):
    if request and request.method == 'GET':
        init_user_login(request)
        user = request.user
        recipe_ids = [int(x) for x in request.GET.getlist('recipes[]')]
        o_ids = [int(x) for x in request.GET.getlist('optional[]')]
        recipes = Recipe.objects.filter(id__in=recipe_ids)
        secondary_ings = Ingredient.objects.filter(id__in=o_ids)
        qd_id = request.GET.get('qd')
        skin_type = request.GET.get('skin_type', None)
        base = Base.objects.get(pk=request.GET.get('base'))
        mixing_agent = MixingAgent.objects.get(
            pk=request.GET.get('mixing_agent'))
        #secondary_ings = [random.choice(SkinTypeConcernIngredient.objects\
        #.filter(skin_type=r.skin_type, skin_concern=r.skin_concern)\
        #.filter(~Q(ingredient=r.mandatory_ingredient))).ingredient\
        #for r in recipes]
        essential_oils = Ingredient.objects.get(
            name__contains="Essential Oils")
        r1 = recipes[0]
        r2 = recipes[1]
        r3 = recipes[2]
        o1 = secondary_ings[0]
        o2 = secondary_ings[1]
        o3 = secondary_ings[2]
        o_ids = [i.id for i in secondary_ings]

        data = {
            'first': {
                'type':
                'primary',
                'base': {
                    'id': base.id,
                    'name': base.name,
                    'image': base.image,
                    'helper': base.helper,
                    'description': base.description,
                },
                'mixing_agent': {
                    'id': mixing_agent.id,
                    'name': mixing_agent.name,
                    'image': mixing_agent.image,
                    'helper': mixing_agent.helper,
                    'description': mixing_agent.description,
                },
                'essential_oils': {
                    'id': essential_oils.id,
                    'name': essential_oils.name,
                    'image': essential_oils.image,
                    'helper': essential_oils.helper,
                    'description': essential_oils.description,
                },
                'recipes': [{
                    'id':
                    r.id,
                    'i_id':
                    r.mandatory_ingredient.id,
                    'i_name':
                    r.mandatory_ingredient.name,
                    'i_image':
                    r.mandatory_ingredient.image,
                    'i_helper':
                    r.mandatory_ingredient.helper,
                    'i_description':
                    r.mandatory_ingredient.description,
                } for r in recipes],
                'b_id':
                base.id,
                'm_id':
                mixing_agent.id,
                'r1_id':
                r1.id,
                'r2_id':
                r2.id,
                'r3_id':
                r3.id,
                'o_ids': [],
                'qd_id':
                qd_id,
            },
            'second': {
                'type':
                'secondary',
                'base': {
                    'id': base.id,
                    'name': base.name,
                    'image': base.image,
                    'helper': base.helper,
                    'description': base.description,
                },
                'mixing_agent': {
                    'id': mixing_agent.id,
                    'name': mixing_agent.name,
                    'image': mixing_agent.image,
                    'helper': mixing_agent.helper,
                    'description': mixing_agent.description,
                },
                'essential_oils': {
                    'id': essential_oils.id,
                    'name': essential_oils.name,
                    'image': essential_oils.image,
                    'helper': essential_oils.helper,
                    'description': essential_oils.description,
                },
                #'recipes': [{
                #'id': r.id,
                #'i_id': r.mandatory_ingredient.id,
                #'i_name': r.mandatory_ingredient.name,
                #'i_image': r.mandatory_ingredient.image,
                #'i_helper': r.mandatory_ingredient.helper,
                #'i_description': r.mandatory_ingredient.description,
                #} for r in recipes],
                'recipes': [{
                    'id': i.id,
                    'i_id': i.id,
                    'i_name': i.name,
                    'i_image': i.image,
                    'i_helper': i.helper,
                    'i_description': i.description,
                } for i in secondary_ings],
                'b_id':
                base.id,
                'm_id':
                mixing_agent.id,
                'r1_id':
                r1.id,
                'r2_id':
                r2.id,
                'r3_id':
                r3.id,
                'o1_id':
                o1.id,
                'o2_id':
                o2.id,
                'o3_id':
                o3.id,
                'o_ids':
                o_ids,
                'qd_id':
                qd_id,
            },
            'qd_id': qd_id,
            'skin_type': skin_type,
        }
        data['cart_size'] = cart_size(request)
        data['valid_user'] = get_valid_user_data(request)
        return render(request, "results.html", data)
Пример #7
0
def view_myaccount(request, option=None):
    valid_options = [
        'account-details',
        'skin-profile',
        'order-history',
        'shipping-&-payments',
        'my-subscriptions',
    ]
    data = {
        'valid_user': get_valid_user_data(request),
        'cart_size': cart_size(request),
        'selected': option,
        'options': valid_options,
    }
    data['photo_upload_url'] = '/post_photo_upload/'
    if not get_valid_user_data(request) or request.user.username.startswith(
            'anon_'):
        return redirect('/signin/?next=/myaccount/account-details', data)
    if not option or option not in valid_options:
        return redirect('/myaccount/account-details', data)
    skin_profile = {
        'skin_concern_1': "",
        'skin_concern_2': "",
        'skin_concern_3': "",
        'skin_type': "",
        'skin_routine_evening': "",
        'skin_routine_morning': "",
        'sunscreen': "",
        'environment': "",
    }
    # Check if wizard data exists
    if QuestionnaireUserData.objects.filter(user=request.user).count() > 0:
        if not hasattr(request.user, 'profile'):
            up = Profile()
            up.user = request.user
            up.save()
        up = request.user.profile
        # Gender
        w = QuestionnaireUserData.objects.filter(
            user=request.user).order_by('-id')[0]
        up.gender = QuestionnaireEntry.objects.filter(
            wizard=w, question=2)[0].option.name
        up.save()
        # Skin profile
        skin_profile['skin_concern_1'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=8)[0].option.name
        skin_profile['skin_concern_2'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=8)[1].option.name
        skin_profile['skin_concern_3'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=8)[2].option.name
        skin_profile['skin_type'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=7)[0].option.name
        skin_profile['skin_routine_evening'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=6)[0].option.name
        skin_profile['skin_routine_morning'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=5)[0].option.name
        skin_profile['sunscreen'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=4)[0].option.name
        skin_profile['environment'] = QuestionnaireEntry.objects.\
                                        filter(wizard=w, question=3)[0].option.name
    if option == 'account-details':
        data['first_name'] = request.user.first_name
        data['last_name'] = request.user.last_name
        data['email'] = request.user.email
        # Check for any user profile data
        if hasattr(request.user, 'profile'):
            up = request.user.profile
            data['gender'] = up.gender or ""
            data['birthday'] = (up.birth_date
                                and up.birth_date.strftime("%b %d, %Y")) or ""
            data['subscription'] = up.subscription or "No"
    elif option == 'skin-profile':
        data.update(skin_profile)
    elif option == 'order-history':
        user = request.user
        orders = []
        if hasattr(user, 'payment_set'):
            for i, py in enumerate(
                    user.payment_set.all().order_by('createdte')):
                for j, ph in enumerate(py.purchasehistory_set.all()):
                    mandatory = []
                    for cfp in CustomFacePack.objects.filter(facepack=ph.item):
                        ing = cfp.optional_ingredient if cfp.optional_ingredient else cfp.recipe.mandatory_ingredient
                        mandatory.append({
                            'name': ing.name,
                            'id': ing.id,
                            'r_id': cfp.recipe.id,
                            'image': ing.image,
                        })
                    fp = FacePack.objects.get(pk=ph.item_id)
                    review_id = None
                    if len(fp.review_set.filter(ph__user=user).all()) > 0:
                        review_id = fp.review_set.filter(
                            ph__user=user).first().id
                    orders.append({
                        'fp_id': fp.id,
                        'sno': i + 1,
                        'first': 'first' if j == 0 else '',
                        'date': py.createdte,
                        'shipping_type': ph.shipping.type,
                        'shipping_cost': '$' + str(ph.shipping.cost),
                        'total': '$' + str(py.total),
                        'name': fp.name,
                        'price': '$' + str(ph.item.price),
                        'quantity': ph.quantity,
                        'base': fp.base.name,
                        'type': ph.type,
                        'subtype': ph.subtype or "-",
                        'mixing_agent': fp.mixing_agent.name,
                        'mandatory': mandatory,
                        'item': ph.item,
                        'review': review_id,
                    })
        data['orders'] = orders
    elif option == 'shipping-&-payments':
        shipping = []
        if hasattr(request.user, 'profile'):
            up = request.user.profile
            for sh in up.shippingaddress_set.all():
                shipping.append({
                    'first_name': sh.first_name,
                    'last_name': sh.last_name,
                    'street1': sh.street1,
                    'street2': sh.street2,
                    'city': sh.city,
                    'state': sh.state,
                    'zip': sh.zipcode,
                    'phone': sh.phone_number,
                    'primary': sh.primary,
                    'id': sh.id,
                })
        data['shipping'] = shipping
        paymenttypes = []
        for pt in request.user.paymenttype_set.all():
            cc = Stripe.objects.get(pk=pt.id)
            paymenttypes.append({
                'first_name':
                " ".join(cc.owner_name.split()[0:-1])
                if cc.owner_name.split() else "",
                'last_name':
                cc.owner_name.split()[-1] if cc.owner_name.split() else "",
                'street':
                cc.street,
                'street1':
                cc.street,
                'street2':
                "",
                'city':
                cc.city,
                'state':
                cc.state,
                'zip':
                cc.zipcode,
                'primary':
                cc.primary,
                'type':
                cc.type,
                'number':
                cc.number[-4:],
                'expiry':
                cc.expiry.strftime("%m/%y"),
                'id':
                cc.id,
            })
        data['paymenttypes'] = paymenttypes
        data['url_save_shipping_address'] = '/post_save_shipping_address/'
        data['url_update_shipping_address'] = '/post_update_shipping_address/'
        data['url_delete_shipping_address'] = '/post_delete_shipping_address/'
        data['url_save_paymenttype'] = '/post_save_paymenttype/'
        data['url_delete_paymenttype'] = '/post_delete_paymenttype/'
    elif option == 'my-subscriptions':
        user = request.user
        subscriptions = []
        if hasattr(user, 'payment_set'):
            for i, py in enumerate(
                    user.payment_set.all().order_by('createdte')):
                for j, ph in enumerate(py.purchasehistory_set.all()):
                    if ph.type == "subscribe":
                        mandatory = []
                        for cfp in CustomFacePack.objects.filter(
                                facepack=ph.item):
                            ing = cfp.optional_ingredient if cfp.optional_ingredient else cfp.recipe.mandatory_ingredient
                            mandatory.append({
                                'name': ing.name,
                                'id': ing.id,
                                'r_id': cfp.recipe.id,
                                'image': ing.image,
                            })
                        fp = FacePack.objects.get(pk=ph.item_id)
                        subscriptions.append({
                            'sno':
                            i + 1,
                            'id':
                            ph.id,
                            'ship_date':
                            ph.ship_date.strftime("%b %d, %Y"),
                            'quantity': {
                                'amount': ph.quantity,
                                'helper': 'per month',
                            },
                            'cost': {
                                'amount': '$' + str(ph.item.price),
                                'helper': 'per pack',
                            },
                            'total': {
                                'amount': '$' + str(py.total),
                                #'helper': 'Savings: $18/month',
                                'helper': '',
                            },
                            'name':
                            fp.name,
                            'base':
                            fp.base.name,
                            'mixing_agent':
                            fp.mixing_agent.name,
                            'mandatory':
                            mandatory,
                            'item':
                            ph.item,
                            'type':
                            ph.type,
                            'subtype':
                            ph.subtype or "-",
                        })
        data['subscriptions'] = subscriptions
        data['url_update_ph'] = '/post_update_ph/'
    #pprint.pprint(data)
    return render(request, "myaccount-" + option.replace('&', 'and') + ".html",
                  data)
Пример #8
0
def thanks(request):
    data = {
        'cart_size' : cart_size(request),
        'valid_user': get_valid_user_data(request)
    }
    return render(request, "thanks.html", data)