Fwd: Re: TransactionMiddleware and SessionMiddleware
On Wednesday 10 December 2008 16:46:36 Thomas Guettler wrote: > Hi, > > I follow: http://docs.djangoproject.com/en/dev/topics/db/transactions/ > {{{ > The order is quite important. The transaction middleware applies not > only to view functions, but also for all middleware modules that come > after it. So if you use the session middleware after the transaction > middleware, session creation will be part of the transaction. > }}} > > # settings.py > MIDDLEWARE_CLASSES = [ > > 'djangotools.middleware.HandleExceptionMiddleware.HandleExceptionMiddleware >', 'django.middleware.common.CommonMiddleware', > 'django.middleware.transaction.TransactionMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.middleware.doc.XViewMiddleware', > ] I found the documentation quite confusing on this point too, and I ended up googling for the middleware name to find other examples. I think the cache middleware should be around the whole set of middleware classes. Here's what I've gone with: MIDDLEWARE_CLASSES = ( 'django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.doc.XViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'MySite.dbtemplates.middleware.FlatpageFallbackMiddleware', 'MySite.dbtemplates.middleware.RedirectFallbackMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware', ) If I'm wrong, someone please correct me! Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Setting the time on a datetimefield
On Monday 14 Jul 2008, Rajesh Dhawan wrote: > On Jul 14, 5:40 pm, Tim Sawyer <[EMAIL PROTECTED]> wrote: > > On Monday 14 Jul 2008, Rajesh Dhawan wrote: > > > The replace method here returns a new instance of a datetime object -- > > > it's not an in-place replace. This should work: > > > > > > self.datetime = self.datetime.replace(hour=23, minute=59) > > > > Hmm, that seemed to make sense to me too, though with my Java background > > I wasn't sure. I get: > > > > Exception Value: 'hour' is an invalid keyword argument for this > > function > > > > on > > > > self.datetime = self.datetime.replace(hour=23, minute=59) > > > > self.datetime is defined as: > > > > datetime = models.DateTimeField() > > Strange...I just ran a few tests on a model field like that and it all > worked perfectly. > > Can you dpaste your relevant code? > > Also, if you print type(self.datetime), do you get the type as > datetime.datetime or something else? Sussed it. In my code, I did this: self.datetime = pForm.cleaned_data['datetime'] the datetime parameter passed from the form only contained the date, with no time, so I assume the value in datetime then was only a date. I've sorted my problem using the following code: self.datetime = datetime(self.datetime.year, self.datetime.month, self.datetime.day, 23, 59) Thanks for your help, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Setting the time on a datetimefield
On Tuesday 15 Jul 2008, Arien wrote: > On Tue, Jul 15, 2008 at 4:57 AM, Tim Sawyer <[EMAIL PROTECTED]> wrote: > > In my code, I did this: > > > > self.datetime = pForm.cleaned_data['datetime'] > > > > the datetime parameter passed from the form only contained the date, with > > no time, so I assume the value in datetime then was only a date. > > This shouldn't happen: a DateTimeField normalizes to a > datetime.datetime object. Are you sure you're not using a DateField > in your form? Well spotted. In my form I have: datetime = forms.DateField(widget=forms.TextInput({'class' : 'date-pick'}),label="Available date") yet it's a DateTimeField in the model. This means that the reason that the value fetched from the form is only a date is because of the type in the form. Assigning this date only value from the form to the model attribute means I can't use replace(hour=23) on it any more. I don't really understand why, but I'm sure there's a logical explanation! Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Defaulting Site in NewFormsAdmin
Hi Folks, I'm trying to build a web app that has many sites, all of which share the same code and database. I'm therefore using the Sites framework, but I need to hide the site that is being edited in the admin. I have done this where my model has a Foreign Key of site, mainly by defining the link as follows: site = models.ForeignKey(Site,default=Site.objects.get_current().id,editable=False) this is a foreign key to site, where the default is the current site, and the user can't edit it in the admin. This is fine, but I've just started using Flatpages (and http://code.google.com/p/django-databasetemplateloader/) to manage the HTML in my site. Both of these have many to many links, and as they're in contrib, I can't easily change the model without copying it. Is there a way to default the Site in Flatpages (to a single site even though it's a many to many) and not have it editable in new forms admin? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Changing Login Page for Admin
Hi, I'm using the newforms admin stuff, and I'd like to use my own URL for the login page for the admin site. So, if someone goes to /admin on my site (which is where the admin site is located), I'd like to redirect to /private/login/?next=/admin. (The reason I want to do that is that I have some custom code on the login that looks for and removes a suffix before passing through to the user authentication code.) Is this straightforward? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Changing Login Page for Admin
On Sunday 24 Aug 2008, Tim Sawyer wrote: > Hi, > > I'm using the newforms admin stuff, and I'd like to use my own URL for the > login page for the admin site. > > So, if someone goes to /admin on my site (which is where the admin site is > located), I'd like to redirect to /private/login/?next=/admin. > > (The reason I want to do that is that I have some custom code on the login > that looks for and removes a suffix before passing through to the user > authentication code.) > > Is this straightforward? Probably not the neatest solution, but it works. 1) in urls.py, set the login template after autodiscover: admin.autodiscover() admin.site.login_template = 'registration/login_redirect.html' In the registration/login_redirect.html template, redirect to the login page you want: Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
sorl thumbnail
Has anyone got sorl thumbnail working with the latest svn code? I'm just getting src="" using src="{% thumbnail image.image 200x100 %}" Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: sorl thumbnail
My bad. I didn't update the sorl-thumbnail code from svn. Didn't realise this until I'd fixed it by using a different thumbnail implementation! It's been a long week. Thanks all. Tim. On Friday 05 Sep 2008, [EMAIL PROTECTED] wrote: > set TEMPLATE_DEBUG=True in settings.py > > On Sep 5, 4:30 pm, Tim Sawyer <[EMAIL PROTECTED]> wrote: > > Has anyone got sorl thumbnail working with the latest svn code? > > > > I'm just getting src="" using src="{% thumbnail image.image 200x100 %}" > > > > Cheers, > > > > Tim. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
INSTALLED_APPS from a template
Hi Folks, I'd like to conditionally add a link based on whether a specific app is included in INSTALLED_APPS or not. Is there an easy way to do this from a template? Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: INSTALLED_APPS from a template
That's just what I needed, thanks very much. Tim. On Thursday 25 Sep 2008, Rock wrote: > from django import template > from django.conf import settings > from django.template.defaultfilters import stringfilter > > register = template.Library() > > @register.filter > @stringfilter > def installed(value): > apps = settings.INSTALLED_APPS > if "." in value: > for app in apps: > if app == value: > return True > else: > for app in apps: > fields = app.split(".") > if fields[-1] == value: > return True > return False --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Set referer header in test client?
Hi, I'm having a problem testing with: c = Client() response = c.post('/guestbook/', { 'name' : 'name', 'email' : 'email', 'realurl' : 'url', }) in that my view checks the referer header available from request.META['HTTP_REFERER'] to make sure the form was submitted from the correct url. Can I simulate this header with the test client? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Set referer header in test client?
On Tuesday 30 Sep 2008, Russell Keith-Magee wrote: > > Can I simulate this header with the test client? > > Yes. > > The full method signature for client.post() is: > def post(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): > > 'extra' is an argument that allows you to specify any additional > header data that you want to send with the request. So, if you want to > > set the HTTP REFERRER in your request, make a call like: > >>> response = c.post('/guestbook/', {...your data...}, > >>> HTTP_REFERRER='foo') > > Yours > Russ Magee %-) Excellent, thanks! Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Template Tags in Text
Hi, I'm trying to puzzle out the best way of achieving something, and I'd appreciate some help. My website contains text writeups of events, and a gallery. I'd like to embed some images from the gallery into the text writeups. The text is not in a template, it's in the database and displayed using the textile filter: {% block body %} {{ Contest.date|date:"jS F Y" }} - {{ Contest.title }} {{ Contest.report|textile }} {% endblock %} What's the best way to embed an image from my gallery into the Contest.report variable? I'm looking to do something like: {% ShowImage 1 200 400 left %} where - ShowImage is a template tag, - 1 is the serial of the image to show, - 200 is the height - 400 is the width - left is the align value so text wraps around it I can generate a thumbnail of the right size, and I can find the image location from the database, but what's the best way of replacing this template tag with the appropriate html? Can I write a filter which "runs" template tags? Or should I be scanning the text for "{% ShowImage" and then reading values until the next "%}" in a custom filter? Thoughts? Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
DateField comparison with date.today()
Hi, I have a model that includes: from datetime import date as pydate, datetime date = models.DateField() I've overridden delete to do: def delete(self): ... if self.date < pydate.today(): Notification.process(None, self, 'Event deleted') and that works fine If I override save to do something similar: def save(self): ... if self.date < pydate.today(): Notification.process(lOldEvent, self, 'Event changed') I get an error running my tests: File "/home/mysite/src/MySite/events/models.py", line 79, in save if self.date < pydate.today(): TypeError: can't compare datetime.datetime to datetime.date I'm confused why it works in delete(), but not in save(). Am I going about this the wrong way, or should my approach work? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: DateField comparison with date.today()
On Wednesday 28 January 2009 04:34:50 Malcolm Tredinnick wrote: > On Tue, 2009-01-27 at 22:03 +0000, Tim Sawyer wrote: > > Hi, > > > > I have a model that includes: > > > > from datetime import date as pydate, datetime > > > > date = models.DateField() > > > > I've overridden delete to do: > > > > def delete(self): > > ... > > if self.date < pydate.today(): > > Notification.process(None, self, 'Event deleted') > > > > and that works fine > > > > If I override save to do something similar: > > > > def save(self): > > ... > > if self.date < pydate.today(): > > Notification.process(lOldEvent, self, 'Event changed') > > > > I get an error running my tests: > > > > File "/home/mysite/src/MySite/events/models.py", line 79, in save > > if self.date < pydate.today(): > > TypeError: can't compare datetime.datetime to datetime.date > > > > I'm confused why it works in delete(), but not in save(). Am I going > > about this the wrong way, or should my approach work? > > The answer is almost certainly because delete() operates on something > that is loaded from the database, so the attribute contains a > datetime.date instance. However, save() operates on something provided > from userspace, which could be a string, or, in this case, a > datetime.datetime object. > > You haven't mentioned how you're creating these objects. Through the > admin? Through forms of your own? Through Python code assigning to the > attributes? In any case, it's not inconceivable that the types could be > different (unfortunately). > > Regards, > Malcolm Thanks for that. The data is all created through the admin, so Save() will be being called on either a new instance created in the admin, or an existing row from the database edited in the admin. Presuming that the same technique for Delete() will work for existing data, What does the admin put in a DateField for a new instance? Or is there a common way of getting hold of the date that will work in all circumstances? Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Fwd: Re: Class coverage report for automated tests in django apps
I'm doing that using coverage.py, I based my solution on these blog posts: http://siddhi.blogspot.com/2007/04/code-coverage-for-your-django-code.html http://siddhi.blogspot.com/2007/07/django-code-coverage-followup.html Cheers, Tim. -- Forwarded Message -- Subject: Re: Class coverage report for automated tests in django apps Date: Friday 06 February 2009 From: Alex Gaynor To: django-users@googlegroups.com On Fri, Feb 6, 2009 at 2:11 AM, ranjan.Kumar wrote: > > hi all.. > > I am trying to automate tests for my website and i need to know the > way in which i can get the code coverage report of the tests. I found > 'coverage.py' which gives the coverage report of 'statements' but > couldn't find any way that gives 'method/class coverage' report. Can > anyone help? > > Thanks in advance. > > > > Perhaps try figleaf, I've never used it but I've heard nice things about it: http://pypi.python.org/pypi/figleaf/ Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --- --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
to_field in model not working
Hi, We're building an application with django on top of a legacy database and we've hit a problem with a to_field option being ignored. We've reproduced it with the latest svn version of django and a different database (oracle -> sqllite) Our model includes: uas_use_oracle_user = models.ForeignKey(Users, to_field='use_oracle_user', db_column='UAS_USE_ORACLE_USER') but when we're selecting (from the admin site) we're seeing: SELECT "USER_AT_SITES"."UAS_SERIAL", "USER_AT_SITES"."UAS_SIT_SERIAL", "USER_AT_SITES"."UAS_USE_ORACLE_USER", "USER_AT_SITES"."UAS_OFFSET_DIR" FROM "USER_AT_SITES" WHERE "USER_AT_SITES"."UAS_USE_ORACLE_USER" = 1 when we should be getting SELECT "USER_AT_SITES"."UAS_SERIAL", "USER_AT_SITES"."UAS_SIT_SERIAL", "USER_AT_SITES"."UAS_USE_ORACLE_USER", "USER_AT_SITES"."UAS_OFFSET_DIR" FROM "USER_AT_SITES" WHERE "USER_AT_SITES"."UAS_USE_ORACLE_USER" = ‘pbk’ Admin options are: class UserAtSitesInline(admin.StackedInline): model = UserAtSites class UsersAdmin(admin.ModelAdmin): list_display = ('use_oracle_user','use_person') fields = ['use_oracle_user','use_person', 'use_current'] inlines = [UserAtSitesInline] Full model is at http://dpaste.com/119269/ We can also provide a small working sqllite based example if anyone wants to play with it. Is this a bug? Have we done something wrong? cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: to_field in model not working
On Thursday 12 February 2009 01:47:31 Malcolm Tredinnick wrote: > On Wed, 2009-02-11 at 10:45 +0000, Tim Sawyer wrote: > > Hi, > > > > We're building an application with django on top of a legacy database and > > we've hit a problem with a to_field option being ignored. We've > > reproduced it with the latest svn version of django and a different > > database (oracle -> sqllite) > > It looks like a bug to me. Please open a ticket for this, we need to > look at it. Presumably nothing more than just a model with a to_field > and a related model with a pk and non-integer field (for the to_field > target) are all that's needed to demonstrate things, right? If not, > that's worth noting in the ticket description, too. > > (And a helpful advance tip aimed at everybody in general: you're no > doubt going to be including code in your ticket description. For the > love of all that's good, use the "preview" button before submitting the > ticket! :-) ) Done, thanks. After further investigation it looks related to the inline admin stuff. Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Anyway to render a template without inheritance?
Yes, just don't do the extends and include all the HTML you need in the template. Tim. > > Hello. > > Is there any way to render a template, omitting the "extends" tag? > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
onkeyup event on form field
Hi, I'd like to add an onkeyup event on a form field. I've defined the following in my form: contest = forms.CharField(max_length=100, widget=forms.TextInput(attrs={"onkeyup" : "lookup(this.value,'id_contest');",} ) ) This comes out as in the html. How do I stop django auto-escaping my javascript and replacing a single quote with #39; ? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
save_formset in admin
Hi, I'm overriding save_formset in a subclass of ModelAdmin. This worked fine using svn 9382, but I've just updated to svn 10674 and it's not working. def save_formset(self, request, form, formset, change): """ Stamp the model as last changed by the current user Set the owner to the current user if it is a blank field """ instances = formset.save(commit=False) for instance in instances: instance.lastChangedBy = request.user try: instance = obj.owner except: instance.owner = request.user instance.save() formset.save() In the above code, instances = formset.save(commit=False) appears to be saving my instance to the database, and I'm getting IntegrityError: null value in column "lastChangedBy_id" violates not-null constraint because I haven't had chance to set it yet. Can anyone give me any clues? Cheers, Tim.. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: save_formset in admin
On Friday 08 May 2009 12:39:59 Alex Gaynor wrote: > On Fri, May 8, 2009 at 1:38 PM, Tim Sawyer wrote: > > Hi, > > > > > > I'm overriding save_formset in a subclass of ModelAdmin. This worked fine > > using svn 9382, but I've just updated to svn 10674 and it's not working. > > > This was fixed earlier today. Please SVN up :) > > Alex Excellent, thanks Alex. Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ForeignKey Select List Filter
Will this do? http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to You could always fallback on doing the droplist manually. Tim. On Friday 08 May 2009 14:23:36 cfiles wrote: > Still stuck on this one. Does anybody have any ideas? > > On Apr 29, 8:36 am, cfiles wrote: > > Let me try to explain this a little more. Here are some example models > > > > class Account(models.Model): > > user = models.ForeignKey(User) > > name= models.CharField('Name on Account', max_length=100) > > description = models.CharField(max_length=100) > > date_added = models.DateField(auto_now_add=True, blank=True) > > > > class Payment(models.Model): > > account = models.ForeignKey(Account) > > date_paid = models.DateField(auto_now_add=True, blank=True) > > amount = models.DecimalField(max_digits=10, decimal_places=2) > > > > When I display the form for a Payment I get all of the Account > > objects. I want to limit the list to accounts that the user owns. How > > is this done? I have looked an I am unable to find the documentation > > for it. > > 1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
I/O operation on closed file
Hi, I'm getting the following error uploading images to my gallery using the admin site, written in django (full stack at bottom of mail) ValueError: I/O operation on closed file It doesn't always happen, and it;s more likely to occur using "Save but keep editing" in the admin. I'm using svn 10712. Any clues? Thanks, Tim. File "/home/mybandsite/django-trunk/django/core/handlers/base.py", line 92, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/home/mybandsite/django-trunk/django/contrib/admin/sites.py", line 480, in root return self.model_page(request, *url.split('/', 2)) File "/home/mybandsite/django-trunk/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/home/mybandsite/django-trunk/django/contrib/admin/sites.py", line 499, in model_page return admin_obj(request, rest_of_url) File "/home/mybandsite/src/MyBandSite/admin.py", line 113, in __call__ return super(SiteOnlyAdmin, self).__call__(request, url) File "/home/mybandsite/django-trunk/django/contrib/admin/options.py", line 1094, in __call__ return self.change_view(request, unquote(url)) File "/home/mybandsite/django-trunk/django/db/transaction.py", line 240, in _commit_on_success res = func(*args, **kw) File "/home/mybandsite/django-trunk/django/contrib/admin/options.py", line 832, in change_view self.save_formset(request, form, formset, change=True) File "/home/mybandsite/src/MyBandSite/admin.py", line 82, in save_formset formset.save() File "/home/mybandsite/django-trunk/django/forms/models.py", line 509, in save return self.save_existing_objects(commit) + self.save_new_objects(commit) File "/home/mybandsite/django-trunk/django/forms/models.py", line 643, in save_new_objects self.new_objects.append(self.save_new(form, commit=commit)) File "/home/mybandsite/django-trunk/django/forms/models.py", line 738, in save_new obj.save() File "/home/mybandsite/src/MyBandSite/gallery/models.py", line 61, in save super(GalleryImage, self).save() File "/home/mybandsite/django-trunk/django/db/models/base.py", line 407, in save self.save_base(force_insert=force_insert, force_update=force_update) File "/home/mybandsite/django-trunk/django/db/models/base.py", line 461, in save_base values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks] File "/home/mybandsite/django-trunk/django/db/models/fields/files.py", line 191, in pre_save file.save(file.name, file, save=False) File "/home/mybandsite/django-trunk/django/db/models/fields/files.py", line 239, in save self._dimensions_cache = get_image_dimensions(content) File "/home/mybandsite/django-trunk/django/core/files/images.py", line 39, in get_image_dimensions data = file.read(1024) File "/home/mybandsite/django-trunk/django/core/files/uploadedfile.py", line 87, in read def read(self, *args): return self._file.read(*args) ValueError: I/O operation on closed file --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: I/O operation on closed file
On Tuesday 12 May 2009 21:28:35 Alex Gaynor wrote: > On Tue, May 12, 2009 at 3:27 PM, Tim Sawyer wrote: > > ValueError: I/O operation on closed file > > This is probably a symptom of http://code.djangoproject.com/ticket/11084 . > Thanks Alex. I've just updated to 10784 (without a fix for that bug) and it seems fine now! Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Oracle and Primary Keys
Hi, I have a django model that looks like this: class Lender(models.Model): id = models.IntegerField(primary_key=True, db_column='lse_serial') version = models.IntegerField(db_column='lse_version') name = models.CharField(max_length=50, db_column='lse_lender') uri = models.TextField(db_column='lse_lender_uri') def __unicode__(self): return self.name class Meta: ordering = ['name'] db_table = 'lender_service_endpoints' I'm connecting to an Oracle database. If I do a python manage.py sqlall home I get the following SQL: CREATE TABLE "LENDER_SERVICE_ENDPOINTS" ( "LSE_SERIAL" NUMBER(11) NOT NULL PRIMARY KEY, "LSE_VERSION" NUMBER(11) NOT NULL, "LSE_LENDER" NVARCHAR2(50) NULL, "LSE_LENDER_URI" NCLOB NULL ) ; COMMIT; It hasn't created a sequence/trigger for the primary key. Why is this? It does work for tables that have an implicit primary key (ie not specified in the model.) I'm using django 1.0.2. Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Oracle and Primary Keys
On Tuesday 19 May 2009 16:20:58 Karen Tracey wrote: > On Tue, May 19, 2009 at 10:51 AM, Tim Sawyer wrote: > > It hasn't created a sequence/trigger for the primary key. Why is this? > > It does work for tables that have an implicit primary key (ie not > > specified in the > > model.) > > I'd guess because you made it a simple IntegerField rather than an > AutoField. If you want it to be automatically assigned and incremented you > need to make it an AutoField: > > http://docs.djangoproject.com/en/dev/ref/models/fields/#autofield Excellent, thanks Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Newbie Django 1.0 help with create object, uopdate object
On Monday 01 June 2009 01:38:30 adelaide_mike wrote: > I found a really clear explanation of creating and updating database > objects in SAMS TeachYourself Django, but it appears to be for v > 0.96. > > I have looked at "Creating forms from models" in the documentation, > and about one-third the way down it shows the following: > > # Create a form instance from POST data. > > >>> f = ArticleForm(request.POST) > > # Save a new Article object from the form's data. > > >>> new_article = f.save() > > # Create a form to edit an existing Article. > > >>> a = Article.objects.get(pk=1) > >>> f = ArticleForm(instance=a) > >>> f.save() > > # Create a form to edit an existing Article, but use > # POST data to populate the form. > > >>> a = Article.objects.get(pk=1) > >>> f = ArticleForm(request.POST, instance=a) > >>> f.save() > > I understand what these code fragments are intended to do (I think) > but I am not clear as to how to use them. Can someone point me to a > more fully displayed example? TIA > > Mike Here's an example from my code, does this help? Tim. def edit_result(request, pResultSerial): """ Edit a single result row """ lContestResult = get_object_or_404(ContestResult, pk=pResultSerial) if request.user != lContestResult.owner: raise Http404() if request.method == 'POST': form = ContestResultForm(request.POST, instance=lContestResult) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('bbr.contests.views.single_contest_event', args=[lContestResult.contest_event.contest.slug, lContestResult.contest_event.date_of_event])) else: form = ContestResultForm(instance=lContestResult) return render_auth(request, 'contests/edit_result.html', {'form': form, 'ContestResult' : lContestResult}) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Newbie Django 1.0 help with create object, uopdate object
Hi, I think the recommended approach in django is for forms to submit to the current URL and for the view to decide whether the request is to display the form (a HTTP GET) or submit the form (HTTP POST). I'd suggest that you attempt to re-write this way. Your error could be caused by nothing in the POST, if your form is wrong - can you post your HTML? You could also put an intentional error into your view which will cause the Django error window to pop up - this contains details of the POST variables in the request. Here's a well commented and cleaner version of the code I posted earlier: def edit_result(request, pResultSerial): """ This method in views.py takes a single parameter from the url - the serial of an object. It will either display the HTML form to edit that object, or it will accept the submit of a form containing the edited data and save it to the database """ # Get an object from the database, using the passed in serial. Raise a 404 # page not found if the object isn't found lContestResult = get_object_or_404(ContestResult, pk=pResultSerial) # if we are doing a post, the we have data to save. Process it. if request.method == 'POST': # create a form instance, populating it with the data in the object # selected from the database earlier, then overwriting it with the # stuff submitted in the HTML form form = ContestResultForm(request.POST, instance=lContestResult) # run the form validation if form.is_valid(): # save the object inside the form instance to the database form.save() # our save completed, so redirect to the next url you want to go to return HttpResponseRedirect('/url/after/successful/save') else: # we aren't doing a POST, so we need to create a form # instance ready for it to be edited in the HTML. # we create this and populate it from the object we selected above form = ContestResultForm(instance=lContestResult) # show the HTML form to allow the user to edit the object # note that this is indented to the same level as the # "if request is a POST" check, so that if the form.is_valid() check fails, # we go back and show the HTML again with the form containing errors. return render__to_response('contests/edit_result.html', {'form': form}) Hope that helps! Tim. On Monday 01 June 2009 15:56:24 adelaide_mike wrote: > Thanks for your response Tim. However, you lost me a bit there, I am > a real newbie. I have narrowed my question down to this: > > # in views.py: > > class PropertyForm(ModelForm): > class Meta: > model = Property > > def property_update(request, property_id='0', street_id='0'): > print "data/property_save, request.method= ", request.method > message = '' > # we attempt to update an edit > print "attempt to update" > form = PropertyForm(request.POST) > if form.is_valid(): > form.save() > > return render_to_response('wha/property_form.html', {'form': form, > 'message': message}) > > My property_update function is called when the form Save button is > clicked. The various "print" commands operate as expected. However, > the validation fails and a form with no data is returned with > "required data" labels. I conclude the line: > form = PropertyForm(request.POST) > does not populate the validation form. What have I got wrong here? > TIA > > Mike > > On Jun 1, 8:14 pm, Tim Sawyer wrote: > > On Monday 01 June 2009 01:38:30 adelaide_mike wrote: > > > I found a really clear explanation of creating and updating database > > > objects in SAMS TeachYourself Django, but it appears to be for v > > > 0.96. > > > > > > I have looked at "Creating forms from models" in the documentation, > > > and about one-third the way down it shows the following: > > > > > > # Create a form instance from POST data. > > > > > > >>> f = ArticleForm(request.POST) > > > > > > # Save a new Article object from the form's data. > > > > > > >>> new_article = f.save() > > > > > > # Create a form to edit an existing Article. > > > > > > >>> a = Article.objects.get(pk=1) > > > >>> f = ArticleForm(instance=a) > > > >>> f.save() > > > > > > # Create a form to edit an existing Article, but use > > > # POST data to populate the form. > > > > > > >>> a = Article.objects.get(pk=1) > > >
Re: user.is_authenticated
You need a RequestContext for the user object to be available in templates http://lincolnloop.com/blog/2008/may/10/getting-requestcontext-your-templates/ I use a render_auth method instead of render_to_response, which automatically adds the RequestContext to all of my templates. Tim. On Monday 01 June 2009 17:40:53 K.Berkhout wrote: > Hi, > > Is there a way I can access the "user.is_authenticated" method in > every view, without having to manually pass the User model to every > template? Basicly I want to show a login or logout link on every page, > depending on wether the visitor is logged in or not. I've included the > following if statement in my base template: > > {% if user.is_authenticated %} >Welcome {{ user }} , showing logout link... > {% else %} >Showing login link... > {% endif %} > > However, it only works with the standard "accounts/login" view, as > that view has acces to the user.is_authenticated method. > > Thanks, > > Kevin > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
django-reversion with recent svn django
Hi, I'm using django svn 10784, and I've just added django-reversion, latest svn version from trunk (198). I'm using the middleware option for django- reversion. It's not working, and I'm getting the following error. I've tried with the same django version and the tagged 1.1.1 release of django-reversion, but I get the same problem. The error occurs on a save and is: Traceback (most recent call last): File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", line 278, in run self.result = application(self.environ, self.start_response) File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", line 636, in __call__ return self.application(environ, start_response) File "/home/mybandsite/django-trunk/django/core/handlers/wsgi.py", line 245, in __call__ response = middleware_method(request, response) File "/home/mybandsite/src/reversion/middleware.py", line 23, in process_response reversion.revision.end() File "/home/mybandsite/src/reversion/revisions.py", line 263, in end serialized_data = serializers.serialize(registration_info.format, [obj], fields=registration_info.fields) File "/home/mybandsite/django-trunk/django/core/serializers/__init__.py", line 87, in serialize s.serialize(queryset, **options) File "/home/mybandsite/django-trunk/django/core/serializers/base.py", line 44, in serialize self.handle_field(obj, field) File "/home/mybandsite/django- trunk/django/core/serializers/xml_serializer.py", line 70, in handle_field self.xml.characters(field.value_to_string(obj)) File "/home/mybandsite/django-trunk/django/db/models/fields/__init__.py", line 518, in value_to_string data = datetime_safe.new_date(val).strftime("%Y-%m-%d") File "/home/mybandsite/django-trunk/django/utils/datetime_safe.py", line 30, in new_date return date(d.year, d.month, d.day) AttributeError: 'unicode' object has no attribute 'year' I think this might be something to do with my MIDDLEWARE_CLASSES which is set to: MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.transaction.TransactionMiddleware', 'reversion.middleware.RevisionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.doc.XViewMiddleware', ) which doesn't match the recommendation from the django-reversion site. I had to put the AuthenticationMiddleware first so that request.user was available for the RevisionMiddleware to use, and that dragged the SessionMiddleware in too. Any clues anyone? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-reversion with recent svn django
Fixed it. I was assigning a string to a date field. Django is ok with this, django- reversion isn't. Changed: lDate = '%s-%s-%s' % (lYear, lMonth, lDay) lContestEvent.date_of_event = lDate to: lContestEvent.date_of_event = date(int(lYear), int(lMonth), int(lDay)) and all appears fine. Tim. On Tuesday 02 June 2009 22:01:26 Tim Sawyer wrote: > Hi, > > I'm using django svn 10784, and I've just added django-reversion, latest > svn version from trunk (198). I'm using the middleware option for django- > reversion. > > It's not working, and I'm getting the following error. I've tried with the > same django version and the tagged 1.1.1 release of django-reversion, but I > get the same problem. > > The error occurs on a save and is: > > > Traceback (most recent call last): > > File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", > line 278, in run > self.result = application(self.environ, self.start_response) > > File "/home/mybandsite/django-trunk/django/core/servers/basehttp.py", > line 636, in __call__ > return self.application(environ, start_response) > > File "/home/mybandsite/django-trunk/django/core/handlers/wsgi.py", line > 245, in __call__ > response = middleware_method(request, response) > > File "/home/mybandsite/src/reversion/middleware.py", line 23, in > process_response > reversion.revision.end() > > File "/home/mybandsite/src/reversion/revisions.py", line 263, in end > serialized_data = serializers.serialize(registration_info.format, > [obj], fields=registration_info.fields) > > File "/home/mybandsite/django-trunk/django/core/serializers/__init__.py", > line 87, in serialize > s.serialize(queryset, **options) > > File "/home/mybandsite/django-trunk/django/core/serializers/base.py", > line 44, in serialize > self.handle_field(obj, field) > > File "/home/mybandsite/django- > trunk/django/core/serializers/xml_serializer.py", line 70, in handle_field > self.xml.characters(field.value_to_string(obj)) > > File "/home/mybandsite/django-trunk/django/db/models/fields/__init__.py", > line 518, in value_to_string > data = datetime_safe.new_date(val).strftime("%Y-%m-%d") > > File "/home/mybandsite/django-trunk/django/utils/datetime_safe.py", line > 30, in new_date > return date(d.year, d.month, d.day) > > AttributeError: 'unicode' object has no attribute 'year' > > I think this might be something to do with my MIDDLEWARE_CLASSES which is > set to: > > MIDDLEWARE_CLASSES = ( > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.middleware.transaction.TransactionMiddleware', > 'reversion.middleware.RevisionMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.middleware.doc.XViewMiddleware', > ) > > which doesn't match the recommendation from the django-reversion site. I > had to put the AuthenticationMiddleware first so that request.user was > available for the RevisionMiddleware to use, and that dragged the > SessionMiddleware in too. > > Any clues anyone? > > Thanks, > > Tim. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Redirects on HTTPS
Hi, I have a django app that works fine using http. We have a requirement to serve the entire site using https, which is being done at the proxy level - so the Apache that my django is running inside (mod_wsgi) doesn't know about the https. I have a problem with using HttpResponseRedirect - the redirect is changing the URL to be http. Everything else about the URL is right. How do I fix this, and have the redirect go to https? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Redirects on HTTPS
I still can't get this to work (original thread at http://groups.google.com/group/django-users/browse_thread/thread/cdece5ef2e7fd280). I'm looking to get a HttpResponseRedirect in my django app to redirect to HTTPS not HTTP. I've tried: * proxy server Apache (the one doing the SSL) does: SetEnv X-Forwarded-Proto=https * Apache running django/mod_wsgi does this: SetEnvIf X-Forwarded-Proto https HTTPS=on I've also tried: * Hard coding HttpRequest.is_secure() in django to True I've tried changing my wsgi file to do this: _application = django.core.handlers.wsgi.WSGIHandler() def application(environ, start_response): environ['HTTPS'] = 'on' return _application(environ, start_response) but no luck. With everything I've tried, it still redirects back to HTTP on a HttpResponseRedirect. Any clues anyone? thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django with GXmlHttp
Not quite sure what you're looking for, but I've used google maps with django, without using GeoDjango. http://www.brassbandresults.co.uk/map/ The script used in this page is here: http://www.brassbandresults.co.uk/map/map_script.js which is generated using this template: function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); {% if Band %} map.setCenter(new GLatLng({{Band.latitude}}, {{Band.longitude}}), 12); {% else %} map.setCenter(new GLatLng(53.800651, -1.454), 8); {% endif %} map.setUIToDefault(); var mgr = new MarkerManager(map); var lBandMarkers = []; {% for band in Bands %} {% if band.latitude %} {% if band.longitude %} lPoint{{band.id}} = new GLatLng({{band.latitude}}, {{band.longitude}}); lMarker{{band.id}} = new GMarker(lPoint{{band.id}}, {title: "{{band.name}}"}); GEvent.addListener(lMarker{{band.id}}, "click", function() { var myHtml = "{{band.name}}{% if band.rehearsal_night_1 %}Rehearsals {{band.rehearsal_nights}}{%endif%}[Contest Results] [Band Website]"; map.openInfoWindowHtml(lPoint{{band.id}}, myHtml); }); lBandMarkers.push(lMarker{{band.id}}); {% endif %} {% endif %} {% endfor %} mgr.addMarkers(lBandMarkers, 0); mgr.refresh(); } } Hope that helps, Tim. 504Django wrote: > Hmm ... the lack of a suggested solution to my question is > discouraging. The lack of common knowledge in the developer community > leads me to think that, aside from using the GeoDjango module, Django > may not be able to elegantly integrate with Google Maps AJAX API. It > that's truly the case, perhaps I should consider looking at a > different framework before I invest too much more effort. > > > On Nov 23, 10:01 pm, 504Django <504cr...@gmail.com> wrote: >> There seems to be a dearth of examples illustrating best practices in >> deploying Google Maps with Django. >> >> Common recommendations are to use GeoDjango. >> >> Of course, it doesn't have to be Google Maps. It could be >> OpenSteetMap, Yahoo Maps, or some other mapping API. >> >> Not necessarily related, there are also suggestions to use JQuery to >> handle AJAX requests. >> >> I'm trying to understand how to take the next step -- to make the >> required GXmlHttp GET requests calling a Django view that returns >> marker points, while not violating the RESTful nature of Django URLs. >> >> What would be the recommendation? >> >> To help the discussion along with an example, this might be the >> implementation of a pure AJAX solution returning XML with a Get >> request to a PHP page: >> >> var request = GXmlHttp.create(); >> request.open('GET','query.php?var1=' + val1 + '&var2=' + val1, true); >> request.onreadystatechange = function() { >> if (request.readyState == 4) { >> if (request.status == 200) { >> var xmlsource = request.responseXML; >> var markers = >> xmlsource.documentElement.getElementsByTagName >> ("marker"); >> for (var i = 0; i < markers.length; i++) { >> var lat = >> parseFloat(markers[i].getAttribute("lat")); >> var lng = >> parseFloat(markers[i].getAttribute("lng")); >> var latlng = new GLatLng(lat,lng); > > -- > > 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: how to import a library in only in django project
Hi Amit, It depends how you're running. If you're using ./manage.py testserver, then change manage.py to add in your new path. If you're using mod-wsgi, then change the site-wsgi.py file: import os, sys sys.path.append('/home/path/to/add') os.environ['DJANGO_SETTINGS_MODULE'] = 'MySite.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() Hope that helps, Tim. Amit Sethi wrote: > > Hi , > I want to use a library in a django project but I don't want to put it > in python path. Where am I supposed to put the sys.append so that it > will available to the whole django project. > -- > A-M-I-T S|S > > -- > > 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.
Feeds from the Tag Framework
Hi Folks, The complex example of an Atom feed (http://docs.djangoproject.com/en/1.1/ref/contrib/syndication/#a-complex-example) is based on a model where it's possible to work out from a single element in the feed (in this case a Crime), what the driving object is (a Beat). So there's a many (Crime) to one (Beat) relationship going on. I'm using the django tags framework on a blog. Each entry has multiple tags. I'd like to create a feed for each tag. Following this example, I can't figure out what to put in the title method - I can get *all* the tags for a given Blog Entry, but not the one that the feed is for. Am I missing something? Does anyone have an example of this? Cheers, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Oracle cursor.execute problem
Hello. This code works fine: >>> import cx_Oracle >>> lDsn = cx_Oracle.makedsn(lDatabaseHost, int(lDatabasePort), lDatabaseName) >>> lConnectString = "%s/%...@%s" % (lDatabaseUsername, lDatabasePassword, lDsn) >>> lConnection = cx_Oracle.connect(lConnectString) >>> cursor = lConnection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN :out := 'N'; END;", {'out' : lOutput}) >>> print lOutput >>> print lOutput.getvalue() N However, if I change this to get the connection from Django, it all falls in a big heap: >>> from django.db import connection >>> cursor = connection.cursor() >>> import cx_Oracle >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN :out := 'N'; END;", {'out' : lOutput}) Traceback (most recent call last): File "", line 1, in File "/dev/HEAD/INTERNAL/websites/Wam3\django\db\backends\util.py", line 19, in execute return self.cursor.execute(sql, params) File "/web/djangocourse\django\db\backends\oracle\base.py", line 435, in execute query = convert_unicode(query % tuple(args), self.charset) TypeError: not all arguments converted during string formatting Can anyone point me in the direction of how I can fix this? Cheers, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Oracle cursor.execute problem
Ian wrote: On Apr 23, 1:59 pm, Tim Sawyer wrote: Hello. This code works fine: >>> import cx_Oracle >>> lDsn = cx_Oracle.makedsn(lDatabaseHost, int(lDatabasePort), lDatabaseName) >>> lConnectString = "%s/%...@%s" % (lDatabaseUsername, lDatabasePassword, lDsn) >>> lConnection = cx_Oracle.connect(lConnectString) >>> cursor = lConnection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN :out := 'N'; END;", {'out' : lOutput}) >>> print lOutput >>> print lOutput.getvalue() N However, if I change this to get the connection from Django, it all falls in a big heap: >>> from django.db import connection >>> cursor = connection.cursor() >>> import cx_Oracle >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN :out := 'N'; END;", {'out' : lOutput}) Traceback (most recent call last): File "", line 1, in File "/dev/HEAD/INTERNAL/websites/Wam3\django\db\backends\util.py", line 19, in execute return self.cursor.execute(sql, params) File "/web/djangocourse\django\db\backends\oracle\base.py", line 435, in execute query = convert_unicode(query % tuple(args), self.charset) TypeError: not all arguments converted during string formatting Can anyone point me in the direction of how I can fix this? Cheers, Tim. Hi Tim, Django cursors universally use the 'format' dbapi paramstyle rather than the 'named' style natively used by cx_Oracle [1]. To convert your query, replace the parameter markers with %s and pass the parameters as a list rather than a dictionary. If you instead want to work with the underlying cx_Oracle cursor directly, you can access that as cursor.cursor. However, this is not documented API, so don't expect it to be stable. I'm also not sure whether it works at all with the sqlite3 backend. HTH, Ian [1] http://docs.djangoproject.com/en/1.1/topics/db/sql/#connections-and-cursors Thanks all, but I'm getting an ORA error now: >>> import cx_Oracle >>> from django.db import connection >>> cursor = connection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN %s := 'N'; END;", [lOutput]) Traceback (most recent call last): File "", line 1, in File "/home/...snip.../django/db/backends/oracle/base.py", line 349, in execute raise e DatabaseError: ORA-06550: line 1, column 23: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; The symbol ";" was substituted for "end-of-file" to continue. Clues anyone? Cheers, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Oracle cursor.execute problem
Ian wrote: On Apr 25, 11:13 am, Tim Sawyer wrote: >>> import cx_Oracle >>> from django.db import connection >>> cursor = connection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN %s := 'N'; END;", [lOutput]) Traceback (most recent call last): File "", line 1, in File "/home/...snip.../django/db/backends/oracle/base.py", line 349, in execute raise e DatabaseError: ORA-06550: line 1, column 23: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; The symbol ";" was substituted for "end-of-file" to continue. The trailing semicolon is automatically stripped by the backend, which is necessary for most of the queries it runs but incorrect for PL/ SQL. The easiest fix is to add a space or a second semicolon at the end. Or you can do what Django does internally, which is to terminate the PL/SQL block with a forward-slash on its own line after the semicolon, as if the block were to be entered into sqlplus. In that case the forward-slash will be stripped, but the semicolon will be left alone. HTH, Ian Hmm, nearly. That gets around the error, but the return value isn't populated. >>> import cx_Oracle >>> from django.db import connection >>> cursor = connection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN %s := 'N'; END; ", [lOutput]) >>> print lOutput >>> print lOutput.getvalue() None >>> Any more clues, or am I just going to have to stick with creating a specific Oracle connection to do this? Cheers, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Oracle cursor.execute problem
Excellent, I'll give trunk a go. Thanks Ian. Tim. Ian wrote: On Apr 27, 2:36 pm, Tim Sawyer wrote: Hmm, nearly. That gets around the error, but the return value isn't populated. >>> import cx_Oracle >>> from django.db import connection >>> cursor = connection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN %s := 'N'; END; ", [lOutput]) >>> print lOutput >>> print lOutput.getvalue() None >>> Any more clues, or am I just going to have to stick with creating a specific Oracle connection to do this? That would be a bug. I've just checked in a fix, which will be included in Django 1.2 and the next 1.1.X release. If you're not willing to use trunk or wait for the release, my recommendation would be to use cursor.callfunc if possible. Otherwise, you can get the cx_Oracle cursor from cursor.cursor and use that directly. Ian -- 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.
subprocess.Popen breaks dev server
Hi Folks, I have code that does this: lCommand = ["hg","history", "-r", "%s:%s" % (pFrom, pTo)] lProcess = subprocess.Popen(lCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE) in a view. When using the dev server, I'm quite often getting a blank page instead of my HTML, and for each page request the server outputs: Django version 1.2.1, using settings 'dewsbury.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. This is happening on every request. If I comment out the code that does the Popen, it works fine. The Popen command is completing fine, I can print out the output on each request, it's just that the dev server is returning a blank page back to the browser. This is on the 1.2.1 release. I've had a wander around the bugs related to this and the ones I could find seems to be closed as duplicate, or closed worksforme. http://code.djangoproject.com/ticket/9286 http://code.djangoproject.com/ticket/4953 http://code.djangoproject.com/ticket/3712 Clues/pointers appreciated! Cheers, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: No module named site - error deploying a django-jython war in tomcat
I got around this problem by downgrading from jython 2.5.2beta1 to jython 2.5.1. Hope that helps! Tim. On 15/07/10 22:47, Jose Flores wrote: Hi guys, Any workaround on this issue? Regards, Jose On Jul 8, 2:43 pm, Rafael Nunes wrote: Same problem here. Any thoughts? On Jun 29, 10:50 am, tobycatlin wrote: Hello everybody, I have followed the install instructions for the latest versions of the following: jython (version: jython-2.5.2b1), django (1.2.1) and jython-django (version 1.1.1) and have built a war of my very simple test application. Oh i built the war on my linux box and have tested in tomcat on both windows and linux machines. When i went to the url i got a 500 exception: javax.servlet.ServletException: Exception creating modjy servlet: ImportError: No module named site com.xhaus.modjy.ModjyJServlet.init(ModjyJServlet.java:124) javax.servlet.GenericServlet.init(GenericServlet.java:211) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java: 105) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java: 541) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: 148) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java: 869) org.apache.coyote.http11.Http11BaseProtocol $Http11ConnectionHandler.processConnection(Http11BaseProtocol.java: 664) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.ja va: 527) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerW orkerThread.java: 80) org.apache.tomcat.util.threads.ThreadPool $ControlRunnable.run(ThreadPool.java:684) java.lang.Thread.run(Thread.java:619) I have managed to find a fair amount of documentation on building the war but all the docs say "just deploy the war normally" so i guess i have missed something in building the war itself. I set a JYTHONPATH env var, is there anything else i should have done? I can supply the war file, but it is 30mb so if it helps i'll post a link to it for folk to download Thanks for any and all help toby -- 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: URL problem
I think the problem is your regular expression: ^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P\w+)/$ This says - four digits for a year (2010 - ok) - slash - three letters from a-z for month (jul - ok) - slash - one or two letters for day (11 - not ok, this should be \d{1,2}) - slash - slug, made up of one or more letters (1ste-blog-post - not ok, there are hypens and numbers. this should be [-\d\w]+ - slash So, try this: ^(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/(?P[-\d\w]+)/$ Hope that helps, Tim. > Hi, > > i have a strange problem with urls. > > Project name: erp > Application name: blog (and some more) > > problem occurs with certain view of blog-application > > This URL works fine: > http://erp/blog/ > > When I use the URL below, I get an 404-error. > http://erp/blog/2010/jul/11/1ste-blog-post/ > > -8< > Page not found (404) > Request Method: GET > Request URL:http://erp/blog/2010/jul/11/1ste-blog-post/ > > Using the URLconf defined in erp.urls, Django tried these URL patterns, > in this order: > > 1. ^admin/ > 2. ^blog/ ^$ > 3. ^blog/ > ^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P\w+)/$ > 4. ^blog/ ^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$ > 5. ^blog/ ^(?P\d{4})/(?P[a-z]{3})/$ > 6. ^blog/ ^(?P\d{4})/$ > 7. ^card/ > 8. ^dashboard/ > 9. ^todo/ >10. ^comments/ >11. ^accounts/login/$ >12. ^accounts/logout/$ >13. ^accounts/password_change/$ >14. ^accounts/password_change_done/$ > > The current URL, blog/2010/jul/11/1ste-blog-post/, didn't match any of > these. > -8< > > > Project urls.py: > > -8< > from django.conf.urls.defaults import include, patterns, url > from django.contrib import admin > > admin.autodiscover() > > urlpatterns = patterns('', > (r'^admin/', include(admin.site.urls)), > (r'^blog/', include('erp.blog.urls')), > (r'^card/', include('erp.card.urls')), > (r'^dashboard/', include('erp.dashboard.urls')), > (r'^todo/', include('erp.todo.urls')), > (r'^comments/', include('django.contrib.comments.urls')), > (r'^accounts/login/$', > 'django.contrib.auth.views.login', > {'template_name': 'login.html'} > ), > (r'^accounts/logout/$', > 'django.contrib.auth.views.logout', > {'template_name': 'logout.html'} > ), > (r'^accounts/password_change/$', > 'django.contrib.auth.views.password_change', > {'template_name': 'password_change_form.html'} > ), > (r'^accounts/password_change_done/$', > 'django.contrib.auth.views.password_change_done', > {'template_name': 'password_change_done.html'} > ), > ) > -8< > > > blog/urls.py: > -8< > from django.conf.urls.defaults import patterns > from models import Post > > info_dict = { > 'date_field': 'pub_date', > 'queryset': Post.objects.all(), > 'template_name': 'blog_index.html', > 'template_object_name': 'posts', > } > > urlpatterns = patterns('django.views.generic.date_based', > (r'^$', > 'archive_index', > info_dict > ), > > (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P\w+)/$', > 'object_detail', > dict(info_dict, slug_field='slug', > template_name='blog_post.html') > ), > (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', > 'archive_day', > info_dict > ), > (r'^(?P\d{4})/(?P[a-z]{3})/$', > 'archive_month', > info_dict > ), > (r'^(?P\d{4})/$', > 'archive_year', > dict(info_dict, template_name='blog_year.html') > ), > ) > -8< > > > What can be wrong? > > Regards, > Stephan > > -- > 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: Search Field on All Pages
What I do is to setup a search that works at /search/q=search_term, and then create a form on each page that submits to /search. This form is in my top level site template. The /search/ url is part of a search application. There's an example of this working at http://www.brassbandresults.co.uk/ Hope that helps, Tim. On 08/08/10 10:41, wchildsuk wrote: Hi, I want a search field on all my pages and was wondering the best way to do this. I could create a function and import it to every view but this doesn't seem to follow the django DRY principles. I was wondering if anyone had any advice on how to best do this with django? Thank in advance Wes -- 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: Search Field on All Pages
On 08/08/10 14:48, kostia wrote: To continue, Tim, do you use haystack? I passed its beginning tutorial and configured with xapian through haystack-xapian module. Now I'm discovering the other haystack docs and api. Not everything is clear. For example I have a user with name Bob. When I type in the search "ob", it does not return the result, only if I type "Bob", or "bob". Not on http://www.brassbandresults.co.uk/. The search field there searches just the name field of various model objects so it's easier to just do model selects. Here's an article I wrote after using Haystack and Whoosh to improve the search on http://www.drumcoder.co.uk/, if that helps. http://drumcoder.co.uk/blog/2010/may/19/django-text-search-haystack-and-whoosh/ Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: accessing a dictionary in template
On 09/08/10 19:56, owidjaya wrote: in php i can do this $some_mapping = array( "var1" : content_var1, "var2" : content_var2, ) for($i =1; $i< 3; $i++){ echo $some_mapping["var"+$i]; } can i do this in django template? You can do this, where Venue.contests.items is a dictionary. contestname contains the keys, eventcount contains the values. {% for contestname, eventcount in Venue.contests.items %} {{contestname}} {{eventcount}} {% endfor %} -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: javascript
Yes myJavaScriptFunction( {{DjangoTemplateVariable}} ); function myJavaScriptFunction( pValue ) { ... } Tim. > Hi > Is it possible to give a javascript function a django variable as a > parameter? > thank you > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-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: Bind variables in Oracle backend - how to use them?
Friends, I'm in need of an implementation which calls for using bind variables (in Oracle sense, not generic) in my SQL in a Django application. Any experience with that, anyone? Here's an example using bind variables to return output values from a PL/SQL block. >>> import cx_Oracle >>> from django.db import connection >>> cursor = connection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN %s := 'N'; END; ", [lOutput]) >>> print lOutput >>> print lOutput.getvalue() None >>> There was a bug in Django that prevented this working (hence the None in the code above) - it's fixed in Django 1.2. The full thread for this is at http://www.mail-archive.com/django-users@googlegroups.com/msg100490.html Hope that will help send you in the right direction. Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Bind variables in Oracle backend - how to use them?
No, I don't think you're mistaken, especially if you want to use hints. I tried this code again today with the django database connection (using 1.2 final), and it didn't work. This only works with cx_Oracle connections. See http://drumcoder.co.uk/blog/2010/apr/23/output-parameters-cx_oracle-and-plsql/ Ian said in the other thread: "Otherwise, you can get the cx_Oracle cursor from cursor.cursor and use that directly." This sounds like a way of being able to use the django connection but use the direct cx_Oracle functionality. Random thought - have you tried sqlalchemy? Does that have hint support? I've never used it. Tim. On 18/08/10 21:58, buddhasystem wrote: Thanks, I'll look into that. In the meantime, I managed to just use the cursor from cx_Oracle (as in the example on Oracle site) and the code looks slightly more elegant. However, both "my" and yours solution suffer from the same defect imho -- that the ORM machinery of Django is unusable. We are back to manual mapping of rows onto objects... Or -- am I mistaken? Tim Sawyer-6 wrote: Friends, I'm in need of an implementation which calls for using bind variables (in Oracle sense, not generic) in my SQL in a Django application. Any experience with that, anyone? Here's an example using bind variables to return output values from a PL/SQL block. >>> import cx_Oracle >>> from django.db import connection >>> cursor = connection.cursor() >>> lOutput = cursor.var(cx_Oracle.STRING) >>> cursor.execute("BEGIN %s := 'N'; END; ", [lOutput]) >>> print lOutput >>> print lOutput.getvalue() None >>> There was a bug in Django that prevented this working (hence the None in the code above) - it's fixed in Django 1.2. The full thread for this is at http://www.mail-archive.com/django-users@googlegroups.com/msg100490.html Hope that will help send you in the right direction. Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Bind variables in Oracle backend - how to use them?
Excellent, thanks Ian. It works a treat, post updated. Tim. > On Aug 19, 11:58 am, Tim Sawyer wrote: >> No, I don't think you're mistaken, especially if you want to use hints. >> >> I tried this code again today with the django database connection (using >> 1.2 final), and it didn't work. This only works with cx_Oracle >> connections. >> >> Seehttp://drumcoder.co.uk/blog/2010/apr/23/output-parameters-cx_oracle-a... > > There are several reasons why that snippet doesn't work: > > 1) Django cursors don't support passing in the bind parameters in a > dictionary. A sequence type is expected. > > 2) Django cursors use the '%s' syntax for placeholders, not the ':out' > syntax. > > 3) The oracle backend automatically trims a trailing semi-colon from > all queries, because its presence causes ordinary queries to fail. To > prevent it from being trimmed, add some whitespace after the semi- > colon, or add a trailing '/' as in sqlplus if you prefer. > > Correcting these three issues, the snippet works as expected in 1.2. > > On Aug 19, 12:14 pm, buddhasystem wrote: >> I'm 90% sure that you can't get the cx cursor out of Django connection. >> These are similar but different classes. I tried something like that. > > It works like this: > > from django.db import connection > django_cursor = connection.cursor() > cx_cursor = django_cursor.cursor > > This is internal API, so it could change in the future. > > On Aug 18, 2:58 pm, buddhasystem wrote: >> However, both "my" and yours solution suffer from the same defect imho >> -- >> that the ORM machinery of Django is unusable. We are back to manual >> mapping >> of rows onto objects... Or -- am I mistaken? > > The raw query mechanism will do the ORM mapping as long as you match > up the column names correctly when writing the query. The problem > with that is that you can't use cursor.var() directly, because you > don't have direct access to the particular cursor used to run the > query. > > There is some more internal API that may help with this. You can pass > in as a bind parameter an object that has a "bind_parameter" method > with the signature "def bind_parameter(self, cursor)". When the > statement is executed, the cursor will call that method, which is > expected to return the actual bind variable, and substitute the bind > variable for the object. > > For an example, have a look at the "InsertIdVar" class in django/db/ > backends/oracle/base.py, which is used within the "RETURNING INTO" > clause of an insert statement to receive the primary key of the > inserted object. > > Hope this helps, > Ian > > -- > 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: command python not recognized with syncdb
Add your python directory to your PATH Control Panel/System/Advanced/Environment Variables You'll need to restart your DOS box to pick up the new PATH. Type SET in the DOS box to see the values. Tim. On 25/08/10 09:21, yotta wrote: Hi i am new on Djagon and i was fellowing the tutorial (part1); but i had some trouble to execute this command "python manage.py syncdb" and i got error message like what the command python is not recognized as an internal command. the 'mysite' directory is inside the django-121 directory and my python directory is in C:\. i am using windows XP. -- 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: writing HTML Code into Template with render_to_response: How?
On 25/08/10 13:36, mdolphin wrote: OK, that's probably a Newbee Question: My Code generates an HTML-Table, that I want to show up inside a {% block %} in my Template. All I get is an encoded output of my generated HTML-Sourcecode inside the Template. so i.e becomesand so on. How could I achieve it to get my generated HTML- Code inserted "as is" into my Template? Instead of {{output}} use {{output|safe}} http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#safe Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: SITE_ID
On 25/09/10 15:57, craphunter wrote: Yes, I have read it, but I don't really get it. What is the meaning of it? Consider a website that has multiple blogs, all of which are deployed to the same database. Consider that you want each blog to be a separate URL: www.blog1.com, www.blog2.com, but you only want one database for ease of backing up etc. So, you have one codebase, one database, but multiple sites. You can achieve this using SITE_ID. www.blog1.com has a settings.py with SITE_ID = 1. www.blog2.com has a settings.py file with SITE_ID = 2. In your database, there are two rows in the django_site database table, with serials 1 and 2. The table that holds the blog entries has a foreign key to Site, and so identifies which site the blog post appears on. At least that's how I used it...hope that helps clarify it a bit! Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 on Apache
On 25/09/10 16:07, Derek wrote: I am about a week into learning Django, having developed with PHP and the CodeIgniter framework for the past 3 years. That said, I'm used to making a change to a file, refreshing my browser and seeing the results. Django's "syncdb" aside, it's been pretty weird having to restart the Django webserver manually on certain occasions. Is this also the case when running Django on Apache? If not, can I set up Django to run with MAMP locally? If you're developing, you can use the built in test server and that will pick up changes without refreshing. If you're deploying on apache using mod_wsgi, you can set that up to automatically pick up your changes when the code updates. Details at: http://drumcoder.co.uk/blog/2009/nov/21/apache-mod_wsgi-config/ Hope that helps, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 on Apache
On 25/09/10 19:36, Derek wrote: on several occasions I've made changes to a view, and got a "cannot load page/no response" (from the browser, not a Django error). Once I quit the server (Control-C), start it up again and refresh the page, it works fine. I get that sometimes too - I think it's just reloading the server as it has noticed a code change. Refresh again in the browser and it's usually working again. I find that if you're developing a template tag it's sometimes required to restart the server to pick up the new code. What I tend to do is try not to restart, and if something isn't working I'll restart the test server as my first test. If it still doesn't work then it's more than likely my fault rather than the server's... Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: error in urlconf
On 25/09/10 20:39, CarloRatm wrote: http://pastebin.com/aY6tZm6j What's wrong with that code ? Thank you, cheers ^blog/ ^(?Pd+)$ should be ^blog/ ^(?P\d+)/$ ?? Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: error in urlconf
On 25/09/10 21:14, bagheera wrote: Dnia 25-09-2010 o 22:04:16 Tim Sawyer napisał(a): On 25/09/10 20:39, CarloRatm wrote: http://pastebin.com/aY6tZm6j What's wrong with that code ? Thank you, cheers ^blog/ ^(?Pd+)$ should be ^blog/ ^(?P\d+)/$ ?? Tim. use raw definitions like django docs says. And why do u put ^ witch means beginning of the string in the middle? That i think would be correct: r'^articles/(?P\d+)/$' I wasn't clear. I was correcting the error message, given that the provided pastebin link didn't include any of the source, but only the 404 text. The error appears to be from two levels of urls.py. The first something like: (r'^blog/', include('application.urls')), And the second, inside the application/urls.py file, is something like: (r'^(?Pd+)', 'applications.views.view_function'), This second one is wrong, I believe it should be: (r'^(?P\d+)/', 'applications.views.view_function'), I hope that is clearer, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: SITE_ID
> On 25/09/2010 18:32, Tim Sawyer wrote: >> On 25/09/10 15:57, craphunter wrote: >>> Yes, I have read it, but I don't really get it. What is the meaning of >>> it? >> >> Consider a website that has multiple blogs, all of which are deployed to >> the same database. >> >> Consider that you want each blog to be a separate URL: www.blog1.com, >> www.blog2.com, but you only want one database for ease of backing up >> etc. >> >> So, you have one codebase, one database, but multiple sites. >> >> You can achieve this using SITE_ID. www.blog1.com has a settings.py >> with SITE_ID = 1. www.blog2.com has a settings.py file with SITE_ID = >> 2. In your database, there are two rows in the django_site database >> table, with serials 1 and 2. The table that holds the blog entries has >> a foreign key to Site, and so identifies which site the blog post >> appears on. >> >> At least that's how I used it...hope that helps clarify it a bit! >> >> Tim. > > Hey Tim, > > the way you used it would mean that you had different settings.py per > site/url and thus > a project per url as 1 project can only have 1 settings file? Is this > correct? > Have do you config the admin then so you see both sites in the same admin? Hi Benedict, Yes that's correct. Each settings.py is a separate virtual host in Apache. The rest of the source was common (on the pythonpath). So the pythonpath was the same for each virtual host but there was a uniquely named settings.py refered to from the mod-wsgi config. These were distinct sites for distinct customers, so each site had its own admin, limited to that site's data. Here's the mechansim I used to limit the admin to that site's objects. I think if you don't do any of this, each admin will have all the data available in it, if that's what you want. Each model had an additional manager: from django.contrib.sites.managers import CurrentSiteManager class Contest(models.Model): ... objects = models.Manager() on_site = CurrentSiteManager() and in the admin.py I redefined the queryset: class ContestAdmin(SiteOnlyAdmin): def queryset(self, request): return self.limitQueryset(request, Contest) admin.site.register(Contest, ContestAdmin) where limitQueryset is defined on the superclass as: def limitQueryset(self, request, pObject): return pObject.on_site.all() Hope that helps, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Removing the 'site' (not the website/url) field from django-comments
> Hi all, > > I'm trying to have comments on my sites shown on all other sites, as I > have a 'mobile' skin for my site on a separate domain and site_id. > > So for example: > Joe posts a comment on http://www.site1.mydomain.com > > Mary goes to http://www.mobilesite.mydomain.com and can see and > respond to Joe's comment. > > I'm not highly experienced in Django or programming in general, it > looks like I will need to override some functions and classes such as > BaseCommentNode and some template tags, and remove 'site__pk = but > I'm not sure which ones or how to do it. When I did something similar, I had the same SITE_ID for the two projects. The two sites still had their own settings.py and application source. The key things that were different in settings.py were that ROOT_URLCONF pointed to different URLs, and TEMPLATE_DIRS pointed to different top level templates. In that way I have different sites, but still referring to the same database tables, and crucially the same SITE_ID, so you wouldn't have the problem with django-comments. Would that work for you? Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Adding help text to Django admin
Set help_text on the appropriate model field name = models.CharField(max_length=100, help_text='Current name of band') Tim. On 04/10/10 09:46, Sithembewena Lloyd Dube wrote: Greetings folks, I need to add "help text" to a Django admin. Sort of like the text below fields in the Django Redirects app. to provide a snippet of information about each field. How can I achieve this? -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.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. -- 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: apache reload
On Oct 3, 5:39 pm, Олег Корсак wrote: Hello. I'm using mod_wsgi 3.3 + apache 2.2.16 on Gentoo Linux box. Is it possible to make apache kinda "reload"/"re-read"/"re-compile" python files from my django code every time they are changed? Yes. You get get mod_wsgi to watch your source files and reload if they change. See http://drumcoder.co.uk/blog/2009/nov/21/apache-mod_wsgi-config/ Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 graphs
I've used http://teethgrinder.co.uk/open-flash-chart-2/ and http://g.raphaeljs.com/ To do charts in a Django app. Tim. > ashy wrote: >> Hi All, >> >> I want to create line graph in django. I have installed django graphs, >> but there aren't sufficient examples for line graphs in the examples >> folder. Any ideas how should I go ahead for graphs in django? >> >> thanks >> ashwin >> > > -- > Thomas Guettler, http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de > > -- > 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 and Flux
> You cant combine Django and Flex Builder - but you can write apps using > Django and Flex. With Flex 3 (and maybe 4, I don't know) you could install it as an Eclipse Plugin, instead of standalone. You could then install pydev into Eclipse as well, and edit both sides of the app in the same Eclipse instance. Having said that, we use Flex standard install for Flex development, and a seperate Eclipse isntance for the back ends (Java/Python/Whatever). It's more stable that way. Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Postgres LATIN1 to UTF-8
Hi Folks, Does anyone have a recommended method for converting a Postgres database from LATIN1 to UTF-8? Am I best sticking to postgres tools or will dumpdata help? I already have accents in my LATIN1 data, and postgres doesn't like importing these back into a database with encoding utf8. For this I used pg_dump to create a sql file, then just ran it from an empty utf8 database. Cheers, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Postgres LATIN1 to UTF-8
On 08/11/10 07:03, Christophe Pettus wrote: On Nov 7, 2010, at 2:17 PM, Tim Sawyer wrote: Does anyone have a recommended method for converting a Postgres database from LATIN1 to UTF-8? Probably the most efficient way is to use pg_dump with the --encoding option: Dump the database in UTF8, and then import it back into a new database created as UTF8. Thanks, that appears to do what I need! Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Mobile website using Django
If it helps, I've used iui and now jquery mobile with Django. http://code.google.com/p/iui/ http://jquerymobile.com/ Some random scribblings of mine on jQueryMobile here: http://drumcoder.co.uk/blog/2010/nov/12/jquery-mobile-basics/ Tim. On 18/11/10 20:51, Helge wrote: Hi I wish to develop a website that is optimized for mobile using Django. Is there any "standard" mobile framework for Django? I've found a couple of Django projects [1] [2] [3] [4] that provide functionality needed for mobile development (like device detection, browser detection, WURFL). Does anyone have experiences with these projects. Which would you recommend? [1] code.google.com/p/django-bloom/ [2] code.google.com/p/djangobile [3] http://sourceforge.net/projects/mobiledjango/ [4] https://github.com/gregmuellegger/django-mobile Best regards, Helge -- 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.
ORA-01425
Hello, I'm using Django against an Oracle 10 database. It used to work. Then they upgraded it to 10.2.0.5 (not sure what from, I can probably find out). This query now gives: ORA-01425: escape character must be character string of length 1. 'SELECT "BROKER_LENDER_LOG"."BLL_SECURITY_TOKEN", "BROKER_LENDER_LOG"."BLL_TRANSACTION", "BROKER_LENDER_LOG"."BLL_TYPE", "BROKER_LENDER_LOG"."BLL_AGREEMENT_NUMBER", "BROKER_LENDER_LOG"."BLL_MODULE", "BROKER_LENDER_LOG"."BLL_LENDER", "BROKER_LENDER_LOG"."BLL_SERIAL", "BROKER_LENDER_LOG"."BLL_VERSION", "BROKER_LENDER_LOG"."BLL_JOBID", "BROKER_LENDER_LOG"."BLL_PROJECT", "BROKER_LENDER_LOG"."BLL_XML", "BROKER_LENDER_LOG"."BLL_LENDER_RESPONSE", "BROKER_LENDER_LOG"."BLL_DATE" FROM "BROKER_LENDER_LOG" WHERE ("BROKER_LENDER_LOG"."BLL_JOBID" LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) AND "BROKER_LENDER_LOG"."BLL_MODULE" = %s ) ORDER BY "BROKER_LENDER_LOG"."BLL_SERIAL" ASC' I guess the problem is: LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) where it thinks that \'\\\' is more than one character? Cheers for any clues, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: ORA-01425
Interesting. I'm using Django 1.2.3. I just manually applied the diff from http://code.djangoproject.com/ticket/5985 which is to change from LIKE to LIKEC and it works now. Has this regressed for some reason? Looks like it was http://code.djangoproject.com/browser/django/trunk/django/db/backends/oracle/base.py?rev=12293 that regressed back to LIKE. http://code.djangoproject.com/ticket/11017 the reason. Tim. On 02/12/10 15:13, Tim Sawyer wrote: Hello, I'm using Django against an Oracle 10 database. It used to work. Then they upgraded it to 10.2.0.5 (not sure what from, I can probably find out). This query now gives: ORA-01425: escape character must be character string of length 1. 'SELECT "BROKER_LENDER_LOG"."BLL_SECURITY_TOKEN", "BROKER_LENDER_LOG"."BLL_TRANSACTION", "BROKER_LENDER_LOG"."BLL_TYPE", "BROKER_LENDER_LOG"."BLL_AGREEMENT_NUMBER", "BROKER_LENDER_LOG"."BLL_MODULE", "BROKER_LENDER_LOG"."BLL_LENDER", "BROKER_LENDER_LOG"."BLL_SERIAL", "BROKER_LENDER_LOG"."BLL_VERSION", "BROKER_LENDER_LOG"."BLL_JOBID", "BROKER_LENDER_LOG"."BLL_PROJECT", "BROKER_LENDER_LOG"."BLL_XML", "BROKER_LENDER_LOG"."BLL_LENDER_RESPONSE", "BROKER_LENDER_LOG"."BLL_DATE" FROM "BROKER_LENDER_LOG" WHERE ("BROKER_LENDER_LOG"."BLL_JOBID" LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) AND "BROKER_LENDER_LOG"."BLL_MODULE" = %s ) ORDER BY "BROKER_LENDER_LOG"."BLL_SERIAL" ASC' I guess the problem is: LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) where it thinks that \'\\\' is more than one character? Cheers for any clues, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: ORA-01425
On 02/12/10 15:40, Jirka Vejrazka wrote: I'm using Django against an Oracle 10 database. It used to work. Then they upgraded it to 10.2.0.5 (not sure what from, I can probably find out). Hi Tim, sorry, I don't have a solution for you, but you might want to check out http://code.djangoproject.com/ticket/14149 and add description of your environment there so there is more "use cases" listed there. Actually, I do have a solution - I do monkeypatch the Oracle backend so it matches my version of Oracle (i.e. 2 or 4 backslashes). Cheers Jirka P.S. This got me thinking - maybe the Oracle backend could do some "autodetection" of which version works fine in the current environment? Yes, it'd be extra query at startup I guess, but don't really see any other way... Thanks for that. Interesting that I'm seeing this in an upgrade from 10.2.0.4 to 10.2.0.5. Instead of changing from LIKE to LIKEC - if I add more backslashes will that work? Cheers, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: ORA-01425
On 02/12/10 19:14, Jirka Vejrazka wrote: It looks as though something like that may be necessary. For those of you running into this problem, do you get the error with the following query? cursor.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING NCHAR_CS) LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") No error for me, but that's on a monkeypatched system. I can try without the patch, but only after weekend :( In [7]: res = c.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING NCHAR_CS) LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") In [8]: list(res) Out[8]: [(u'1',)] Jirka I unpatched mine (changed LIKEC to LIKE) and then ran: >>> from django.db import connection >>> cursor = connection.cursor() >>> result = cursor.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING NCHAR_CS) LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") >>> rows = cursor.fetchall() >>> for row in rows: > ... print row[0] > ... > 1 >>> print rows > ((1,),) Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Initial Create Table Script
Is there a way to generate a sql script that gets the entire table structure required for a django project? Including contrib.auth etc. ./manage.py sql django.contrib.auth is giving me: Error: App with label django.contrib.auth could not be found. Are you sure your INSTALLED_APPS setting is correct? INSTALLED_APPS = ( 'django.contrib.auth', ... ) I don't have direct access to the database that I'm running against on a customer site - therefore I need a script to create the database. Thanks, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Initial Create Table Script
Excellent, thanks. I needed to run ./manage.py sql auth ./manage.py sql sites ./manage.py sql sessions ./manage.py sql admin ./manage.py sql contenttypes to get what I needed. Cheers, Tim. On 03/12/10 12:45, Anurag Chourasia wrote: Yes there is. You need to use *./manage.py sql auth* instead of *./manage.py sql django.contrib.auth* Regards, Anurag On Fri, Dec 3, 2010 at 5:48 PM, Tim Sawyer mailto:list.dja...@calidris.co.uk>> wrote: Is there a way to generate a sql script that gets the entire table structure required for a django project? Including contrib.auth etc. ./manage.py sql django.contrib.auth is giving me: Error: App with label django.contrib.auth could not be found. Are you sure your INSTALLED_APPS setting is correct? INSTALLED_APPS = ( 'django.contrib.auth', ... ) I don't have direct access to the database that I'm running against on a customer site - therefore I need a script to create the database. Thanks, Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com <mailto:django-users%2bunsubscr...@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. -- 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: ORA-01425
On 03/12/10 12:52, Jani Tiainen wrote: On Thursday 02 December 2010 17:13:48 Tim Sawyer wrote: Hello, I'm using Django against an Oracle 10 database. It used to work. Then they upgraded it to 10.2.0.5 (not sure what from, I can probably find out). This query now gives: ORA-01425: escape character must be character string of length 1. 'SELECT "BROKER_LENDER_LOG"."BLL_SECURITY_TOKEN", "BROKER_LENDER_LOG"."BLL_TRANSACTION", "BROKER_LENDER_LOG"."BLL_TYPE", "BROKER_LENDER_LOG"."BLL_AGREEMENT_NUMBER", "BROKER_LENDER_LOG"."BLL_MODULE", "BROKER_LENDER_LOG"."BLL_LENDER", "BROKER_LENDER_LOG"."BLL_SERIAL", "BROKER_LENDER_LOG"."BLL_VERSION", "BROKER_LENDER_LOG"."BLL_JOBID", "BROKER_LENDER_LOG"."BLL_PROJECT", "BROKER_LENDER_LOG"."BLL_XML", "BROKER_LENDER_LOG"."BLL_LENDER_RESPONSE", "BROKER_LENDER_LOG"."BLL_DATE" FROM "BROKER_LENDER_LOG" WHERE ("BROKER_LENDER_LOG"."BLL_JOBID" LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) AND "BROKER_LENDER_LOG"."BLL_MODULE" = %s ) ORDER BY "BROKER_LENDER_LOG"."BLL_SERIAL" ASC' I guess the problem is: LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) where it thinks that \'\\\' is more than one character? Cheers for any clues, I'm running against 10.2.0.5 (64 bit) and I don't see that problem appear. Same appliest to other 10.2.0.x series, all of them work with that LIKE part. Reason just was that LIKEC queries took ages in my modest 21M rows containing address table. Could that be some artifacts from upgrade migration progress - I know it has happened sometimes. Can you also post you charsets you're using, maybe they're causing some oddities here - with Oracle you never know . Hi, We're on Solaris Sparc, 64-bit. Charset is WE8MSWIN1252 Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: ORA-01425
On 03/12/10 17:29, Ian wrote: On Dec 2, 3:17 pm, Tim Sawyer wrote: I unpatched mine (changed LIKEC to LIKE) and then ran: >>> from django.db import connection >>> cursor = connection.cursor() >>> result = cursor.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING NCHAR_CS) LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") >>> rows = cursor.fetchall() >>> for row in rows: > ... print row[0] > ... > 1 >>> print rows > ((1,),) Nuts. What if you remove the first TRANSLATE call, i.e. cursor.execute(r"SELECT 1 FROM DUAL WHERE 'A' LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") If that also doesn't trigger the error, then maybe we need an actual column in the mix. Please try this also: cursor.execute(r"SELECT 1 FROM DUAL WHERE DUMMY LIKE TRANSLATE('X' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") Thanks, Ian Oracle is very weird sometimes. >>> from django.db import connection >>> cursor = connection.cursor() >>> result = cursor.execute(r"SELECT 1 FROM DUAL WHERE 'A' LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") >>> rows = cursor.fetchall() >>> for row in rows: ...print row[0] ... 1 >>> print rows ((1,),) >>> result = cursor.execute(r"SELECT 1 FROM DUAL WHERE DUMMY LIKE TRANSLATE('X' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)") Traceback (most recent call last): File "", line 1, in File "/dev/HEAD/BESPOKE/app/websites/app\django\db\backends\util.py", line 15, in execute return self.cursor.execute(sql, params) File "/dev/HEAD/BESPOKE/app/websites/app\django\db\backends\oracle\base.py", line 507, in execute return self.cursor.execute(query, self._param_generator(params)) DatabaseError: ORA-01425: escape character must be character string of length 1 Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Apache & mod_wsgi are configured correctly. Need Django to recognize my django.wsgi file.
Here's the config I'm using for mod_wsgi: http://drumcoder.co.uk/blog/2009/nov/21/apache-mod_wsgi-config/ Hope that helps, Tim. On 11/12/10 23:35, jc wrote: You definitely lost me in some places but you've also cleared some things up in the process. I also noticed that I had "", which is lacking a directory for the WSGIScriptAlias. I've fixed that now. *Now*, I no longer get my listing of my files in my project when I go to my address *but* I now get 500 Internal Server Error. I'm not sure if I should trust the logs or maybe I've misconfigured something else (either in Apache or in my django.wsgi file)...I had this same issue yesterday 500 error... Also, when you said "Somewhere in your Apache config you have denied access to the entire filesystem", do you mean *Apache* has done this so that it will keep others out of my project (not that I've actually done this somewhere, right?) After these changes, the project is still not running and I'm still not sure if it's my django app that's the issue or wsgi and my Apache configs. :/ thanks for the reply back, I do appreciate it... j. On Dec 11, 5:29 pm, Mike Dewhirst wrote: On 12/12/2010 7:14am, jc wrote: Apache&mod_wsgi are configured correctly (I've created a hello world .html apache file and a hello world mod_wsgi application with no problems). I know need my Django app to recognize my django.wsgi file. What makes me think that it's not recognizing my wsgi file is that I went into my django.wsgi file I created and completely deleted all of the code in the file and restarted Apache and it still gives me the same page (a listing of the files from Django app, not my actual Django application. Configuring Apache and mod_wsgi went really well but I'm at a loss of how to fix this. Here are some details instead of "it's not working": You are correct. Apache is not looking at the wsgi script. Have a look at the suggestions below ... before playing with django.wsgi. Here is my current django.wsgi file: import os import sys sys.path.append('/srv/www/duckling.org/store/') os.environ['PYTHON_EGG_CACHE'] = '/srv/www/duckling.org/ store/.python- egg' os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() I've tried a few different versions of the django.wsgi file (including a version like the one over athttp://www.djangoproject.com/). This version of my wsgi is from here: http://library.linode.com/frameworks/django-apache-mod-wsgi/ubuntu-10... Also, here is my vhost apache configuration file below. I think these are the main files that are suppose to do the job for me. Let me know if you see any errors in what I'm doing and what else I might do to fix this. The django app runs fine on the django's built-in development server so I'm thinking it *might have* something with my paths. No errors in my apache error.log file as well. It's acting as there's no problem at all, which is not the case...the project isn't loading, like I said just a listing of my files and directories of my Django project. Here is my apache config file: ServerAdmin h...@duckling.org ServerName duckling.org ServerAliaswww.duckling.org DocumentRoot /srv/www/duckling.org/store/ # DocumentRoot is where you keep non-django stuff eg., static files # which is served by Apache without needing your Django code DocumentRoot /srv/www/duckling.org/htdocs/ Order Allow,Deny Allow from all # now let the public access anything here AllowOverride None Order deny,allow Allow from all WSGIScriptAlias /django /srv/www/duckling.org/store/wsgi-scripts/ django.wsgi Order allow,deny Allow from all Somewhere in your Apache config you have denied access to the entire filesystem to prevent outsiders from hacking in. Your Django code must also be hidden from outsiders so it will live safely in /srv/www/duckling.org/store because you haven't allowed anyone except Apache to see it. Now you need to provide an allowed conduit to your Django code. So make an Apache script alias to map the website root (ie '/') to your Django code. Because you are using mod_wsgi the entry point is your django.wsgi script. So map / to the script: WSGIScriptAlias / /srv/www/duckling.org/store/wsgi-scripts/django.wsgi # and give the public full access - but only to the entry point Order deny,allow Allow from all hth Mike And here are versions of the stack that I'm using, I saw over at the mod_wsgi site that you all would like the versions of what I'm using on the server: Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.5 with Suhosin-Patch mod_python/3.3.1 Python/2.6.5 mod_wsgi/2.8 I would remove mod_python if possible thanks, j. -- 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..
Optimistic Locking
Hi Folks, I'm just evaluating django for use on a project. I have a multiuser application where many users can be changing data at once. What's the status of hibernate style optimistic locking, where each object has a version and update/deletes are prevented if the last saved version of that object is newer than the one being saved? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Newbie Question
My model includes: surname = models.CharField(maxlength=50) forenames = models.CharField(maxlength=50) def __str__(self): return self.name def name(self): return self.forenames + ' ' + self.surname Referencing name in a template works fine, but in the admin site I get __str__ returned non-string (type instancemethod) when displaying a list of my object. why is this? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Newbie Question
On Tuesday 29 Jan 2008, Tim Chase wrote: > your __str__ returns a function...you omitted the call to that > function: > > def __str__(self): > return self.name() Ah - knew it would be obvious. Thanks. Simple typo on my part, I've just split the name field in two, so it used to be a property. On Tuesday 29 Jan 2008, Krzysztof Ciesielski wrote: > No problem, but better read Dive into python first :D I read the O'Reilly python book ages ago...am rusty! I'm a java developer really, experimenting with something better. Er, I'll get my coat... Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Newbie Question
Thanks everyone, I've been reading my Python In a Nutshell ("covers python 2.2!") and it's reminded me of what I've forgotten! Any suggestions for good books? Was going to get the django book and the O'Reilly Python Cookbook. On Tuesday 29 Jan 2008, Ivan Illarionov wrote: > or, better: >def name(self): > return '%s %s' % (self.forenames, self.surname) why is this "better"? Performance or just clearer code? Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Optimistic Locking
On Sunday 03 Feb 2008, code_berzerker wrote: > How about rewriting save method complately and make additional > condition in WHERE clausule like this: > UPDATE ... WHERE id=666 AND mtime=object_mtime > Checking number of updated rows would give you information about > success and would guarantee that there is no data manipulation between > mtime check and save. If you're going to do that, then couldn't we change the framework to add a new VersionField. If there is a VersionField defined on the object, then the code on save could automatically be added. This VersionField would simply hold a version number for the record, that is incremented at save. This is a similar idea to the date thing, but slightly more robust - in a high traffic environment there is a theoretical (albeit small) possibility of two objects picking up the same time. This is how hibernate recommends that you do it. I saw someone suggesting this method on this mailing list (found it with a web search I did when I first started looking at django), this sounds like the optimum solution for optimistic locking to me, and it would open up more use cases for django, at least for me. Would this be straightforward to add? Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Optimistic Locking
On Monday 04 Feb 2008, Michael Hipp wrote: > Tim Sawyer wrote: > > If you're going to do that, then couldn't we change the framework to add > > a new VersionField. If there is a VersionField defined on the object, > > then the code on save could automatically be added. This VersionField > > would simply hold a version number for the record, that is incremented at > > save. This is a similar idea to the date thing, but slightly more robust > > - in a high traffic environment there is a theoretical (albeit small) > > possibility of two objects picking up the same time. > > > > This is how hibernate recommends that you do it. I saw someone > > suggesting this method on this mailing list (found it with a web search I > > did when I first started looking at django), this sounds like the optimum > > solution for optimistic locking to me, and it would open up more use > > cases for django, at least for me. > > > > Would this be straightforward to add? > > I'd love to see something like this added. > > Can it be done entirely in SQL or does it require some stored triggers > or rules in the database? I believe it can be done entirely in SQL. * Select Object (for example ID, Version, Surname, Forename) - version column defaults to 0 for new inserts * When object is updated, do an UPDATE blah WHERE id = :id and version = :version. If your update updated no rows, raise a locking error There would also have to be code added into the admin front end to deal with locking errors. Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Deploying django framework with site
Folks, Has anyone got any documentation on deploying the django framework as part of the site? I'm considering using django for an app at work (on Oracle - so need SVN version?) and our release team will want a self contained site to deploy. They're used to WAR files and like them. It'll be a struggle to get them to install mod_python never mind getting a framework out of SVN! Ta, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problems selecting correct object in view
Hi Folks, I'm sure I'm missing something here, can anyone enlighten me? In my urls.py I have: (r'^(\d+)/$', 'rtb2.contests.views.single_contest'), and in my views.py I have def single_contest(request, pSerial): lContest = Contest.objects.filter(pk=pSerial) return render_to_response('single_contest.html', {"Contest" : lContest}) lContest seems to be null, so the html doesn't render with any content. If I change the filter line to be lContest = Contest.objects.all()[0] Then it works and displays the html correctly with data in. This code in a shell works fine: >>> pSerial = 1 >>> lContest = Contest.objects.filter(pk=pSerial) >>> print lContest [] I am new at python. Can someone point me in the right direction please? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problems selecting correct object in view
On Saturday 16 Feb 2008, Nils L wrote: > Hi Tim, > Contest.objects.filter(pk=pSerial) yields a list (in this case of > length 1), not a Contest object. If you want to fetch a single object > based on it's primary key you can use: Contest.objects.get(pk=pSerial) > See http://www.djangoproject.com/documentation/tutorial01/ Of course! Knew it would be straightforward. Many thanks. Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Authentication Question
Hi Folks, I've read the docs for authentication but I can't see how I can replicate existing functionality I have using php. I have a directory /private on the web server, marked using .htaccess and .htpasswd to only allow access if a username is passed. Anything I put inside this directory (images, html etc) all require the password before the asset can be returned to the browser. Is there any way to do this with django auth? I need to have confidence that nothing can be returned (including direct image urls) from the /private directory without login. Can I use http .htaccess style authentication with django? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Authentication Question
On Monday 18 Feb 2008, Rajesh Dhawan wrote: > If you want to make Apache use a Django auth backend, > take a look at: > http://www.djangoproject.com/documentation/apache_auth/ Thanks Rajesh, I think this is exactly what I was fumbling towards! (Excellent analysis of my non-MVC ramblings as well, bravo) Cheers, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Assigning Dates to DateField instances
I'm not sure I understand what I'm doing here. I'm trying to create an Event object from the data in a form (a simple html form, not a django form). I want to do this: lDay = int(request.POST['DayNo']) lMonth = int(request.POST['MonthNo']) lYear = int(request.POST['YearNo']) lEvent = Event(request.POST) if lEvent.id == 0: lEvent.id = None lEvent.date = datetime(lYear,lMonth,lDay) lEvent.save() and I'm getting the error Exception Type: ProgrammingError Exception Value:can't adapt Exception Location: /usr/lib/python2.5/site-packages/django/db/backends/util.py in execute, line 12 where the last bit of my code it hit was the save method. Have I obviously done something wrong or is the problem data related? I suspect it's caused by the date assignment? Any thoughts/pointers appreciated. Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Using mod in if in template
Hi Folks, I want to do this: {% for image in Images %} {{ image.name }} {{ image.comment }} {% if forloop.counter % 4 %} {% endif %} {% endfor %} which should hopefully give me a gallery of images where each line has four thumbnails on it. Unfortunately, I can't do the mod (%) in the if statement, as it's not valid syntax. Is there a way around this, or a simpler solution? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using mod in if in template
On Monday 24 Mar 2008, James Bennett wrote: > The first thing to do is to step back and remember that the Django > template language is not Python I know that - writing it as python code was the quickest way to get across what I wanted! :-) > The second thing to do is to read the template documentation to see > what is available, because doing so will turn up things like this: > > http://www.djangoproject.com/documentation/templates/#divisibleby I saw that, but I couldn't work out how to conditionally output html based on its value. {% if forloop.counter|divisibleby: "4" %} doesn't work. On Monday 24 Mar 2008, Michael Wieher wrote: > Can you simulate it with an incremental variable? Sorry, I don't know what you mean. Can you explain more or give me a quick example? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using mod in if in template
On Monday 24 Mar 2008, Evert Rol wrote: > On 24 Mar 2008, at 19:29 , Tim Sawyer wrote: > >> The second thing to do is to read the template documentation to see > >> what is available, because doing so will turn up things like this: > >> > >> http://www.djangoproject.com/documentation/templates/#divisibleby > > > > I saw that, but I couldn't work out how to conditionally output html > > based on > > its value. {% if forloop.counter|divisibleby: "4" %} doesn't work. > > If that's your literal code, you should probably remove the space > between the colon and quote: divisibleby:"4" A-ha, sorted thanks. It wasn't obvious from the documentation that I read that you could actually use the filters inside {% %} blocks. I know better now! Thanks again everyone, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: tutorial __str__() method not working
Looks like your indentation is wrong (assuming it's not just a copy/paste issue). Remember python code needs to be indented correctly in order to work. Your def __str__(self): line needs to start at the same indentation as the attributes (question/pub_date) inside your class. Tim. On Wednesday 26 Mar 2008, [EMAIL PROTECTED] wrote: > Hello, > > I'm just going through the mysite tutorial and can't seem to get the > __str__() method to work when adding it to the two classes, I still > get []. > > polls/models.py: > > from django.db import models > import datetime > > class Poll(models.Model): > question = models.CharField(maxlength=200) > pub_date = models.DateTimeField('date published') > def __str__(self): > return self.question > def was_published_today(self): > return self.pubdate.date() == datetime.date.today() > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice = models.CharField(maxlength=200) > votes = models.IntegerField() > def __str__(self): > return self.choice > > Thanks for any help, > > Jason > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
mod_python authentication problem
Hi, I'm trying to secure /site_media/private and /site_media/pictures so that only logged in users can see the files in those directories and below. The error I'm getting (sometimes - seems to be a bit inconsistent) is [Fri Mar 28 09:39:06 2008] [error] [client XXX.XXX.XXX.XXX] PythonAuthenHandler django.contrib.auth.handlers.modpython: ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined., referer: http://site/private/pictures/ Here's my apache virtual host configuration (site name changed to site). Have I done anything obviously wrong? The PythonPath entries are indented correctly in the original. Thanks, Tim ServerAdmin [EMAIL PROTECTED] ServerName www.site ServerAlias site DocumentRoot /home/tjs/web/site Options -Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all allow from all CustomLog /home/tjs/log/site pink AuthType Basic AuthName "site" Require valid-user AuthBasicAuthoritative Off AuthzDefaultAuthoritative Off AuthzGroupFileAuthoritative Off AuthzUserAuthoritative Off SetEnv DJANGO_SETTINGS_MODULE site.settings PythonPath "['/home/tjs/web','/home/tjs/django/sorl-thumbnail-read-only','/home/tjs/django/django-trunk'] + sys.path" PythonAuthenHandler django.contrib.auth.handlers.modpython PythonOption DjangoRequireStaffStatus Off PythonOption DjangoPermissionName members.can_access_private_area AuthType Basic AuthName "site" Require valid-user AuthBasicAuthoritative Off AuthzDefaultAuthoritative Off AuthzGroupFileAuthoritative Off AuthzUserAuthoritative Off SetEnv DJANGO_SETTINGS_MODULE site.settings PythonPath "['/home/tjs/web','/home/tjs/django/sorl-thumbnail-read-only','/home/tjs/django/django-trunk'] + sys.path" PythonAuthenHandler django.contrib.auth.handlers.modpython PythonOption DjangoRequireStaffStatus Off PythonOption DjangoPermissionName members.can_access_private_area SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE site.settings PythonDebug Off PythonPath "['/home/tjs/web','/home/tjs/django/sorl-thumbnail-read-only','/home/tjs/django/django-trunk'] + sys.path" SetHandler None SetHandler None --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: mod_python authentication problem
Hi, I'm following the instructions at http://www.djangoproject.com/documentation/apache_auth/ I've just noticed a bit at the bottom of that page which says - Note that sometimes SetEnv doesn't play well in this mod_python configuration, for reasons unknown. If you're having problems getting mod_python to recognize your DJANGO_SETTINGS_MODULE, you can set it using PythonOption instead of SetEnv. Therefore, these two Apache directives are equivalent: SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonOption DJANGO_SETTINGS_MODULE mysite.settings I've done that and now it's prompting me to login a normal browser dialog box. If I use my django login it works - is this expected behaviour or can I stop the login box appearing for users that have logged into django auth? Thanks, Tim. On Friday 28 Mar 2008, Graham Dumpleton wrote: > Variables set with SetEnv aren't available to authentication handlers, > only to the content handler. Thus, even if the Django authentication > handler is looking for it, it will not find it and thus would not be > able to update os.environ variable of same name from it. The only way > it could work is if the first page hit was a Django application page > which had the side effect of setting os.environ. You probably wouldn't > want to rely on that being the case. > > For alternate mechanism for doing all this see mod_wsgi. > > http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms > > Graham > > Tim Sawyer wrote: > > Hi, > > > > I'm trying to secure /site_media/private and /site_media/pictures so that > > only logged in users can see the files in those directories and below. > > > > The error I'm getting (sometimes - seems to be a bit inconsistent) is > > > > [Fri Mar 28 09:39:06 2008] [error] [client XXX.XXX.XXX.XXX] > > PythonAuthenHandler django.contrib.auth.handlers.modpython: ImportError: > > Settings cannot be imported, because environment variable > > DJANGO_SETTINGS_MODULE is undefined., referer: > > http://site/private/pictures/ > > > > Here's my apache virtual host configuration (site name changed to site). > > Have I done anything obviously wrong? The PythonPath entries are > > indented correctly in the original. > > > > Thanks, > > > > Tim > > > > > > ServerAdmin [EMAIL PROTECTED] > > ServerName www.site > > ServerAlias site > > > > DocumentRoot /home/tjs/web/site > > > > > > Options -Indexes FollowSymLinks MultiViews > > AllowOverride All > > Order allow,deny > > allow from all > > > > > > > > allow from all > > > > > > CustomLog /home/tjs/log/site pink > > > > > > AuthType Basic > > AuthName "site" > > Require valid-user > > AuthBasicAuthoritative Off > > AuthzDefaultAuthoritative Off > > AuthzGroupFileAuthoritative Off > > AuthzUserAuthoritative Off > > > > SetEnv DJANGO_SETTINGS_MODULE site.settings > > > > PythonPath > > "['/home/tjs/web','/home/tjs/django/sorl-thumbnail-read-only','/home/tjs/ > >django/django-trunk'] + sys.path" > > PythonAuthenHandler > > django.contrib.auth.handlers.modpython PythonOption > > DjangoRequireStaffStatus Off > > PythonOption DjangoPermissionName > > members.can_access_private_area > > > > > > > > AuthType Basic > > AuthName "site" > > Require valid-user > > AuthBasicAuthoritative Off > > AuthzDefaultAuthoritative Off > > AuthzGroupFileAuthoritative Off > > AuthzUserAuthoritative Off > > > > SetEnv DJANGO_SETTINGS_MODULE site.settings > > > > PythonPath > > "['/home/tjs/web','/home/tjs/django/sorl-thumbnail-read-only','/home/tjs/ > >django/django-trunk'] + sys.path" > > PythonAuthenHandler > > django.contrib.auth.handlers.modpython PythonOption > > DjangoRequireStaffStatus Off > > PythonOption DjangoPermissionName > > members.can_access_private_area > > > > > > > > SetHandler pytho
Re: mod_python authentication problem
On Friday 28 Mar 2008, Graham Dumpleton wrote: > On Mar 28, 9:21 pm, Tim Sawyer <[EMAIL PROTECTED]> wrote: > > I've done that and now it's prompting me to login a normal browser dialog > > box. If I use my django login it works - is this expected behaviour or > > can I stop the login box appearing for users that have logged into django > > auth? > > Yes it is expected behaviour. The recipe you are using is for HTTP > Basic Authentication, which makes use of a browser implemented popup > login window. In general you cannot make this disappear. Thanks Graham. My site looks a bit rubbish like that - users have to login twice, to different types of login box, to get site_media files that only logged in users are allowed to see. Does the WSGI stuff let me get around this? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Finding out the index of a model instance in a list
Hi Folks, If I have an image, and a list of images, how can I work out what position in the list my image is so I can do a Image 4 of 24 type annotation? lImage = GalleryImage.objects.filter(pk=pImageSerial).select_related()[0] lAlbumImages = GalleryImage.objects.filter(album__id = lImage.album.id) lImagesInAlbum = lAlbumImages.count() lImagePosition = ??? My view is passed pImageSerial which is the id of the image to display. I can work out the Image object from this. I can also get the full list of images for this particular album, and work out how many images there are in total. The images are ordered by filename, so I know the order will be consistent. How do I work out lImagePosition? Can anyone give me any pointers? Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Finding out the index of a model instance in a list
Is there a better way that this? lImage = GalleryImage.objects.filter(pk=pImageSerial).select_related()[0] lAlbumImages = GalleryImage.objects.filter(album__id = lImage.album.id) lImagesInAlbum = lAlbumImages.count() lImagePosition = None lPreviousImage = None lNextImage = None for lPosition in range(lImagesInAlbum): lEachImage = lAlbumImages[lPosition] if lEachImage.id == lImage.id: lImagePosition = lPosition + 1 if lPosition > 0: lPreviousImage = lAlbumImages[lPosition-1] if lPosition < lImagesInAlbum-1: lNextImage = lAlbumImages[lPosition+1] break On Saturday 29 Mar 2008, Tim Sawyer wrote: > Hi Folks, > > If I have an image, and a list of images, how can I work out what position > in the list my image is so I can do a Image 4 of 24 type annotation? > > lImage = GalleryImage.objects.filter(pk=pImageSerial).select_related()[0] > lAlbumImages = GalleryImage.objects.filter(album__id = lImage.album.id) > lImagesInAlbum = lAlbumImages.count() > lImagePosition = ??? > > My view is passed pImageSerial which is the id of the image to display. I > can work out the Image object from this. I can also get the full list of > images for this particular album, and work out how many images there are in > total. The images are ordered by filename, so I know the order will be > consistent. > > How do I work out lImagePosition? Can anyone give me any pointers? > > Thanks, > > Tim. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Serving binary files "through" django
Hi Folks, I'd like to have a site that gives away and sells PDFs, and tracks downloads of those PDFs. For example, I'd like to know the IP address/useragent of who downloaded the free files, and I'd like to record the same plus the logged in user for the pay ones (after authenticating the user is allowed to download that file). I've done this in Java by returning binary content (the PDF) from a servlet, and having the servlet write to the database to say what was downloaded and who downloaded it. I'd like to migrate this app to django (less heavyweight!) can anyone point me towards a mechanism for doing this? I'm fairly new at python but loving it... Thanks, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
EmailMessage and BCC fields
Hi Folks, I've just sent an email using EmailMessage setting the bcc field to be a list of recipients. It sent the email, to the correct recipients, but all my addresses are visible in the mail header, in an email header called bcc. It's not supposed to do that is it, hence the B bit of the BCC? def send_email(pSubject, pMessage, pRecipients): lMessage = EmailMessage(subject=pSubject, body=pMessage, from_email='info <[EMAIL PROTECTED]>', to=['webmaster <[EMAIL PROTECTED]>'], bcc=pRecipients) lMessage.send() I'm using 0.97-pre-SVN-7176 according to the runserver output, and talking to an exim4 mailserver on a debian linux box. Any suggestions of how to fix this gratefully received! Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: EmailMessage and BCC fields
On Sunday 06 Apr 2008, Karen Tracey wrote: > Update to a revision with the fix for > http://code.djangoproject.com/ticket/6841, that is r7347 or higher. Fixed, thanks! Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
1 2 >