Beispiel #1
0
def subscribe(request):
    if request.method == 'POST':
        from django.forms.fields import email_re
        if email_re.match(request.POST['email']):
            sub = Subscription(email=request.POST['email'])
            sub.save()
            create_message(request, "Dodano do newslettera")
            return conditional_redirect(request, '/')
        else:
            create_message(request, "Błędny adres e-mail")
            return conditional_redirect(request, '/')
    else:
        return conditional_redirect(request, '/')
Beispiel #2
0
def subscribe(request):
  if request.method == 'POST':
    from django.forms.fields import email_re
    if email_re.match(request.POST['email']):
      sub = Subscription(email=request.POST['email'])
      sub.save()
      create_message(request, "Dodano do newslettera")
      return conditional_redirect(request, '/')
    else:
      create_message(request, "Błędny adres e-mail")
      return conditional_redirect(request, '/')
  else:
      return conditional_redirect(request, '/')
Beispiel #3
0
def login_user(request):
    password_form = PasswordResetForm()
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('logout'))
    if request.method == 'POST':
        login_form = LoginForm(data=request.POST)
        if login_form.is_valid():
            login(request, login_form.get_user())
            request.session.set_expiry(1800)
            return conditional_redirect(request, reverse('profile'))
        else:
            # invalid login form
            create_message(
                request,
                _("Due to recent complex changes in our shop you have to register even if you've had an account in old biolander"
                  ),
                type=1)
            return render_to_response('customers/login.html', {
                'form': login_form,
                'password_form': password_form
            },
                                      context_instance=RequestContext(request))
    else:
        # empty form
        login_form = LoginForm()
        return render_to_response('customers/login.html', {
            'form': login_form,
            'password_form': password_form,
            'next': request.GET.get('next', '')
        },
                                  context_instance=RequestContext(request))
def toggle_activation(request, partner_id):
    partner = get_object_or_404(Partner, pk=partner_id)
    if partner.is_active:
        partner.is_active = False
    else:
        partner.is_active = True
    partner.save()
    return conditional_redirect(request, "/panel/resellers/partner/%d/" % partner.pk)
Beispiel #5
0
def search(request, page=1):
    if request.method == 'GET':
        q = request.GET.get('q', "").strip()
        if len(q) < 3:
            create_message(request, "Fraza zbyt któtka")
            return conditional_redirect(request, '/')
        products = Product.published.filter(
            Q(name__icontains=q) | Q(description__icontains=q)
            | Q(usage__icontains=q) | Q(ingredients__icontains=q))
    else:
        return conditional_redirect(request, '/')
    template = 'products/product_search.html'
    return list_detail.object_list(request,
                                   queryset=products,
                                   paginate_by=PRODUCTS_PER_PAGE,
                                   page=page,
                                   allow_empty=True,
                                   template_name=template,
                                   extra_context={'phrase': q})
Beispiel #6
0
def address_delete(request, address_id):
  address = Address.published.get(pk=address_id)
  if not address.customer == request.user.get_profile() or request.user.is_staff:
    raise Http404
  try:
    address.delete()
    #create_message(request, "Address successfully deleted")
    create_message(request, _("Address successfully deleted"))
  except: 
    create_message(request, _("You cannot delete all your addresses"))
  return conditional_redirect(request, reverse('profile_address'))
Beispiel #7
0
def address_delete(request, address_id):
    address = Address.published.get(pk=address_id)
    if not address.customer == request.user.get_profile(
    ) or request.user.is_staff:
        raise Http404
    try:
        address.delete()
        #create_message(request, "Address successfully deleted")
        create_message(request, _("Address successfully deleted"))
    except:
        create_message(request, _("You cannot delete all your addresses"))
    return conditional_redirect(request, reverse('profile_address'))
Beispiel #8
0
def search(request, page=1):
    if request.method == "GET":
        q = request.GET.get("q", "").strip()
        if len(q) < 3:
            create_message(request, "Fraza zbyt któtka")
            return conditional_redirect(request, "/")
        products = Product.published.filter(
            Q(name__icontains=q) | Q(description__icontains=q) | Q(usage__icontains=q) | Q(ingredients__icontains=q)
        )
    else:
        return conditional_redirect(request, "/")
    template = "products/product_search.html"
    return list_detail.object_list(
        request,
        queryset=products,
        paginate_by=PRODUCTS_PER_PAGE,
        page=page,
        allow_empty=True,
        template_name=template,
        extra_context={"phrase": q},
    )
Beispiel #9
0
def panel(request):
    if not request.user.get_profile().is_active_partner():
        create_message(request, _("You have not registered as partner or your account has not been aprooved"))
        return conditional_redirect(request, reverse('profile'))
    partner = Partner.objects.get(user=request.user)
    history = PartnerHistory.objects.income_daily(partner=partner)
    return render_to_response(
        'resellers/panel.html', {
            'partner':partner,
            'history':json.dumps(history),
            'next': request.REQUEST.get('next', ''),
        }, context_instance=RequestContext(request))
Beispiel #10
0
def address_edit(request, address_id):
  address = Address.published.get(pk=address_id)
  if not address.customer == request.user.get_profile():
    raise Http404
  if request.method == 'POST' and not request.user.is_staff:
    form = AddressEditForm(request.POST, instance=address)
    if form.is_valid():
      form.save()
      create_message(request, _("Operation successfull"))
      return conditional_redirect(request, reverse('profile_address'))
  else:
    form = AddressEditForm(instance=address)
  return render_to_response('customers/profile_address_add.html', {'form':form }, context_instance=RequestContext(request)) 
Beispiel #11
0
def address_list(request, page=1):
    try:
        address = Address.published.filter(customer=request.user.get_profile())
    except Customer.DoesNotExist:
        return conditional_redirect(request, reverse('profile'))
    except:
        raise Http404
    return list_detail.object_list(request,
                                   queryset=address,
                                   paginate_by=6,
                                   page=page,
                                   allow_empty=True,
                                   extra_context={'user': request.user})
Beispiel #12
0
def address_add(request):
  next = request.REQUEST.get('next', False)
  if request.method == 'POST' and not request.user.is_staff:
    form = AddressEditForm(request.POST)
    if form.is_valid():
      address = form.save(commit=False)
      customer = request.user.get_profile()
      address.customer = customer
      address.save()
      create_message(request, _("Operation successfull"))
      return conditional_redirect(request, reverse('profile_address'))
  else:
    form = AddressEditForm()
  return render_to_response('customers/profile_address_add.html', {'form':form, 'next':next }, context_instance=RequestContext(request)) 
Beispiel #13
0
def address_list(request, page=1):
  try:
    address = Address.published.filter(customer=request.user.get_profile())
  except Customer.DoesNotExist:
    return conditional_redirect(request, reverse('profile'))
  except:
    raise Http404
  return list_detail.object_list(
      request,
      queryset=address,
      paginate_by=6,
      page=page,
      allow_empty=True,
      extra_context={'user':request.user})
Beispiel #14
0
def register(request):
    if request.user.get_profile().is_active_partner():
        return conditional_redirect(request, reverse('profile'))
    if request.method == 'GET':
        form = RegistrationForm(user=request.user)
    else:
        form = RegistrationForm(request.POST, user=request.user)
        if form.is_valid():
            partner = form.save(commit=False)
            partner.user = request.user
            partner.save()
            create_message(request, _("Registration successfull"))
            subject = "Nowy partner: %s %s" % (partner.user.first_name, partner.user.last_name)
            subject = ''.join(subject.splitlines())
            message = render_to_string('email/new_reseller.html', {
                'partner':partner
            })
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, settings.SHOP_STAFF_EMAILS)
            return conditional_redirect(request, reverse("profile"))
    return render_to_response(
        'resellers/registration.html', {
            'form':form,
            'next': request.REQUEST.get('next', ''),
        }, context_instance=RequestContext(request))
Beispiel #15
0
def address_edit(request, address_id):
    address = Address.published.get(pk=address_id)
    if not address.customer == request.user.get_profile():
        raise Http404
    if request.method == 'POST' and not request.user.is_staff:
        form = AddressEditForm(request.POST, instance=address)
        if form.is_valid():
            form.save()
            create_message(request, _("Operation successfull"))
            return conditional_redirect(request, reverse('profile_address'))
    else:
        form = AddressEditForm(instance=address)
    return render_to_response('customers/profile_address_add.html',
                              {'form': form},
                              context_instance=RequestContext(request))
Beispiel #16
0
def address_add(request):
    next = request.REQUEST.get('next', False)
    if request.method == 'POST' and not request.user.is_staff:
        form = AddressEditForm(request.POST)
        if form.is_valid():
            address = form.save(commit=False)
            customer = request.user.get_profile()
            address.customer = customer
            address.save()
            create_message(request, _("Operation successfull"))
            return conditional_redirect(request, reverse('profile_address'))
    else:
        form = AddressEditForm()
    return render_to_response('customers/profile_address_add.html', {
        'form': form,
        'next': next
    },
                              context_instance=RequestContext(request))
Beispiel #17
0
def login_user(request):
  password_form = PasswordResetForm()
  if request.user.is_authenticated():
    return HttpResponseRedirect(reverse('logout'))
  if request.method == 'POST':
    login_form = LoginForm(data=request.POST)
    if login_form.is_valid():
      login(request, login_form.get_user())
      request.session.set_expiry(1800)
      return conditional_redirect(request, reverse('profile'))
    else:
      # invalid login form
      create_message(request, _("Due to recent complex changes in our shop you have to register even if you've had an account in old biolander"), type=1)
      return render_to_response('customers/login.html', {'form':login_form, 'password_form':password_form}, context_instance=RequestContext(request)) 
  else:
    # empty form
    login_form = LoginForm()
    return render_to_response('customers/login.html', {'form':login_form, 'password_form':password_form, 'next':request.GET.get('next', '')}, context_instance=RequestContext(request)) 
Beispiel #18
0
def activate(request, activation_key):
  activation_key = activation_key.lower() # Normalize before trying anything with it.
  account = Customer.objects.activate_user(activation_key)
  create_message(request, _("Activation successfull"))
  return conditional_redirect(request, reverse('login'))
Beispiel #19
0
def activate(request, activation_key):
    activation_key = activation_key.lower(
    )  # Normalize before trying anything with it.
    account = Customer.objects.activate_user(activation_key)
    create_message(request, _("Activation successfull"))
    return conditional_redirect(request, reverse('login'))