Git Product home page Git Product logo

Comments (9)

bmihelac avatar bmihelac commented on July 22, 2024

I would say that we need order_required decorator.

from django-shop.

mbrochh avatar mbrochh commented on July 22, 2024

Hmm sounds like a good idea!

from django-shop.

alesdotio avatar alesdotio commented on July 22, 2024

we should put the decorator on the payment views as well

from django-shop.

alesdotio avatar alesdotio commented on July 22, 2024

@stephenmuss how exactly should the callable be used?

If i do this

@on_method(order_required(some_function))

I get

AttributeError
'function' object has no attribute 'user'
/django-shop/shop/util/order.py in get_order_from_request
12.    if request.user and not isinstance(request.user, AnonymousUser): 

from django-shop.

stephenmuss avatar stephenmuss commented on July 22, 2024

@alesdotio it should be a url path.

You could pass in a raw string or better to use django.core.urlresolvers.reverse.

e.g.

@on_method(order_required(reverse('shop_welcome')))

Note: Not tested. Just off the top of my head.

Edit: OK. So I didn't think about this at the time, but of course using reverse here won't work. Which means the decorator in its current state will only take a url path as a string.

Some refactoring may be warranted. A simple lazy reverse could do the trick.

I'm happy to take a look if you'd like. What's your preference in terms of the optional argument supplied? Leave it as a url or would you prefer to pass in a callable instead?

from django-shop.

stephenmuss avatar stephenmuss commented on July 22, 2024

I've just made a commit to my fork which approaches it slightly different.

So now we could use @on_method(order_required('shop_welcome'))

Perhaps that would be more flexible? Happy to open a pull request.

I'd still need to rework it so that args and kwargs etc can be passed in the same as in django.core.urlresolvers.reverse.

from django-shop.

alesdotio avatar alesdotio commented on July 22, 2024

@stephenmuss
Having both options would probably be best. I thought that was the whole point of the if callable(redirect_url) part. If you could make that work that would be great, even if you have to call reverse through another function (which is what I tried to do)

def get_cart_url():
    return reverse('cart')

@on_method(order_required(get_cart_url))
def some_view()...

from django-shop.

stephenmuss avatar stephenmuss commented on July 22, 2024

@alesdotio
The if callable(redirect_url) was to allow it to be used with a default value for redirect_url which just redirected to '/'.

However, I agree that being able to pass in a callable or just a string might be a nicer way to do it.

Making the developer explicitly pass in redirect_url is probably a better idea anyway.

I'll make some changes and open another pull request.

Cheers.

from django-shop.

alesdotio avatar alesdotio commented on July 22, 2024

awesome, thank you

from django-shop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.