Re: Distributed databases
I've never seen anything that would make this "easy" in Django itself. You will probably have more luck looking into sql proxies. Django will talk to the proxy, the proxy will figure out what database to actually query and return results to Django. This way Django doesn't have to change, doesn't have to even know any thing funky is going on. Btw, Isolated layers like that is a great way to architect a system. I don't have a sql proxy to recommend, Google does though. ___ Get out and about this spring with the Statesman! In print and online, the Statesman has the area's Best Bets and recreation events. Pick up your copy today or go to statesman.com 24/7. --~--~-~--~~~---~--~~ 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: How to extend django.views.generic.date_based to return more "context variables"?
fizban wrote: > > On 14 Apr, 16:54, "Norman Harman" <[EMAIL PROTECTED]> wrote: > >> Why don't you use the extra_context parameter to generic views? Or am I >> misunderstanding what you are trying to do? >> >> def myview(request): >>context = dict() >>context["my_custom_var"] = "wwgd" >>return generic_view(request, extra_context = context, bla=blah,...) >> > > I have just tried setting it up but it is returning a 404 when I try > to load the page (and it obviously works with date_based.object_detail > and/or my custom "entry_detail") > > This is the view I tried to setup: > > def myview(request, year, month, day, queryset, date_field, > month_format, slug, template_object_name): > context = dict() > context['year'] = year > context['month'] = month > context['day'] = day > > return date_based.object_detail( > request, year, month, day, queryset, date_field, month_format, > slug, > template_object_name, extra_context=context, > ) > > As far as I understood your suggestion and the docs I found it should > work, shouldn't it? > > The urlconf, beside the from ... import statements is the following: > > > entry_info_dict = { > 'queryset': Entry.live.all(), > 'date_field': 'pub_date', > } > > urlpatterns = patterns('django.views.generic.date_based', > (r'(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w\d\-] > +)/$', myview, dict(entry_info_dict, month_format='%m', > template_object_name='entry')), > ) > > (I'm using django.views.generic.date_based there since it's needed by > the other patterns, I didn't include them since they are relevant -- > however it won't work even if I snip it out) > > myview should be in the views.py of your app. The urlpatterns above is pointing to some django views file. You shouldn't edit the django source if you can avoid it. urlpatterns = patterns('', (r'(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w\d\-] +)/$', "myapp.views.myview", dict(entry_info_dict, month_format='%m', template_object_name='entry')), ) Not sure if that caused your 404. They are usually caused by missing data (if you used incorrect slug in url), or if regex in urlpatterns is wrong. Turning debug=True in your settings.py should give you more information on why there is 404's. -- Norman J. Harman Jr. 512 912-5939 Technology Solutions Group, Austin American-Statesman ___ Get out and about this spring with the Statesman! In print and online, the Statesman has the area's Best Bets and recreation events. Pick up your copy today or go to statesman.com 24/7. --~--~-~--~~~---~--~~ 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: How to extend django.views.generic.date_based to return more "context variables"?
Why don't you use the extra_context parameter to generic views? Or am I misunderstanding what you are trying to do? def myview(request): context = dict() context["my_custom_var"] = "wwgd" return generic_view(request, extra_context = context, bla=blah,...) -- Norman J. Harman Jr. 512 912-5939 Technology Solutions Group, Austin American-Statesman ___ Get out and about this spring with the Statesman! In print and online, the Statesman has the area's Best Bets and recreation events. Pick up your copy today or go to statesman.com 24/7. --~--~-~--~~~---~--~~ 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: how do I create a zebra table using a template?
Kenneth Gonsalves wrote: > On 11-Apr-08, at 9:36 PM, Kenneth Gonsalves wrote: > > >> On 11-Apr-08, at 9:28 PM, Chas. Owens wrote: >> >> >>> {% if forloop.counter % 2 %} >>> >> divisibleby >> > > http://www.djangoproject.com/documentation/templates/#divisibleby > > Wouldn't http://www.djangoproject.com/documentation/templates/#cycle be a better solution? I think it was designed exactly for zebra tables. -- Norman J. Harman Jr. 512 912-5939 Technology Solutions Group, Austin American-Statesman ___ Get out and about this spring with the Statesman! In print and online, the Statesman has the area's Best Bets and recreation events. Pick up your copy today or go to statesman.com 24/7. --~--~-~--~~~---~--~~ 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: Link that performs an action
Taylor wrote: > Thanks for the replies, but I guess I didn't make myself clear > enough. Counter was just as an example, I don't want an actual page > counter. > > I guess part of my question is: Yes, I can use AJAX-y XMLHttpRequest > to send info to the server in the background, but has someone done > this already in django somewhere and posted code that can be plugged > in? > > The idea is to have a view like this: > def my_view(request,num=0): > counter = Counter.objects.get(id=someid) > counter.count += num > counter.save() > # setup view stuff > > but without specifying num in the URL or having to use a in my > template. > > Thanks > > If num isn't in the URL and it isn't a GET/POST parameter, where is it coming from? For front end of AJAX, use whatever Javascript lib/code you like, Jquery is my choice. Django doesn't come with or dictate a particular one. The back end, Django part, of AJAX works exactly like any other view but return JSON or XML data instead of HTML. def my_view(request) data = simplejson.dumps(Model.objects.filter(somefilter=whatever)) return HttpResponse(data, mimetype="text/javascript") or http://www.djangoproject.com/documentation/serialization/ -- Norman J. Harman Jr. 512 912-5939 Technology Solutions Group, Austin American-Statesman ___ Get out and about this spring with the Statesman! In print and online, the Statesman has the area's Best Bets and recreation events. Pick up your copy today or go to statesman.com 24/7. --~--~-~--~~~---~--~~ 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: Link that performs an action
Taylor wrote: > Does something exist so that a link on a page performs an action > rather than just showing a view? > For example: I have a counter saved to the db, and every time a user > clicks the link, the counter increases by a certain number and saves. > > > without even visiting the page that the link > is on by visiting the URL directly. They can only visit the page if you provide an url it. Just don't make any url that displays page without your counter I don't think I understand what you want, since what I think you want is super trivial. But... def my_view(request): counter = Counter.objects.get(id=someid) counter.count += 1 counter.save() # Or see http://www.djangoproject.com/documentation/request_response/ if you want to use different value/counter based on what page led them to current view. # referer is unreliable refer = request.META.get( "HTTP_REFERER", None) counter = Counter.objects.get(refer=refer) counter.count += 1 counter.save() # do whatever to show view Which is not a great way of doing it (db hit every page view, fails when you start caching results) but those don't matter unless your site is real busy. another option parsing apache/nginx/whatever logs for whenever particular url(s) where responded to. -- Norman J. Harman Jr. 512 912-5939 Technology Solutions Group, Austin American-Statesman ___ Get out and about this spring with the Statesman! In print and online, the Statesman has the area's Best Bets and recreation events. Pick up your copy today or go to statesman.com 24/7. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
"Best" way to save / restore python list to db
I made a sublcass of DjangoEmailMessage that stores email in db for later batch processing. class EmailMessage(DjangoEmailMessage): def send(self): email = Email(status=Email.STATUS_NEW, from_email=self.from_email, to_email=self.to, email.save() return True A recent change to core/email.py which forces to and bcc to lists broke my hack of using plain strings. Now I find my self needing to save lists and restore python lists from db. save is np. def save(self): # must convert to_email list into string self.to_email = repr(self.to_email) super(Email, self).save() But I'm not sure where to convert string back into list on select? I could use a python property to do change at attribute access instead of at db write/read, not the best solution but in this instance not horrid. What would be best practice for this issue? thanks, njharman --~--~-~--~~~---~--~~ 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: Deploying Django
Chris Hoeppner wrote: > Well, just to know. What are you using? This should also be useful for > my "little" project, the django deployer, still unnamed. I had the most frustration with a software in recent memory trying to use lighttpd. Config syntax was utterly weird and the docs conflicted with actual behavior. I dumped it for nginx. Nginx has been a near dream. The syntax makes sense(YMMV), and it has done what I wanted without hassle. Use it to: - serve static and proxy to three separate django-servers(on different ports) for development - serve static and proxy to mod_python/apache a test server - serve static and proxy to mod_python/apache a production server I'm familiar with apache/mod_python so the backend is that rather than something "trendier". When traffic becomes an issue, one problem we are glad to have :) we'll do some stress/load testing. Probably comparing ngix->apache/mod_python to ngix->fcgi nginx -> http://wiki.codemongers.com/Main my site -> http://StoryMash.com I really can't recommend nginx enough, norm --~--~-~--~~~---~--~~ 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: Cache middleware causing unit tests to fail
Eratothene wrote: > I think you better not disable cache middleware in tests. If tests > fail, so will be in production. I had similar problem, I thought it > was something wrong with tests, but really it was problem in the code. > My site was running well on django built-in server, but not on apache > mod_python. My site was working fine. My unittests was what were in error. Yeah there are going to be differences between production and devel. But, personally I believe unittests should test one thing. Not many things at once such as cache/view/db (as an aside I'm sort of sad django doesn't have a mock db for view unittests) So, I think you should test your cache framework and how your app uses it, but, those tests should not be part of the view unittests. I was testing that a specific template was being used to render page. With caching the correct behavior is to not use any template, not to render at all, but rather to pump contents of cache down the wire. In my test_settings.py file I have: # disable cache for testing MIDDLEWARE_CLASSES.remove('django.middleware.cache.CacheMiddleware') CACHE_BACKEND = "dummy:///" Then run python manage.py --settings=test_settings test works beautifully. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Cache middleware causing unit tests to fail
Hi, request.template is None instead of what it should be because the response is from the cache middleware. Which is fine. My question is there a good way to disable the cache middleware during tests? "good" being atleast the following. is automatic, isn't based of value of DEBUG, doesn't require changing django distro. Is there a special settings file or other file imported during tests only? thanks, njharman --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---