|
Blinkz0rz posted:Do you guys have any suggestions for implementing the "user activity or logout" functionality that a lot of banks have? It'd be easy enough to write a view mixin (assuming CBVs, use a decorator if you're using FBVs) that, on required recent-login views, checks their login time against a timedelta. If it's over a certain threshold, make 'em log in again. If you want it to be based on activity, just store an additional last_action_time datetime in their session. That'd be best solved with a middleware. Someone actually proposed something like this to django-braces so we might build and include it in that soon.
|
# ? May 30, 2014 00:00 |
|
|
# ? Jun 6, 2024 07:06 |
|
I decided that I want a view to add a message to a template depending on in what way it was called. That is to say, for example, if you go to the login page when already logged in, it redirects to the homepage and displays a helpful message. The "redirects" part works, but the "message" part has hit a few snags. Right now, it looks like this: code:
I want the 'upsets:index' part to say "You're already logged in". I know that reverse takes kwargs, but it would be kind of stupid to expose this functionality in the url as the goal is foolproofing.
|
# ? May 31, 2014 11:15 |
|
I might be misunderstanding, but is this not a job for the messaging framework in django? https://docs.djangoproject.com/en/1.6/ref/contrib/messages/
|
# ? May 31, 2014 12:13 |
|
Sounds like it.
|
# ? May 31, 2014 12:26 |
|
supermikhail posted:One (rather complicated) way I can think of is have the login button be part of a form with a hidden field for the current url (found like this http://stackoverflow.com/questions/2882490/get-the-current-url-within-a-django-template). This goes to your GET login view which passes the hidden field on to the login page, from which you POST it back to the login view, and voila. But maybe I'm overthinking it. Nimrod posted:request.META['HTTP_REFERER'] ? Thermopyle posted:FWIW, I use django-allauth on all my projects requiring registration and login stuff, and when you get redirect to a login page it appends the url to redirect to on login to the url. ufarn posted:Here is what project of mine looks like: Thank you very much. I used Nimrod's solution of request.META['HTTP_REFERER']: Python code:
Dominoes fucked around with this message at 12:35 on May 31, 2014 |
# ? May 31, 2014 12:32 |
|
NtotheTC posted:I might be misunderstanding, but is this not a job for the messaging framework in django? ufarn posted:Sounds like it. Thanks!
|
# ? May 31, 2014 12:43 |
|
Are there conventional ways of doing update and comments feeds in Django?
|
# ? Jun 1, 2014 18:23 |
|
Is there any way to not cache template fragments? My notifications (messages, form errors, etc.) are loaded via an include and they never dismiss correctly. My guess is that something is caching the template and so the message sticks around even though it's not in the message store anymore. I can't think that this is an uncommon request. Maybe I'm just doing something wrong?
|
# ? Jun 2, 2014 21:47 |
|
Blinkz0rz posted:Is there any way to not cache template fragments? I haven't had them stick around, even when using a message include. But it's really hard to debug code I can't see.
|
# ? Jun 2, 2014 23:48 |
Let's say I have a couple models: Blog and BlogComment. BlogComment has a ForeignKey to Blog. How to I use the ORM to find all the Blogs that have at least 1 comment? Or should I add a comment_count field to Blog and just filter on that?
|
|
# ? Jun 5, 2014 02:16 |
|
fletcher posted:Let's say I have a couple models: Blog and BlogComment. BlogComment has a ForeignKey to Blog. How to I use the ORM to find all the Blogs that have at least 1 comment? Or should I add a comment_count field to Blog and just filter on that? Annotations to the rescue! code:
|
# ? Jun 5, 2014 12:02 |
Haven't used annotate or Count yet. That's pretty sweet! Thanks Blinkz0rz!! Here's the SQL it generated: code:
|
|
# ? Jun 5, 2014 19:50 |
|
Because you're specifically looking to distinguish zero from non-zero, you can also do it like this: Blog.objects.filter(comments__pk__isnull=False).distinct() That will do an inner join, so blogs with no comments won't be in the result.
|
# ? Jun 5, 2014 20:29 |
|
Pumpkin Pirate posted:Because you're specifically looking to distinguish zero from non-zero, you can also do it like this: I didn't know you could do a null test against a RelatedManager model property. That's pretty awesome.
|
# ? Jun 6, 2014 00:00 |
Is there a way to programatically set an ImageField to an existing local file and have it run through my upload_to override?
|
|
# ? Jun 6, 2014 19:34 |
This seemed to work for me: http://stackoverflow.com/questions/3723220/how-do-you-convert-a-pil-image-to-a-django-file
|
|
# ? Jun 9, 2014 19:04 |
How come django.core.context_processors.request isn't part of the default TEMPLATE_CONTEXT_PROCESSORS? Any reason you wouldn't want to have it in there?
|
|
# ? Jun 12, 2014 00:01 |
|
fletcher posted:How come django.core.context_processors.request isn't part of the default TEMPLATE_CONTEXT_PROCESSORS? Any reason you wouldn't want to have it in there? I dunno, I've never used it. Surely most of the request information is handled by the view, so that leaves cherry picking certain properties for your template, which a dedicated context processor is probably better suited for. I imagine more than anything not having it as the default is a way to discourage certain anti patterns like switchs based on the request method in the template.
|
# ? Jun 13, 2014 06:50 |
|
I'm trying to implement a simple search, and use the same view as for normal browsing. Maybe it's not the best idea, as now I don't know how to implement the combined navigation, so that if search is going on it navigates over the search items. My first thought was to somehow pass the search_form via the navigation link, but I'm not sure that's even possible. What's the normal procedure? I guess I could attach the form with javascript, but that seems like a convoluted solution for a commonplace problem.
|
# ? Jun 16, 2014 15:32 |
|
supermikhail posted:I'm trying to implement a simple search, and use the same view as for normal browsing. Maybe it's not the best idea, as now I don't know how to implement the combined navigation, so that if search is going on it navigates over the search items. My first thought was to somehow pass the search_form via the navigation link, but I'm not sure that's even possible. What's the normal procedure? I guess I could attach the form with javascript, but that seems like a convoluted solution for a commonplace problem. What exactly is the desired result? Do you want a search form as part of the navigation and on every page? If that is what you want then you can just add a context processor that always brings the form into your template. Maybe I've misunderstood what you're trying to do though.
|
# ? Jun 17, 2014 14:15 |
|
Hm. The desired result is that during search when you click a ">" link it takes you to the next page of search, with the search form (that, yes, is present everywhere) filled as before. That's as opposed to regular browsing, when it's the next page of the whole list. I'm not sure if context processors help there (admittedly, I just skimmed the documentation for the first time).
|
# ? Jun 17, 2014 15:17 |
|
supermikhail posted:Hm. The desired result is that during search when you click a ">" link it takes you to the next page of search, with the search form (that, yes, is present everywhere) filled as before. That's as opposed to regular browsing, when it's the next page of the whole list. I'm not sure if context processors help there (admittedly, I just skimmed the documentation for the first time). So long as you always instantiate the search form using the data that it expects (request.GET, I'd suspect), you'll get it filled in like you expect.
|
# ? Jun 17, 2014 17:41 |
|
I guess I should pass the form data along the link then. It kind of feels stupid having all that form validation stuff, and then just passing the search term as a simple argument. But I guess it doesn't matter since the form is not processed at this point. Also additional url patterns. Or can you add to GET in a link, other than by javascript?
|
# ? Jun 17, 2014 18:28 |
|
supermikhail posted:I guess I should pass the form data along the link then. It kind of feels stupid having all that form validation stuff, and then just passing the search term as a simple argument. But I guess it doesn't matter since the form is not processed at this point. Also additional url patterns. Or can you add to GET in a link, other than by javascript? Search forms aren't changing data so they should just be passed through the GET. You'll probably want a templatetag that re-adds the GET params to your next/prev/# links.
|
# ? Jun 17, 2014 18:49 |
|
Turns out my code from the last post was in the wrong order, but now I'm on to a new and exciting problem... Has anyone ever used django-dynamic-formset before? It adds information well, but I can't seem to get it to prefill in my UpdateView. I'm starting to become concerned that it was only designed with creating data in mind...
|
# ? Jun 19, 2014 15:56 |
|
Today I started getting a few "Invalid HTTP_HOST header:" that point back to my Amazon AWS external IP. Should I be concerned about this? Django is running through WSGI to nginx on a local tcp socket. From quick googling it looks like something not to worry about (just spoofers) but wanted to make sure and kind of understand what's going on here. Are people just forging headers with a from address of my public IP? Hed fucked around with this message at 01:16 on Jun 21, 2014 |
# ? Jun 21, 2014 01:09 |
|
I have a situation where I want to make a third party request INSIDE a current users request. Essentially I want to alter the traditional oauth2 flow where the user is redirected back to the Application after authorizing their credentials for the first time. I would like the Application to receive the authorization code once the user approves it via an internal Request inside Django. But I want to redirect the user to stay within my site for some additional account process wizards. This is a situation where oath is being used to authorize a third part iOS or Android application, not a browser app so I essentially don't care if the user is redirected to the Application's own post-authorization splash page.
|
# ? Jul 8, 2014 00:16 |
What's the easiest way to read a fixture while writing tests to confirm the test data is showing up properly in my views? I don't want to have to have a bunch of constants at the top of the file, i.e. TEST_USERNAME, TEST_EMAIL, etc. Should I just open it and decode the JSON or is there already a method supplied by Django? Edit: I guess I can just retrieve the test data out of the database on a start up method. Some times the most obvious answer comes to you without thinking about the problem. Don Mega fucked around with this message at 00:34 on Jul 27, 2014 |
|
# ? Jul 26, 2014 22:10 |
|
Don Mega posted:What's the easiest way to read a fixture while writing tests to confirm the test data is showing up properly in my views? I don't want to have to have a bunch of constants at the top of the file, i.e. TEST_USERNAME, TEST_EMAIL, etc. Should I just open it and decode the JSON or is there already a method supplied by Django? Use model_mommy to make a bunch of test models in your tests.
|
# ? Jul 27, 2014 02:30 |
|
What is the recommended way to load test an app? Primarily I want to load test and optimize my queries.
|
# ? Jul 31, 2014 19:04 |
Ahz posted:What is the recommended way to load test an app? Primarily I want to load test and optimize my queries. I like using Django Debug Toolbar to figure out where I am missing some select_related and prefetch_related type stuff. A lot of my app is AJAX based though, so I also tend to just tail the General Query Log in MySQL. I also use the Slow Query Log in MySQL. As far as throwing a bunch of requests at your app, Apache Bench, Siege, JMeter, and httperf are a few to take a look at.
|
|
# ? Jul 31, 2014 19:10 |
|
I recommend http://locust.io it's got a low barrier of entry.
|
# ? Aug 1, 2014 01:11 |
|
Hi all, I'm messing around with Django and I'm trying to make a sample app (called "blog") and I'm running into a problem with using the url template tag. I have one app "blog" inside a project called "orion". I've been googling this for almost two days and it seems to be a common problem. I've double checked and tried a lot of things, however, most of the problems that people have online seem to have a root cause unrelated to mine (mostly typos and stuff). I beg you, goons, help me. Here is the root urls.py file: code:
code:
code:
|
# ? Aug 6, 2014 22:07 |
What if you change r'(|^blog/)' to just r'^blog/'?
|
|
# ? Aug 6, 2014 23:23 |
|
Storgar posted:<<snip>> 1 pattern(s) tried: [u'(|^blog/)login/'] Looks like it is trying to find <url>/(|^blog/)login/ which is almost certainly not what you intended. e:f;b
|
# ? Aug 6, 2014 23:24 |
|
Ah ok. I was trying to make localhost:8000 and localhost:8000/blog/ both redirect to the index view of the blog app. I separated that into two lines. Also I should learn more about regex. Additionally, I noticed that the index view of the blog app matches ''. I think this was causing the index view to be matched to everything. I changed this to ^$. Works now... Thanks!
|
# ? Aug 7, 2014 01:29 |
|
I'm thinking about totally forgoing Django's views and forms and doing everything with django-rest-framework. Anyone else doing this? Stupid idea? Brilliant idea? My motivation for this is that it seems like a lot of redundant effort maintaing views, forms, serializers, and viewsets when really you could do it all with serializers and viewsets along with JS on the client.
|
# ? Aug 10, 2014 20:52 |
|
Thermopyle posted:I'm thinking about totally forgoing Django's views and forms and doing everything with django-rest-framework. Anyone else doing this? Stupid idea? Brilliant idea?
|
# ? Aug 10, 2014 21:03 |
|
Thermopyle posted:I'm thinking about totally forgoing Django's views and forms and doing everything with django-rest-framework. Anyone else doing this? Stupid idea? Brilliant idea? I'm with you on this in theory. Haven't actually done it, but I have thought about it and it honestly doesn't seem like a bad idea.
|
# ? Aug 10, 2014 21:36 |
|
|
# ? Jun 6, 2024 07:06 |
Thermopyle posted:I'm thinking about totally forgoing Django's views and forms and doing everything with django-rest-framework. Anyone else doing this? Stupid idea? Brilliant idea? That's what I did for my Django project. It's been great, I would definitely do it again.
|
|
# ? Aug 10, 2014 21:45 |