Example #1
0
def _show_cart(request, cart, form=None):
    """
    Display the contents of the cart selected
    """
    products = models.Item.objects.filter(cart=cart).order_by('description')
    
    paginator = DiggPaginator(products, MAX_RESULTS, **DIGG_ATTRS)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try: 
        products = paginator.page(page)
    except (EmptyPage, InvalidPage):
        products = paginator.page(paginator.num_pages)
        
    data = dict(
        cart=cart,
        products=products,
        curpage=page,
        form=form,
        tax_rate=settings.TAX_RATE,
        shipping_rate=settings.SHIPPING_RATE
    )
    return request_to_response(request, 'cart/index.html', data)
Example #2
0
 def save(self):
     data = self.cleaned_data
     
     user = User.objects.create_user(
         data['username'],
         data['email'],
         data['password']
     )
     
     user.first_name = data['first_name']
     user.last_name = data['last_name']
     user.save()
     
     profile = models.UserProfile.objects.create(
         user=user,
         number=data['number'],
     )
     
     subject = 'Confirm New Account'
     data = dict(
         user=user,
         data=data,
     )
     message = request_to_response(self.request, 'accounts/email/new_account.txt', data)
     send_mail(subject, message, settings.EMAIL_FROM, [user.email], fail_silently=True)
     
     return user
Example #3
0
def home(request):
    profile = get_object_or_404(models.UserProfile, user=request.user)
    past_orders = cart.Cart.objects.filter(user=request.user, completed=True)
    data = dict(
        profile=profile,
        past_orders=past_orders,
    )
    return request_to_response(request, 'accounts/index.html', data)
Example #4
0
def reset_password(request):
    if request.method == 'POST':
        form = forms.ResetPasswordForm(request, data=request.POST)
        if form.is_valid():
            user = form.save()
            form = forms.LoginForm(request)
            data = dict(
                messages=[u'A new Password has been sent to %s.' % user.email],
                form=form
            )
            return request_to_response(request, 'accounts/login.html', data)
    else:
        form = forms.ResetPasswordForm(request)
    data = dict(
        form=form
    )
    return request_to_response(request, 'accounts/reset_password.html', data)
Example #5
0
def create(request):
    if request.method == 'POST':
        form = forms.AccountCreateForm(request, data=request.POST)
        if form.is_valid():
            user = form.save()
            form = forms.LoginForm(request)
            data = dict(
                messages=['A new account has been created.',],
                form=form
            )
            return request_to_response(request, 'accounts/login.html', data)
    else:
        form = forms.AccountCreateForm(request)
    data = dict(
        form=form,
    )
    return request_to_response(request, 'accounts/create.html', data)
Example #6
0
def logout_user(request):
    logout(request)
    form = forms.LoginForm(request)
    data = dict(
        messages=[u'You have been logged out.',],
        form=form,
    )
    return request_to_response(request, 'accounts/login.html', data)
Example #7
0
def _render(request, template, data):
    data['category_list'] = models.Category.objects.all()
    data['form_add'] = cart.AddProductForm(request, None)
    
    try:
        data['form']
    except KeyError:
        data['form'] = forms.ProductSearchForm(request)

    return request_to_response(request, template, data)
Example #8
0
def login(request):
    if request.method == 'POST':
        form = forms.LoginForm(request, data=request.POST)
        if form.is_valid():
            return http.HttpResponseRedirect(reverse('account_home'))
    else:
        form = forms.LoginForm(request)
    data = dict(
        form=form,
    )
    return request_to_response(request, 'accounts/login.html', data)
Example #9
0
def update(request):
    if request.method == 'POST':
        form = forms.AccountForm(request, data=request.POST)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message=u'Account profile has been updated.')
            return http.HttpResponseRedirect(reverse('account_home'))
    else:
        form = forms.AccountForm(request)
    data = dict(
        form=form
    )
    return request_to_response(request, 'accounts/update.html', data)
Example #10
0
 def save(self):
     data = self.cleaned_data
     
     user = User.objects.get(email=data['email'])
     password = ''.join(Random().sample(string.letters+string.digits, 6))
     user.set_password(password)
     user.save()
     
     subject = 'Password Updated'
     data = dict(
         user=user,
         data=data,
         password=password,
     )
     message = request_to_response(self.request, 'accounts/email/new_password.txt', data)
     send_mail(subject, message, settings.EMAIL_FROM, [user.email], fail_silently=False)
     
     return user
Example #11
0
def home(request):
    data = dict()
    return request_to_response(request, "index.html", data)
Example #12
0
def home(request):
    return request_to_response(request, "index.html", {})
Example #13
0
def home(request):
    news_list = models.News.objects.all().order_by("-created")
    data = dict(news_list=news_list)
    return request_to_response(request, "news/index.html", data)
Example #14
0
def view(request, slug):
    news_item = get_list_or_404(models.News.objects, slug=slug)
    data = dict(news_list=news_list)
    return request_to_response(request, "news/index.html", data)