Re: Registration
Before going to answer of your question i am really sure that you have not read the docs of django-registration and django docs any way if you want to make it use django-registration(default) then install it and write in settings.py 'registration'(below of your appname) in your site url (r'^accounts/', include('registration.urls')), now you need to create registration_form.html (you go to in registration packages and see all the views they have mentioned there required html page) create a folder named 'registration' and put your 'registration_form.html' inside that. first create a simple template with only plain html and write their User name : {{form.user}} Password : {{form.password1}} On Apr 20, 4:28 pm, TPwrote: > Thanks for the continued help. > > I have written the URLS.py now they are as below: > > urlpatterns = patterns('', > # Activation keys get matched by \w+ instead of > the more specific > # [a-fA-F0-9]{40} because a bad activation key > should still get to the view; > # that way it can return a sensible "invalid > key" message instead of a > # confusing 404. > url(r'^activate/(?P\w+)/$', > activate, > name='registration_activate'), > url(r'^login/$', > auth_views.login, > {'template_name': 'registration/ > login.html'}, > name='auth_login'), > url(r'^logout/$', > auth_views.logout, > {'template_name': 'registration/ > logout.html'}, > name='auth_logout'), > url(r'^password/change/$', > auth_views.password_change, > name='auth_password_change'), > url(r'^password/change/done/$', > auth_views.password_change_done, > name='auth_password_change_done'), > url(r'^password/reset/$', > auth_views.password_reset, > name='auth_password_reset'), > url(r'^password/reset/confirm/(?P[0-9A- > Za-z]+)-(?P.+)/$', > auth_views.password_reset_confirm, > name='auth_password_reset_confirm'), > url(r'^password/reset/complete/$', > auth_views.password_reset_complete, > name='auth_password_reset_complete'), > url(r'^password/reset/done/$', > auth_views.password_reset_done, > name='auth_password_reset_done'), > url(r'^register/$', > register, > name='registration_register'), > url(r'^register/complete/$', > direct_to_template, > {'template': 'registration/ > registration_complete.html'}, > name='registration_complete'), > ) > > I think that is correct. > > When I load the HTML page I still cannot see a form and only see: > > {% load i18n %} > {% block header %} {% trans "Home" %} | {% if user.is_authenticated %} > {% trans "Logged in" %}: {{ user.username }} ({% trans "Log out" %} | > {% trans "Change password" %}) {% else %} {% trans "Log in" %} {% > endif %} {% endblock %} > {% block content %}{% endblock %} > {% block footer %} {% endblock %} > > I think I am quite close to getting this working, just having a hard > time with linking the HTML. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django-importer released!
Hi all, I've released a project on Google Code to create importers for Django models. Here is the blog release and the project page: http://ricobl.wordpress.com/2009/04/21/django-importer-released/ http://code.google.com/p/django-importer/ Any comments are welcome! Best regards, Enrico --~--~-~--~~~---~--~~ 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: Best way to get a proxy model instance from a base class instance
Ryan, Thank you so much. The custom auth backend is the perfect solution. I feel silly now that I didn't think of that :) Very nice work. Hope I can pay you back someday. Paul On Apr 20, 7:26 pm, Ryan Kellywrote: > On Mon, 2009-04-20 at 15:17 -0700, Paul McLanahan wrote: > > I'm using a proxy model of django.contrib.auth.models.User to override > > __unicode__ and add some extra methods. This also means that I use my > > proxy model class in my ForeignKey and ManyToMany fields. This is all > > find and good until I need to use request.user and assign it to an > > instance of another of my models. Django tells me that I can't assign > > an instance of User where I need an instance of my proxy class. Right > > now I'm doing something I'm sure is very inefficient to get around > > this: > > > obj.author = ProxyUser.objects.get(pk=request.user.pk) > > You could assign the ID directly rather than assigning the object > instance: > > obj.author_id = request.user.id > > But if you then try to use the obj.author object in your code, it will > still perform an extra DB lookup. > > Another approach is to install a custom authentication backend that > returns instances of ProxyUser instead of User. This would ensure that > request.user is always an instance of your proxy class. I'm using a > backend like the following in a similar situation and it works great: > > class ProxyUserBackend(ModelBackend): > > def authenticate(self,username=None,password=None): > try: > user = ProxyUser.objects.get(username=username) > except ProxyUser.DoesNotExist: > user = None > if user is not None and user.check_password(password): > return user > return None > > def get_user(self,user_id): > try: > return ProxyUser.objects.get(pk=user_id) > except ProxyUser.DoesNotExist: > return None > > Cheers, > > Ryan > > -- > Ryan Kellyhttp://www.rfk.id.au | This message is digitally signed. Please > visit > r...@rfk.id.au | http://www.rfk.id.au/ramblings/gpg/for details > > signature.asc > < 1KViewDownload --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Multi Page Form With Database Persistence
I need to create a multiple page form that upon submit the information is saved to the database so the user can finish it later. I want to be able to check the data filled out on the form and depending on the values entered present different pages to the user. I know this is possible, I just don't know how and the best way to accomplish this. I have looked into the FormWizard but it looks like it is more meant for forms that go in a straight line. Formwizard Page1 --> Page2 --> Page3 --> Page4 --> Page5 --> Page6 --> Page7 --> Page8 I want my form to be able to skip a page or insert one, depending on the input given on those pages. Page1 --> Page3 --> Page5 --> Page7 --> Page8 or Page1 --> Page2 --> Page4 --> Page5 --> Page8 Example of my model: #models.py from django.db import models class Poll(models.Model): question1 = models.CharField(max_length=200) pub_date1 = models.DateTimeField('date published') question2_state = USStateField() question3 = models.CharField(max_length=200) question4 = models.CharField(max_length=200) question5 = models.CharField(max_length=200) question6... agree = models.BooleanField(help_text='I agree that this is correct') #forms.py from django import forms class PollForm1(forms.Form): question1 = forms.CharField(max_length=200) question2 = forms.ChoiceField(max_length=200) class PollForm2(forms.Form): question3 = forms.CharField(max_length=200) class PollForm3(forms.Form): question4 = forms.CharField(max_length=200) class PollForm4(forms.Form): question5 = forms.CharField(max_length=200) question6 = forms.CharField(max_length=200) class PollForm5... class PollFormN... agree = forms.BooleanField() Thanks in advance for the 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 -~--~~~~--~~--~--~---
Re: Best way to get a proxy model instance from a base class instance
On Mon, 2009-04-20 at 15:17 -0700, Paul McLanahan wrote: > I'm using a proxy model of django.contrib.auth.models.User to override > __unicode__ and add some extra methods. This also means that I use my > proxy model class in my ForeignKey and ManyToMany fields. This is all > find and good until I need to use request.user and assign it to an > instance of another of my models. Django tells me that I can't assign > an instance of User where I need an instance of my proxy class. Right > now I'm doing something I'm sure is very inefficient to get around > this: > > obj.author = ProxyUser.objects.get(pk=request.user.pk) You could assign the ID directly rather than assigning the object instance: obj.author_id = request.user.id But if you then try to use the obj.author object in your code, it will still perform an extra DB lookup. Another approach is to install a custom authentication backend that returns instances of ProxyUser instead of User. This would ensure that request.user is always an instance of your proxy class. I'm using a backend like the following in a similar situation and it works great: class ProxyUserBackend(ModelBackend): def authenticate(self,username=None,password=None): try: user = ProxyUser.objects.get(username=username) except ProxyUser.DoesNotExist: user = None if user is not None and user.check_password(password): return user return None def get_user(self,user_id): try: return ProxyUser.objects.get(pk=user_id) except ProxyUser.DoesNotExist: return None Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part
Re: TemplateSyntaxError "Invalid block tag: 'include'"
Nevermind! I figured it out. Just for reference for those with a similar problem: "extends" and "include" aren't part of 'Template' and must be separately included: from django.template import Template, Context, loader from django.http import HttpResponse def render(request): admin_template = utility.getTemplate('templates/test.tpl') admin_context = getModelContext(); html = admin_template.render(admin_context); return HttpResponse(html) On Apr 20, 6:42 pm, Renato Untalanwrote: > Hey guys, new to Django, and i'm having a little trouble just getting > basic includes working. > > I have a basic template "world.html" as follows: > > > {% include 'hello.html' %} > World > > > > With "hello.html" as follows: > Hello > > - > > I'm getting the following error: > > TemplateSyntaxError at /test/ > > Invalid block tag: 'include' > > Request Method: GET > Request URL:http://localhost:8080/test/ > Exception Type: TemplateSyntaxError > Exception Value: > > Invalid block tag: 'include' > > Exception Location: /usr/local/lib/python2.4/site-packages/django/ > template/__init__.py in invalid_block_tag, line 333 > Python Executable: /usr/bin/python > Python Version: 2.4.2 > > -- > > I'm pretty sure i'm running Django 1.0, so what would cause my > %include tag not to function correctly? > Thanks for the 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 -~--~~~~--~~--~--~---
Re: How to relate child instance to Parent?
Thanks Dougal, That was really helpful. I was only picking User auth as an example. But the truth is there are many others models of mine that inherit from another class. Thank you very much On Apr 21, 1:25 am, Dougal Matthewswrote: > I think its as simple as; > > x = Staff() > user_obj = x.user > > I found that by just printing out the result of dir(Staff()) ;) > > I think however, you want to add to add a subclass for a user that > already exists. I'm not sure how you can do that, or if you can. The > recommended guide to extending/adding to the user object is > here;http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-... > > You might find that way easier. > > Cheers, > Dougal > > --- > Dougal Matthews - @d0ugalhttp://www.dougalmatthews.com/ > > 2009/4/20 Joshua Partogi : > > > > > > > Dear all, > > > I have an inheritance model as such: > > > class User(models.Model) > > > class Staff(User) > > > Now I already have the instance of User inside view: > > > user = User.objects.create(name="Joe") > > > now how do I relate this user instance to the staff instance? > > > I tried looking in the documentation but can not find anything about it. > > > Thank you very much in advance. > > > -- > > If you can't believe in God the chances are your God is too small. > > > Read my blog:http://joshuajava.wordpress.com/ > > Follow us on twitter:http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
TemplateSyntaxError "Invalid block tag: 'include'"
Hey guys, new to Django, and i'm having a little trouble just getting basic includes working. I have a basic template "world.html" as follows: {% include 'hello.html' %} World With "hello.html" as follows: Hello - I'm getting the following error: TemplateSyntaxError at /test/ Invalid block tag: 'include' Request Method: GET Request URL:http://localhost:8080/test/ Exception Type: TemplateSyntaxError Exception Value: Invalid block tag: 'include' Exception Location: /usr/local/lib/python2.4/site-packages/django/ template/__init__.py in invalid_block_tag, line 333 Python Executable: /usr/bin/python Python Version: 2.4.2 -- I'm pretty sure i'm running Django 1.0, so what would cause my %include tag not to function correctly? Thanks for the 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 -~--~~~~--~~--~--~---
Best way to get a proxy model instance from a base class instance
I'm using a proxy model of django.contrib.auth.models.User to override __unicode__ and add some extra methods. This also means that I use my proxy model class in my ForeignKey and ManyToMany fields. This is all find and good until I need to use request.user and assign it to an instance of another of my models. Django tells me that I can't assign an instance of User where I need an instance of my proxy class. Right now I'm doing something I'm sure is very inefficient to get around this: obj.author = ProxyUser.objects.get(pk=request.user.pk) That results in an extra hit to the DB. The other way that seems to work is: obj.author = ProxyUser(**request.user.__dict__) I think that should be fine, but it feels hackish. How would you guys do 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 -~--~~~~--~~--~--~---
Secure way to allow user with permission to delete a model instance from template?
>From the docs: "A good example is the delete() method on each Django model object. The template system shouldn't be allowed to do something like this: I will now delete this valuable data. {{ data.delete }}" What method should I use for allowing a user to delete an instance of the model using a link clicked on the 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: Webpy vs Django
On Mon, 2009-04-20 at 11:39 -0700, Vishwajeet wrote: > Hi All, > > This is not to flame any war; I just wanted to know the key features > to consider among the two web frame works. > > What advantage and disadvantages you have when you decide using any > one of them. > > Thanks for your help > Do your own homework? The two applications mentioned are wildly different and for different purposes, if you visit the homepage of both sites, you should have a clear idea of what advantages one has over the other. I believe this is what your tutor is wanting you to do. HTH Tom --~--~-~--~~~---~--~~ 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: nested loop issue
yes! that works exactly the way i wanted shouldnt that be part of Django? feels like a very fundamental piece of logic. Also yeah you're right about the URL. On Apr 20, 6:14 am, Tom Evanswrote: > On Sun, 2009-04-19 at 16:40 -0700, Johan wrote: > > Hello > > I have a problem I cant get my head around. > > I want to list through a bunch of people and see which one im friends > > with and which ones i can add as a friend. sort of twitter style. > > If it throw in an else it will hit on every step of the 2nd > > (supporters) loop, I obviously want either supporter OR an add me > > link. > > > {% for d in dreamers %} > > > > {{ d.user }} > > {% for s in supporters %} > > {% ifequal d.id s.id %} > > supporter > > {% endifequal %} > > {% endfor %} > > > > {% endfor % > > > result: > > > johan > > > sven supporter > > > glen supporter > > > ben > > > ken > > > {% for d in dreamers %} > > > > {{ d.user }} > > {% for s in supporters %} > > {% ifequal d.id s.id %} > > supporter > > {% else % } > > add me! > > {% endifequal %} > > > {% endfor %} > > > > {% endfor % > > > result: > > > sven supporter add me! > > > glen add me! supporter > > > ben add me! add me! > > > ken add me! add me! > > Looks like you hit the same thing I did. What you want to do is test to > see if d is in supporters, so something like this: > > {% for d in dreamers %} > > {{ d.user }} > {% IfInList d in supporters %} > supporter > {% else % } > add me! > {% endif %} > > {% endfor %} > > Unfortunately, this doesn't exist yet in django, I added an > implementation of IfInList if you want a custom tag [1], or you can wait > for us to stop arguing about the right way to do it [2] and have it in > the regular if tag. > > (Also, your href link should really be using {% url %} and should it > really be 'dreamer.user' and then 'd.user'?) > > Cheers > > Tom > > [1]http://code.djangoproject.com/ticket/10821 > [2]http://code.djangoproject.com/ticket/8087 --~--~-~--~~~---~--~~ 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: Problem pickling querysets with memcached
Thanks for replying Anatolly, I'm 0-2 on it crashing on other peoples machines. I have it doing the identical thing on 2 machines, one of which is using python 2.5 and django svn. The other is using python 2.6 and django svn. Both are using the 1.2 series of memcached and I have tried using both python-memcache and cmemcache for the bindings. The two machines I am having problems on are Ubuntu 9.04 and whatever webfaction is running on. After installing cmemcache I end up with an error while running test.py file... == FAIL: test_memcache (__main__.TestCmemcache) -- Traceback (most recent call last): File "test.py", line 254, in test_memcache self._test_base(cmemcache, cmemcache.StringClient(self.servers), ok=1) File "test.py", line 132, in _test_base self.failUnlessEqual(len(stats), 1) AssertionError: 0 != 1 -- Ran 1 test in 0.556s FAILED (failures=1) which someone else seemed to run into on this post http://ubuntuforums.org/archive/index.php/t-1044135.html Even with the test failing I was able to drop into the shell and test both cmemcache and python-memcach manually and they seemed to be operating correctly. Plus if instead of caching the querysets I cache the list version all is well. So I'm stumped at the cause. Thanks for taking a look. Will On Apr 20, 12:31 pm, Anatoliywrote: > Works for me. > > What version of python, django, memcached and python memcache bindings > you use? > > On 20 апр, 11:41, libwilliam wrote: > > >http://dl.getdropbox.com/u/174510/pickle_test.tar.gz > > > I am having trouble pickling querysets. I don't have any problem when > > using local memory but I do when using memcached. I have a link to a > > test project that shows the problem. The settings file is using > > memcached on port 2559. I started memcached using this command. > > > memcached -d -m 200 -l 127.0.0.1 -p 2559 > > > then ran the test framework... > > > python manage.py test main > > > == > > FAIL: Doctest: main.models.Place > > -- > > Traceback (most recent call last): > > File "/usr/local/lib/python2.6/dist-packages/django/test/ > > _doctest.py", line 2180, in runTest > > raise self.failureException(self.format_failure(new.getvalue())) > > AssertionError: Failed doctest test for main.models.Place > > File "/home/will/Projects/pickle_test/main/models.py", line 5, in > > Place > > > -- > > File "/home/will/Projects/pickle_test/main/models.py", line 16, in > > main.models.Place > > Failed example: > > loads(cache.get("places")).count() == 1 > > Exception raised: > > Traceback (most recent call last): > > File "/usr/local/lib/python2.6/dist-packages/django/test/ > > _doctest.py", line 1267, in __run > > compileflags, 1) in test.globs > > File "", line 1, in > > loads(cache.get("places")).count() == 1 > > File "/usr/lib/python2.6/pickle.py", line 1374, in loads > > return Unpickler(file).load() > > File "/usr/lib/python2.6/pickle.py", line 858, in load > > dispatch[key](self) > > File "/usr/lib/python2.6/pickle.py", line 1090, in load_global > > klass = self.find_class(module, name) > > File "/usr/lib/python2.6/pickle.py", line 1124, in find_class > > __import__(module) > > TypeError: __import__() argument 1 must be string without null > > bytes, not str > > > It looks to me that the pickling code is creating a string with null > > bytes, which memcached has a problem with but seems to work when using > > CACHE_BACKEND = 'locmem:///' > > > I think that but I had a guy try it out on a > > tickethttp://code.djangoproject.com/ticket/10865andhe didn't have the > > problem. So I was wondering if anyone had an idea of what I am doing > > wrong because I can't seem to figure it out. > > > Thank You, Will --~--~-~--~~~---~--~~ 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: FileUploadHandler not called in realtime
legutierrwrote: > Thomasz- Have you figured out a solution to this problem? Did you log > a bug in the defect tracker? No and no. Never thought it might be connected to Django in any way if it's already in the docs and everything. Might well be worth a try. I will file a bug report today. Let us know here please if You find any solution. I will keep you updated in this thread as well. Best regards, Tomasz Kopczuk --~--~-~--~~~---~--~~ 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: Problem pickling querysets with memcached
Works for me. What version of python, django, memcached and python memcache bindings you use? On 20 апр, 11:41, libwilliamwrote: > http://dl.getdropbox.com/u/174510/pickle_test.tar.gz > > I am having trouble pickling querysets. I don't have any problem when > using local memory but I do when using memcached. I have a link to a > test project that shows the problem. The settings file is using > memcached on port 2559. I started memcached using this command. > > memcached -d -m 200 -l 127.0.0.1 -p 2559 > > then ran the test framework... > > python manage.py test main > > == > FAIL: Doctest: main.models.Place > -- > Traceback (most recent call last): > File "/usr/local/lib/python2.6/dist-packages/django/test/ > _doctest.py", line 2180, in runTest > raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for main.models.Place > File "/home/will/Projects/pickle_test/main/models.py", line 5, in > Place > > -- > File "/home/will/Projects/pickle_test/main/models.py", line 16, in > main.models.Place > Failed example: > loads(cache.get("places")).count() == 1 > Exception raised: > Traceback (most recent call last): > File "/usr/local/lib/python2.6/dist-packages/django/test/ > _doctest.py", line 1267, in __run > compileflags, 1) in test.globs > File "", line 1, in > loads(cache.get("places")).count() == 1 > File "/usr/lib/python2.6/pickle.py", line 1374, in loads > return Unpickler(file).load() > File "/usr/lib/python2.6/pickle.py", line 858, in load > dispatch[key](self) > File "/usr/lib/python2.6/pickle.py", line 1090, in load_global > klass = self.find_class(module, name) > File "/usr/lib/python2.6/pickle.py", line 1124, in find_class > __import__(module) > TypeError: __import__() argument 1 must be string without null > bytes, not str > > It looks to me that the pickling code is creating a string with null > bytes, which memcached has a problem with but seems to work when using > CACHE_BACKEND = 'locmem:///' > > I think that but I had a guy try it out on a > tickethttp://code.djangoproject.com/ticket/10865and he didn't have the > problem. So I was wondering if anyone had an idea of what I am doing > wrong because I can't seem to figure it out. > > Thank You, Will --~--~-~--~~~---~--~~ 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: don't know how to use http://docs.djangoproject.com/en/dev/howto/initial-data/
On Apr 20, 8:16 pm, bconnorswrote: > How do I set up a initial_data.json file? > Athttp://docs.djangoproject.com/en/dev/howto/initial-data/ > > I came across this “Or, you can write fixtures by hand; fixtures can > be written as XML, YAML, or JSON documents. The serialization > documentation has more details about each of these supported > serialization formats. > As an example, though, here’s what a fixture for a simple Person model > might > look like in JSON: > [ > { > "model": "myapp.person", > "pk": 1, > "fields": { > "first_name": "John", > "last_name": "Lennon" > } > }, > { > "model": "myapp.person", > "pk": 2, > "fields": { > "first_name": "Paul", > "last_name": "McCartney" > } > } > ] So, what's the problem? The instructions seem clear enough. Where are you having trouble? -- 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-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 -~--~~~~--~~--~--~---
don't know how to use http://docs.djangoproject.com/en/dev/howto/initial-data/
How do I set up a initial_data.json file? At http://docs.djangoproject.com/en/dev/howto/initial-data/ I came across this “Or, you can write fixtures by hand; fixtures can be written as XML, YAML, or JSON documents. The serialization documentation has more details about each of these supported serialization formats. As an example, though, here’s what a fixture for a simple Person model might look like in JSON: [ { "model": "myapp.person", "pk": 1, "fields": { "first_name": "John", "last_name": "Lennon" } }, { "model": "myapp.person", "pk": 2, "fields": { "first_name": "Paul", "last_name": "McCartney" } } ] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Webpy vs Django
Hi All, This is not to flame any war; I just wanted to know the key features to consider among the two web frame works. What advantage and disadvantages you have when you decide using any one of them. Thanks 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 -~--~~~~--~~--~--~---
django.views.generic.date_based.object_detail called through a custom function - simple issue
Hi all, i'm trying to calling a genric view from a simple custom view (why? see this http://groups.google.com/group/django-users/browse_thread/thread/b5692e73f2b52b9) but i'm running into trouble when feeding the django.views.generic.date_based.object_detail my slug parameter. I'm trying this: def search_object_detail(request, year, month, day, slug): return date_based.object_detail( request, year, month, day, Mymodel.objects.filter(status=1), 'pub_date', slug = 'slug', slug_field = 'slug', template_name = 'detail.html', extra_context = { 'error': error, } ) which seems to be what the django API is wanting: 295 -def object_detail(request, year, month, day, queryset, date_field, 296 month_format='%b', day_format='%d', object_id=None, slug=None, 297 slug_field='slug', template_name=None, template_name_field=None, 298 template_loader=loader, extra_context=None, context_processors=None, 299 template_object_name='object', mimetype=None, allow_future=False): but not. What am i doing wrong? Sorry for posting a lamo query but maybe someone else will learn from this, cheers, --~--~-~--~~~---~--~~ 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: recieving GET from generic views - arrrrgh
cheers again for the response. However the code i used to get the wrapper working is given below def searchwrap(request): error = False if 'q' in request.GET: q = request.GET['q'] if not q: error = True else: articles = Mymodel.objects.filter(title__icontains=q) return django.views.generic.date_based.archive_index( request, queryset = set, template_name = 'search_results.html', extra_context = {'set': set} ) return date_based.archive_index( request, Mymodel.objects.filter(status=1), 'pub_date', template_name = 'search_form.html', extra_context = { 'error': error, } ) great! So, in order to get a (very simple) search box on each page in a default blog app with url which goes like /year/month/day/slug/ i wrapped archive_index, archive_year, archive_month, archive_day and object_detail from django.views.generic import date_based with a function that picks up the from GET. This is obviously a very thick way of achieving this. In the interests of elegant code could i pass the relevant generic function view name to my wrapper? I tried this by just including a parameter in the call for the wrapper view but it didn't work, i thought something like this would suffice, but no: (r'^$',views.searchwrap(generic.view)), am i way off? Cheers, On Apr 20, 5:50 am, Anatoliywrote: > Try this: > > return date_based.archive_index( > request, > Mymodel.objects.filter(status=1), > 'date_field': 'pub_date', > template_name = 'search_form.html', > extra_context = { > 'error': error, > } > ) > > On 20 апр, 02:01,SoCow wrote: > > > ok, i'm getting there. i figured out that i need to wrap the generic > > view in my own function. To make the problem clear i'm trying to get a > > simple search to live in the base.html template of a blog which uses > > the date_based generic view. My wrapper function consists of: > > > def searchwrap(request): > > error = False > > if 'q' in request.GET: > > q = request.GET['q'] > > if not q: > > error = True > > else: > > set= Mymodel.objects.filter(title__icontains=q) > > return django.views.generic.date_based.archive_index( > > request, > > queryset = set, > > template_name = 'search_results.html', > > extra_context = {'set': set} > > ) > > > return date_based.archive_index( > > request, > > template_name = 'search_form.html', > > extra_context = { > > 'error': error, > > 'queryset': Mymodel.objects.filter(status=1), > > 'date_field': 'pub_date' > > } > > ) > > > I'm now getting the error: > > > archive_index() takes at least 3 non-keyword arguments (1 given) > > > i thought that i was passing it 3 non-keyword arguments, no? > > > anyone any experience with this? > > > Thanks > > > On 19 Apr, 19:02,SoCow wrote: > > > > Hi all, > > > thanks for reading. > > > > I've implemented search for my site following the example in > > > thehttp://www.djangobook.com/en/2.0/chapter07/. My search view receives > > > the search term from a GET event. > > > > I want to use this same method in a generic view, but don't know how > > > Any ideas? > > > > Many thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Configuring the database
Hi guys, I'm reading django book chapter 5 (www.djangobook.com), and it is about how to connect with databases and how to use them with django. I've been having really hard time downloading MySQL and using it! I rock when it comes to SQL, and i really would love to use mysql, it's just that the information on the mysql site is pretty complicated and i'm having problem downloading it and downloading the server. Could you help me with it please, i'd really appreciate it if you tell me step by step how to download, what to download and how to get to the interpretor where i can write mysql code to create a database and connect it with django. I'm using windows xp, django 1, and python 2.5. Thanx a million for the help in advance --~--~-~--~~~---~--~~ 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: Problem with in long text fields in templates
On Mon, 2009-04-20 at 09:47 -0700, NoviceSortOf wrote: > By digging around here in this group I found > an answer in using > > {{ book.description|safe }} > It's just a minor thing, since you said this content comes from data entry, but this allows all HTML in book.description to be displayed, including potentially unsafe elements
Problem creating object
I'm trying to manually create an object (from a signal). My problem is that the object has a 'sites' M2M field: class News_item(models.Model): ... sites = models.ManyToManyField(Site) ... but when I try to create the object: news = News_item( ... sites = site, .. ) I'm getting a type error TypeError: 'sites' is an invalid keyword argument for this function What am I doing wrong here? --~--~-~--~~~---~--~~ 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: Problem with in long text fields in templates
On Apr 20, 11:31 am, NoviceSortOfwrote: [...] > When attempt to using {{ book.description }} in the template, it > outputs all the tags onto the screen, > when what we want is actual line breaks. > [...] > > Can someone please give me a clue as to how to make this work or where > to find information to make this work. Check the Django docs for the filters linebreaks, linebreaksbr, and safe. http://docs.djangoproject.com/en/dev/ref/templates/builtins/#built-in-template-tags-and-filters --~--~-~--~~~---~--~~ 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: Problem with in long text fields in templates
By digging around here in this group I found an answer in using {{ book.description|safe }} --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with in long text fields in templates
I've a template that displays descriptions of books. The descriptions are long text fields usually containing 1-3 paragraphs of text. Inside the text description during data entry tags are placed to indicate line breaks. When attempt to using {{ book.description }} in the template, it outputs all the tags onto the screen, when what we want is actual line breaks. I've attempted as well using {{ book.description|escape }} but that yields the same result. Obviously I'm missing part of the concept involved with displaying long text fields with embeded html via django . Can someone please give me a clue as to how to make this work or where to find information to make this work. --~--~-~--~~~---~--~~ 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: Django ACL Design Question
Tim, Thanks for the sample code. It was exactly what I was looking for. I'm still debating my route but it's nice to know what I want to do is possible. Thanks. On Mon, Apr 20, 2009 at 3:35 AM, Tim Chasewrote: > > >def MustHavePermission(*required_perms): > > def decorate(f): > >def new_f(request, *args, **kwargs): > > perms = UserCompanies.objects.filter( > >user=request.user, > >company=determine_company(request), > >) > > for perm in required_perms: > >perms = perms.filter(permission=perm) > > if not perms: > >raise Http403("Sorry, Dave, I can't let you do that.") > > return f(request, *args, **kwargs) > >return new_f > > return decorate > > I noticed some serious bogosity in this logic (it only passed if > a single permission was required, never if multiple permissions > were required). That innermost function should be something like > > def new_f(request, *args, **kwargs): > have = set( >UserCompanies.objects.filter( > user=request.user, > company=determine_company(request) > ).values_list("permission", flat=True) > ) > if have.issuperset(set(required_perms)): >return f(request, *args, **kwargs) > raise Http403("No way, Jose!") > > > -tim > > > > > > > --~--~-~--~~~---~--~~ 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: Split models.py to smaller parts.
On Apr 20, 2:57 am, x_Owrote: > Hi > > I'm looking for some general solution how to split models.py. Right > now my models.py reached 1000 lines and that argues some how with good > programing behaviour that I used use. > > I'm thinking about: > myproject/ > settings.py > myapp/ > models/ > file.py > directory.py > > instead of classic solution: > myproject/ > settings.py > myapp/ > models.py > views.py > > to In the simple case where in models we are able to avoid cyclic > import there is no problem. But what when classes definition use each > other implementation. > Django implements very nice and tricky solution using 'string' to > import definition in related > fields.http://docs.djangoproject.com/en/dev/ref/models/fields/#module-django... > but in current case its useless. > > Any idea how to win with that problem? > > x_O Hi, You're actually dealing with two separate issues: 1) How to move the model files into a separate package (i.e., a directory named "models/"). 2) How to reference models in different modules, that may or may not have been defined. To move the models into their own packages, move them into a directory named "models/", and create a file name __init__.py to make the directory a package: myapp/ models/ __init__.py one.py two.py In one.py, define your first model, but you'll need to add the attribute "app_label" to the Meta inner class. Here's one.py: from django.db import models class ModelOne(models.Model): class Meta: app_label = 'myapp' Now, in two.py, you can either reference ModelOne using its name, or by importing it first. Here's the string version of two.py: from django.db import models class ModelTwo(models.Model): one = models.ForeignKey('ModelOne') class Meta: app_label = 'myapp' Here's the import version of two.py: from django.db import models from one import ModelOne class ModelTwo(models.Model): one = models.ForeignKey(ModelOne) class Meta: app_label = 'myapp' Finally, you're going to need to import these models into the __init__.py modules, so that when it's imported later, it finds your models. Here's the contents of __init__.py: from one import ModelOne from two import ModelTwo A way to check that all of this is working is to either use "manage.py validate", or "manage.py sql myapp", to view the SQL that will be used to created the models' tables. Here's what I see: rpwagner$ ./manage.py validate 0 errors found rpwagner$ ./manage.py sql myapp BEGIN; CREATE TABLE "myapp_modelone" ( "id" integer NOT NULL PRIMARY KEY ) ; CREATE TABLE "myapp_modeltwo" ( "id" integer NOT NULL PRIMARY KEY, "one_id" integer NOT NULL REFERENCES "myapp_modelone" ("id") ) ; COMMIT; rpwagner$ Hope this helps. --Rick --~--~-~--~~~---~--~~ 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: inlineformsets version 1.0.2
Good stuff, thanks for the reply all. Roll on 1.0.3! On Apr 20, 4:19 pm, Karen Traceywrote: > On Mon, Apr 20, 2009 at 11:03 AM, Alex Gaynor wrote: > > On Mon, Apr 20, 2009 at 7:18 AM, chewynougat < > > peter_i_campb...@hotmail.co.uk> wrote: > > >> We have recently upgraded django to 1.0.2 but this has subsequently > >> broken some inlineformsets we have. I'm not sure if this is a django > >> bug or if it is an error in our code, although the code pretty much > >> reflects that in the SVN documentation. Any help on this issue would > >> be much appreciated, in the meantime, I shall keep digging! Traceback > >> is as follows: > > >> Traceback (most recent call last): > > >> [snip] > >> File "/usr/lib/python2.4/site-packages/django/forms/models.py", line > >> 494, in add_fields > >> form.fields[self.fk.name] = InlineForeignKeyField(self.instance, > >> label=form.fields[self.fk.name].label) > > >> KeyError: 'activity' > > >> Cardiovascular object is an fk to Activity object. > > >> Thanks again, > > >> Pete > > > This is a bug that was fixed in the 1.0.X branch, and will be a part of the > > 1.0.3 release. I can't remember the bug number right now unfortunately. > > I'd guess it was #9863: > > http://code.djangoproject.com/ticket/9863 > > Trying with a checkout of the 1.0.X branch would confirm. > > Karen --~--~-~--~~~---~--~~ 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: How to relate child instance to Parent?
I think its as simple as; x = Staff() user_obj = x.user I found that by just printing out the result of dir(Staff()) ;) I think however, you want to add to add a subclass for a user that already exists. I'm not sure how you can do that, or if you can. The recommended guide to extending/adding to the user object is here; http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users You might find that way easier. Cheers, Dougal --- Dougal Matthews - @d0ugal http://www.dougalmatthews.com/ 2009/4/20 Joshua Partogi: > > Dear all, > > I have an inheritance model as such: > > class User(models.Model) > > class Staff(User) > > Now I already have the instance of User inside view: > > user = User.objects.create(name="Joe") > > now how do I relate this user instance to the staff instance? > > I tried looking in the documentation but can not find anything about it. > > Thank you very much in advance. > > -- > If you can't believe in God the chances are your God is too small. > > Read my blog: http://joshuajava.wordpress.com/ > Follow us on twitter: http://twitter.com/scrum8 > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Inline admin model and id of parent model object
Hi! I've got 2 admin models like these: class MyUserServiceAdminForm(forms.ModelForm): class Meta: model = UserService def clean(self): Get client_id for validation??? return cleaned_data class UserServiceAdmin(admin.TabularInline): model = UserService fields = ('service','tariff') form = MyUserServiceAdminForm class ClientAdmin(admin.ModelAdmin): inlines = [ UserServiceAdmin, ] I need custom validation for MyUserServiceAdminForm and I want to get client_id in clean method. The point is 'client' doesn't present in UserServiceAdmin.fields. But django gets this client_id somehow and store it in database. How can I access client_id from clean method? --~--~-~--~~~---~--~~ 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: inlineformsets version 1.0.2
On Mon, Apr 20, 2009 at 11:03 AM, Alex Gaynorwrote: > On Mon, Apr 20, 2009 at 7:18 AM, chewynougat < > peter_i_campb...@hotmail.co.uk> wrote: > >> >> We have recently upgraded django to 1.0.2 but this has subsequently >> broken some inlineformsets we have. I'm not sure if this is a django >> bug or if it is an error in our code, although the code pretty much >> reflects that in the SVN documentation. Any help on this issue would >> be much appreciated, in the meantime, I shall keep digging! Traceback >> is as follows: >> >> Traceback (most recent call last): >> >> [snip] >> File "/usr/lib/python2.4/site-packages/django/forms/models.py", line >> 494, in add_fields >> form.fields[self.fk.name] = InlineForeignKeyField(self.instance, >> label=form.fields[self.fk.name].label) >> >> KeyError: 'activity' >> >> Cardiovascular object is an fk to Activity object. >> >> Thanks again, >> >> Pete >> >> > This is a bug that was fixed in the 1.0.X branch, and will be a part of the > 1.0.3 release. I can't remember the bug number right now unfortunately. > I'd guess it was #9863: http://code.djangoproject.com/ticket/9863 Trying with a checkout of the 1.0.X branch would confirm. Karen --~--~-~--~~~---~--~~ 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: inlineformsets version 1.0.2
On Mon, Apr 20, 2009 at 7:18 AM, chewynougatwrote: > > We have recently upgraded django to 1.0.2 but this has subsequently > broken some inlineformsets we have. I'm not sure if this is a django > bug or if it is an error in our code, although the code pretty much > reflects that in the SVN documentation. Any help on this issue would > be much appreciated, in the meantime, I shall keep digging! Traceback > is as follows: > > Traceback (most recent call last): > > File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", > line 86, in get_response > response = callback(request, *callback_args, **callback_kwargs) > > File "/var/www/django/primus/contrib/statsandgoals/views.py", line > 826, in add_cardio > cardio_form = CardiovascularFormSet() > > File "/usr/lib/python2.4/site-packages/django/forms/models.py", line > 468, in __init__ > queryset=qs) > > File "/usr/lib/python2.4/site-packages/django/forms/models.py", line > 352, in __init__ > super(BaseModelFormSet, self).__init__(**defaults) > > File "/usr/lib/python2.4/site-packages/django/forms/formsets.py", > line 67, in __init__ > self._construct_forms() > > File "/usr/lib/python2.4/site-packages/django/forms/models.py", line > 474, in _construct_forms > super(BaseInlineFormSet, self)._construct_forms() > > File "/usr/lib/python2.4/site-packages/django/forms/formsets.py", > line 76, in _construct_forms > self.forms.append(self._construct_form(i)) > > File "/usr/lib/python2.4/site-packages/django/forms/models.py", line > 477, in _construct_form > form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs) > > File "/usr/lib/python2.4/site-packages/django/forms/models.py", line > 357, in _construct_form > return super(BaseModelFormSet, self)._construct_form(i, **kwargs) > > File "/usr/lib/python2.4/site-packages/django/forms/formsets.py", > line 96, in _construct_form > self.add_fields(form, i) > > File "/usr/lib/python2.4/site-packages/django/forms/models.py", line > 494, in add_fields > form.fields[self.fk.name] = InlineForeignKeyField(self.instance, > label=form.fields[self.fk.name].label) > > KeyError: 'activity' > > Cardiovascular object is an fk to Activity object. > > Thanks again, > > Pete > > > This is a bug that was fixed in the 1.0.X branch, and will be a part of the 1.0.3 release. I can't remember the bug number right now unfortunately. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Running django test suite
Regarding failures 1 and 2 in the error output for the django test suite which are listed here http://dpaste.com/34864/ . I recently ran the tests on svn revision 10604. Failure 1 - The error was referred to in ticket http://code.djangoproject.com/ticket/6802 . Should this ticket be reopened? Failure 2- Any recommendations on how to resolve the windows error? Thanks, Jeff - Original Message - From: jeffh...@comcast.net To: django-users@googlegroups.com Sent: Friday, April 17, 2009 1:19:05 PM GMT -06:00 US/Canada Central Subject: Re: Running django test suite Karen, Thanks so much for the explanation! Actually, I was incorrect I used the development version via SVN revision 10369. I just downloaded the latest version today. Also, I missed putting in the first error, a cut and paste problem. I included all the 3 errors are included here http://dpaste.com/34864/ Regarding failure 1: I am running Python 2.6 on Windows XP using sqlite3. I do not believe I have anything running simultaneously trying to open the files while the test is trying to delete the files. I just downloaded the latest version today which is revision 10581 and still get the same error. Regarding the first error in the link above which was not included originally. I searched the tickets regarding this error. I found the following ticket which states that it was fixed http://code.djangoproject.com/ticket/6802 Thanks, Jeff - Original Message - From: "Karen Tracey"To: django-users@googlegroups.com Sent: Friday, April 17, 2009 10:46:27 AM GMT -06:00 US/Canada Central Subject: Re: Running django test suite On Thu, Apr 16, 2009 at 1:26 PM, jeffhg58 < jeffh...@comcast.net > wrote: I recently installed django 1.1 beta and I needed to run the django test suite. So, under the tests directory I executed runtests.py. I received some errors when trying to execute all the tests. I was expected that all the tests would have passed. I am thinking it might be with my setup. Here are the errors I encountered. http://dpaste.com/34433/ First, I'm curious how you got tests for 1.1 beta? The tests weren't included in the tarfile until quite recently (post 1.1 beta, I believe, since my downloaded un-tarred copy of 1.1 does not have a tests directory). If you are getting tests out of svn you just need to be careful that you are running a version that matches the code you are using -- if you use more-recent tests against backlevel code you are liable to hit test failures resulting from bugfixes where the bugfix changeset has included a test that fails prior to the code fix. I don't believe that is what you are seeing here though. Second, the failure summary you point to lists 3 failure but I only see details of 2 failures listed above. Is that output complete? As for the failures: 1 - The Windows error on attempting to delete a file is something we've seen before, and fixed (though I'm not sure in this particular place). I cannot recreate the error on my Windows box with Python 2.6 and the beta 1.1 (nor current trunk) level code. What exact level of Python 2.6 are you running? -- the specifics of this error have been dependent on Python level in the past. Are you running anything on this machine (like a virus scanner) that may be opening these files created by the tests while the test itself is simultaneously trying to delete them? There was also at least one fix made after 1.1 beta that cleaned up some issues with temp files on Windows getting closed and deleted properly, so I'd be interested to know if you tried running with trunk level code if you still see this error. 2 - I've not seen the markup test error before but it looks like it may be textile-level dependent. I can recreate the problem with textile 2.1.3 (on Windows, where I previously had no textile installed) but not 2.0.10 (what I happen to have on Linux). The test may be overly sensitive to slight changes in what textile produces. I was going to say please open a ticket but upon searching I see this has already been reported: http://code.djangoproject.com/ticket/10843 On the general question as to whether all the test should pass -- in an ideal world, yes, but we are not quite there yet. There are OS and database backend issues that cause some known test failures. Linux/sqlite generally runs cleanly, Windows/sqlite may, but it is dependent on Python level (Python 2.5 on Windows has a particularly problematic sqlite level that it shipped with). I generally also see clean runs using MySQL/MyISAM (both Linux and Windows) but MySQL/InnoDB has many failures resulting from InnoDB's inability to do deferred constraint checking (there's a ticket open on that). Some levels of PostgreSQL show failures with the admin_views test (again, there's a ticket open on it). Most test failures I know of have either tickets
Re: Help request: postgresql_psycopg2 connection problem under wsgi (but under runserver and dbshell its fine!)
My guess is that your connection string specifies connecting as user "acacian", specifies no password and that you've been logged in as a user with the same name to run runserver. The default configuration of postgresql allows users to connect as a postgresql user of the same name as them without a password (over local sockets). I suspect the apache process is not running as user "acacian" thus password-less authentication is failing. To fix it you'll need to fiddle around with postgresql authentication settings (unless you want to change the user which apache runs as). On Apr 19, 11:54 pm, Darylwrote: > Hello, > > I'm getting the following error when deployed under mod_wsgi > > File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/ > django/db/backends/postgresql_psycopg2/base.py", line 98, in _cursor > self.connection = Database.connect(**conn_params) > OperationalError: FATAL: Ident authentication failed for user > "acacian" > --~--~-~--~~~---~--~~ 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: Creating custom feeds
Even more. How feeds are different from any other pages? What if I will simply generate a template of needed structure using django models + views (as described in tutorials) Thanks, Oleg On Mon, Apr 20, 2009 at 3:14 PM, Oleg Oltarwrote: > Hi! > > I want to create RSS2 feed. I read the doc > http://www.djangoproject.com/documentation/0.96/syndication_feeds/ > > So created a class > > # coding: utf-8 > from django.contrib.syndication.feeds import Feed > from articleManager.models import Article as article > > > class LatestEntries(Feed): > title = 'TITLE' > link = 'http://example.com' > description = "DESCRIPTION HERE" > > > > def items(self): > return article.objects.order_by("-pub_date")[:10] > > > But I need to add 2 custom attributes to my feed: > 1. image_logo - need to add an image logo of my site > 2. fulltext - a full text of an article (from my model) > > Is there a way I can do 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: nested loop issue
On Sun, 2009-04-19 at 16:40 -0700, Johan wrote: > Hello > I have a problem I cant get my head around. > I want to list through a bunch of people and see which one im friends > with and which ones i can add as a friend. sort of twitter style. > If it throw in an else it will hit on every step of the 2nd > (supporters) loop, I obviously want either supporter OR an add me > link. > > {% for d in dreamers %} > > {{ d.user }} > {% for s in supporters %} > {% ifequal d.id s.id %} >supporter > {% endifequal %} > {% endfor %} > > {% endfor % > > result: > > > johan > > sven supporter > > glen supporter > > ben > > ken > > {% for d in dreamers %} > > {{ d.user }} > {% for s in supporters %} > {% ifequal d.id s.id %} >supporter > {% else % } >add me! > {% endifequal %} > > {% endfor %} > > {% endfor % > > result: > > sven supporter add me! > > glen add me! supporter > > ben add me! add me! > > ken add me! add me! > Looks like you hit the same thing I did. What you want to do is test to see if d is in supporters, so something like this: {% for d in dreamers %} {{ d.user }} {% IfInList d in supporters %} supporter {% else % } add me! {% endif %} {% endfor %} Unfortunately, this doesn't exist yet in django, I added an implementation of IfInList if you want a custom tag [1], or you can wait for us to stop arguing about the right way to do it [2] and have it in the regular if tag. (Also, your href link should really be using {% url %} and should it really be 'dreamer.user' and then 'd.user'?) Cheers Tom [1] http://code.djangoproject.com/ticket/10821 [2] http://code.djangoproject.com/ticket/8087 --~--~-~--~~~---~--~~ 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: Models Aliases
Thanks Alex, I didn't know this function, that's what I needed! Bastien On Apr 20, 1:40 pm, Alex Koshelevwrote: > Hi, Bastien. > > I think the simple solution with property may be the best aproach if > you cannot change dependent code: > > user = property(lambda self: self.author) > > > > On Mon, Apr 20, 2009 at 3:37 PM, Bastien wrote: > > > You're right Dougal, I *should* do that I have various apps already > > working with the whole project trying to access object.user in general > > and I was wondering if there was a clean way to alias author. I'm > > already using some workarounds but it's dirty... > > > On Apr 20, 1:26 pm, Dougal Matthews wrote: > >> why don't you just access entry.author rather than entry.user? > >> I think perhaps I'm not quite following your question. > > >> Dougal > > >> --- > >> Dougal Matthews - @d0ugalhttp://www.dougalmatthews.com/ > > >> 2009/4/20 Bastien > > >> > Hi, > > >> > I searched the doc but couldn't find anything about this: I have a > >> > model for a blog entry that contains a foreign key to user and is > >> > named author. But that would be really convenient for me if the object > >> > would respond to the keyword 'user' as well: entry.user doesn't exist > >> > in the model but I would like it to return what entry.author usually > >> > returns, just like an alias. Does anything like that exists in Django? > >> > is it considered good practice? I could just use the author key or > >> > rename it to user but what happens is that I have various applications > >> > that already work with either object.user or object.author and I don't > >> > want to rewrite them all. Thanks. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to relate child instance to Parent?
Dear all, I have an inheritance model as such: class User(models.Model) class Staff(User) Now I already have the instance of User inside view: user = User.objects.create(name="Joe") now how do I relate this user instance to the staff instance? I tried looking in the documentation but can not find anything about it. Thank you very much in advance. -- If you can't believe in God the chances are your God is too small. Read my blog: http://joshuajava.wordpress.com/ Follow us on twitter: http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Creating custom feeds
Hi! I want to create RSS2 feed. I read the doc http://www.djangoproject.com/documentation/0.96/syndication_feeds/ So created a class # coding: utf-8 from django.contrib.syndication.feeds import Feed from articleManager.models import Article as article class LatestEntries(Feed): title = 'TITLE' link = 'http://example.com' description = "DESCRIPTION HERE" def items(self): return article.objects.order_by("-pub_date")[:10] But I need to add 2 custom attributes to my feed: 1. image_logo - need to add an image logo of my site 2. fulltext - a full text of an article (from my model) Is there a way I can do 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: Models Aliases
Hi, Bastien. I think the simple solution with property may be the best aproach if you cannot change dependent code: user = property(lambda self: self.author) On Mon, Apr 20, 2009 at 3:37 PM, Bastienwrote: > > You're right Dougal, I *should* do that I have various apps already > working with the whole project trying to access object.user in general > and I was wondering if there was a clean way to alias author. I'm > already using some workarounds but it's dirty... > > > On Apr 20, 1:26 pm, Dougal Matthews wrote: >> why don't you just access entry.author rather than entry.user? >> I think perhaps I'm not quite following your question. >> >> Dougal >> >> --- >> Dougal Matthews - @d0ugalhttp://www.dougalmatthews.com/ >> >> 2009/4/20 Bastien >> >> >> >> >> >> > Hi, >> >> > I searched the doc but couldn't find anything about this: I have a >> > model for a blog entry that contains a foreign key to user and is >> > named author. But that would be really convenient for me if the object >> > would respond to the keyword 'user' as well: entry.user doesn't exist >> > in the model but I would like it to return what entry.author usually >> > returns, just like an alias. Does anything like that exists in Django? >> > is it considered good practice? I could just use the author key or >> > rename it to user but what happens is that I have various applications >> > that already work with either object.user or object.author and I don't >> > want to rewrite them all. Thanks. > > > --~--~-~--~~~---~--~~ 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: Models Aliases
You're right Dougal, I *should* do that I have various apps already working with the whole project trying to access object.user in general and I was wondering if there was a clean way to alias author. I'm already using some workarounds but it's dirty... On Apr 20, 1:26 pm, Dougal Matthewswrote: > why don't you just access entry.author rather than entry.user? > I think perhaps I'm not quite following your question. > > Dougal > > --- > Dougal Matthews - @d0ugalhttp://www.dougalmatthews.com/ > > 2009/4/20 Bastien > > > > > > > Hi, > > > I searched the doc but couldn't find anything about this: I have a > > model for a blog entry that contains a foreign key to user and is > > named author. But that would be really convenient for me if the object > > would respond to the keyword 'user' as well: entry.user doesn't exist > > in the model but I would like it to return what entry.author usually > > returns, just like an alias. Does anything like that exists in Django? > > is it considered good practice? I could just use the author key or > > rename it to user but what happens is that I have various applications > > that already work with either object.user or object.author and I don't > > want to rewrite them all. Thanks. --~--~-~--~~~---~--~~ 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: Registration
Thanks for the continued help. I have written the URLS.py now they are as below: urlpatterns = patterns('', # Activation keys get matched by \w+ instead of the more specific # [a-fA-F0-9]{40} because a bad activation key should still get to the view; # that way it can return a sensible "invalid key" message instead of a # confusing 404. url(r'^activate/(?P\w+)/$', activate, name='registration_activate'), url(r'^login/$', auth_views.login, {'template_name': 'registration/ login.html'}, name='auth_login'), url(r'^logout/$', auth_views.logout, {'template_name': 'registration/ logout.html'}, name='auth_logout'), url(r'^password/change/$', auth_views.password_change, name='auth_password_change'), url(r'^password/change/done/$', auth_views.password_change_done, name='auth_password_change_done'), url(r'^password/reset/$', auth_views.password_reset, name='auth_password_reset'), url(r'^password/reset/confirm/(?P[0-9A- Za-z]+)-(?P.+)/$', auth_views.password_reset_confirm, name='auth_password_reset_confirm'), url(r'^password/reset/complete/$', auth_views.password_reset_complete, name='auth_password_reset_complete'), url(r'^password/reset/done/$', auth_views.password_reset_done, name='auth_password_reset_done'), url(r'^register/$', register, name='registration_register'), url(r'^register/complete/$', direct_to_template, {'template': 'registration/ registration_complete.html'}, name='registration_complete'), ) I think that is correct. When I load the HTML page I still cannot see a form and only see: {% load i18n %} {% block header %} {% trans "Home" %} | {% if user.is_authenticated %} {% trans "Logged in" %}: {{ user.username }} ({% trans "Log out" %} | {% trans "Change password" %}) {% else %} {% trans "Log in" %} {% endif %} {% endblock %} {% block content %}{% endblock %} {% block footer %} {% endblock %} I think I am quite close to getting this working, just having a hard time with linking the HTML. --~--~-~--~~~---~--~~ 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: Registration
Thanks for the continued help. I have written the URLS.py now they are as below: urlpatterns = patterns('', # Activation keys get matched by \w+ instead of the more specific # [a-fA-F0-9]{40} because a bad activation key should still get to the view; # that way it can return a sensible "invalid key" message instead of a # confusing 404. url(r'^activate/(?P\w+)/$', activate, name='registration_activate'), url(r'^login/$', auth_views.login, {'template_name': 'registration/ login.html'}, name='auth_login'), url(r'^logout/$', auth_views.logout, {'template_name': 'registration/ logout.html'}, name='auth_logout'), url(r'^password/change/$', auth_views.password_change, name='auth_password_change'), url(r'^password/change/done/$', auth_views.password_change_done, name='auth_password_change_done'), url(r'^password/reset/$', auth_views.password_reset, name='auth_password_reset'), url(r'^password/reset/confirm/(?P[0-9A- Za-z]+)-(?P.+)/$', auth_views.password_reset_confirm, name='auth_password_reset_confirm'), url(r'^password/reset/complete/$', auth_views.password_reset_complete, name='auth_password_reset_complete'), url(r'^password/reset/done/$', auth_views.password_reset_done, name='auth_password_reset_done'), url(r'^register/$', register, name='registration_register'), url(r'^register/complete/$', direct_to_template, {'template': 'registration/ registration_complete.html'}, name='registration_complete'), ) I think that is correct. When I load the HTML page I still cannot see a form and only see: {% load i18n %} {% block header %} {% trans "Home" %} | {% if user.is_authenticated %} {% trans "Logged in" %}: {{ user.username }} ({% trans "Log out" %} | {% trans "Change password" %}) {% else %} {% trans "Log in" %} {% endif %} {% endblock %} {% block content %}{% endblock %} {% block footer %} {% endblock %} I think I am quite close to getting this working, just having a hard time with linking the HTML. --~--~-~--~~~---~--~~ 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: Models Aliases
why don't you just access entry.author rather than entry.user? I think perhaps I'm not quite following your question. Dougal --- Dougal Matthews - @d0ugal http://www.dougalmatthews.com/ 2009/4/20 Bastien> > Hi, > > I searched the doc but couldn't find anything about this: I have a > model for a blog entry that contains a foreign key to user and is > named author. But that would be really convenient for me if the object > would respond to the keyword 'user' as well: entry.user doesn't exist > in the model but I would like it to return what entry.author usually > returns, just like an alias. Does anything like that exists in Django? > is it considered good practice? I could just use the author key or > rename it to user but what happens is that I have various applications > that already work with either object.user or object.author and I don't > want to rewrite them all. Thanks. > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
inlineformsets version 1.0.2
We have recently upgraded django to 1.0.2 but this has subsequently broken some inlineformsets we have. I'm not sure if this is a django bug or if it is an error in our code, although the code pretty much reflects that in the SVN documentation. Any help on this issue would be much appreciated, in the meantime, I shall keep digging! Traceback is as follows: Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 86, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/var/www/django/primus/contrib/statsandgoals/views.py", line 826, in add_cardio cardio_form = CardiovascularFormSet() File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 468, in __init__ queryset=qs) File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 352, in __init__ super(BaseModelFormSet, self).__init__(**defaults) File "/usr/lib/python2.4/site-packages/django/forms/formsets.py", line 67, in __init__ self._construct_forms() File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 474, in _construct_forms super(BaseInlineFormSet, self)._construct_forms() File "/usr/lib/python2.4/site-packages/django/forms/formsets.py", line 76, in _construct_forms self.forms.append(self._construct_form(i)) File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 477, in _construct_form form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs) File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 357, in _construct_form return super(BaseModelFormSet, self)._construct_form(i, **kwargs) File "/usr/lib/python2.4/site-packages/django/forms/formsets.py", line 96, in _construct_form self.add_fields(form, i) File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 494, in add_fields form.fields[self.fk.name] = InlineForeignKeyField(self.instance, label=form.fields[self.fk.name].label) KeyError: 'activity' Cardiovascular object is an fk to Activity object. Thanks again, Pete --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
auth.contrib silently catching TypeError. Bug?
Hi, The function authenticate in django/contrib/auth/__init__.py reads: 31def authenticate(**credentials): 32 """ 33 If the given credentials are valid, return a User object. 34 """ 35 for backend in get_backends(): 36 try: 37 user = backend.authenticate(**credentials) 38 except TypeError: 39 # This backend doesn't accept these credentials as arguments. Try the next one. 40 continue 41 if user is None: 42 continue 43 # Annotate the user object with the path of the backend. 44 user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__) 45 return user As you can see the code catches and silently ignores all TypeError exceptions: The problems with this approach are: - Why not fail as early as possible if one of the authentication backends configured in settings.py has a wrong signature? If nothing else at least a warning should be logged IMHO. - The bigger is that the code silently catches all TypeError exceptions. If the signature is correct, but the custom backend authenticator somewhere has a bug and a TypeError is raised as a result, the exception will be hidden away. TypeError is a common exception, so I don't think that catching and ignoring it in code that others will write is a good idea. I intended to raise this as a bug, but first I wanted to make sure that others would consider it a bug too. Cheers, Tamas --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem pickling querysets with memcached
http://dl.getdropbox.com/u/174510/pickle_test.tar.gz I am having trouble pickling querysets. I don't have any problem when using local memory but I do when using memcached. I have a link to a test project that shows the problem. The settings file is using memcached on port 2559. I started memcached using this command. memcached -d -m 200 -l 127.0.0.1 -p 2559 then ran the test framework... python manage.py test main == FAIL: Doctest: main.models.Place -- Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/django/test/ _doctest.py", line 2180, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for main.models.Place File "/home/will/Projects/pickle_test/main/models.py", line 5, in Place -- File "/home/will/Projects/pickle_test/main/models.py", line 16, in main.models.Place Failed example: loads(cache.get("places")).count() == 1 Exception raised: Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/django/test/ _doctest.py", line 1267, in __run compileflags, 1) in test.globs File "", line 1, in loads(cache.get("places")).count() == 1 File "/usr/lib/python2.6/pickle.py", line 1374, in loads return Unpickler(file).load() File "/usr/lib/python2.6/pickle.py", line 858, in load dispatch[key](self) File "/usr/lib/python2.6/pickle.py", line 1090, in load_global klass = self.find_class(module, name) File "/usr/lib/python2.6/pickle.py", line 1124, in find_class __import__(module) TypeError: __import__() argument 1 must be string without null bytes, not str It looks to me that the pickling code is creating a string with null bytes, which memcached has a problem with but seems to work when using CACHE_BACKEND = 'locmem:///' I think that but I had a guy try it out on a ticket http://code.djangoproject.com/ticket/10865 and he didn't have the problem. So I was wondering if anyone had an idea of what I am doing wrong because I can't seem to figure it out. Thank You, Will --~--~-~--~~~---~--~~ 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: Simple_tag strange behaviour
Yes, that's what I suspect. I've just tested the script through a python interpretor (stripped out the django only stuff first) and it definitely works. So I'm wondering if it might be a timing issue, that somehow on a refresh, perhaps due some kind of cacheing, the queryset is not being fetched quickly enough so the script runs without it and therefore the update doesn't work? Is that even possible? On Apr 20, 6:48 pm, Anatoliywrote: > So what is your problem? > > update_cal_links() doesn't work after page refresh? > > On Apr 20, 1:05 pm, Tonne wrote: > > > > > > I didn't see how you return array to template context. > > > Okay... well, it's actually a string that I finally send to the > > template. It's a long story (sorry), but I use the array to build a > > string (i.e values from the array get embedded in HTML source). The > > place where the string is return to the template is the last line on > > the tag, i.e. "return home_calendar". > > > The line above it "home_calendar = print_cal()", shows how > > print_calendar is a value derived from the function that builds the > > string. > > > I could show you the source of the array and string building function, > > but I'm afraid you eyes might bleed :) > > > On Apr 20, 4:37 pm, Anatoliy wrote: > > > > Tonne, > > > > I didn't see how you return array to template context. > > > > On Apr 20, 11:44 am, Tonne wrote: > > > > > Thanks > > > > > > Can you show code of your tag and template where it used? > > > > > Well, sure, but the tag is quite a big one, 150 lines long due to the > > > > large array and string concatenation going on. So I've shown here only > > > > what I assume to be the critical bits. > > > > > (btw. the tag discussed here was the solution to this > > > > issuehttp://groups.google.com/group/django-users/browse_thread/thread/ae40...) > > > > > tag > > > > -- > > > > > cal = { 2007: > > > > > { > > > > 1: [ [1], [2], #etcetera... a > > > > fairly big multidimensional > > > > array > > > > > def update_cal_links(year, month, day): > > > > """updates 'cal' array with a link to entry""" > > > > link = "/%d/%d/%d/" %(year, month, day) > > > > cal[year][month][day-1].insert(1,link) > > > > return > > > > > def print_cal(): > > > > """ Returns a string, compiling calender into a series of nested > > > > unordered lists""" > > > > #I've removed the body of this function cos it's long, ugly > > > > and it does seem to work fine > > > > > @register.simple_tag > > > > def do_home_calendar(): > > > > """ Populates calendar with links to entries, > > > > returns a formatted calendar to the template.""" > > > > entries = Entry.objects.all() > > > > for date in entries: > > > > link = date.splitDate() #model method > > > > update_cal_links(int(link['year']), int(link['month']), > > > > int(link > > > > ['day'])) # function expects integers > > > > home_calendar = print_cal() > > > > return home_calendar > > > > > template > > > > > > > > > {% extends "base.html" %} > > > > {% load simple_tags %} > > > > > {% block content %} > > > > {% do_home_calendar %} > > > > {% if archive_list %} > > > > hello > > > > > > > > {% for entry in archive_list %} > > > > {{ entry.date }} > > > li> > > > > {% endfor %} > > > > > > > > {% else %} > > > > FAIL! > > > > {% endif %} > > > > {% 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Models Aliases
Hi, I searched the doc but couldn't find anything about this: I have a model for a blog entry that contains a foreign key to user and is named author. But that would be really convenient for me if the object would respond to the keyword 'user' as well: entry.user doesn't exist in the model but I would like it to return what entry.author usually returns, just like an alias. Does anything like that exists in Django? is it considered good practice? I could just use the author key or rename it to user but what happens is that I have various applications that already work with either object.user or object.author and I don't want to rewrite them all. Thanks. --~--~-~--~~~---~--~~ 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: Simple_tag strange behaviour
So what is your problem? update_cal_links() doesn't work after page refresh? On Apr 20, 1:05 pm, Tonnewrote: > > I didn't see how you return array to template context. > > Okay... well, it's actually a string that I finally send to the > template. It's a long story (sorry), but I use the array to build a > string (i.e values from the array get embedded in HTML source). The > place where the string is return to the template is the last line on > the tag, i.e. "return home_calendar". > > The line above it "home_calendar = print_cal()", shows how > print_calendar is a value derived from the function that builds the > string. > > I could show you the source of the array and string building function, > but I'm afraid you eyes might bleed :) > > On Apr 20, 4:37 pm, Anatoliy wrote: > > > Tonne, > > > I didn't see how you return array to template context. > > > On Apr 20, 11:44 am, Tonne wrote: > > > > Thanks > > > > > Can you show code of your tag and template where it used? > > > > Well, sure, but the tag is quite a big one, 150 lines long due to the > > > large array and string concatenation going on. So I've shown here only > > > what I assume to be the critical bits. > > > > (btw. the tag discussed here was the solution to this > > > issuehttp://groups.google.com/group/django-users/browse_thread/thread/ae40...) > > > > tag > > > -- > > > > cal = { 2007: > > > > { > > > 1: [ [1], [2], #etcetera... a fairly > > > big multidimensional > > > array > > > > def update_cal_links(year, month, day): > > > """updates 'cal' array with a link to entry""" > > > link = "/%d/%d/%d/" %(year, month, day) > > > cal[year][month][day-1].insert(1,link) > > > return > > > > def print_cal(): > > > """ Returns a string, compiling calender into a series of nested > > > unordered lists""" > > > #I've removed the body of this function cos it's long, ugly > > > and it does seem to work fine > > > > @register.simple_tag > > > def do_home_calendar(): > > > """ Populates calendar with links to entries, > > > returns a formatted calendar to the template.""" > > > entries = Entry.objects.all() > > > for date in entries: > > > link = date.splitDate() #model method > > > update_cal_links(int(link['year']), int(link['month']), > > > int(link > > > ['day'])) # function expects integers > > > home_calendar = print_cal() > > > return home_calendar > > > > template > > > > > > > {% extends "base.html" %} > > > {% load simple_tags %} > > > > {% block content %} > > > {% do_home_calendar %} > > > {% if archive_list %} > > > hello > > > > > > {% for entry in archive_list %} > > > {{ entry.date }} > > li> > > > {% endfor %} > > > > > > {% else %} > > > FAIL! > > > {% endif %} > > > {% 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django ACL Design Question
>def MustHavePermission(*required_perms): > def decorate(f): >def new_f(request, *args, **kwargs): > perms = UserCompanies.objects.filter( >user=request.user, >company=determine_company(request), >) > for perm in required_perms: >perms = perms.filter(permission=perm) > if not perms: >raise Http403("Sorry, Dave, I can't let you do that.") > return f(request, *args, **kwargs) >return new_f > return decorate I noticed some serious bogosity in this logic (it only passed if a single permission was required, never if multiple permissions were required). That innermost function should be something like def new_f(request, *args, **kwargs): have = set( UserCompanies.objects.filter( user=request.user, company=determine_company(request) ).values_list("permission", flat=True) ) if have.issuperset(set(required_perms)): return f(request, *args, **kwargs) raise Http403("No way, Jose!") -tim --~--~-~--~~~---~--~~ 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: Registration
The templates are basically your HTML pages. You need to write your urls.py so that when a user visits a certain page, the view that corresponds to that url is just a render_to_response with a path to the HTML page. I can't really be bothered to explain it in detail but once you get the hang of views and templates you should be able to make sense of what i wrote :) --~--~-~--~~~---~--~~ 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: euro djangocon talks
Probably best to ask @djangocon or @robertlofthouse on twitter. Cheers, Dougal --- Dougal Matthews - @d0ugal http://www.dougalmatthews.com/ 2009/4/20 Aljosa Mohorovic: > > anybody has any information about possible euro djangocon talks? > or any idea when will talks schedule be available? > > Aljosa Mohorovic > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
euro djangocon talks
anybody has any information about possible euro djangocon talks? or any idea when will talks schedule be available? Aljosa Mohorovic --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Split models.py to smaller parts.
Hi I'm looking for some general solution how to split models.py. Right now my models.py reached 1000 lines and that argues some how with good programing behaviour that I used use. I'm thinking about: myproject/ settings.py myapp/ models/ file.py directory.py instead of classic solution: myproject/ settings.py myapp/ models.py views.py to In the simple case where in models we are able to avoid cyclic import there is no problem. But what when classes definition use each other implementation. Django implements very nice and tricky solution using 'string' to import definition in related fields. http://docs.djangoproject.com/en/dev/ref/models/fields/#module-django.db.models.fields.related but in current case its useless. Any idea how to win with that problem? x_O --~--~-~--~~~---~--~~ 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: Registration
I have a fair understanding of Python, and have been interested in Django for a while now, I have read the documentation and done some tutorials. Now I want to get my teeth stuck into a working project, As I said I want to set up a working registration application, and I am working through the tutorial posted previously. According to that tutorial, the only prereq's I need are the reg app. and a working version of Django, so for my problem I do just need registration for now. The problem lies with the Templates, I am unsure about how these should be working, Im not sure whether I have done something wrong or I have to make the HTML forms myself in this certain tutorial. --~--~-~--~~~---~--~~ 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: Registration
> How should I go about moving the site onto the django platform? Learn Python, then Django. This implies reading lots of documentation and being really interested in the whole thing. Also, you should try to understand your needs before asking questions about how to address them. Do you need just "registration"? No you don't. Again, please read Eric's essay (see link above). --~--~-~--~~~---~--~~ 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: Registration
I am working through the following tutorial : http://www.mangoorange.com/2008/09/17/django-registration-tutorial/ A sample working document is provided, im just not sure how to get it working! I am unsure whether I have to provide the HTML myself to create the forms for the registration, as its meant to be a 'working' copy, OR its just the app that is working and I need to create the HTML myself. If it is the latter how do I make sure the App is working? --~--~-~--~~~---~--~~ 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: Simple_tag strange behaviour
> I didn't see how you return array to template context. Okay... well, it's actually a string that I finally send to the template. It's a long story (sorry), but I use the array to build a string (i.e values from the array get embedded in HTML source). The place where the string is return to the template is the last line on the tag, i.e. "return home_calendar". The line above it "home_calendar = print_cal()", shows how print_calendar is a value derived from the function that builds the string. I could show you the source of the array and string building function, but I'm afraid you eyes might bleed :) On Apr 20, 4:37 pm, Anatoliywrote: > Tonne, > > I didn't see how you return array to template context. > > On Apr 20, 11:44 am, Tonne wrote: > > > > > Thanks > > > > Can you show code of your tag and template where it used? > > > Well, sure, but the tag is quite a big one, 150 lines long due to the > > large array and string concatenation going on. So I've shown here only > > what I assume to be the critical bits. > > > (btw. the tag discussed here was the solution to this > > issuehttp://groups.google.com/group/django-users/browse_thread/thread/ae40...) > > > tag > > -- > > > cal = { 2007: > > > { > > 1: [ [1], [2], #etcetera... a fairly > > big multidimensional > > array > > > def update_cal_links(year, month, day): > > """updates 'cal' array with a link to entry""" > > link = "/%d/%d/%d/" %(year, month, day) > > cal[year][month][day-1].insert(1,link) > > return > > > def print_cal(): > > """ Returns a string, compiling calender into a series of nested > > unordered lists""" > > #I've removed the body of this function cos it's long, ugly > > and it does seem to work fine > > > @register.simple_tag > > def do_home_calendar(): > > """ Populates calendar with links to entries, > > returns a formatted calendar to the template.""" > > entries = Entry.objects.all() > > for date in entries: > > link = date.splitDate() #model method > > update_cal_links(int(link['year']), int(link['month']), > > int(link > > ['day'])) # function expects integers > > home_calendar = print_cal() > > return home_calendar > > > template > > > > > {% extends "base.html" %} > > {% load simple_tags %} > > > {% block content %} > > {% do_home_calendar %} > > {% if archive_list %} > > hello > > > > {% for entry in archive_list %} > > {{ entry.date }} > li> > > {% endfor %} > > > > {% else %} > > FAIL! > > {% endif %} > > {% 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Registration
On Apr 20, 9:50 am, soniiicwrote: > you can't just add django funcationality to an already-made HTML > site. The whole site has to be moved on the django platform. Sorry for the lack of detail surrounding my problem. soniiic, thanks for the help. How should I go about moving the site onto the django platform? --~--~-~--~~~---~--~~ 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: Registration
you can't just add django funcationality to an already-made HTML site. The whole site has to be moved on the django platform. --~--~-~--~~~---~--~~ 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: Simple_tag strange behaviour
Tonne, I didn't see how you return array to template context. On Apr 20, 11:44 am, Tonnewrote: > Thanks > > > Can you show code of your tag and template where it used? > > Well, sure, but the tag is quite a big one, 150 lines long due to the > large array and string concatenation going on. So I've shown here only > what I assume to be the critical bits. > > (btw. the tag discussed here was the solution to this > issuehttp://groups.google.com/group/django-users/browse_thread/thread/ae40...) > > tag > -- > > cal = { 2007: > > { > 1: [ [1], [2], #etcetera... a fairly big > multidimensional > array > > def update_cal_links(year, month, day): > """updates 'cal' array with a link to entry""" > link = "/%d/%d/%d/" %(year, month, day) > cal[year][month][day-1].insert(1,link) > return > > def print_cal(): > """ Returns a string, compiling calender into a series of nested > unordered lists""" > #I've removed the body of this function cos it's long, ugly > and it does seem to work fine > > @register.simple_tag > def do_home_calendar(): > """ Populates calendar with links to entries, > returns a formatted calendar to the template.""" > entries = Entry.objects.all() > for date in entries: > link = date.splitDate() #model method > update_cal_links(int(link['year']), int(link['month']), > int(link > ['day'])) # function expects integers > home_calendar = print_cal() > return home_calendar > > template > > > {% extends "base.html" %} > {% load simple_tags %} > > {% block content %} > {% do_home_calendar %} > {% if archive_list %} > hello > > {% for entry in archive_list %} > {{ entry.date }} li> > {% endfor %} > > {% else %} > FAIL! > {% endif %} > {% 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: timesince template tag filter format
I end up using a custom template tag by 'realmac' found here: http://www.djangosnippets.org/snippets/557/ that calculate the age from the birthdate and only returns the years. On Apr 18, 11:06 pm, Bastienwrote: > Hi, > > I'm using the timesince filter in a template where I print a list of > users along with some info about these users. Among this info I print > the user's age which I get from the user's birthdate and I return the > result of {{ user.get_profile.birthdate|timesince }} to get the age. > Everything works fine but the format returned is of the type 'year, > month' and I just want to print the year. I tried to format this with | > date or with |time or to find some doc about this but I can't get > nowhere. > > Anybody has an idea? Thanks! --~--~-~--~~~---~--~~ 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: Simple_tag strange behaviour
Thanks > Can you show code of your tag and template where it used? Well, sure, but the tag is quite a big one, 150 lines long due to the large array and string concatenation going on. So I've shown here only what I assume to be the critical bits. (btw. the tag discussed here was the solution to this issue http://groups.google.com/group/django-users/browse_thread/thread/ae40745aca946cf8/7b536034daa92e2b?lnk=gst=tonne#7b536034daa92e2b) tag -- cal = { 2007: { 1: [ [1], [2], #etcetera... a fairly big multidimensional array def update_cal_links(year, month, day): """updates 'cal' array with a link to entry""" link = "/%d/%d/%d/" %(year, month, day) cal[year][month][day-1].insert(1,link) return def print_cal(): """ Returns a string, compiling calender into a series of nested unordered lists""" #I've removed the body of this function cos it's long, ugly and it does seem to work fine @register.simple_tag def do_home_calendar(): """ Populates calendar with links to entries, returns a formatted calendar to the template.""" entries = Entry.objects.all() for date in entries: link = date.splitDate() #model method update_cal_links(int(link['year']), int(link['month']), int(link ['day'])) # function expects integers home_calendar = print_cal() return home_calendar template {% extends "base.html" %} {% load simple_tags %} {% block content %} {% do_home_calendar %} {% if archive_list %} hello {% for entry in archive_list %} {{ entry.date }} {% endfor %} {% else %} FAIL! {% endif %} {% 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using admin search
What i would like to know is, Is it possible to import django admin search , outside django admin something like django.contrib.admin.search may be thanks On Mon, Apr 20, 2009 at 1:01 PM, Anatoliywrote: > > Hi, Silva. > > You can use > http://docs.djangoproject.com/en/dev/ref/models/querysets/#icontains > for simple search: >Entry.objects.get(headline__icontains=search_query) > > For more complex search you need separate search engine like Sphinx > (http://www.sphinxsearch.com/). > > > On Apr 20, 11:22 am, Waruna de Silva wrote: > > Hi All, > > > > I'm building simple search for website, i would like to know whether is > > possible to use > > admin search outside the django admin. If yes how can i do that. Any code > > examples or > > tutorials. > > > > Thank u, > > Waruna de Silva. > > > --~--~-~--~~~---~--~~ 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: Using admin search
Hi, Silva. You can use http://docs.djangoproject.com/en/dev/ref/models/querysets/#icontains for simple search: Entry.objects.get(headline__icontains=search_query) For more complex search you need separate search engine like Sphinx (http://www.sphinxsearch.com/). On Apr 20, 11:22 am, Waruna de Silvawrote: > Hi All, > > I'm building simple search for website, i would like to know whether is > possible to use > admin search outside the django admin. If yes how can i do that. Any code > examples or > tutorials. > > Thank u, > Waruna de Silva. --~--~-~--~~~---~--~~ 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: Simple_tag strange behaviour
Hello, Tonne. Can you show code of your tag and template where it used? On Apr 20, 10:50 am, Tonnewrote: > I have a simple_tag that receives a queryset, then updates an array > based on the queryset result (using a function), and finally it > returns the array to the template context. > > It works beautifully the first time it is viewed with a browser. > However, on subsequent "pageviews" the array is not update, and an > "untouched" array is sent in the context. > > If I resave the simple_tag source file, it will again work perfectly > for the first view, while subsequent views will do as above. > > So clearly the first time the server receives a HTTP request it the > script runs correctly, but somehow either the queryset is not being > received of the function is not being called after first request. > > This is while running on the development server by the way. > > I'm a bit stumped. Anyone have an idea of that this could be? --~--~-~--~~~---~--~~ 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 admin search
Hi All, I'm building simple search for website, i would like to know whether is possible to use admin search outside the django admin. If yes how can i do that. Any code examples or tutorials. Thank u, Waruna de Silva. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Simple_tag strange behaviour
I have a simple_tag that receives a queryset, then updates an array based on the queryset result (using a function), and finally it returns the array to the template context. It works beautifully the first time it is viewed with a browser. However, on subsequent "pageviews" the array is not update, and an "untouched" array is sent in the context. If I resave the simple_tag source file, it will again work perfectly for the first view, while subsequent views will do as above. So clearly the first time the server receives a HTTP request it the script runs correctly, but somehow either the queryset is not being received of the function is not being called after first request. This is while running on the development server by the way. I'm a bit stumped. Anyone have an idea of that this could be? --~--~-~--~~~---~--~~ 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: ..... in templates
On 17/04/2009 11:26 PM, Christian Berg wrote: > Sorry if this sounds harsh, but it is useless to learn how to drive a > Truck, if you can't drive an car. Slightly tangential, but not true! My Grandfather learned to drive a truck in the army before learning to drive a car and failed his civilian test the first time because he went wide (onto the wrong side of the road!) to take a corner... Cheers -D --~--~-~--~~~---~--~~ 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: how to organize favorites in template?
On 17/04/2009 12:53 PM, James wrote: > What I've done is store the keys of a users favorite videos in a dict, > and I try to determine if I should be allowing them to add or remove > this video from their favorites like this (truncated): > > {% for video in video_list %} > {% if favorites[video.key] %} >... offer to remove > {% endif %} > {% endfor %} > > ... but this of course blows up because the template system can't > understand favorites[video.key]. I wonder how I should organize this > data and write the tags so that it works... should I be adding a > property to each video to mark it as a favorite? I've tried this: > > for video in videos: >video.favorite = True > > but that property (or attribute or whatever it's called) doesn't show > up in my template as true ... ?? Without seeing the context of the code above, I would guess you would need to save() the video for it to show up, but of course that would probably not work in your situation either. A quick google search shows the following snippet should do what you want: http://www.djangosnippets.org/snippets/1350/ {% for video in video_list %} {% if video.key in favorites.keys %} ... offer to remove {% endif %} {% endfor %} Regards Darryl -- Darryl Ross AFOYI, Information Technology Solutions e: dar...@afoyi.com p: +61 8 7127 1831 f: +61 8 8425 9607 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---