Re: django and ldap
Mike Dewhirst wrote: > On 4/02/2010 11:14pm, David De La Harpe Golden wrote: >> On 04/02/10 08:33, andreas schmid wrote: >>> @brad: can you show me some sample code for this? >>> > > David > > I am using Peter Herndon's django-ldap-groups successfully. He has two > backends; one for Novell's eDirectory which I'm using and another for > MS Active Directory which I haven't tried. > >http://pypi.python.org/pypi/django-ldap-groups/0.1.3 > > ... and here the relevant bits of my settings.py. Peter's comments all > start on a new line while mine don't. I haven't adjusted anything here > - this is working code. The getcreds() method simply fetches userid > and password from a non-versioned file. I try and keep such stuff out > of the repository ... > > ssl = True # switch between SSL and non-SSL > SEARCH_DN = 'O=pq8nw' # Organization name > # NT4_DOMAIN is used with Active Directory only, comment out for > eDirectory > # NT4_DOMAIN = 'EXAMPLE' > # sAMAccountName is used with Active Directory > # Use the following for Active Directory > # SEARCH_FIELDS = > ['mail','givenName','sn','sAMAccountName','memberOf','cn'] > # Use the following for Novell eDirectory > # SEARCH_FIELDS = ['mail', 'givenName', 'sn', 'groupMembership', 'cn'] > SEARCH_FIELDS = ['mail', 'givenName', 'sn', 'groupMembership', 'cn'] > > nds = credsdir + APP + '.nds' # contains credentials > cred = getcreds(nds)# returns a 2-element list > BIND_USER = 'cn=%s,%s' % (cred[0], SEARCH_DN) > BIND_PASSWORD = cred[1] # valid password too > # CERT_FILE = ''# not used if ssl == False > ldap_srv = '192.168.0.108' > ldap_port = 389 > protocol = 'ldap' > if ssl: > protocol = 'ldaps' > ldap_port = 636 > CERT_FILE = credsdir + 'cert_pq8nw_9a30.b64' > > LDAP_URL = protocol + '://%s:%s' % (ldap_srv, ldap_port) > > AUTHENTICATION_BACKENDS = ( > 'ldap_groups.accounts.backends.eDirectoryGroupMembershipSSLBackend', > > #'ldap_groups.accounts.backends.ActiveDirectoryGroupMembershipSSLBackend', > > 'django.contrib.auth.backends.ModelBackend', > ) > im experimenting with django-ldap-groups too now and im going forward. its still not working how i want but ill test it a bit more. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
[ANN] djangogolf
Hi, I just released djangogolf - software for managing golf tournaments. The scoring module is ready, handicapping and draw are in the pipeline. The demo site is here: http://greenchilly.in/ - feedback, feature requests and contributions are welcome. -- regards Kenneth Gonsalves Senior Project Officer NRC-FOSS http://nrcfosshelpline.in/web/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: update with where clause constraints?
On Thu, Feb 4, 2010 at 8:08 PM, Jared Smithwrote: > My use case is that I'll have multiple users trying to update a set of > objects and I want to make sure that any user committing a change has > knowledge of the existing state. I was going to model that with a version > number so an update would look like: > > update table set col=foo, col1=bar where id=pknum && > version_number= > > Desired result are the following:: > > --If a user has the correct previous version the update goes through > --if they don't have the correct previous version it should do nothing > (I'll throw an exception or return something to the upper layer to indicate > the fact that the user needs to try again from the latest version...) > > My question is how can I do an update like the above in Django? > http://docs.djangoproject.com/en/dev/topics/db/queries/#updating-multiple-objects-at-once Though it sounds like you do not want to update multiple at once, you can use the same call and know based on its returned value (it returns how many rows it updated) whether it worked or not. If one is returned, you know the version read was unchanged for the update and all is fine. If zero is returned then apparently someone else changed the row in the meantime. (You probably also want to include an increment of the version_number field as an F expression in the update call.) 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
update with where clause constraints?
My use case is that I'll have multiple users trying to update a set of objects and I want to make sure that any user committing a change has knowledge of the existing state. I was going to model that with a version number so an update would look like: update table set col=foo, col1=bar where id=pknum && version_number= Desired result are the following:: --If a user has the correct previous version the update goes through --if they don't have the correct previous version it should do nothing (I'll throw an exception or return something to the upper layer to indicate the fact that the user needs to try again from the latest version...) My question is how can I do an update like the above in Django? It looks like the save API hides the fact whether it is insert or update; however I can easily determine this myself (haven't found a way that I can add additional criteria on the update). I saw the following patch: http://code.djangoproject.com/ticket/2705 And that could maybe meet my needs but I'm wondering if there is any existing way to accomplish this without having to patch Django? (hoping I'm missing some existing way to accomplish this) Please let me know if you have any suggestions. Thanks, Jared -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django and ldap
On 4/02/2010 11:14pm, David De La Harpe Golden wrote: On 04/02/10 08:33, andreas schmid wrote: @brad: can you show me some sample code for this? David I am using Peter Herndon's django-ldap-groups successfully. He has two backends; one for Novell's eDirectory which I'm using and another for MS Active Directory which I haven't tried. http://pypi.python.org/pypi/django-ldap-groups/0.1.3 ... and here the relevant bits of my settings.py. Peter's comments all start on a new line while mine don't. I haven't adjusted anything here - this is working code. The getcreds() method simply fetches userid and password from a non-versioned file. I try and keep such stuff out of the repository ... ssl = True # switch between SSL and non-SSL SEARCH_DN = 'O=pq8nw' # Organization name # NT4_DOMAIN is used with Active Directory only, comment out for eDirectory # NT4_DOMAIN = 'EXAMPLE' # sAMAccountName is used with Active Directory # Use the following for Active Directory # SEARCH_FIELDS = ['mail','givenName','sn','sAMAccountName','memberOf','cn'] # Use the following for Novell eDirectory # SEARCH_FIELDS = ['mail', 'givenName', 'sn', 'groupMembership', 'cn'] SEARCH_FIELDS = ['mail', 'givenName', 'sn', 'groupMembership', 'cn'] nds = credsdir + APP + '.nds' # contains credentials cred = getcreds(nds)# returns a 2-element list BIND_USER = 'cn=%s,%s' % (cred[0], SEARCH_DN) BIND_PASSWORD = cred[1] # valid password too # CERT_FILE = ''# not used if ssl == False ldap_srv = '192.168.0.108' ldap_port = 389 protocol = 'ldap' if ssl: protocol = 'ldaps' ldap_port = 636 CERT_FILE = credsdir + 'cert_pq8nw_9a30.b64' LDAP_URL = protocol + '://%s:%s' % (ldap_srv, ldap_port) AUTHENTICATION_BACKENDS = ( 'ldap_groups.accounts.backends.eDirectoryGroupMembershipSSLBackend', #'ldap_groups.accounts.backends.ActiveDirectoryGroupMembershipSSLBackend', 'django.contrib.auth.backends.ModelBackend', ) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Ajax with Django
On Fri, Feb 5, 2010 at 2:49 AM, Rohan Shahwrote: > Any good documentation available on how to implement AJAX with Django ? > http://www.b-list.org/weblog/2006/jul/31/django-tips-simple-ajax-example-part-1/ -- regards, Prashanth twitter: munichlinux blog: prashanthblog.appspot.com irc: munichlinux, JSLint, munichpython. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Ajax with Django
http://code.google.com/p/dojango/ What is dojango Dojango is a reusable django application that helps you to use the client-side framework dojo within your django project. - It provides capabilites to easily switch between several dojo versions and sources (e.g. aol, google, local) - Delivers helping utilities, that makes the development of rich internet applications in combination with dojo more comfortable. - It makes the building of your own packed dojo release easier. Another goal of this project is, that you can learn how you have to structure your html to use dojo within your projects. _ @jonathanorlando Linux user # 458151 Geek Emprendedor !! Cucuta / Norte de Santander / Colombia 2010/2/4 Rohan Shah> Any good documentation available on how to implement AJAX with Django ? > > -- > Thanks and Regards, > Rohan Shah > > > ++[>>++>+++>+-] > >++. >+++.---. ---.. >++. <<+. >--. > ---.+++. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Ajax with Django
El 04/02/10 18:19, Rohan Shah escribió: > Any good documentation available on how to implement AJAX with Django ? http://lmgtfy.com/?q=django+ajax=1 -- Gonzalo Delgado-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Problem when trying to validate a field in a ModelAdmin which has inline forms
See http://code.djangoproject.com/ticket/12780 . I will upload a patch and provide an example, but I can't yet say when. Best, Mart Sõmermaa On Jan 15, 8:10 pm, Gabriel Reiswrote: > Hey Marcos, > > In the clean() method of my ClipModelForm class I couldn't manage how to > reach the ClipDescriptions that are coming from the inline > ClipDescriptionInline. I think I can't validate there. I spent the whole day > trying and I couldn't fix. Any help would be very handy! > > Thanks for your atention. > > Kind regards, > > Gabriel > > Gabriel de Carvalho Nogueira Reis > Software Developer > +44 7907 823942 > > On Fri, Jan 15, 2010 at 4:45 PM, Marco Rogers wrote: > > > I've never had to do this but it sounds you want to work with > > Form.clean() in stead of Form.clean_is_approved(). From the docs: > > > "The Form subclass’s clean() method. This method can perform any > > validation that requires access to multiple fields from the form at > > once." > > > So in your clean method you would grab the submitted inlines and check > > them against the is_approved field on the Clip. I'm not a django > > expert, but that's where I would start. Good luck. > > > :Marco > > > On Jan 14, 6:45 pm, Gabriel Reis wrote: > > > Hi people, > > > > I am having some problem to validate a data in my application. I will try > > to > > > simply the model in here to help you guys to understand the problem. > > > I have 2 models: > > > > class Clip(models.Model): > > > is_approved = models.BooleanField(default=False) > > > language = models.ForeignKey(Language) > > > > class ClipDescription(models.Model): > > > clip = models.ForeignKey(Clip) > > > text = models.TextField() > > > language = models.ForeignKey(Language) > > > > I am editing via ModelAdmin. I defined a ClipModelAdmin class as above > > > (simplified): > > > > class ClipAdmin(admin.ModelAdmin): > > > inlines = [ > > > ClipDescriptionInline > > > ] > > > > So, as you can see, both Clip and ClipDescription are edited in the same > > > page (using the 'inlines' feature). > > > > But the rule is: if the user trigger the 'Save' action, the attribute > > > Clip.is_approved can be True only if there is a ClipDescription instance > > > associated to the Clip instance, having the same language. For example, > > if I > > > have a clip with id=1, language=english and is_approved=True, it can be > > > saved only if there is a clip description with clip_id=1, > > language=english. > > > If not, I want to show the error message 'Cannot approve this clip > > without > > > having a description in English' in the form. > > > > I have already read the official documentation and tried to work with > > > validators, tried to define a ModelForm and its clean_is_approved method, > > > among other workarounds. And I still couldn't make this work. The problem > > is > > > at the clean_is_approved context I couldn't figure out how to get access > > to > > > the form data that is being entered at that moment, to retrieve the Clip > > > descriptions. > > > > I don't if I was clear enough, I can give more details. Any ideas and > > > suggestions will be very appreciated. > > > > Thank you very much for your attention. > > > > Kind regards, > > > > Gabriel > > > > Gabriel de Carvalho Nogueira Reis > > > Software Developer > > > +44 7907 823942 > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Ajax with Django
Any good documentation available on how to implement AJAX with Django ? -- Thanks and Regards, Rohan Shah ++[>>++>+++>+-] >++. >+++.---. ---.. >++. <<+. >--. ---.+++. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django-debug-toolbar with runserver not running on localhost
gah you're correct, I can't believe I missed that setting. thanks On Feb 4, 4:48 pm, rebus_wrote: > On 4 February 2010 22:06, HARRY POTTRER wrote: > > > I've noticed that if I run the django dev server on localhost, debug- > > toolbar works, but if I try to run he server like this: > > > ./manage.py runserver 192.168.1.145:8000 > > > the site will work, but the toolbar won't show up. Is there a work- > > around for this? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > Do you maybe have INTERNAL_IPS set in your settings? > It's used to decide on which addresses the toolbar will be shown. > > Read more about this on:http://github.com/robhudson/django-debug-toolbar. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django-debug-toolbar with runserver not running on localhost
On 4 February 2010 22:06, HARRY POTTRERwrote: > I've noticed that if I run the django dev server on localhost, debug- > toolbar works, but if I try to run he server like this: > > ./manage.py runserver 192.168.1.145:8000 > > the site will work, but the toolbar won't show up. Is there a work- > around for this? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > Do you maybe have INTERNAL_IPS set in your settings? It's used to decide on which addresses the toolbar will be shown. Read more about this on: http://github.com/robhudson/django-debug-toolbar. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
entering scores (one model) for a list of students (another model)
I'm creating a form that students fill in as they arrive at class. Just name, email, etc. When the class is over I want to display a form for the teacher to enter the grades. So, no problem on the students entering their info, I just have a Student model. I have a Score model that has the score and a ForeignKey to the student. That makes sense to me, but I'm have bunches of trouble figuring out how to display the form to the teacher I want a list of student names with an form for each grade. So I'm figuring a formset is what I need, based on the Score model. But I don't get how to associate the student with the score the teacher enters. thanks for any pointers. --Tim Arnold -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
django-debug-toolbar with runserver not running on localhost
I've noticed that if I run the django dev server on localhost, debug- toolbar works, but if I try to run he server like this: ./manage.py runserver 192.168.1.145:8000 the site will work, but the toolbar won't show up. Is there a work- around for this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
Thanks a lot, i did miss to pass context_instance=RequestContext(request) in my view code def access(request): return render_to_response('tool.html',context_instance=RequestContext(request)) after I added "context_instance=RequestContext(request)" It is working now like a charm! Thanks again! On Feb 4, 11:54 am, Karen Traceywrote: > On Thu, Feb 4, 2010 at 2:39 PM, weiwei wrote: > > Thanks.. > > > Here is my code > > You repeated the code for the template tag and the context processors > setting; that's not what I asked for. > > I still don't see the code for the view that renders the template that > includes the template tag you are working with. That is the code that must > specify a RequestContext if you want to access the variables set by the > request context processor in your template tag. The context processor won't > set variables in a plain Context, the view code (or whatever code is > supplying the context for the template render) must specify a > RequestContext. See for example 'some_view' under: > > http://docs.djangoproject.com/en/dev/ref/templates/api/#id1 > > 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
On Thu, Feb 4, 2010 at 2:39 PM, weiweiwrote: > Thanks.. > > Here is my code > > You repeated the code for the template tag and the context processors setting; that's not what I asked for. I still don't see the code for the view that renders the template that includes the template tag you are working with. That is the code that must specify a RequestContext if you want to access the variables set by the request context processor in your template tag. The context processor won't set variables in a plain Context, the view code (or whatever code is supplying the context for the template render) must specify a RequestContext. See for example 'some_view' under: http://docs.djangoproject.com/en/dev/ref/templates/api/#id1 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
Thanks.. Here is my code from django import template from django.template import RequestContext register = template.Library() @register.inclusion_tag('userinfo.html',takes_context = True) def userinfo(context): request = context['request'] address = request.session['address'] return {'address':address} and request = context['request'] causing problem, seems context doesn't have a key 'request' And i do have TEMPLATE_CONTEXT_PROCESSORS =( "django.core.context_processors.request", "django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", ) in settings.py On Feb 4, 11:17 am, Karen Traceywrote: > On Thu, Feb 4, 2010 at 1:41 PM, weiwei wrote: > > "DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST > > If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every > > RequestContext will contain a variable request, which is the current > > HttpRequest. Note that this processor is not enabled by default; > > you'll have to activate it. " from this page > > >http://docs.djangoproject.com/en/dev/ref/templates/api/ > > > But i didn't find how to activate it > > You activate it by including it in TEMPLATE_CONTEXT_PROCESSORS in > settings.py. That is all you have to do. > > > Here is my question > > >http://stackoverflow.com/questions/2160261/access-request-in-django-c... > > > after i followed the answer i still got errors > > I do not see where you show the view code in that question. Possibly you are > not using a RequestContext to render the template? > > 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Trying to get an image in a RadioSelect
Hi, I am trying to get an image as a label in a RadioSelect... I have been trying to get a grasp on using the RadioFieldRenderer() but I am having no luck. I currently have this in my widgets.py from django.forms import widgets from django.utils.encoding import force_unicode from django.utils.safestring import mark_safe class BackgroundRadioRenderer(widgets.RadioFieldRenderer): def render(self): return mark_safe(u'\n'.join([u'' % w for w in self])) I current have this in my forms.py class ExampleForm(forms.Form): CHOICES = ( (1,'thumb1.gif'), (2,'thumb2.gif'), (3,'thumb3.gif'), (4,'thumb4.gif'), ) background = forms.ChoiceField(choices=CHOICES,widget=forms.RadioSelect(renderer=BackgroundRadioRenderer)) The output of this is: thumb1.gif"> thumb2.gif"> thumb3.gif"> thumb4.gif"> How can I get the image to be the actual label itself? Thanks Jeff -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
When does syncd create new tables
Hello, I am developing my models. I have quite a lot of legacy data which I have to take into account, so I try hard to understand the logic of syncdb. My current situation is as follows: 1. I had written the model defintion of several models in Python and created the corresponding tables with "./manage.py syncdb". 2. I then realized that I needed to change the model definitions somewhat. Then I: a) Deleted the databes tables manually, using a regular databese client. I did not touch tables like ~ auth_user. b) I updatet my models.py files. c) I tried to recreate the tables with "./manage.py syncdb" - but to no avail, nothing happened? Any tips on what I am doing wrong greatly appreciated. Joakim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
On Thu, Feb 4, 2010 at 1:41 PM, weiweiwrote: > "DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST > If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every > RequestContext will contain a variable request, which is the current > HttpRequest. Note that this processor is not enabled by default; > you'll have to activate it. " from this page > > http://docs.djangoproject.com/en/dev/ref/templates/api/ > > But i didn't find how to activate it > > You activate it by including it in TEMPLATE_CONTEXT_PROCESSORS in settings.py. That is all you have to do. > Here is my question > > > http://stackoverflow.com/questions/2160261/access-request-in-django-custom-template-tags > > after i followed the answer i still got errors > > I do not see where you show the view code in that question. Possibly you are not using a RequestContext to render the template? 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: CheddarGetter module for Django/Python - easy recurring billing
On Feb 1, 2010, at 1:11 PM, Jason Ford wrote: > Anyone who's built commercial web app knows that payment processing > can be one of the toughest pieces to put in place - and it can > distract you from working on the core functionality of your app. > CheddarGetter is a web service that abstracts the entire process of > managing credit cards, processing transactions on a recurring basis, > and even more complex setups like free trials, setup fees, and overage > charges. > > We're using CheddarGetter for FeedMagnet.com and we thought the Django > community in general could benefit from the module we wrote to > interact with it. More just just a Python wrapper for CheddarGetter, > pycheddar gives you class objects that work a lot like Django models, > making the whole experience of integrating with CheddarGetter just a > little more awesome and Pythonic. > > - Jason Jason, We are looking at recurring billing systems, could you give some more info on why you chose CheddarGetter over Paypal or Amazon FPS? -- Eric Chamberlain -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: It looks like Django is working from a stale DB. What am I doing wrong?
On Thu, Feb 4, 2010 at 12:02 PM, Luke Sneeringerwrote: > Good morning, everyone! > Apologies in advance if this is the wrong place to ask this question. > > First of all, the setup. I'm using MySQL and InnoDB tables. > > I've encountered an unusual problem, which has reared its ugly head on > several fronts. The basic jist is that Django seems to not recognize > database changes made... > [snip] > > What am I doing wrong? > You are seeing the same things as described in this thread: http://groups.google.com/group/django-users/browse_thread/thread/e25cec400598c06d 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django and ldap
On Feb 4, 2:33 am, andreas schmidwrote: > @brad: can you show me some sample code for this? the code that I have is all very specific to where I work. I'd have to clean it up a bit to try to make it useful to you. There's also several other people who have posted snippets for backends based on LDAP or Active Directory: http://www.djangosnippets.org/tags/ldap/ A few of these are very similar to what I've done. I'd suggest taking it look. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Is there a way to access a field's verbose_name from a object_list generic view template?
I'm using the object_list generic view and it seems there should be a way to pull the field verbose_name from the model, without having to hard code the name in the template. Any suggestions? -- Eric Chamberlain -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django standards?
On Feb 4, 10:29 am, David Parkerwrote: > Right on. I haven't gotten much into testing Django yet. My previous > experience is with Rails (RSpec/Shoulda/Cucumber) and Java (JUnit). I > plan on actually driving my app with TDD, but I was curious to know > which "way" most developers in the Django arena code their url > patterns Ooops sorry - I work on a mature project where I have not actually used url patterns yet, so I was just blowing smoke! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
"DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every RequestContext will contain a variable request, which is the current HttpRequest. Note that this processor is not enabled by default; you'll have to activate it. " from this page http://docs.djangoproject.com/en/dev/ref/templates/api/ But i didn't find how to activate it Here is my question http://stackoverflow.com/questions/2160261/access-request-in-django-custom-template-tags after i followed the answer i still got errors TemplateSyntaxError at / Caught an exception while rendering: 'request' Original Traceback (most recent call last): File "C: \Python25\lib\site-packages\django\template\debug.py", line 71, in render_node result = node.render(context) File "C:\Python25\lib\site- packages\django\template__init__.py", line 936, in render dict = func(*args) File "c:\...\myapp_extras.py", line 7, in login request = context['request'] File "C:\Python25\lib\site-packages\django\template \context.py", line 44, in getitem raise KeyError(key) KeyError: 'request' tho code causing problem is request = context['request'] Thanks for any 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django standards?
Right on. I haven't gotten much into testing Django yet. My previous experience is with Rails (RSpec/Shoulda/Cucumber) and Java (JUnit). I plan on actually driving my app with TDD, but I was curious to know which "way" most developers in the Django arena code their url patterns (granted, I understand what you mean... if it's well tested, then does it really matter which way it is designed?). On Feb 4, 11:08 am, Phlipwrote: > David Parker wrote: > > verses = Verse.objects.filter(version__iexact=version, > > book__iexact=book, chapter__iexact=chapter, verse__iexact=verse) > > else: > > logging.debug("chapter: " + chapter) > > logging.debug("verse : " + verse) > > logging.debug("verse2 : " + verse2) > > Now, is this the standard way of doing this kind of thing? Or should > > I break the method up into different methods and have several > > different url patterns? Thanks! > > Thou shalt write developer tests. ("Unit tests".) > > Each of your temporary debug statements should instead be permanent > assert_equal() statements. > > Tested code is, perforce, highly decoupled, so that tests can easily > reach any situation. So Test-Driven Development tends to obviate > questions about design - the best design is the one that works under > pressure from both test cases and the real application. > > -- > Phlip > http://twitter.com/Pen_Bird -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
uniquely identifying an entry
hi (sorry about this newbie question..) I have designed an entry and a category as follows. The entry doesn't have a title.(The user is not expected to provide a title for it )It is uniquely identified by a combination of its published datetime and the name of the category it belongs to. class MyCategory(models.Model): name=models.CharField(max_length=10) description=models.TextField() slug=models.SlugField(unique=True) def __unicode__(self): return self.name class MyEntry(models.Model): posted_time=models.DateTimeField(default=datetime.now) category=models.ForeignKey(MyCategory) description=models.TextField() author=models.ForeignKey(User) def __unicode__(self): return "%s%s"%(self.category.name,self.posted_time) I would like to list all entries posted at different minutes in an hour. and also show the details of a single entry.I am not sure how I can do this. I am wondering if I can get details of an entry like /myapp/entries/2010/jan/01/10/35/splcat sothat I can get an entry belonging to 'splcat' posted at 10 hrs,35 minutes on 1st jan 2010. Is there some way I can do lookup on the hour,minute of posted_time? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django standards?
David Parker wrote: > verses = Verse.objects.filter(version__iexact=version, > book__iexact=book, chapter__iexact=chapter, verse__iexact=verse) > else: > logging.debug("chapter: " + chapter) > logging.debug("verse : " + verse) > logging.debug("verse2 : " + verse2) > Now, is this the standard way of doing this kind of thing? Or should > I break the method up into different methods and have several > different url patterns? Thanks! Thou shalt write developer tests. ("Unit tests".) Each of your temporary debug statements should instead be permanent assert_equal() statements. Tested code is, perforce, highly decoupled, so that tests can easily reach any situation. So Test-Driven Development tends to obviate questions about design - the best design is the one that works under pressure from both test cases and the real application. -- Phlip http://twitter.com/Pen_Bird -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Please Help With POST Problem
If you are running behind, for example, apache, and the content type headers are correct, apache might expand the gzip stuff for you. I wouldn't be surprised to find that the python/django http request stuff doesn't handle gzip, but it might. It might be possible to return an error response saying coding not accepted, prompting gnip to retry without gzip. I've certainly seen spotty adherence to standards for applications to do posts for non-browserish things. The "None" as request.encoding is suspicious, if that is spelled correctly. As diagnostic stuff you might poke in the request object (using pdb on the development server) to see if they are correctly setting the content type for the mime part. And you could catch the post earlier than where it gets converted to a querydict (possibly using python urllib(2), et al rather than django) to save the post section to a file and see if it gunzips. If the data is good gzipped stuff, and the headers are correct, then you know to look on your (python, django, front end server) side. If the headers are bogus, you should push back to get gnip to fix them. Good luck. On Thu, Feb 4, 2010 at 9:15 AM, Kenneth Loafmanwrote: > Guys, > > I hope you can help with a major Django problem I'm having. I have a > feed from Gnip 2.0 using POST and its coming in as pure garbage in > request.POST, like below: > > None > twitter keyword > [04/Feb/2010 13:55:15] "POST /api/gnip/collect/twitter/keyword/ > HTTP/1.0" 200 7 > POST = ' {u'm...@\u0480\ufffd\ufffd\ufffd\ufffda\ufffd\ufffdtp\ufffd\\\ufffd\ufffd... > META = '{'PYTHONIOENCODING': 'UTF-8', 'wsgi.multiprocess': False,... > len raw = 693 > > The structure of the QueryDict, when printed fully, is a dictionary, > complete with garbage keys and values. > > The code for this is quite simple: > def api_gnip_collect( request, publisher=None, rule_type=None ): > print request.encoding > request.encoding = "utf-8" # I've tried utf-8,16,32,zlib,... > print publisher, rule_type > print "POST = '%s'" % request.POST > print "META = '%s'" % request.META > print "len raw =", len( request.raw_post_data ) > > So, Gnip's other customers, not using Django, are not having this > problem. Gnip says that the POST is gzip encoded. Is it possible that > Django is not handling gzip'ed input? > > I've tried this on all versions 0.96 through 1.2alpha. No luck. > > ...Thanks, > ...Ken > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django bases blog solutions
Thanks a ton Peter. I totally agree that I should just write my own since that is exactly the type of thing django was built to do and I intend on doing so. The reason I ask is that I tend to learn much faster by examining good examples. On Thu, Feb 4, 2010 at 11:09 AM, Peter Herndonwrote: > > On Feb 4, 2010, at 10:02 AM, Joel Stransky wrote: > > > Hi all, > > I'm brand new to Django/Python but not software development. I just to > say hi and ask for your understanding on my newbish questions. > > I realize Django, when used correctly makes it stupidly easy to create > webblogs but I'm curious as to whats out there as far as django based blog > installs go a la wordpress. > > > > Any input is appreciated. > > > Hi Joel, > > I'm tempted to suggest you write your own blog engine, as that seems to be > the first thing every new-to-Django programmer does, and it will provide a > good learning experience. However, if you are looking for an actual really > good, pre-built blog app, you can't really go wrong with django-mingus ( > http://github.com/montylounge/django-mingus). There are dozens of other > options out there (since, as written above, darn near everyone writes their > own at some point), but django-mingus is both easy to use and provides an > excellent example of both good software engineering and good deployment > practices. > > ---Peter Herndon > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- --Joel Stransky stranskydesign.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to use CheckboxSelectMultiple() widget
I'll take you at your word that you have a list of file (names?), rather than a queryset. class xxx(forms.Form): def __init__(self, list_of_files, *args, **kwargs): self.fields['files'].choices = enumerate(list_of_files) super(xxx, self).__init__(*args, **kwargs) files = forms.MultipleChoiceField(widget=CheckboxSelectMultiple, choices=[]) You then put multiple submit buttons on the form so that you can choose to save the checked files, delete the checked files, or what (you need to give them a "name" attribute to make them show up in the POST data). When your view instantiates the form, you pass the list of files. When a posted form if valid, form.checked_data['files'] will be a list of indexes into list of files. You need to be sure that you have the same list when you get the post as you had for the get that rendered the form. Untested, but I've done similar. Should be close. Bill On Thu, Feb 4, 2010 at 1:27 AM, mojitowrote: > I have a list of files I'd like to render as a list of check boxes > with multiple selection. Then from the frontend I want to add the > ability to save and delete these files. How can I achieve this using > CheckboxSelectMultiple() widget ? > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Access apache environment variable in template
Ya, It did work luke, What was I thinking, accessing it like {{ request.meta["TIER"] }} Sorry for that and thanks again for your help. Sonal On Feb 4, 9:30 am, Sonal Breedwrote: > I mean to say {{ request.meta["TIER"] }} > > On Feb 4, 9:25 am, Sonal Breed wrote: > > > Hi all, > > In my default-server.conf, I set an env variable as > > setenv TIER hi > > > Can anybody let me know how can I access this variable in the > > template. > > I tried to use a bunch of expressions like > > {% request.meta["TIER"] %} or > > {% request.environ[TIER] %} but they do not return anything. > > > Any help will be greatly appreciated. > > > Thanks, > > Sincerely, > > Sonal. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Access apache environment variable in template
If you are using render_to_response, you will need to explicitly send request in the dictionary of items going to the template. Also, variable access in Django templates is done with the {{ and }} enclosure, and uses all dots (.) for separators. I have never tried to directly access something out of a QueryDict, but I expect that {{ request.META.TIER }} would work. Regards, Luke On February 4, 2010, at 11:25 , Sonal Breed wrote: > Hi all, > In my default-server.conf, I set an env variable as > setenv TIER hi > > Can anybody let me know how can I access this variable in the > template. > I tried to use a bunch of expressions like > {% request.meta["TIER"] %} or > {% request.environ[TIER] %} but they do not return anything. > > Any help will be greatly appreciated. > > Thanks, > Sincerely, > Sonal. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Access apache environment variable in template
I mean to say {{ request.meta["TIER"] }} On Feb 4, 9:25 am, Sonal Breedwrote: > Hi all, > In my default-server.conf, I set an env variable as > setenv TIER hi > > Can anybody let me know how can I access this variable in the > template. > I tried to use a bunch of expressions like > {% request.meta["TIER"] %} or > {% request.environ[TIER] %} but they do not return anything. > > Any help will be greatly appreciated. > > Thanks, > Sincerely, > Sonal. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Access apache environment variable in template
Hi all, In my default-server.conf, I set an env variable as setenv TIER hi Can anybody let me know how can I access this variable in the template. I tried to use a bunch of expressions like {% request.meta["TIER"] %} or {% request.environ[TIER] %} but they do not return anything. Any help will be greatly appreciated. Thanks, Sincerely, Sonal. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: FieldError with get_object_or_404
On 2010-02-04, at 7:36 AM, harryos wrote: > In the shell I tried this > from django.shortcuts import get_object_or_404 as gtobj > e1=gtobj(MyEntry,posted_time__year=2010,posted_time__month=2,posted_time__day=1) > This is successful ,it gives this message > MultipleObjectsReturned: get() returned more than one MyEntry -- it > returned 4! get(..) assumes there's one and only one object, hence the error. > However when I tried , > e1=gtobj(MyEntry,posted_time__year=2010,posted_time__month=2,posted_time__day=1,posted_time__hour=10) > > I get this error, > FieldError: Join on field 'posted_time' not permitted. Did you > misspell 'hour' for the lookup type? There are lookups for year, month and day as documented here: http://docs.djangoproject.com/en/dev/ref/models/querysets/#year But *not* hour or minute. -- Andy McKay, @clearwind http://clearwind.ca/djangoski -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
It looks like Django is working from a stale DB. What am I doing wrong?
Good morning, everyone! Apologies in advance if this is the wrong place to ask this question. First of all, the setup. I'm using MySQL and InnoDB tables. I've encountered an unusual problem, which has reared its ugly head on several fronts. The basic jist is that Django seems to not recognize database changes made...I think since the beginning of the request. It's caused some interesting issues, like getting an IntegrityError on a get_or_create call (which one would think would not be possible). The most succinct reproduction case I can give would be this. Assume a model "Source" (and corresponding table in MySQL). It has an empty table. I will start a shell, try to pull the source with the id of 1. It will raise DoesNotExist (correctly). I will then go add one, with an id of 1. I now expect the same request to work, but in fact it does not. $ ./manage.py shell >>> from mysite.myapp.models import Source >>> s = Source.objects.get(id = 1) Traceback (most recent call last): File "", line 1, in File "/usr/local/share/django/django/db/models/manager.py", line 120, in get return self.get_query_set().get(*args, **kwargs) File "/usr/local/share/django/django/db/models/query.py", line 305, in get % self.model._meta.object_name) DoesNotExist: Source matching query does not exist. >>> >>> # added a database entry here, and confirmed its primary key (id) was 1 >>> >>> s = Source.objects.get(id = 1) Traceback (most recent call last): File "", line 1, in File "/usr/local/share/django/django/db/models/manager.py", line 120, in get return self.get_query_set().get(*args, **kwargs) File "/usr/local/share/django/django/db/models/query.py", line 305, in get % self.model._meta.object_name) DoesNotExist: Source matching query does not exist. What am I doing wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
[ANN] Morelia - a BDD framework for Python
Djangoists: Morelia /viridis/ is a Behavior Driven Development system for Python. We use Morelia on all our private Django projects here at http://github.com/cuker . (Other than that, Morelia itself does not require Django, but it works great with django-test-extensions behind it!) Morelia lets you write business rules in plain English: Scenario the customer bought too much When the customer bought $999 worth of swag Then we send them a free tee-shirt Scenario the customer bought too little much When the customer bought $800 worth of swag Then we don't send them a free tee-shirt When you run your unit tests, Morelia builds a test case out of each Scenario, and calls steps in your test suite whose doc-strings match the step definitions, as regular expressions: def step_the_customer_bought_(self, more_than): r'the customer bought \$(\d+) worth of swag' self.customer = get_some_customer() self.customer.total_sales = int(more_than) def step_we_might_send_them_a_free_tee_shirt(self, might): r'we (don't send|send) them a free tee-shirt' qualified = might == 'send' assert self.customer.qualifies_for_free('tee-shirt') == qualified Note that you can pass variables between steps using the self handle. Another write-up for Morelia, for those who already grok BDD, appears here: http://groups.google.com/group/cukes/browse_frm/thread/40facb6998f778cb The complete user's manual, with illustrations, is here: http://c2.com/cgi/wiki?MoreliaViridis Good hunting! -- Phlip http://penbird.tumblr.com/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django standards?
Hey all, I'm working on my first real Django app. I've been tinkering with it since last June, but I actually get to use it now. So my question is about what's the Django standard for what I'm doing... It's a Bible application, and so far, I have a url pattern: urlpatterns = patterns('', (r'^(?P\w+)?/?(?P\w+)/?(?P\d+)?/?(?P\d +)?(\-)?(?P\d+)?/$', verses), ) which correlates to the method verses: def verses(request, version, book, chapter, verse, verse2): logging.debug("version: " + version) logging.debug("book : " + book) # for multi-word books "1 Kings", remove _ and replace with space book = re.sub('_', ' ', book) if chapter is None: verses = Verse.objects.filter(version__iexact=version, book__iexact=book) elif verse is None: logging.debug("chapter: " + chapter) verses = Verse.objects.filter(version__iexact=version, book__iexact=book, chapter__iexact=chapter) elif verse2 is None: logging.debug("chapter: " + chapter) logging.debug("verse : " + verse) verses = Verse.objects.filter(version__iexact=version, book__iexact=book, chapter__iexact=chapter, verse__iexact=verse) else: logging.debug("chapter: " + chapter) logging.debug("verse : " + verse) logging.debug("verse2 : " + verse2) #verse2 can't come before verse1 if verse2 < verse: raise Http404 #filter for a range verses = Verse.objects.filter(version__iexact=version, book__iexact=book, chapter__iexact=chapter, verse__in=range(int(verse),int(verse2)+1)) if verses.count() == 0: logging.debug("No verses found!") raise Http404 return list_detail.object_list( request, queryset = verses, template_name = 'verse.html', template_object_name = 'verses', extra_context = {'book':book,'chapter':chapter,'verse':verse,'verse2':verse2} ) Now, is this the standard way of doing this kind of thing? Or should I break the method up into different methods and have several different url patterns? 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django bases blog solutions
On Feb 4, 2010, at 10:02 AM, Joel Stransky wrote: > Hi all, > I'm brand new to Django/Python but not software development. I just to say hi > and ask for your understanding on my newbish questions. > I realize Django, when used correctly makes it stupidly easy to create > webblogs but I'm curious as to whats out there as far as django based blog > installs go a la wordpress. > > Any input is appreciated. > Hi Joel, I'm tempted to suggest you write your own blog engine, as that seems to be the first thing every new-to-Django programmer does, and it will provide a good learning experience. However, if you are looking for an actual really good, pre-built blog app, you can't really go wrong with django-mingus (http://github.com/montylounge/django-mingus). There are dozens of other options out there (since, as written above, darn near everyone writes their own at some point), but django-mingus is both easy to use and provides an excellent example of both good software engineering and good deployment practices. ---Peter Herndon -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
FieldError with get_object_or_404
hi I was trying out in django's python shell the get_object_or_404 method on a set of entries I created in the db.I created an entry with a DateTimeField called 'posted_time'.I used datetime.datetime.now as default value and it created Date:2010-02-01 Time:10:02:22 I also created many other such entries with different datetime values In the shell I tried this from django.shortcuts import get_object_or_404 as gtobj e1=gtobj(MyEntry,posted_time__year=2010,posted_time__month=2,posted_time__day=1) This is successful ,it gives this message MultipleObjectsReturned: get() returned more than one MyEntry -- it returned 4! However when I tried , e1=gtobj(MyEntry,posted_time__year=2010,posted_time__month=2,posted_time__day=1,posted_time__hour=10) I get this error, FieldError: Join on field 'posted_time' not permitted. Did you misspell 'hour' for the lookup type? Why is this happening?can someone help me figure this out?I tried various values for the hour and minute ..the same error happens for minute also. thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Unicode/ASCII problems
On 04/02/10 14:46, bruno desthuilliers wrote: On Feb 4, 9:18 am, Nohinderwrote: Hello, i ran into this problem too, the solution was to specify the page coding from the very begining: " # -*- coding: latin-1 -*-" This is for .py files, not templates. well, just to note, a similar declaration can help to remove any doubt in templates too. I try to make sure templates have a {# -*- coding: utf-8 -*- #} (to match the FILE_CHARSET default) where emacs (where the -*- coding: -*- thing comes from...) and other editors which expect it can pick it up (i.e. the first line, which appears to be okay with {%extend%} too, I guess since {#...#} is template syntax, not a tag like {%comment%} ) After all, a lot of template files won't have a relevant html/xml encoding declaration in them, as they'll be extend or include fragments. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: SQL statement runs in a loop
On 4 Feb., 11:48, Daniel Rosemanwrote: > On Feb 4, 6:23 am, äL wrote: > > > I have an SQL statement in views.py: > > > karatekas = Karateka.objects.extra(where = ["bsc = 1 OR skr = > > 1"]).select_related() > > > This statement runs in a loop an no data will come back. > > > If I change the little word "OR" to "AND", > > > karatekas = Karateka.objects.extra(where = ["bsc = 1 AND skr = > > 1"]).select_related() > > > the right data will show up. > > > Why does it not work with "OR"? > > What do you mean by 'runs in a loop'? I can't parse that sentence. > What is the actual behaviour? Do you get an error? The browser seems to load and load an load. But no data will come up. No, I don't get any error. > > I'm not sure why you're doing this in SQL, anyway. This can be done > directly in the ORM: > Karateka.objects.filter(Q(bsc=1) | Q(skr=1)).select_related() I tried with your example. Now it works how I want it. Thanks a lot for your help. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: kss with django
> > Does somebody know which AJAX is the best for Django - jQuery, JSON or > something similar (KSS not any more?). > So I can search for instructions. > > Best regards > Ogi Neither jQuery nor JSON are AJAX. JSON is JavaScript Object notation -- the object type in JavaScript. If you're doing AJAX, you will certainly be using JSON or XML. jQuery is a library of JavaScript functionality that very nicely allows you to do the same thing in pretty much every browser type, without having to code for their peculiarities. You can do AJAX very well with jQuery -- it's something it does well. There are a couple of working examples in this thread: http://groups.google.com/group/django-users/browse_thread/thread/45ba4d8f0f71d8d6/ed1002002178633d Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: kss with django
Take a look to http://dajaxproject.com/ Hope this helps you 2010/2/4 Vranesic Ogi> Am Donnerstag 04 Februar 2010 15:39:21 schrieb bruno desthuilliers: > > On Feb 4, 10:32 am, ogi wrote: > > > Hi > > > > > > I'm new in Django but rather old in Python. > > > I followed the tutorialhttp://code.djangoproject.com/wiki/KSSInDjango > > > to integrate KSS with Django and installed kss.django > > > did all settings. > > > But in views.py after > > > commands = KSSCommands() > > > commands.core.replace... > > > I got attribute error 'core' > > > Any hint will be very appreciated. > > > > I suspect the tutorial is either wrong or not up to date. Anyway, this > > is a KSS problem, not a Django problem, so you may have better luck > > searching in KSS documentation, website or whatever. > > > > Yeps, not very helpful, I know - sorry :-/ > > > Bruno thanks anyway for reply. > > Does somebody know which AJAX is the best for Django - jQuery, JSON or > something similar (KSS not any more?). > So I can search for instructions. > > Best regards > Ogi > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Benito Jorge Bastida jo...@thecodefarm.com thecodefarm SL Av. Gasteiz 21, 1º Derecha 01008 Vitoria-Gasteiz http://thecodefarm.com Tel: (+34) 945 06 55 09 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Editing a model in console: form validation fails
On Feb 3, 2:10 pm, Daniel Rosemanwrote: > On Feb 3, 5:45 pm, pjmorse wrote: > > I narrowed the problem down to form validation in the view, and using > > pdb and some debug logging commands I got the validation errors out. > > Here's the problematic code: > > (Pdb) pf.errors > > {'athlete': [u'This field is required.'], 'language': [u'This field is > > required.']} > You don't show the code of the Athlete or AthleteProfile forms. Are > they just standard model forms, with no excluded fields? > > Secondly, is the language field actually displayed on the HTML > template for the athleteprofile form? It's significant that it's not > in the POSTed data, which would seem to indicate that you haven't > included the field in the template. If you've left it out for a > reason, you should also exclude it from the form, by adding it to the > 'exclude' tuple in the form's inner Meta class, so that it doesn't > prevent validation. Thanks, Daniel, good questions. The second one - that the language wasn't actually in the field - turned out to be the key; the language is set based on the user session inside the view (code below) but when I followed your idea and used hidden form fields to add the athlete and language IDs to the form, everything got assigned appropriately in the view and validation passed. The form code is so simple I didn't think it was relevant: class AthleteForm(forms.ModelForm): class Meta: model = Athlete class AthleteProfileForm(forms.ModelForm): class Meta: model = AthleteProfile These are the associated models (I've trimmed commented code for brevity): class Athlete(models.Model): def __unicode__(self): return '%s %s' % (self.name, self.surname) name = models.CharField(max_length=255) surname = models.CharField(max_length=255) country = models.ForeignKey(Country) dob = models.DateField() gender = models.CharField(max_length=1,choices = (('m','Male'), ('f','Female'))) user = models.ForeignKey(AdminUser, related_name='athleter_owner_set', verbose_name = 'Creator') modified = models.ForeignKey(AdminUser, blank = True, null = True, related_name='athlete_modified_set', verbose_name='Modified by') deleted = models.BooleanField(default = False) date_created = models.DateTimeField(null = True, blank = True, default = datetime.now) date_modified = models.DateTimeField(null = True, blank = True, default = datetime.now) image = models.CharField(max_length = 255, null = True, default = 'GENERIC.jpg') class AthleteProfile(models.Model): def __unicode__(self): return '%s %s' % (self.athlete.name, self.athlete.surname) athlete = models.ForeignKey(Athlete) language = models.ForeignKey(Language) pbest = models.CharField("Personal best",max_length=255,blank=True ,null = True, default = '00:00:00') highlights = models.TextField(null = True, blank=True, default = '') career_notes = models.TextField(blank=True ,null = True, default = '') personal_notes = models.TextField(blank=True ,null = True, default = '') additional_career_highlights = models.TextField(blank=True ,null = True, default = '') other_personal_bests = models.TextField(blank=True ,null = True, default = '') upcoming_marathons = models.TextField(blank=True ,null = True, default = '') wmm_highlights = models.TextField("WMM highlights",blank=True ,null = True, default = '') translated = models.BooleanField(default = False ,null = True, blank = True) It's not clear to me why the original programmer chose to normalize the database this way, but I think their intention was to separate translatable fields. "Language" is not displayed in the HTML template; it's set in the view a few lines before the code I included, and based on the user submitting the form: def athletes_edit(request, athlete_id): language = get_object_or_404(Language, locale = request.session['adminlangID']) """ Get current athlete object """ athlete_obj = get_object_or_404(Athlete, pk = athlete_id) athleteprofile, created = AthleteProfile.objects.get_or_create(athlete = athlete_obj, language = language) My assumption was that when the AthleteProfileForm was created from `athleteprofile` (which is an AthleteProfile object) that the language value would be maintained, but apparently such is not the case. Thanks again, Daniel, this has been a thorn in my side for several days and now I've closed it up. pjm -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at
Re: kss with django
Am Donnerstag 04 Februar 2010 15:39:21 schrieb bruno desthuilliers: > On Feb 4, 10:32 am, ogiwrote: > > Hi > > > > I'm new in Django but rather old in Python. > > I followed the tutorialhttp://code.djangoproject.com/wiki/KSSInDjango > > to integrate KSS with Django and installed kss.django > > did all settings. > > But in views.py after > > commands = KSSCommands() > > commands.core.replace... > > I got attribute error 'core' > > Any hint will be very appreciated. > > I suspect the tutorial is either wrong or not up to date. Anyway, this > is a KSS problem, not a Django problem, so you may have better luck > searching in KSS documentation, website or whatever. > > Yeps, not very helpful, I know - sorry :-/ > Bruno thanks anyway for reply. Does somebody know which AJAX is the best for Django - jQuery, JSON or something similar (KSS not any more?). So I can search for instructions. Best regards Ogi -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django bases blog solutions
Hi all, I'm brand new to Django/Python but not software development. I just to say hi and ask for your understanding on my newbish questions. I realize Django, when used correctly makes it stupidly easy to create webblogs but I'm curious as to whats out there as far as django based blog installs go a la wordpress. Any input is appreciated. -- --Joel Stransky stranskydesign.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Unicode/ASCII problems
On Feb 4, 9:18 am, Nohinderwrote: > Hello, > i ran into this problem too, the solution was to specify the page coding > from the very begining: > " # -*- coding: latin-1 -*- " This is for .py files, not templates. > this is my first line in a .py file where i have/deal with special chars. > it latin-1 does not work, try utf-8, although it should work "programming by accident", eh ? This declaration must match the encoding _effectively_ used to save your .py file - else it won't work correctly (even if it seems to). Hint : if you don't want to have encoding problems, enforce the use of utf-8 on the *whole* production chain (source files encoding _and_ declaration, html files idem, webserver, database, etc). Lesson I learned the hard way years ago... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Problem with apache server
If you are in development, you can just use django dev server. "./ manage.py runserver" from your project. If you have deployed your app, then the best way to avoid restarting is to use mod_wsgi's reloading feature. If you deploy in daemon mode, you can just touch the wsgi file to trigger a reload. That is the easiest way. If you want django dev server-like automatic reload on change, you should look at this: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode Some links for deploying django using mod_wsgi. http://docs.djangoproject.com/en/1.1/howto/deployment/modwsgi/#howto-deployment-modwsgi http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango Hope that helps, Alex On Feb 3, 5:30 am, Zygmuntwrote: > Hi! > When i create some changes in my page, i need restart apache server. > How can i avoid restarting? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: kss with django
On Feb 4, 10:32 am, ogiwrote: > Hi > > I'm new in Django but rather old in Python. > I followed the tutorialhttp://code.djangoproject.com/wiki/KSSInDjango > to integrate KSS with Django and installed kss.django > did all settings. > But in views.py after > commands = KSSCommands() > commands.core.replace... > I got attribute error 'core' > Any hint will be very appreciated. I suspect the tutorial is either wrong or not up to date. Anyway, this is a KSS problem, not a Django problem, so you may have better luck searching in KSS documentation, website or whatever. Yeps, not very helpful, I know - sorry :-/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Wp-super-cache clone for django
On Sun, Jan 3, 2010 at 2:22 PM, Alessandro Ronchi < alessandro.ron...@soasi.com> wrote: > In wordpress there is a plugin that caches in a file (gzipped) a page > and returns it instead of recalculate all from database, directly from > apache. > A garbage collector removes cached pages older than cache life. > > Is there anything similar in django, that returns a page without using > the django more expensive cache? I'm using memcached, but the speed of > a wordpress wp-super-cache page is higher that a django memcached one. > This could be a solution: http://superjared.com/projects/static-generator/ Do you know if it's possible to cache only requests without sessions? (i.e. to let satchmo users to get cached files until they put something into their chart). -- Alessandro Ronchi http://www.soasi.com SOASI - Sviluppo Software e Sistemi Open Source http://hobbygiochi.com Hobby & Giochi, l'e-commerce del divertimento -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Any way to make get_or_create() to create an object without saving it to database?
On Wed, Feb 3, 2010 at 9:44 PM,wrote: > I have a similar problem. In my database is a result class. > You need an exam, a user and the points to create a result and points are > without null-values. > Now I want to use Result.objects.get_or_create(exam=e,user=u) to get the > result if there already is one or create a new one. > This won't work because get_or_create tries to save the object to db and > fails. > I want to get_or_create a result and change the points without manual > validating if it already exists. > > The postcondition have to be "result object with given exam, user and points > saved in database, only one result per user/exam combination" > r, c = Exam_result.objects.get_or_create( user = u, exam = e ) > r.points = p > r.save() > > Result(exam = e, user = u) generates a new object i think, if I save this I > have two results for one person at one exam, that's not what I want. > > Sorry if I'm completly wrong with this, would be nice if somebody is able to > enlighten me. > > -- Florian > > Er, r, c = Exam_result.objects.get_or_create(user=u, exam=e, defaults={'points': p, }) if not c: r.points = p r.save() See http://www.djangoproject.com/documentation/models/get_or_create/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using variable in place of field name in Django query .filter()
D'oh! I must have clicked "reply to author" (I'm so used to hitting "reply to all" in Gmail). I discovered a post which gives an example of Itay's suggestion in action: http://yuji.wordpress.com/2009/09/12/django-python-dynamically-create-queries-from-a-string-and-the-or-operator/. I also found this section of Python's documentation useful: http://docs.python.org/tutorial/controlflow.html#keyword-arguments. Thanks for your replies. Sorry for being slow on the uptake. I am relatively new to Python and didn't realize that it's possible to pass a dictionary to a function in place of arguments. Cool! On Feb 5, 2:25 am, Itay Donenhirschwrote: > i don't see any way for a python function to _require_ a parameter to > be hardcoded. > i would be VERY surprised otherwise. this must work... > i agree about python being designed awesomely though! :) > > On Thu, Feb 4, 2010 at 3:13 PM, davidchambers > > wrote: > > Thanks for the suggestion. Unless I'm mistaken, though, using a > > dictionary does not solve the problem which is that .filter() seems to > > require field names to be hard-coded. Django is incredibly well > > designed, though, and continually surprises me, so I'm almost > > _expecting_ to be pleasantly surprised here. :) > > > On Feb 5, 12:23 am, Itay Donenhirsch wrote: > >> i guess you can do it with a dictionary, i'll give you a general example: > > >> def foo(x,y,z): > >> print "x=" + x > >> print "y=" + y > >> print "z=" + z > > >> d = { 'x' : 1, 'y': 2, 'z' : 3 } > >> foo( **d ) # same as foo( x=1, y=2, z=3 ) > > >> it's a python thing, not django necessarily > > >> On Thu, Feb 4, 2010 at 1:20 PM, davidchambers > > >> wrote: > >> > I'm familiar with hard-coding filters in the standard fashion, e.g. > >> > posts = Post.objects.filter(title__contains='django'). > > >> > I'm interested in finding out whether it's possible to replace > >> > title__contains in the above example with a variable. Why do I want to > >> > do this? Well, here's some pseudocode: > > >> > posts = Post.objects.all() > >> > if title checkbox is checked: > >> > posts = posts.filter(title__contains='django') > >> > if subheading checkbox is checked: > >> > posts = posts.filter(subheading__contains='django') > >> > if body checkbox is checked: > >> > posts = posts.filter(body__contains='django') > > >> > I would love to be able to do this with a loop: > > >> > posts = Post.objects.all() > >> > for field in ['title', 'subheading', 'body']: > >> > posts = posts.filter(field__contains='django') > > >> > Clearly the above will not work, but is there a way to achieve the > >> > result I'm after? > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups "Django users" group. > >> > To post to this group, send email to django-us...@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > django-users+unsubscr...@googlegroups.com. > >> > For more options, visit this group > >> > athttp://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using variable in place of field name in Django query .filter()
i don't see any way for a python function to _require_ a parameter to be hardcoded. i would be VERY surprised otherwise. this must work... i agree about python being designed awesomely though! :) On Thu, Feb 4, 2010 at 3:13 PM, davidchamberswrote: > Thanks for the suggestion. Unless I'm mistaken, though, using a > dictionary does not solve the problem which is that .filter() seems to > require field names to be hard-coded. Django is incredibly well > designed, though, and continually surprises me, so I'm almost > _expecting_ to be pleasantly surprised here. :) > > > On Feb 5, 12:23 am, Itay Donenhirsch wrote: >> i guess you can do it with a dictionary, i'll give you a general example: >> >> def foo(x,y,z): >> print "x=" + x >> print "y=" + y >> print "z=" + z >> >> d = { 'x' : 1, 'y': 2, 'z' : 3 } >> foo( **d ) # same as foo( x=1, y=2, z=3 ) >> >> it's a python thing, not django necessarily >> >> On Thu, Feb 4, 2010 at 1:20 PM, davidchambers >> >> wrote: >> > I'm familiar with hard-coding filters in the standard fashion, e.g. >> > posts = Post.objects.filter(title__contains='django'). >> >> > I'm interested in finding out whether it's possible to replace >> > title__contains in the above example with a variable. Why do I want to >> > do this? Well, here's some pseudocode: >> >> > posts = Post.objects.all() >> > if title checkbox is checked: >> > posts = posts.filter(title__contains='django') >> > if subheading checkbox is checked: >> > posts = posts.filter(subheading__contains='django') >> > if body checkbox is checked: >> > posts = posts.filter(body__contains='django') >> >> > I would love to be able to do this with a loop: >> >> > posts = Post.objects.all() >> > for field in ['title', 'subheading', 'body']: >> > posts = posts.filter(field__contains='django') >> >> > Clearly the above will not work, but is there a way to achieve the >> > result I'm after? >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "Django users" group. >> > To post to this group, send email to django-us...@googlegroups.com. >> > To unsubscribe from this group, send email to >> > django-users+unsubscr...@googlegroups.com. >> > For more options, visit this group >> > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using variable in place of field name in Django query .filter()
On Thu, Feb 4, 2010 at 8:13 AM, davidchamberswrote: > Thanks for the suggestion. Unless I'm mistaken, though, using a > dictionary does not solve the problem which is that .filter() seems to > require field names to be hard-coded. Django is incredibly well > designed, though, and continually surprises me, so I'm almost > _expecting_ to be pleasantly surprised here. Why do you say ".filter() seems to require field names to be hard-coded"? It does not. Try the dictionary suggestion. 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using variable in place of field name in Django query .filter()
Thanks for the suggestion. Unless I'm mistaken, though, using a dictionary does not solve the problem which is that .filter() seems to require field names to be hard-coded. Django is incredibly well designed, though, and continually surprises me, so I'm almost _expecting_ to be pleasantly surprised here. :) On Feb 5, 12:23 am, Itay Donenhirschwrote: > i guess you can do it with a dictionary, i'll give you a general example: > > def foo(x,y,z): > print "x=" + x > print "y=" + y > print "z=" + z > > d = { 'x' : 1, 'y': 2, 'z' : 3 } > foo( **d ) # same as foo( x=1, y=2, z=3 ) > > it's a python thing, not django necessarily > > On Thu, Feb 4, 2010 at 1:20 PM, davidchambers > > wrote: > > I'm familiar with hard-coding filters in the standard fashion, e.g. > > posts = Post.objects.filter(title__contains='django'). > > > I'm interested in finding out whether it's possible to replace > > title__contains in the above example with a variable. Why do I want to > > do this? Well, here's some pseudocode: > > > posts = Post.objects.all() > > if title checkbox is checked: > > posts = posts.filter(title__contains='django') > > if subheading checkbox is checked: > > posts = posts.filter(subheading__contains='django') > > if body checkbox is checked: > > posts = posts.filter(body__contains='django') > > > I would love to be able to do this with a loop: > > > posts = Post.objects.all() > > for field in ['title', 'subheading', 'body']: > > posts = posts.filter(field__contains='django') > > > Clearly the above will not work, but is there a way to achieve the > > result I'm after? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django and ldap
On 04/02/10 08:33, andreas schmid wrote: @brad: can you show me some sample code for this? @david: i tried different configuration options but with no luck, i can bind and search manually over python-ldap so i can definitely connect. There are logging calls liberally sprinkled through the source of django-auth-ldap. Django doesn't really give you any help with logs out-of-box (I suppose the argument is python already has its logging package (quite the baroque one) that you can setup how you want), they may be going nowhere? For debugging rather than production logging needs, there are packages that can inject log messages encountered during answering requests into the html response [1] - extremely useful. I'm still stuck for now with our homegrown ldap auth we grew before django-auth-ldap appeared, but I've been keeping an eye on the django-auth-ldap package as a possible replacement. I can confirm it worked completely straightforwardly on python 2.5 and django 1.1.1 (including log messages when auth failed etc.) - at least trunk when checked out from the repo rather than easy_installed or whatever - here's the entirety of the relevant settings.py config I used for my last test, as per the documentation: AUTHENTICATION_BACKENDS = ( 'django_auth_ldap.backend.LDAPBackend', ... ) # I have a slapd setup for testing on my dev box. AUTH_LDAP_SERVER_URI = "ldap://localhost/; import ldap from django_auth_ldap.config import LDAPSearch # If you can't anonymously find users, you might need values here. AUTH_LDAP_BIND_DN = "" AUTH_LDAP_BIND_PASSWORD = "" # obviously I used our actual path here AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)") [1] http://code.google.com/p/django-logging/wiki/Overview - apparently no longer maintained (still works though): http://robhudson.github.com/django-debug-toolbar/ has a superset of its functionality though I haven't got around to switching to it yet. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: You're seeing this error because you have DEBUG = True in your Django settings file.
On Feb 4, 3:54 am, punwaicheungwrote: > Page not found (404) > Request Method: GET > Request URL:http://www.cadal.zju.edu.cn/djvu_ulib/16003525/0001.djvu > > Using the URLconf defined in cadal.urls, Django tried these URL > patterns, in this order: > > ^personal/?$ > ^personal/Eng/?$ > ^personal/addrule/book/? > ^personal/delrule/(\d+)/?$ > ^personal/addfld/([^/]+)/?$ > ^personal/renrule/(\d+)/([^/]+)/?$ > ^personal/hotbooks/?$ > ^personal/hotbooks/Eng/?$ > ^personal/quicksearch/(\w+)/?$ > ^personal/mytags/?$ > ^personal/mytags/Eng/?$ > ^personal/mybookmarks/?$ > ^personal/mybookmarks/Eng/?$ > ^personal/mybookmarks/(?P\d{8})/?$ > ^personal/info/?$ > ^personal/password/?$ > ^personal/subtree/? > ^personal/quickadd/? > ^fulltext/search/?$ > ^fulltext/text/(?P\d+)/(?P\d+)/?$ > ^book/(?P\d+)/$ > ^book/(?P\d+)/Eng/$ > ^book/(?P\d+)/(?P\d+)/$ > ^book/(?P\d+)/(?P\d+)/Eng/$ > ^book/(?P\d+)/(?P\d+)/list/$ > ^book/(?P\d+)/(?P\d+)/list/Eng/$ > ^book/(?P\d+)/catalog/$ > ^book/(?P\d+)/sidebar/$ > ^book/(?P\d+)/sidebar/Eng/$ > ^book/(?P\d+)/navigator/$ > ^book/(?P\d+)/navigator/Eng/$ > ^book/(?P\d+)/submitComment/$ > ^book/(?P\d+)/delComment/$ > ^book/(?P\d+)/submitMeta/$ > ^book/(?P\d+)/allComments/$ > ^book/(?P\d+)/allComments/Eng/$ > ^book/(?P\d+)/addBookmark/$ > ^book/(?P\d+)/deleteBookmark/$ > ^book/(?P\d+)/tags/$ > ^book/(?P\d+)/tags/Eng/$ > ^book/(?P\d+)/delTag/(?P[^/]+)/$ > ^book/tags/(?P[^/]+)/$ > ^book/tags/(?P[^/]+)/Eng/$ > ^book/tags/(?P[^/]+)/(?P\d+)/$ > ^book/tags/(?P[^/]+)/(?P\d+)/Eng/$ > ^book/(?P\d+)/submitTag/$ > ^book/(?P\d+)/recommendation/$ > ^book/(?P\d+)/recommendation/Eng/$ > ^class/$ > ^class/(?P[^/]+)/$ > ^class/(?P[^/]+)/(?P\d+)/$ > ^class/(?P[^/]+)/cards/(?P\d+)/$ > ^account/login/(?P\d+)/(?P\d+)/$ > ^account/login/Eng/(?P\d+)/(?P\d+)/$ > ^account/login/$ > ^account/login/Eng/$ > ^account/logout/$ > ^account/logout/Eng/$ > ^account/register/Eng/$ > ^account/register/$ > ^auth/(?P\d{8})/?$ > ^auth/user/?$ > ^admin/?$ > ^admin/login/?$ > ^admin/logout/?$ > ^admin/group_auth/?$ > ^admin/show_ug/?$ > ^admin/add_ug/?$ > ^admin/del_ug/?$ > ^admin/show_rg/?$ > ^admin/show_rg/(?P\w+)/?$ > ^admin/show_rg/(?P\w+)/(?P\d+)/?$ > ^admin/add_rg/?$ > ^admin/del_rg/?$ > ^admin/modify_rg_view/?$ > ^admin/modify_rg/?$ > ^admin/show_books/(?P\d+)/?$ > ^admin/show_books/(?P\d+)/(?P\d+)/?$ > ^admin/add_book_rg_view/?$ > ^admin/add_book_rg/?$ > ^admin/del_book_rg/(?P\d+)/?$ > ^admin/addtogroup/?$ > ^admin/show_ACL/?$ > ^admin/show_users/(?P\d+)/?$ > ^admin/show_IPs/(?P\d+)/?$ > ^admin/add_group_ip/?$ > ^admin/del_group_ip/?$ > ^admin/add_user2group/?$ > ^admin/del_group_user/?$ > ^admin/search_user/?$ > ^admin/show_scancenter/?$ > ^djvu/(?P\d+)/(?P\d{8})(?P\w{7}).djvu/?$ > ^djvu/get_mask/(?P\d+)/(?P\d{8})/?$ > ^djvu/(?P\d+)/(?P\d+).tif/?$ > ^cover/(?P\d{8}) > ^tag/(?P\d{8})/?$ > ^captcha/image/?$ > ^captcha/?$ > ^captcha/en/?$ > ^captcha/en/image/?$ > ^meta/page/(\d{8})/?$ > ^html/(?P\d+)/(?P\d+).htm/?$ > ^html/(?P\d+)/(?P[\-\d]+).gif/?$ > ^html/(?P\d+)/(?P[\-\d]+).jpg/?$ > ^flexSupport/(?P\d+)/(?P[\-\d]+).jpg/?$ > ^ulib/(?P\d+)/?$ > ^Reader\.action > ^ReaderEng\.action > ^personal/imagesearch/(?P[^/]*)/(?P\d+)/? > ^personal/callisearch/(?P[^/]*)/(?P\d+)/? > ^catalogsearch/?$ > ^catalogsearch/detail/(\d{8})/? > ^personal/recsysdemo/?$ > The current URL, /djvu_ulib/16003525/0001.djvu, didn't match any > of these. > > You're seeing this error because you have DEBUG = True in your Django > settings file. Change that to False, and Django will display a > standard 404 page. To actually help you though, /djvu_ulib/16003525/0001.djvu isn't being matched because there isn't a regex for it in the list! There are two similar regexes in your list: > ^ulib/(?P\d+)/?$ > ^djvu/(?P\d+)/(?P\d{8})(?P\w{7}).djvu/?$ Presumably you meant the second, but it wouldn't match because it has 8 chars before .djvu not 7, and the url has djvu/ not djvu_ulib/. Also, I don't think you need to put "/?" at the end of the url even if you may send it GET data. It looks like you need to either change your url or the regex for it. There is also a lot of inconsistency in your naming conventions for the groups in the regex (sometimes page_id sometimes pageId). It is usually best to decide to use one and stick to it so you don't have to keep going back to check which it should be. HTH, Emily -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using variable in place of field name in Django query .filter()
i guess you can do it with a dictionary, i'll give you a general example: def foo(x,y,z): print "x=" + x print "y=" + y print "z=" + z d = { 'x' : 1, 'y': 2, 'z' : 3 } foo( **d ) # same as foo( x=1, y=2, z=3 ) it's a python thing, not django necessarily On Thu, Feb 4, 2010 at 1:20 PM, davidchamberswrote: > I'm familiar with hard-coding filters in the standard fashion, e.g. > posts = Post.objects.filter(title__contains='django'). > > I'm interested in finding out whether it's possible to replace > title__contains in the above example with a variable. Why do I want to > do this? Well, here's some pseudocode: > > posts = Post.objects.all() > if title checkbox is checked: > posts = posts.filter(title__contains='django') > if subheading checkbox is checked: > posts = posts.filter(subheading__contains='django') > if body checkbox is checked: > posts = posts.filter(body__contains='django') > > I would love to be able to do this with a loop: > > posts = Post.objects.all() > for field in ['title', 'subheading', 'body']: > posts = posts.filter(field__contains='django') > > Clearly the above will not work, but is there a way to achieve the > result I'm after? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Using variable in place of field name in Django query .filter()
I'm familiar with hard-coding filters in the standard fashion, e.g. posts = Post.objects.filter(title__contains='django'). I'm interested in finding out whether it's possible to replace title__contains in the above example with a variable. Why do I want to do this? Well, here's some pseudocode: posts = Post.objects.all() if title checkbox is checked: posts = posts.filter(title__contains='django') if subheading checkbox is checked: posts = posts.filter(subheading__contains='django') if body checkbox is checked: posts = posts.filter(body__contains='django') I would love to be able to do this with a loop: posts = Post.objects.all() for field in ['title', 'subheading', 'body']: posts = posts.filter(field__contains='django') Clearly the above will not work, but is there a way to achieve the result I'm after? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
kss with django
Hi I'm new in Django but rather old in Python. I followed the tutorial http://code.djangoproject.com/wiki/KSSInDjango to integrate KSS with Django and installed kss.django did all settings. But in views.py after commands = KSSCommands() commands.core.replace... I got attribute error 'core' Any hint will be very appreciated. Thanks in advance ogi -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: SQL statement runs in a loop
On Feb 4, 6:23 am, äLwrote: > I have an SQL statement in views.py: > > karatekas = Karateka.objects.extra(where = ["bsc = 1 OR skr = > 1"]).select_related() > > This statement runs in a loop an no data will come back. > > If I change the little word "OR" to "AND", > > karatekas = Karateka.objects.extra(where = ["bsc = 1 AND skr = > 1"]).select_related() > > the right data will show up. > > Why does it not work with "OR"? What do you mean by 'runs in a loop'? I can't parse that sentence. What is the actual behaviour? Do you get an error? I'm not sure why you're doing this in SQL, anyway. This can be done directly in the ORM: Karateka.objects.filter(Q(bsc=1) | Q(skr=1)).select_related() -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django-app user clashes with python-module user
On Thursday 04 February 2010 01:17:46 patrickk wrote: > our hosting-provide told me that I should rename my django-app "user" > to something else, because there´s a python-module "user" and with > using user.urls (within our url configuration), we do get an error. > my question is, if this is the correct way to solve this problem. so > far, I´ve never noticed that there are restrictions to django app- > names (and I guess there aren´t). > we didn´t have this problem with our previous hosting-provider and > before I´m going to rename my app (for several websites), I´d like to > know if the problem is caused by the "wrong" app-name or if it´s a > server setup problem. > > regards, > patrick > It's a "wrong" app-name, apps can't conflict with existing python modules and follow the rules of python module naming conventions, because just like a project a django app is really a python module, just with a different name. FYI: Help on module user: NAME user - Hook to allow user-specified customization code to run. FILE /usr/lib/python2.6/user.py MODULE DOCS http://docs.python.org/library/user DESCRIPTION As a policy, Python doesn't run user-specified code on startup of Python programs (interactive sessions execute the script specified in the PYTHONSTARTUP environment variable if it exists). However, some programs or sites may find it convenient to allow users to have a standard customization file, which gets run when a program requests it. This module implements such a mechanism. Mike -- Don't be concerned, it will not harm you, It's only me pursuing something I'm not sure of, Across my dreams, with neptive wonder, I chase the bright elusive butterfly of love. signature.asc Description: This is a digitally signed message part.
django-app user clashes with python-module user
our hosting-provide told me that I should rename my django-app "user" to something else, because there´s a python-module "user" and with using user.urls (within our url configuration), we do get an error. my question is, if this is the correct way to solve this problem. so far, I´ve never noticed that there are restrictions to django app- names (and I guess there aren´t). we didn´t have this problem with our previous hosting-provider and before I´m going to rename my app (for several websites), I´d like to know if the problem is caused by the "wrong" app-name or if it´s a server setup problem. regards, patrick -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django and ldap
@brad: can you show me some sample code for this? @david: i tried different configuration options but with no luck, i can bind and search manually over python-ldap so i can definitely connect. ive seen that the requirements for django-auth-ldap are python2.3 and django1.0 so maybe thats one of the problems. is someone who is using a higher pyhton version and maybe django1.1 and have it working? any advise would be appreciated. brad wrote: >> i need to authenticate users through ldap but i need also to store their >> preferences in the database, i cant really understand if >> > > >> what is the best way to go? >> > > One thing you might consider doing is just write a custom backend: > (http://docs.djangoproject.com/en/1.1/ref/authbackends/#ref- > authentication-backends). > > I have a project where user's authenticate agains Active Directory. > If the authentication is successful, the backend checks to see if an > corresponding User (from django.contrib.auth) exists. If not, it > pulls the their full name, username, and email from Active Directory > and creates the User object. > > The pitfall to this approach is that if their info changes in AD, the > corresponding User data is out-of-sync. > > This approach works well for me, but YMMV. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Unicode/ASCII problems
Hello, i ran into this problem too, the solution was to specify the page coding from the very begining: " # -*- coding: latin-1 -*- " this is my first line in a .py file where i have/deal with special chars. it latin-1 does not work, try utf-8, although it should work Good Luck Karen Tracey-2 wrote: > > On Wed, Feb 3, 2010 at 3:52 PM, zenWeaselwrote: > >> I am new to Django development, and have not been able to find this in >> the documentation. >> >> In my templates, if I use any characters that are Unicode and not >> straight ASCII e.g. é or ˝, the template fails. Is this normal >> behavior? Is there an easy way to expand the templates to handle the >> Unicode set or convert them to entities? >> > > No, it's not normal behavior. Please read: > > http://docs.djangoproject.com/en/dev/ref/unicode/ > > If you still have problems after reading that, likely someone on this list > will be able to help work out what is wrong. However you will get much > better help if you are a bit more specific about what goes wrong than "the > template fails." > > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- View this message in context: http://old.nabble.com/Unicode-ASCII-problems-tp27443539p27449101.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.