problem with twitter app
I am using python-twitter on my site. I have a problem when the Twitter site is down. This results in an error message. I did not found out if the users gets an error message or not. To use Twitter on my site I have this context_processors.py import datetime import time from django.conf import settings from django.core.cache import cache import twitter def latest_tweet( request ): tweet = cache.get( 'tweet' ) if tweet: return {"tweet": tweet} tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER, count=5 ) for s in tweet: s.date = datetime.datetime(*(time.strptime( s.created_at, "%a %b %d %H:%M:%S + %Y" )[0:6])) cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT ) return {"tweet": tweet} My idea is to put the cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT ) in a view, and call this view in a cron job. Is this the right way to solve this? The context_processors.py is heavily based on the example i found in this site btw: http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-site/ Rob -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: problem with twitter app
I solved it making this context_processor.py: import datetime import time from django.conf import settings from django.core.cache import cache import twitter def latest_tweet( request ): tweet = cache.get( 'tweet' ) if tweet: return {"tweet": tweet} else: tweet = {} return {"tweet": tweet} And this view: def update_tweet(request): import time from django.conf import settings from django.core.cache import cache import twitter tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER, count=5 ) for s in tweet: s.date = datetime.datetime(*(time.strptime( s.created_at, "%a %b %d %H:%M:%S + %Y" )[0:6])) cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT ) return HttpResponseRedirect('http://www.wieskamp.nl') It looks like everything works fine now. I think the advantage now is too that i can manually update the cache (when i set the twitter_timeout low) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
get_absolute_url error with sitemaps
I am trying to get automatic sitemap generation working with Django 1.2.1, but i think i missed something simple. I get this error: + File "/usr/lib/python2.4/site-packages/django/contrib/sitemaps/ __init__.py", line 47, in __get return attr(obj) File "/usr/lib/python2.4/site-packages/django/contrib/sitemaps/ __init__.py", line 54, in location return obj.get_absolute_url() AttributeError: 'dict' object has no attribute 'get_absolute_url' ++ I made a sitemap.py with this content; from django.contrib.sitemaps import Sitemap from jouwsta.verkoop.models import * class PaginaSitemap(Sitemap): changefreq = "never" priority = 0.5 def items(self): return Pagina.objects.all() And this to urls.py: sitemaps = { "pagina": PaginaSitemap } And added this to my models.py to class Pagina: def get_absolute_url(self): return "/%s/" % self.slug Here is the complete class Pagina: class Pagina(models.Model): menu_titel = models.CharField(max_length=60) slug = models.SlugField(max_length=60, unique=True) menu_order = models.IntegerField(default='99') MENU_CHOICES = ( ('L', 'Links'), ('O', 'Onder'), ) menu_positie = models.CharField(max_length=1, choices=MENU_CHOICES) pagina_tekst = models.TextField() pagina_keywords = models.CharField(max_length=120) pagina_beschrijving = models.CharField(max_length=120) pagina_titel = models.CharField(max_length=120) javascript = models.CharField(max_length=900, blank=True, help_text='niet verplicht') def __unicode__(self): return self.menu_titel class Meta: verbose_name_plural = "Pagina" def get_absolute_url(self): return "/%s/" % self.slug What am I doing wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: get_absolute_url error with sitemaps
Ok I use a slug field to retrieve an url from the database and apperently get_absolute_url() doesn't work with slugs. I added a location to my sitemap.py which gives the following result; - http://www.example.com/{'slug': u'assortiment'} Here is my sitemap.py: from django.contrib.sitemaps import Sitemap from jouwsta.verkoop.models import * class PaginaSitemap(Sitemap): def items(self): return Pagina.objects.values('slug') def location(self, obj): return obj Seems that i am almost there :-) Who can give me a hint for the last step to get a correct url? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: get_absolute_url error with sitemaps
It was as easy as: def location(self, obj): return obj['slug'] Finally :-) :-) ...is this the right way to make a good sitemap.xml file? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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-use the sitemap.xml
I want to put a sitemap on my page with all the links for better navigation. I could write a new view to fetch all links, but is there a way to include my sitemap.xml (i use the sitemap framework) in a template? I could convert the xml to html by using xslt. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Mobile website using Django
I have implemented a mobile site according the instructions on this site: http://www.packtpub.com/article/multiple-templates-in-django Same approach on this site: http://tech.agilitynerd.com/conditional-mobile-web-site-redirect-in-djang A different template is loaded for mobile users. When a user decides to go to go from the mobile site to the main (not mobile) site this setting is remembered, in my case until the browser is closed. Therefore I did set SESSION_EXPIRE_AT_BROWSER_CLOSE = True in settings.py Rob -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: main categories in menu
Thank you for explaining. This is indeed exact what I was looking for. I thought I could only pass one argument to the view. Rob On 4 dec, 18:32, wayne wrote: > > So if a user enters mydomain.com/main1/page1 --> check if main1 exists > > in the database --> render a menu of all pages which are linked to > > main1 --> show page1 > > So, I take it that if the user enters the above, and main1 does not > exist in the db, then you will raise an error (probably 404)? > > If so, then like I mentioned, it should suffice to do something like: > > r'^(?P\w+)/(?P\w+)$', 'view_to_pass_to' > > to match against. It will then call the view you specify, and pass > the kwargs main_obj and page_obj. You can then look up these two > slugs in your db, check if they exist, find all page_objs that link to > main_obj, etc. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: css templates
Here you find a page about serving multiple templates on the same site (and saving the preference in a session): http://www.packtpub.com/article/multiple-templates-in-django -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
modify date in django twitter app
I am almost done implementing tweets on my site using a tutorial which a found here: http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-site/ The problem is that i want to modify the date output when i retrieve multiple tweets. The example above is written for retrieving only one most recent tweet from twitter. The context_preprocessor i have now is (mostly taken from the site above): import datetime import time from django.conf import settings from django.core.cache import cache import twitter def latest_tweet( request ): tweet = cache.get( 'tweet' ) if tweet: return {"tweet": tweet} tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER, count=3 ) tweet.date = datetime.datetime(*(time.strptime( tweet.created_at, "%a %b %d %H:%M:%S + %Y" )[0:6])) cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT ) return {"tweet": tweet} This results in the following error: AttributeError: 'list' object has no attribute 'created_at' The twitter api let me call a human readable date in the template using relative_created_at. Unfortunately the output is in English. Any idea how i get an easy readable date? The output is now: Fri Oct 30 10:18:53 + 2009 Or: about 6 days ago When i use relative_created_at -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: modify date in django twitter app
Thank you for the reply. When i add the [0] to tweet, the date conversion is only applied to the last tweet On 7 mrt, 23:24, Daniel Roseman wrote: > On Mar 7, 9:57 pm, "het.oosten" wrote: > > > > > I am almost done implementing tweets on my site using a tutorial which > > a found > > here:http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-s... > > > The problem is that i want to modify the date output when i retrieve > > multiple tweets. The example above is written for retrieving only one > > most recent tweet from twitter. > > > The context_preprocessor i have now is (mostly taken from the site > > above): > > > import datetime > > import time > > from django.conf import settings > > from django.core.cache import cache > > import twitter > > > def latest_tweet( request ): > > tweet = cache.get( 'tweet' ) > > > if tweet: > > return {"tweet": tweet} > > > tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER, > > count=3 ) > > tweet.date = datetime.datetime(*(time.strptime( tweet.created_at, > > "%a %b %d %H:%M:%S + %Y" )[0:6])) > > cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT ) > > > return {"tweet": tweet} > > > This results in the following error: > > AttributeError: 'list' object has no attribute 'created_at' > > > The twitter api let me call a human readable date in the template > > using relative_created_at. Unfortunately the output is in English. > > > Any idea how i get an easy readable date? > > > The output is now: > > Fri Oct 30 10:18:53 + 2009 > > > Or: > > about 6 days ago > > When i use relative_created_at > > I don't know the Twitter API, but you're calling GetUserTimeline with > a count of 3, which presumably returns a list of 3 items. The list > itself doesn't have a 'created_at' attribute, hence the error. Perhaps > if you did: > > tweet = twitter.Api().GetUserTimeline(settings.TWITTER_USER, > count=3) [0] > > you would have better luck. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: modify date in django twitter app
I am getting somewhere now: import datetime import time import twitter tweet = twitter.Api().GetUserTimeline('username', count=3) for s in tweet: s.date = datetime.datetime(*(time.strptime( s.created_at,"%a %b %d %H:%M:%S + %Y" )[0:6])) print [x.text for x in tweet] print [y.date for y in tweet] However the output is now: [datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2, 22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)] I still miss a little thing to completeanybody a little hint? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: modify date in django twitter app
I forgot to mention that my desired output of the date is: 2010-02-22 20:46:03 On 8 mrt, 22:13, "het.oosten" wrote: > I am getting somewhere now: > > import datetime > import time > import twitter > > tweet = twitter.Api().GetUserTimeline('username', count=3) > for s in tweet: > s.date = datetime.datetime(*(time.strptime( s.created_at,"%a > %b %d %H:%M:%S + %Y" )[0:6])) > print [x.text for x in tweet] > print [y.date for y in tweet] > > However the output is now: > [datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2, > 22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)] > > I still miss a little thing to completeanybody a little hint? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: modify date in django twitter app
I figured it out finally. For anybody who is interested. I have this setup for showing multiple tweets: settings.py: from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS TEMPLATE_CONTEXT_PROCESSORS = TEMPLATE_CONTEXT_PROCESSORS + ( "wieskamp.verkoop.context_processors.latest_tweet", ) TWITTER_USER = "username" TWITTER_TIMEOUT = 3600 This context_processor: import datetime import time from django.conf import settings from django.core.cache import cache import twitter def latest_tweet( request ): tweet = cache.get( 'tweet' ) if tweet: return {"tweet": tweet} tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER, count=3 ) for s in tweet: s.date = datetime.datetime(*(time.strptime( s.created_at, "%a %b %d %H:%M:%S + %Y" )[0:6])) cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT ) return {"tweet": tweet} And this in my template: {% if tweet %} {% for x in tweet %} {{ x.text|urlize}} {{ x.date|date:"d/m/Y" }} {% endfor %} {% endif %} Thanks for the help and hints :-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Select dates with querywhich arent already available
I want to make a simple reservation app with a arrival date en a departure date. I have this simple model: class Booking(models.Model): Houses = models.CharField(max_length=3) Reservation = models.ForeignKey('Data', blank=True) def __unicode__(self): return self.Houses class Data(models.Model): Name = models.CharField(max_length=30) Arrival = models.DateField() Departure = models.DateField() def __unicode__(self): return '%s %s %s' % (self.Name, self.Arrival, self.Departure) I made a simple form were users can enter and arrival and depature date. With these dates I want to make a query to get a list of houses which are available at this time. Can anybody push me a bit in the right direction? I had a look at Entry.objects.filter(pub_date__range=(start_date, end_date)) but this does the opposite. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Select dates with querywhich arent already available
I think i made some progress. The first tests with this query are promising: bereik = Data.objects.exclude(Aankomst__range=(Check_aankomst, Check_vertrek), Vertrek__range=(Check_aankomst, Check_vertrek)) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
query a foreignkey
I have this model: class House(models.Model): Huisnumber = models.CharField(max_length=3) Reservation = models.ForeignKey('Data', blank=True) def __unicode__(self): return self.Huisnumber class Data(models.Model): Name = models.CharField(max_length=30) Arrival = models.DateField() Departure = models.DateField() def __unicode__(self): return '%s %s %s' % (self.Naam, self.Arrival, self.Departure) And this query: range = House.objects.exclude( Reservation__Arrival__range=(Check_arrival, Check_departure) ).exclude( Reservation__Departure__range=(Check_arrival, Check_departure) ) This should get a list of houses which are available. This works fine when only one date (reservation) is entered. When a house has two reservations, only the last entry is evaluated. How should I handle multiple entries? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: query a foreignkey
Thank you very much for your reply. It really makes sense to change the foreignkey, and have have changed this. The core of the problem however remains the same. Everything works fine when only one reservation per house is entered. When I enter two reservations on one house, only one one of the two reservations is checked by the query. If i have for example two reservations on house 121 1. 12/03/2010 - 14/03/2010 2. 23/04/2010 - 26/04/2010 Only entry 2 is reviewed. When I enter a new reservation from 11/03/2010 - 15/03/2010 "it" says the house is available. Everything works fine with only one reservation per house. Rob -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: query a foreignkey
To clarify. If I have three houses, and house 120 has two reservations, I get a list like this: 120 121 122 120 (if all are available) If the query matches one reservation of house 120 i get a list like this: 121 122 120 House 120 should been excluded from the list though. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: query a foreignkey
I translated my model into english to make everything more understandable for the list. There is were I messed up (next time i do everything in English right away). I rechecked everything after the message of Nuno and removed an error. Now everything works perfectly. Thank you Bruno and Nuno! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
content type printed as first line in mails
When I send mails with my Django app the first line of every mail is: Content-Type: text/html; charset=utf-8 When i watch the message source i noticed that charset=utf-8 is changed into charset=3Dutf-8 I also saw that in the message header the mail is marked as: Content-Type: text/plain; charset="utf-8" Why is the contect type printed in the first line of the mail? This is my view: from django.core.mail import send_mail subject = "subject" message = render_to_response('mymail', { 'Mailaddress': Mailaddress, 'Mailhash': Mailhash, }) sender = "myemailaddress" recipients = [form.cleaned_data['Mailaddress']] send_mail(subject, message, sender, recipients) mymail is a text file in my template directory. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: content type printed as first line in mails
Thank you for the answers! Everything is much clearer now :-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Sorting the output of regroup
I have a small cms. I have two models, one for Mainmenu items, and one for page with content with a foreignkey to the main menu items: class Mainmenu_items(models.Model): title = models.CharField(max_length=60) mainmenu_order = models.IntegerField(default='99') class Page(models.Model): title = models.CharField(max_length=60) text = models.TextField(blank=True) menu = models.ForeignKey(Mainmenu, null=True, blank=True) menu_order = models.IntegerField(default='99') In the view: menu_items = Page.objects.select_related() In de template I have: {% regroup menu_items by menu.titel as menu_list %} {% for menu in menu_list %} {{ menu.grouper }} {% for item in menu.list %} {{ item.menu_titel }} {% endfor %} {% endfor %} This renders a menu correctly: Mainmenu2 -page1 -page2 -page3 Mainmenu1 -links -content I want however control the order of appearance of the mainmenu items, and the pages (using the mainmenu_order and the menu_order from the model) When I use dictsort in the template, or order_by in the view things go wrong. When page1 and page2+3 have different menu_order values the menu is rendered like this: Mainmenu2 -page1 Mainmenu2 -page2 -page3 Mainmenu1 etc.. Mainmenu2 appears also twice. Any idea what is the best way to accomplish this? Rob -- 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: Sorting the output of regroup
> > Sort the list in Python in your view. Its easier to do, easier to test > and easier to maintain. Thank you for the reply. This is indeed the best way. I left the regroup tag completely, and used some nested for loops in the template. Everything works fine now. Rob -- 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.
onetoone field in admin
When i select a onetoone field in admin which has already been taken, I get an error message (already exist). This is of course expected behaviour. The problem i have is that the list to select from gets very long because all items are listed. Is there a way to hide all options that are already used/existing? I use version 1.2.3 -- 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.
Stuck with a dynamic form within formwizard
On Django 1.2.3 i am trying to get a dynamic form working. On the first page a user have to give their address/client id and on the second page customers can order dishes for catering. To dynamically add forms on the second page i use http://code.google.com/p/django-dynamic-formset/ Here is my models.py: * class Catering(models.Model): customer_id = models.CharField(max_length=20) company = models.CharField(max_length=40) class DishesForm(forms.Form): gerecht = fields.CharField(max_length=200) aantal = fields.IntegerField(required=False) DishesFormset = formsets.formset_factory(DishesForm) class TestWizard(FormWizard): def done(self, request, form_list): return render_to_response('testwizard', { 'form_data': [form.cleaned_data for form in form_list], }) * urls.py: * (r'^testwizard/$', TestWizard([CateringForm, DishesFormset])), * The problem i have is that in the template I can only call the complete form with {{form}} . In order to get the javascript working properly I need to call the fields seperately like {{form.gerecht}} When i test the dynamic form (DishesFormset) seperately without the formwizard everything works fine. How do i call the seperate formfields within the formwizard? -- 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: Stuck with a dynamic form within formwizard
I saw that lots will change in formwizard in future releases of Django, and i could not get this working. Therefore i switched to Jquery formwizard http://thecodemine.org/ This plugin makes it possible to show parts of forms on different pages (and do some server side validation when switching between two pages) I am running in some issues with this as well, but i will start a new topic for this. -- 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.
acces cleaned data from a dynamic form
Django 1.2.3 For a restaurant i want to make a form, were the user can add their address, and their order. The order part is dynamic (users can add extra fields). I used jquery.formset for this. To accomplish this i have an address form and a dishes formset: class Address(models.Model): name = models.CharField(max_length=20) class AddressForm(ModelForm): class Meta: model = Address class DishesForm(forms.Form): dish = forms.CharField(max_length=200) DishesFormset = formsets.formset_factory(DishesForm) In the view i call these forms with: form = AddressForm() formset = DishesFormset() I have two problems with the formset: 1. in the template i can only get a form with {{formset}} . {{formset.dish}} doesn't work 2. how do i access the cleaned_data from the formset? When I test I see in the POST that multiple dishes are posted, but I can only get the first one in the cleaned_data Rob -- 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: acces cleaned data from a dynamic form
Thank you for your help! > I don't understand your questions. I am sorry about that, I probably ask my question the wrong way because of my lack of experience > A formset is a set of forms. What would {{ formset.dish }} even refer to? > Only the forms inside the formset have a `dish` field. When I try {% for form in formset %}{{form.dish}} I get a "non iterable" error In order to style the form right I need to call the seperate formfields. > > Question 2 is impossible to answer without seeing your view code. > -- > DR. My views.py is very basic so not much to show (see below). When I view the POST info all information is posted right. One address, Dish1, Dish2 The only thing i want is validate the form and show/mail the results. When i try "for form in formset.cleaned_data" i get that "non iterable" error again. Till now i only managed to validate and show Dish1. I probably oversee something very basic. def testform(request): if request.method == 'POST': form = AddressForm(request.POST) formset = DishesFormset(request.POST) if formset.is_valid(): return render_to_response('test', { 'form_data': formset.cleaned_data, }) else: form = AddressForm() formset = DishesFormset() return render_to_response('testform', { 'form': form, 'formset': formset, }, context_instance = RequestContext(request)) -- 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: acces cleaned data from a dynamic form
The answer to question 1: *** 1. in the template i can only get a form with {{formset}} . {{formset.dish}} doesn't work *** Was as easy as {{formset.form.dish}} (...sighs...) >So hmm, you're re-presenting the form on the same url? I guess for >debugging that works, but generally you'd redirect here. This is only to get a basic prototype working. When it works i want to redirect to another page with a confirmation. When i enter in my form "Pancakes" and "Steak" this is the result: [{}, {'dish': u'Steak'}] -- 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: acces cleaned data from a dynamic form
This is how the POST looks: nameu'Johnson' form-MAX_NUM_FORMS u' ' form-1-dish u'fried egg' dishu'steak' form-INITIAL_FORMS u'0' csrfmiddlewaretoken u'c12349d127dbbd44e829e756613719c' form-TOTAL_FORMSu'2' -- 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: acces cleaned data from a dynamic form
Ok when i render {{formset}} in the template everything works fine. When i render the form fields seperately, the first field of the "dishes form" is missing. This wont be hard to figure out further. Thanks for all the help! Rob -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/FCYEOz2PZ8sJ. 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.
time part of datetime not saved
I have a model start = models.DateTimeField() In my view I create a datetime: x = datetime.datetime(*(time.strptime(str(component.get('dtstamp')),'%Y %m%dT%H%M%SZ')[0:6])) . This return a valid datetime: >>> x datetime.datetime(2011, 9, 4, 8, 45, 32) The problem is that only the date part is saved in the database. The time is saved as zero's: >>> db.created datetime.datetime(2011, 9, 4, 0, 0) Do i need to convert the date before saving it into the database? -- 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: time part of datetime not saved
Here is a code dump (still work in progress :-) ): http://pastebin.com/szQKRw7d -- 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: time part of datetime not saved
Oh btw, it is all about importing a facebook eventcalendar (in icalendar format) into a database. -- 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: time part of datetime not saved
It is a python 2.4 workaround for using strptime. Without the '[0:6]' I get this error: TypeError: function takes at most 8 arguments (9 given) -- 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: time part of datetime not saved
On 5 sep, 13:40, bik...@gmail.com wrote: > Just call it a hunch, but can you try [0:8] please..? I get this error in that case TypeError: tzinfo argument must be None or of a tzinfo subclass, not type 'int' I think that the strptime works correctly, because the returned datetime is: datetime.datetime(2011, 9, 4, 8, 45, 32) (see topicstart) -- 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: time part of datetime not saved
I did change the model from DateField to DateTimeField, removed the table, synced the database and restarted the wsgi instance. As I found out I should have restarted the wsgi server right after deleting the table from the database. The second time I did remove, recreate and restart in the same sequence, and it still didn't work. After the third time everything works great :-) You were absolutely right there. Thanks a lot for your help! -- 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.
mobile sitemap
Google recommends to add to every entry in a mobile sitemap. Who can help me with this? -- 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.
Customizing error message in ModelForm
I want to show a custom error message in a Modelform. With a normal form I can add an error message like this: error_messages={'required': 'Vul aub een geldig Email adres in', 'invalid': 'Het email adres is niet geldig'} With a ModelForm this won't work. Is there a way to add a custom error message to the ModelForm, or should i write a custom clean method? I am using Django 1.2.3 Rob -- 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: Customizing error message in ModelForm
@Martin Thank you for your reply. I tried to do this, but I still get the default error message (the custom error from the code field works as it should): from django.db import models from django.forms import ModelForm from django import forms class Prijsvraag(models.Model): naam = models.CharField(max_length=60) code = models.CharField(max_length=18) ingeschreven = models.DateField(auto_now_add=True) mail = models.EmailField(unique=True) nieuwsbrief = models.BooleanField(default=1) class PrijsvraagForm(ModelForm): class Meta: mail = forms.EmailField(error_messages={'required': 'Vul aub een geldig Email adres in', 'invalid': 'Het email adres is niet geldig'}) model = Prijsvraag def clean_code(self): super(PrijsvraagForm, self).clean() x = self.cleaned_data['code'] try: y = Code.objects.all()[0] except: raise forms.ValidationError("Er is iets fout gegaan") if x != y.code: raise forms.ValidationError("De code is niet juist") pass return x Rob -- 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: Customizing error message in ModelForm
Yes indeed! Thank you very much for your help. Rob -- 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.
merge images into a webpage
I have two models. One containing images, and one containing the text of a web page. While the text remains the same, the selection of images vary, depending on the session ( I use different themes/moods depending on the season). The selection of images works perfectly, but now i am stuck merging the images into the web page. Ideally I would like to use image tags like {{ image1 }} {{ image2 }} in the web text, and render the result in a web page. I have done something similar using javascript, but due to seo issues javascript is not an option for this site. Can anybody point me in the right direction how to accomplish this? -- 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: merge images into a webpage
> Would using the get_absolute_url() method on your model and then using > that in your tags work? thanks for the reply. This works when you have one dictionary and one template. I want to merge the output of two queries, and render this in a template. Query one gives me: lots of text {{ image1 }} even more text {{ image2 }} Query two gives me: Merging those two would give me: lots of text even more text I would render the result in a template -- 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: merge images into a webpage
On Jul 9, 10:36 pm, Shawn Milochik wrote: > Make an iterable in your view (list or tuple) containing lists or tuples > of two items -- the text and the image link. > > Then iterate through that in your template with a 'for' tag. This doesn't work. The webpage text is one object (just one textfield), and the images are multiple objects.The list of images would be added before or after the text, instead of replacing {{ image1 }} with I would get: lots of text even more text Instead of the desired: lots of text even more text -- 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: merge images into a webpage
I got is working like this: In my model: titel = models.CharField(max_length=200) alt = models.CharField(max_length=200) plaatje = models.ImageField(upload_to='plaatjes/') menu = models.ForeignKey(Menu) seizoenen = models.ManyToManyField(Seizoenen) def __unicode__(self): return '' % (self.plaatje, self.alt) In my view: content_tekst = Tekst.objects.filter(menu__slug__iexact=seizoen)[:1] content_images = Images.objects.filter(menu__slug__iexact=seizoen) from django.template import Context, Template for x in content_text: t = Template(x.text) c = Context({"image": content_images}) y = t.render(c) In the text i store in the database (content_text): text {{ image.0| safe}} more text {{ image.1|safe}} Finally I render y in an existing template with a RequestContext -- 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: merge images into a webpage
Oops i posted too fastis there a better way to accomplish the above? On Jul 10, 12:41 pm, "het.oosten" wrote: > I got is working like this: > > In my model: > titel = models.CharField(max_length=200) > alt = models.CharField(max_length=200) > plaatje = models.ImageField(upload_to='plaatjes/') > menu = models.ForeignKey(Menu) > seizoenen = models.ManyToManyField(Seizoenen) > def __unicode__(self): > return '' % (self.plaatje, > self.alt) > > In my view: > content_tekst = Tekst.objects.filter(menu__slug__iexact=seizoen)[:1] > content_images = > Images.objects.filter(menu__slug__iexact=seizoen) > from django.template import Context, Template > for x in content_text: > t = Template(x.text) > c = Context({"image": content_images}) > y = t.render(c) > > In the text i store in the database (content_text): > text > {{ image.0| safe}} > more text > {{ image.1|safe}} > > Finally I render y in an existing template with a RequestContext -- 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: merge images into a webpage
Adding a method/property to my model is a thing i haven't considered. You have a good point there. I will do some more reading to find a solution in this direction. Thanks! Rob On Jul 10, 5:54 pm, Shawn Milochik wrote: > I'd rather see the contents of your __unicode__ function as a > get_absolute_url function, with the __unicode__ maybe returning just the > filename or the parent object's title and the filename. > > I strongly dislike the embedding of template code in a text field of > your model, because it makes maintenance a lot harder. I don't know what > your code looks like that reads and writes that, so maybe it works for > you. In any case, have a look at adding a method or property to your > model that returns an iterable of image links. I think it'll be a lot > easier to maintain in the long run. -- 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: merge images into a webpage
Ok perhaps a basic question. I wrote a custom method for my model: def image_list(self): return '' % (self.image, self.alt) And i indeed get a nice list of image in the template. I want however control where the single images show up. With something like {{image. 1}} other text {{image.2}} in the text. How do i accomplist this? On Jul 10, 5:54 pm, Shawn Milochik wrote: > I'd rather see the contents of your __unicode__ function as a > get_absolute_url function, with the __unicode__ maybe returning just the > filename or the parent object's title and the filename. > > I strongly dislike the embedding of template code in a text field of > your model, because it makes maintenance a lot harder. I don't know what > your code looks like that reads and writes that, so maybe it works for > you. In any case, have a look at adding a method or property to your > model that returns an iterable of image links. I think it'll be a lot > easier to maintain in the long run. -- 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: merge images into a webpage
Here is the link to pastebin: http://pastebin.com/1FuVH7Hu It is all about getting specific content for a season a user chooses (it is a site for a campground) If you need more info, i will be happy to provide. -- 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: merge images into a webpage
> have the variable image_list in your context which is a list, you can do > this: > > {{ image_list.0 }} and {{ image_list.1 }} This is what i tried, but the only way to show the images is(plaatjes_lijst=image_list): {% for x in plaatje %} {{x.plaatjes_lijst|safe}} {% endfor %} -- 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: merge images into a webpage
One addition to the above, when i do: def __unicode__(self): return '' % (self.plaatje, self.alt) I can call the single images in the template with {{plaatje.1}} etc I found out in this thread that it is not a good idea to "abuse" unicode for this On Jul 10, 9:28 pm, "het.oosten" wrote: > > have the variable image_list in your context which is a list, you can do > > this: > > > {{ image_list.0 }} and {{ image_list.1 }} > > This is what i tried, but the only way to show the images > is(plaatjes_lijst=image_list): > {% for x in plaatje %} > {{x.plaatjes_lijst|safe}} > {% endfor %} -- 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: merge images into a webpage
Ye, I think this was the only option i didnt try :-) Thanks Cal and Shawn! In a previous i translated the Dutch into English, and mixed things up, making everything more confusing. Rob On Jul 10, 9:40 pm, "Cal Leeming [Simplicity Media Ltd]" wrote: > Nice, not often I come across code written in nederlands ;p > > Is this what you are looking for by any chance?? > > {{plaatje.1.plaatjes_lijst}} > > On Sun, Jul 10, 2011 at 8:33 PM, het.oosten wrote: > > One addition to the above, when i do: > > def __unicode__(self): > > return '' % > > (self.plaatje, self.alt) > > > I can call the single images in the template with {{plaatje.1}} etc > > I found out in this thread that it is not a good idea to "abuse" > > unicode for this > > > On Jul 10, 9:28 pm, "het.oosten" wrote: > > > > have the variable image_list in your context which is a list, you can > > do > > > > this: > > > > > {{ image_list.0 }} and {{ image_list.1 }} > > > > This is what i tried, but the only way to show the images > > > is(plaatjes_lijst=image_list): > > > {% for x in plaatje %} > > > {{x.plaatjes_lijst|safe}} > > > {% endfor %} > > > -- > > 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. -- 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: merge images into a webpage
> > Just so happens I'm learning Dutch at the moment, and was able to read a lot > of the code ;p I guess that was my luck :-) -- 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.
session and caching
I have site with with a lay-out depending on a session, set in my view. I first tried site-wide caching, and this obviously didn't work. The caching is not session aware, and the lay-out changes almost randomly. Therefore I tried my luck with the @vary_on_headers decorator, using my session variable. This didn't make any change. Looking at the http request I did found out that the session variable isn't send with the http header (Confirmed by the docs). Is there a way to make caching session aware? One way perhaps is setting a cookie. But what happens with users who don't use cookies (like search engine spiders) -- 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: session and caching
> Are you sure because in the docs I find the opposite. > When I read it correct this is about caching the session. I was referring to (or trying to) caching the entire webpage using a custom session key for the lay-out (I use memcached) When I look at the request headers my custom session key, doesn't show up, therefore I doubt now if @vary_on_headers is the right option for me. -- 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: session and caching
I want indeed cache all users using the same lay-out. I haven't considered writing my own middleware for this yet. I will look into it. Thanks! Rob On 13 jul, 15:24, "Henrik Genssen" wrote: > you can inherit the cache system (UpdateCacheMiddleware, > FetchFromCacheMiddleware) with your own get_Cache_Key function > that you extend by layout (as you hopefully do not want to cache every single > user, but all user using the same layout) > Then create a new middleware, that uses your both new created > CacheMiddlewares. See django.middleware.cache.py > > > > > > > > >reply to message: > >date: 13.07.2011 08:08:31 > >from: "het.oosten" > >to: "Django users" > >subject: [] Re: session and caching > > >> Are you sure because in the docs I find the opposite. > > >When I read it correct this is about caching the session. I was > >referring to (or trying to) caching the entire webpage using a custom > >session key for the lay-out (I use memcached) > > >When I look at the request headers my custom session key, doesn't show > >up, therefore I doubt now if @vary_on_headers is the right option for > >me. > > >-- > >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 > >athttp://groups.google.com/group/django-users?hl=en. -- 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: session and caching
As always afterwards everything is very logical :-) Never used caching before. -- 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.
memcached occasional errors
On the memcached mailing list they suspected this is a Django/python issue so I started a thread here. A user named dormando replied that the problem below looks like a connection failure (sock has gone null) I use memcached on a low traffic website with Django 1.2.4. Sometimes I get this error message in my mail (full error below): AttributeError: 'NoneType' object has no attribute 'recv' I use memcache to cache some Twitter messages. I fetch them using this in a context-preprocessor: def latest_tweet( request ): tweet = cache.get( 'tweet_mysite_nl' ) if tweet: return {"tweet": tweet} else: tweet = {} return {"tweet": tweet} I tried to trigger this error hitting refresh all the time, but with my pc everything works fine. I update the cache twice an hour with another view, using cron (because I don't want to rely on an external site for performance): def update_tweet(request): import time from django.conf import settings from django.core.cache import cache import twitter tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER, count=5 ) for s in tweet: s.date = datetime.datetime(*(time.strptime( s.created_at, "%a %$ cache.set( 'tweet_mysite_nl', tweet, settings.TWITTER_TIMEOUT ) return HttpResponseRedirect('mysite') Here is the full error message: Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/django/core/handlers/ base.py", line 100, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.4/site-packages/django/views/generic/ simple.py", line 16, in direct_to_template c = RequestContext(request, dictionary) File "/usr/lib/python2.4/site-packages/django/template/context.py", line 149, in __init__ self.update(processor(request)) File "/home/wieskamp/django/wieskamp/verkoop/context_processors.py", line 8, in latest_tweet tweet = cache.get( 'tweet_mysite_nl' ) File "/usr/lib/python2.4/site-packages/django/core/cache/backends/ memcached.py", line 48, in get val = self._cache.get(smart_str(key)) File "/usr/lib/python2.4/site-packages/memcache.py", line 337, in get rkey, flags, rlen, = self._expectvalue(server) File "/usr/lib/python2.4/site-packages/memcache.py", line 411, in _expectvalue line = server.readline() File "/usr/lib/python2.4/site-packages/memcache.py", line 511, in readline recv = self.socket.recv AttributeError: 'NoneType' object has no attribute 'recv' -- 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: memcached occasional errors
Thanks for the replies. I installed python-memcached through the package manager. This version was outdated. I updated python-memcached to the latest version now (1.47) When I keep getting these error messages I will look into PyLibMC. Anybody have any experience with PyLibMC and Django 1.2.4? Rob -- 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.
another foreignkey question
I have two models: class Frontpage(models.Model): title = models.CharField(max_length=200) text = models.TextField() def __unicode__(self): return self.title class Meta: verbose_name_plural = "Frontpage" class FrontpageImages(models.Model): title = models.CharField(max_length=200) alt = models.CharField(max_length=200) image = models.ImageField(upload_to='upload/%Y/%m/%d') page = models.ForeignKey(Frontpage) def __unicode__(self): return self.title I will have one page with 4 blocks in it. In every block i want to show the text from the frontpage model, and all his related images. Like: Block1: Block2:etc. text text - image1 -image4 - image2 -image5 - image3 -image6 I cannot fetch all object from Frontpage and access frontpageimages using _set I could solve it by making 4 queries for id 1 till 4 but that would be a bit overkill. What is the right way to use this data in my template? Regards, Rob -- 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: another foreignkey question
Just after I posted my question i found the solution: In the view: content = Frontpage.objects.all() In the template; {% for x in content %} Tekst: {{x.text}} {% for y in x.frontpageimages_set.all %} alt: {{ y.image }} {% endfor %} {% endfor %} (just in case anybody runs into the same problem) -- 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.
processing POST data from jquery
I am trying to get a jquery form validator working. I am stuck now trying to work with the POST data. When i use a simple view for testing: def Code(request): if request.method == 'POST': message = request.POST data = dict(ok=True, msg=message) from django.utils import simplejson return HttpResponse(simplejson.dumps(data),mimetype='application/json') The returned json is: {"msg": {"code": [""]}, "ok": true} This should be: {"msg": "code", "ok": true} The javascripts sends a POST with a dictionary containing an empty key. How should i handle the post data? I am trying to work out an example from this page: http://jqueryfordesigners.com/using-ajax-to-validate-forms/ Here is the javascript i use: $(document).ready(function () { var validateUsername = $('#validatecode'); $('#id_code').keyup(function () { var t = this; if (this.value != this.lastValue) { if (this.timer) clearTimeout(this.timer); validateUsername.removeClass('error').html(' check$ this.timer = setTimeout(function () { $.ajax({ url: '/code-validatie/', data: t.value, dataType: 'json', type: 'post', success: function (j) { validateUsername.html(j.msg); } }); }, 200); this.lastValue = this.value; } }); }); -- 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: processing POST data from jquery
That was exactly what i needed. I didn't think of changing the javascript data. Thank you. -- 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.