2

I would like to be able to add a the following: [(?P<slug>[-\w]+)] after /dashboard/' between that and the rest of any possible url that comes after, i.e. '/dashboard/ (?P<slug>[-\w]+) /catalogue/. The point of this would be to make it 'partner-specific' for my particular project.

How would I go about doing this? I currently am working directly with Oscar code for several reasons, meaning that I do not have to 'fork' any apps - I just change the Oscar code within my project. The strategy I am trying to accomplish this URL-change is to go into app.py and adding it there after 'dashboard', or going into dashboard/app.py and adding it before each url defined there.

Whenever I change I keep getting 'NoReverseMatch at ---' and errors like:

Reverse for 'MY-URL-IS-HERE' with no arguments not found. 1 pattern(s) tried: ['dashboard/(?P<slug>[-\\w]+)/logout/$']

I am familiar with this error, but now seem unable to ever locate the exact location of the error message. And whenever I do get the page to load (was able to when adding it before 'reviews'), I still get an error something like the following in the terminal:

Invalid URL name dashboard:reviews-list Traceback (most recent call last): File "/Users/myname/Desktop/Developer/wybe-all/wybe/apps/oscar/dashboard/nav.py", line 83, in default_access_fn

If someone that has done this before perhaps could point me in the right direction, that would be greatly appreciated!

Best regards,

William Karlsson

William Karlsson
  • 219
  • 2
  • 16
  • 1
    This is close to what django's own internationalization does. You can check [the docs](https://docs.djangoproject.com/en/2.1/topics/i18n/translation/#module-django.conf.urls.i18n) & possibly implement it via a custom middleware with [request url manipulation](https://stackoverflow.com/questions/9320693/is-there-a-way-to-alter-the-request-path-before-matching-the-urls) while allocating some special request.PARTNER variable or something, and then freely use this special variable in your view classes to default filter querysets or something. – shad0w_wa1k3r Jan 27 '19 at 14:34
  • @shad0w_wa1k3r To make sure I understand this approach: it would mean having one url entered, changing it in custom middleware thus 'redirecting' to a url without the slug, ultimately using the old urls? As well of course as having request.PARTNER (or something) added? Would this not be problematic and difficult to use for a user? – William Karlsson Jan 27 '19 at 15:54
  • 1
    There won't be any redirection as such, just that you are internally processing the URL such that it doesn't break existing oscar processing (less effort / changes). This won't affect end user since all handling is on the backend, but yeah, given the effort, might give quite a headache to the developer. And of course, this is just one approach that I could right away think of. You'd still likely end up changing base classes to filter querysets (or add a decorator or something to classes that depend on this), but it seems less effort & DRY than modifying all views to handle new url formats. – shad0w_wa1k3r Jan 27 '19 at 16:08
  • @shad0w_wa1k3r It seems to be working fine! However, in working with this, I noticed that GET-requests seem to be done continuously while write my url. For example, writing '127.0.0.1:8000/dashboard' without actually 'pressing enter' is registered in my terminal as a GET-request, this is without any middleware added but also with it active. Is this normal for oscar? Would this become a problem? Sometimes when my middleware is instructed to redirect, entering a path without actually 'hitting enter' can register several redirects if the path is long (i.e. 'dashboard/partner/...'). – William Karlsson Jan 30 '19 at 20:47
  • 1
    That may just be Google Chrome doing some weird tricks, try in some other browser (even if yours isn't Chrome). – shad0w_wa1k3r Jan 30 '19 at 20:53
  • Depending on what exactly you intend to achieve, you might be able to do it with just a simple session variable (partner) that you could be set on login or via some simple navbar dropdown that hits a POST request to change this session variable. So, instead of accessing URL param in the view, just get the session variable for the given request. – shad0w_wa1k3r Feb 14 '19 at 19:17

0 Answers0