Re: Understanding sessions
Thanks Stephen. That helps a lot. On Mar 13, 4:29 pm, Stephen DeGrace <degr...@gmail.com> wrote: > It's not putting anything into the session. The session is basically a > jazzed-up dictionary, and the get method works pretty much just like it does > with the dictionary, it will try and get the objected pointed to by the key > (the first argument) but if that doesn't work, it returns the default (the > second argument) instead. Just like with a dictionary, there is no implicit > assignment. If you want to assign a value to the entry in the session, you > have to do so explicitly. > > The expression: > > cart = request.session.get('cart', None) or Cart() > > tries first to look for the key 'cart' in the session dictionary. If it is > there, because of the short-circuit logic of the or operator, the Cart() > never gets evaluated. If the key isn't in the dictionary, the get returns > None and the part after the or gets evaluated, which results in a new Cart > getting constructed and assigned to cart. Then if you want to save that > object and put it in the session, you have to cart.save() and > request.session['cart'] =cart just like you have in your get_cart method. > > Stephen > > On Fri, Mar 13, 2009 at 5:02 PM, sotirac <soti...@gmail.com> wrote: > > > Looking at the django-cart open source code: > > > cart = request.session.get('cart', None) or Cart() > > > Does the new cart object that recently got created be put back into > > request.session['cart']. > > > I was thinking of improving the code located in > > >http://code.google.com/p/django-cart/source/browse/trunk/django-cart/... > > by adding a get_cart() > > > def get_cart(request): > > cart = request.session['cart'] > > if cart == None > > cart = Cart() > > cart.save() > > request.session['cart'] = cart > > return cart > > > Is there a cleaner way of doing this. > > > Thanks in advance. > > > On Mar 13, 3:57 pm, sotirac <soti...@gmail.com> wrote: > > > What is happening here: > > > > fav_color = request.session.get('fav_color', 'red') > > > > Is it trying to retrieve 'fav_color' from the session. If it doesn't > > > exist, does it put it in the session and assign the value 'red' for > > > it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Understanding sessions
Looking at the django-cart open source code: cart = request.session.get('cart', None) or Cart() Does the new cart object that recently got created be put back into request.session['cart']. I was thinking of improving the code located in http://code.google.com/p/django-cart/source/browse/trunk/django-cart/shop/views.py by adding a get_cart() def get_cart(request): cart = request.session['cart'] if cart == None cart = Cart() cart.save() request.session['cart'] = cart return cart Is there a cleaner way of doing this. Thanks in advance. On Mar 13, 3:57 pm, sotirac <soti...@gmail.com> wrote: > What is happening here: > > fav_color = request.session.get('fav_color', 'red') > > Is it trying to retrieve 'fav_color' from the session. If it doesn't > exist, does it put it in the session and assign the value 'red' for > it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Understanding sessions
What is happening here: fav_color = request.session.get('fav_color', 'red') Is it trying to retrieve 'fav_color' from the session. If it doesn't exist, does it put it in the session and assign the value 'red' for it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
using django-gcal, how do i defined the "instance" parameter
I'm implementing django-gcal into my project. (http://code.google.com/p/django-gcal) I'm trying to invoke the get_event_data() method from view.py but I'm kind of clueless how to pass the instance parameter. def get_event_data(self, instance): """ Returns a CalendarEventData object filled with data from the adaptee. """ return CalendarEventData( start=instance.start_time, end=instance.end_time, title=instance.title ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
use vObject for event calender application?
Has anybody had any experience using vObject (http:// vobject.skyhouseconsulting.com/). I want to try to create an event calendar application in django and all blogs/website suggest that I use this as part of the backend. Just want to make sure that I am going down the correct path. I haven't seen a prepackage event app yet, does one exist. If not, is this the best way to go. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using forloop variable to get the provide special tags for the 4th element.
Hi Steve, the cycle tag fixed the issue. Thanks. On Sep 15, 1:00 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Lee Hinde wrote: > > > On Sun, Sep 14, 2008 at 10:00 PM, sotirac <[EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>> wrote: > > > In the django template where I am using a for loop, I have to use a > > special tag (div class="yui-u first" instead of div class="yui") for > > every forth item. Im trying to create a table with three columns. I > > can access the first loop but how do I do it for every third. > > -- > > > > {% extends "base.html" %} > > > {% block content %} > > {% for website in websites %} > > {% if forloop.first %} > > > > {% else %} > > > > {% endif %} > [...] > > Check the template tags. I think divisibleby might work for you. > > An easy way to implement this feature is the "cycle" tag. > > > {% if forloop.first %} > > > > {% else %} > > > > {% endif %} > > would then become > > > > However I'm not really able to understand the rest of your logic enough > to determine how the remainder of the code would change, because I'm not > sure I understand it well enough. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
strategy for deploying to production server
Just trying to get a feel for what other developers are doing when deploying to a production server. There are some differences between my development machine and production server such as the location of my media files, the database settings, and if I want to enable caching or not. Right now my option is to comment out some of the code and uncomment the other values. This is time consuming and error proned. How do you deal with this issue of working in your development machine and then having to deploy the same code into your production server. Some files I modify are the settings.py/url.py/views.py. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using forloop variable to get the provide special tags for the 4th element.
Thank you. I'll test this out. I also found the "cycle" tag which looks very promising. On Sep 15, 1:05 am, "Lee Hinde" <[EMAIL PROTECTED]> wrote: > On Sun, Sep 14, 2008 at 10:00 PM, sotirac <[EMAIL PROTECTED]> wrote: > > > In the django template where I am using a for loop, I have to use a > > special tag (div class="yui-u first" instead of div class="yui") for > > every forth item. Im trying to create a table with three columns. I > > can access the first loop but how do I do it for every third. > > -- > > > > {% extends "base.html" %} > > > {% block content %} > > {% for website in websites %} > > {% if forloop.first %} > > > > {% else %} > > > > {% endif %} > > {{ website.title > > }} > h1> > > {% for entry in website.entries_one_to_ten %} > > > > > href="{{entry.url}}">{{ entry.title }} > > > > {% endfor %} > > {% if website.entries_eleven_to_twenty %} > > > > > > {% for entry in website.entries_eleven_to_twenty %} > > > > > href="{{entry.url}}">{{ entry.title }} > > > > {% endfor %} > > > > > > More/Less > > {% endif %} > > > > {% endfor %} > > {% endblock %} > > > > Check the template tags. I think divisibleby might work for you. > > > > >http://docs.djangoproject.com/en/dev/ref/templates/builtins/#divisibleby --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
using forloop variable to get the provide special tags for the 4th element.
In the django template where I am using a for loop, I have to use a special tag (div class="yui-u first" instead of div class="yui") for every forth item. Im trying to create a table with three columns. I can access the first loop but how do I do it for every third. -- {% extends "base.html" %} {% block content %} {% for website in websites %} {% if forloop.first %} {% else %} {% endif %} {{ website.title }} {% for entry in website.entries_one_to_ten %} {{ entry.title }} {% endfor %} {% if website.entries_eleven_to_twenty %} {% for entry in website.entries_eleven_to_twenty %} {{ entry.title }} {% endfor %} More/Less {% endif %} {% endfor %} {% endblock %} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
working with yaml fixtures
I'm trying to initialize my database using yaml fixtures. I've created a yaml fixtures directory (src/fixtures). Within the yaml fixtures directory, I created a yaml fixtures file title websites.yaml. I first had error saying that: neptune:$ python manage.py loaddata fixtures/websites.yml Problem installing fixture 'fixtures/websites': yml is not a known serialization format. I think the solution to that problem was to install pyyaml package. I have done that. Now when I try to invoke the command "python manage.py loaddata fixtures/websites" inside my src directory, it gives me no error message but nothing is added into my sqlite database. --- sample of my yaml file -- - model: src.website fields: title: Our Awesome Planet url: http://www.ourawesomeplanet.com feed: http://feeds.feedburner.com/ourawesomeplanet - model: src.website fields: title: The Unlawyer url: http://www.unlawyer.net feed: http://www.unlawyer.net/?feed=rss --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
how do i do background tasks
i'm creating an application that will read rss feeds. i'm using the universal feed parser library. i have a feed model (has the url to the feed) and an entry model (for each individual entry). Is there a method in the model that I have to overwrite that will allow me to retrieve rss entries in the background and save it into the model. that way the rss feeds from a particular blog are read every hour and stored into the database for viewing. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---