Re: I18n when using standalone templates
Malcolm, On Dec 23, 2:00 am, Malcolm Tredinnickwrote: > You can do it this way: > > from django.utils import translation > > translation.activate(locale) > > where "locale" is a variable containing the name of the locale you wish > to activate. You should call that as early as possible in the processing > pipeline once you know the right locale value. Thanks. Is this thread-safe? I looked at the code in trans_real.py (def activate), and from my understanding it is not thread-safe, since it accesses the _active dictionary? - Iwan --~--~-~--~~~---~--~~ 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: Is there a bug in http://docs.djangoproject.com/en/dev/topics/db/models/ ?
I got another idea for it now. Thank for your reminder. :-) On Dec 15, 2:00 pm, Malcolm Tredinnickwrote: > On Sun, 2008-12-14 at 21:32 -0800, lee wrote: > > [...] > > > It seems that official docs hasn't give a reference to howto define > > 'ON DELETE CASCADE ON UPDATE CASCADE' in models, > > so, is there a bug inhttp://docs.djangoproject.com/en/dev/topics/db/models/ > > ? > > No, there isn't. We don't have documentation for features that don't > exist. :-) > > There is no way to specify that in your model. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: Table inheritance and polymorphic admin forms
On Mon, 2008-12-22 at 22:17 -0800, George Sakkis wrote: [...] > 1. With explicit concrete inline admin classes, the interface shows > one section per class ("Book reviews", "Movie reviews", etc.). This > might be a feature under some circumstances (you get a "group by > review type" for free), but an inconvenience if you want to show a > single list of all reviews regardless of type (a more real use case is > entities that have children of a single review class only, e.g. only > movie reviews; these will still show up sections for all review types, > although it is guaranteed that only one section will be non-empty). You're talking about the *admin* interface here. It's really primarily for data entry. Stuff like "showing a list of combined reviews" isn't something you're going to use the admin interface to do. > > 2. The main problem though is that it essentially cancels the major > benefit of inheritance: polymorphism. That's subjective. Inheritance also provides a way to factor out commonality and *that* is the benefit that is being exploited at the boundary between object-based and relation-based data structures that we're working with here. Polymorphism is not a concept that translates well into the relational database model and is intentionally left as being a bit of a manual process for that reason. > Every time I add a new Review > model subclass, I have to add a respective ModelAdmin subclass *and* > add it explicitly to the inlines of every ModelAdmin that handles > lists of reviews, i.e. change at least three places instead of one. > Apparently inheritance doesn't buy me much this way; might as well > code each review type completely independently. It would be neat if by > declaring inlines = [ReviewInline], there was a single "Reviews" > section listing all child reviews, regardless of type. Um .. it sounds to me like if you were doing this a lot you would be writing a subclass that could handle a lot of this automatically. Just because it doesn't work out of the box doesn't mean you shouldn't write code to do it. Ultimately, it seems that you have some particular data entry requirements that aren't met by the admin out of the box. Fortunately, the admin is heavily customisable by writing Python code. So have at it. Malcolm --~--~-~--~~~---~--~~ 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: Post tutorial help needed - generic.create_update.create_object
OK, that makes sense then. Thank you! On Mon, Dec 22, 2008 at 5:11 PM, Malcolm Tredinnick < malc...@pointy-stick.com> wrote: > > On Mon, 2008-12-22 at 15:32 -0700, Greg Schwimer wrote: > [...] > > > > > I suspect I've now moved on to a problem in a new area. The thing I > > don't quite get is why adding auto_now_add to the pub_date field in > > the model broke this. Any ideas? > > Because auto_now_add fields are not editable. They are automatically > given a value at creation time. > > Regards, > Malcolm > > > > > > --~--~-~--~~~---~--~~ 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: Table inheritance and polymorphic admin forms
On Dec 22, 7:04 pm, Malcolm Tredinnickwrote: > On Mon, 2008-12-22 at 09:42 -0800, George Sakkis wrote: > > [...] > > > > > Unfortunately it doesn't work for what I tried. What I am trying to do > > is have the Child classes as InlineModelAdmin in some other class that > > references them. Here's a sample: > > > # === models.py === > > class Review(models.Model): > > # general fields > > class Meta: > > abstract = True > > > class BookReview(Review): > > # book-specific review fields > > > class MoviewReview(Review): > > # movie-specific review fields > > > # === admin.py === > > > class ReviewInline(admin.StackedInline): > > model = models.Review > > extra = 0 > > > class UserReviewAdmin(admin.ModelAdmin): > > inlines = [ReviewInline] > > # more stuff > > > admin.site.register(models.User, UserReviewAdmin) > > > This dies with "type object 'Review' has no attribute > > '_default_manager'", apparently because Review is not a table-backed > > model. What should I be doing differently ? > > I don't really understand at all why you're trying to create the admin > like this. You want to edit BookReview and MovieReview objects, so > create admin classes for those two models. Creating an admin class for > Review is impossible (since it's abstract -- which wasn't something I > realised you were doing in your original explanation) and not really > necessary, since it's not Review objects that you're editing. Thanks, that's what I eventually did, and it sort of works. There are at least two reasons though I'd like to be able to declare generic Reviews: 1. With explicit concrete inline admin classes, the interface shows one section per class ("Book reviews", "Movie reviews", etc.). This might be a feature under some circumstances (you get a "group by review type" for free), but an inconvenience if you want to show a single list of all reviews regardless of type (a more real use case is entities that have children of a single review class only, e.g. only movie reviews; these will still show up sections for all review types, although it is guaranteed that only one section will be non-empty). 2. The main problem though is that it essentially cancels the major benefit of inheritance: polymorphism. Every time I add a new Review model subclass, I have to add a respective ModelAdmin subclass *and* add it explicitly to the inlines of every ModelAdmin that handles lists of reviews, i.e. change at least three places instead of one. Apparently inheritance doesn't buy me much this way; might as well code each review type completely independently. It would be neat if by declaring inlines = [ReviewInline], there was a single "Reviews" section listing all child reviews, regardless of type. A future feature request maybe ? George --~--~-~--~~~---~--~~ 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 +Appy Framework+ generate pdf and odt file
On Mon, 2008-12-22 at 21:01 -0800, jai_python wrote: > No one here to solve my problem :( Please show some simple patience. It's been less than 24 hours since you originally posted a question that has zero Django content in it to a Django-specific mailing list. You *might* get lucky and find somebody here who knows the answer off the top of their head, but if this is the only place you're hoping to see an answer, you should also be looking elsewhere (for example the support groups / forums / whatever for Appy). We are a helpful bunch, but you have to have realistic expectations. Regards, Malcolm --~--~-~--~~~---~--~~ 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 +Appy Framework+ generate pdf and odt file
No one here to solve my problem :( --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)
I am always amazed by the support here, thank you. After seeing Brian's code I switched resize_image() to be a model method and then I switched from saving the form to saving the profile profile = request.user.get_profile() profile.save_picture(pform.cleaned_data['picture'].read()) instead of new_profile = pform.save(commit=False) new_profile.picture.save(filename, thumbnail_content) Merrick On Dec 22, 1:10 pm, brianmac44wrote: > With my code, what are you using as "content"? > > I'm using: form.cleaned_data['source'].read() > > So my code looks something like this: > PHOTO_MEDIUM_SIZE = 400,400 > source_image = form.cleaned_data['source'].read() > resized_image = resize_photo(source_image,PHOTO_MEDIUM_SIZE)) > photos.save(image_name,resized_image) > > You may want to also want to check the image file you are using for > testing, interlaced PNG's are not supported by > PIL.http://www.pythonware.com/library/pil/handbook/format-png.htm > > -Brian > > On Dec 22, 2:46 pm,Merrick wrote: > > > I got the same result with brianmac44's code. I also verified that the > > my resize_image() works when opening the file from the local > > filesystem - so I am somehow not passing the file in a manner that > > Image.open likes. > > > On Dec 22, 4:45 am, brianmac44 wrote: > > > > I had the same problem two weeks ago. This is what I wrote: > > > > def resize_photo(self,content,size): > > > img = Image.open(ContentFile(content)) > > > img.thumbnail(size, Image.ANTIALIAS) > > > io = StringIO.StringIO() > > > img.save(io, 'PNG') > > > return ContentFile(io.getvalue()) > > > > Hope this helps. > > > > -Brian > > > > On Dec 22, 4:41 am,Merrick wrote: > > > > > Thank you I tried that and I still get the same error. > > > > > I spent a little more time looking at PIL / Image.py and cleaning up > > > > the code. From what I can tell the Image.open method is having trouble > > > > with what I am passing to it. > > > > > def resize_image(file, size=(50, 50)): > > > > from PIL import Image > > > > from cStringIO import StringIO > > > > from django.core.files.base import ContentFile > > > > > image_data = StringIO(file.read()) > > > > > ### this line below is where the issue is ### > > > > image = Image.open(image_data) > > > > > if image.mode not in ('L', 'RGB'): > > > > image = image.convert('RGB') > > > > image.thumbnail(size, Image.ANTIALIAS) > > > > o = StringIO() > > > > image.save(o, "JPEG") > > > > return ContentFile(o.getvalue()) > > > > > This is how I call it: > > > > picture = pform.cleaned_data['picture'] > > > > thumbnail_content = resize_image(picture) > > > > > Thank you for looking at this. > > > > > On Dec 21, 3:08 pm, "j...@zigzap.com" wrote: > > > > > > From what I can tell your not wrapping the thumbnailfilein > > > > > ContentFile your just returning the rawfilefrom the string IO. To > > > > > use the the ImageField django provides you must provide it with afile > > > > > that is in a special wrapper called ContentFile. I would suggest > > > > > trying this: > > > > > > from django.core.files.base import ContentFile (import this function > > > > > at the top of your view or where ever you put def resize_image) > > > > > > change the last line of def resize_image from "return o.getvalue()" to > > > > > "return ContentFile(o.getvalue())" > > > > > > I would also recommend changing "new_profile.picture.save(filename, > > > > > thumbnail_content)" to "new_profile.picture.save(filename, > > > > > thumbnail_content, save=False)" so that you are not hitting the > > > > > database twice. --~--~-~--~~~---~--~~ 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: where are the code that handle image file upload in Django admin page?
Anyone can help on this? I get stuck with image file upload. On Dec 21, 11:33 pm, Chuck22wrote: > I have three ImageField in my form and model, I want to know how to > upload the three image files in the form processing code. I found > Django Admin page handles the image file upload nicely. And I want to > do the exactly same work. But I can not find the piece of code that > does the job when searching the Django source code. Can anyone point > to me where these code are located? Or share some code snippets > related to this. > > in my model: > image1 = models.ImageField(upload_to='img/bk', blank=True) > image2 = models.ImageField(upload_to='img/bk', blank=True) > image3 = models.ImageField(upload_to='img/bk', blank=True) > > in my form processing: > > if request.method == 'POST': > f = MyForm(request.POST, request.FILES) > if f.is_valid(): > email = f.cleaned_data['email'] > title = f.cleaned_data['title'] > ... > > # save the uploaded images > for v in request.FILES: > save_upload_file(v) < this is where i am stuck --~--~-~--~~~---~--~~ 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: MultiValueDictKeyError when accessing POST items
On Mon, 2008-12-22 at 19:03 -0800, DragonSlayre wrote: > I've created my own form: > > > Login: > Username: > > Password: > > > > > I am mappying /accounts/login/ to a view of mine, which is then > calling: > > if request.method == 'POST': > username = request.POST['login_username'] > > I have no idea why I'm getting the error - "Key 'login_username' not > found in ". > > What am I doing wrong? login_username is the value of the id attribute on the label, not on the form input element. Basically, your HTML isn't correct for the type of form you're after. You need to identify the form input elements, rather than the label elements. Compare the output from a Django form to what you have an you should see the difference fairly quickly. Regards, Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
MultiValueDictKeyError when accessing POST items
I've created my own form: Login: Username: Password: I am mappying /accounts/login/ to a view of mine, which is then calling: if request.method == 'POST': username = request.POST['login_username'] I have no idea why I'm getting the error - "Key 'login_username' not found in ". What am I doing wrong? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: dynamic mod wsgi
Have some further questions about what you want to do. Do you want a separate daemon process for each distinct Django site, or are you happy with one really fat process which contains each Django site in a separate sub interpreter of that process? How much memory does each Django site instance take up? How many different site instances would you have? Are all the site instances distinguishable by server name alone? Graham On Dec 23, 9:00 am, Graham Dumpletonwrote: > On Dec 22, 9:44 pm, Ben Eliott wrote: > > > Hi Graham, > > I've finally managed to get back to the wildcard subdomains & mod_wsgi > > today. Unfortunately the discussion thread you mentioned has > > disappeared and after a few hours i still seem to be doing a good job > > of getting nowhere. > > I can still access thread with no problems. > > > Although you mentioned using mod_rewrite to get hold of the url > > variable, it looks like the %{SERVER} variable in mod_wsgi might take > > care of this already? > > > My main issue seems to be to accessing the %{SERVER} (or relevant > > mod_rewrite) variable in the .wsgi script, to specify a particular > > settings file. > > > Within a VirtualHost i have: > > WSGIApplicationGroup %{SERVER} > > WSGIDaemonProcess %{SERVER} ...threads etc > > WSGIProcessGroup %{SERVER} > > The %{SERVER} value is only magic when used with WSGIApplicationGroup > directive. > > > So this is probably hoplessly wrong also, but if you can give some > > further pointers that would be most kind. > > Can you post a more complete example of your Apache configuration > showing what you are trying to achieve. > > Sorry I didn't get back to you last time, it was a hectic few weeks. > Things have settled down somewhat now, so I'll go back over your > original post and work out again what it is you were trying to do. > > Graham > > > Thanks and Regards, > > Ben > > > On 9 Dec 2008, at 10:18, Graham Dumpleton wrote: > > > > On Dec 9, 8:05 pm, Ben Eliott wrote: > > >> Graham, > > >> Thank you for coming back personally to such a lowly wsgi question! I > > >> started reading your email and thinking the answer was 'no', then > > >> ended up thinking 'definitely maybe'. I'll keep an eye out in case > > >> you > > >> post more, otherwise i'll follow those links and your directions and > > >> hope to report back with some progress. > > > > I'll definitely try and say more later when get a chance. > > > > Just do be aware of one thing. By using a single WSGI script file for > > > multiple sites, you loose the ability with mod_wsgi daemon mode to > > > touch the WSGI script file and cause a single site to be reloaded. One > > > would normally use this as a way of reloading a single site without > > > the need to restart the whole of Apache. When sharing the single WSGI > > > script file across sites, touching the WSGI script file will restart > > > all sites using that WSGI script file. If they share the code this may > > > actually be want you want, so not a problem, but worth mentioning. > > > > In this arrangement, if you did want to reload one site, for example > > > because you change its settings file, you would need to use 'ps' to > > > identify process(es) in that daemon process group, based on what > > > display-name option was set to, and send all those processes in that > > > daemon process group a SIGINT using the 'kill' command. Alternatively, > > > you would need to setup a background thread which monitored something > > > like the distinct settings file for each site and have the process > > > itself send a SIGINT to itself. This would be a variation on > > > background reloader described in: > > > > http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_... > > > > More later. > > > > Graham > > > >> Thanks and Regards, > > >> Ben > > > >> On 9 Dec 2008, at 08:23, Graham Dumpleton wrote: > > > >>> On Dec 9, 6:53 pm, "ben.dja...@googlemail.com" > > >>> wrote: > > Hi, I'm converting to the excellent mod_wsgi and wondering if it's > > possible to make a single httpd virtual host/wsgi file to manage > > wildcard subdomains. > > > Basically I have an app where i'm creating a new instance for each > > client and using subdomains. So client1.example.com and > > client2.example.com both point to the same app, but their own > > settings.py/django instance. > > > So far so fine. I've been happily converting to mod_wsgi daemons, > > creating virtual hosts and independent .wsgi files for each one. > > But > > now just wondering whether there is some way i can make this > > process > > dynamic so one virtual host/.wsgi file will take care of all these > > subdomains. > > > I see the advice on the wsgi wiki to push domain sub-directories to > > different django instances, but i'd rather keep using the > >
Re: RSS...my parameters are not correct
On Tuesday 11 December 2007 12:33:23 pm Greg wrote: > Hello, > I'm trying to get my RSS feed items to link to the right url, however > I'm having trouble. I was orginally having my blogs appear in my RSS > feed. When I clicked on one of them I would get the error: > > ' Invalid feed parameters. Slug u'latest' is valid, but other > parameters, or lack thereof, are not. ' > > However, after changing some of my code my blog entries are not even > showing up in my RSS feed. Here is what I have so far. > > > > urls.py > > from mysite.app.models import LatestEntries, LatestEntriesByCategory > > feeds = { > 'latest': LatestEntries, > 'categories': LatestEntriesByCategory, > } > > urlpatterns = patterns('', > (r'^feeds/(?P.*)/$', 'django.contrib.syndication.views.feed', > {'feed_dict': feeds}), > ) > > /// > > models.py > > from django.contrib.syndication.feeds import Feed > > class LatestEntries(Feed): > title = "MySite.com News" > link = "Not Sure what goes here" > description = "Updates on changes and additions to Mysite.com." > > class LatestEntriesByCategory(Feed): > def get_object(self, bits): > if len(bits) < 1: > raise ObjectDoesNotExist > return Blog.objects.get(slug=bits[-1]) > > def title(self, obj): > return "My blog for %s" % obj.name > > def link(self, obj): > return obj.get_absolute_url() > > def description(self, obj): > return "Blog entries recently posted in category %s" % > obj.name > > def items(self, obj): > return Blog.objects.filter(blogslug=obj.slug).order_by('- > created_at')[:10] > > class Blog(models.Model): > title = models.CharField(maxlength=200) > blogslug = models.SlugField(prepopulate_from=["title"]) > content = models.TextField(maxlength=5000) > > def get_absolute_url(self): > return "/app/feeds/latest/%i/" % self.id > I ran into this recently, what's going on is the feed class is trying to find a blog slug object with get_object() that matches 'latest', when you define get_object(). If you use something like this with a valid slug, your feed will work fine. http://mysite.com/feeds/latest/some-cool-blog-item/ Removing get_object() from the feed class, then it will work with this url: http://mysite.com/feeds/latest/ Mike -- Apathy Club meeting this Friday. If you want to come, you're not invited. --~--~-~--~~~---~--~~ 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: Integrity error with get_or_create()
I've looked into this further, and it looks like it's actually an issue with PostgreSQL, not django. The field I'm querying is of type inet, and I'm inputting an IPv6 address. However, it appears that in PostgreSQL (running version 8.3.5) IPv6 addresses only match a query when the string being queried is in compressed IPv6 format (e.g., ::1). So, when I run a model.objects.get_or_create(ip=myipv6) where myipv6 was not in compressed format, the get() would fail, and the insert would fail because the address really does already exist, but then the subsequent get() would fail again. Regards, Casey On Mon, Dec 22, 2008 at 2:47 PM, Casey Decciowrote: > Hi, > > I'm running django-1.0 in a multi-threaded application (PostgreSQL > backend), and I'm getting an IntegrityError occasionally when I run a > model.objects.get_or_create(). I can see in the get_or_create() method of > db/models/query.py that it excepts an Integrity error, and then rolls back > the transaction and tries to get the object. I can see from the traceback > that this get() raises a model.DoesNotExist, which then causes it to > re-raise the IntegrityError that was saved previously. I'm not doing any > changes or deletions in any other threads. Any ideas as to what I'm > missing? > > Regards, > Casey > --~--~-~--~~~---~--~~ 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 Help with Models and Views
Paul, Thanks for the help. I switched to the get method, and the data prints correctly now. Thanks! -Mike On Dec 22, 5:44 pm, "Wayper, Paul"wrote: > > .filter returns a list of the items that match the query. So > > you're trying to stringify a list. That's where the '[' and > > ']' are coming from. > > I should have mentioned that the get method (e.g. Post.objects.get(id = > 1)) will return a single object, or raise a DoesNotExist error. You may > want to look into the 'get_object_or_404' helper. > > Have fun, > > -- > Paul Wayper > SYSTEMS ENGINEER > TransACT > > Telephone: 02 6229 8026 > Mobile: 0422 392 081 > > PO Box 1006, Civic Square ACT 2608 > > www.transact.com.au --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Integrity error with get_or_create()
Hi, I'm running django-1.0 in a multi-threaded application (PostgreSQL backend), and I'm getting an IntegrityError occasionally when I run a model.objects.get_or_create(). I can see in the get_or_create() method of db/models/query.py that it excepts an Integrity error, and then rolls back the transaction and tries to get the object. I can see from the traceback that this get() raises a model.DoesNotExist, which then causes it to re-raise the IntegrityError that was saved previously. I'm not doing any changes or deletions in any other threads. Any ideas as to what I'm missing? Regards, Casey --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ACL module
Hi. I'm interested if there is some 3rd party ACL(http://en.wikipedia.org/ wiki/Access_control_list) module for django. If there is can u advice me some of them or give some useful links? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Post tutorial help needed - generic.create_update.create_object
On Mon, 2008-12-22 at 15:32 -0700, Greg Schwimer wrote: [...] > > I suspect I've now moved on to a problem in a new area. The thing I > don't quite get is why adding auto_now_add to the pub_date field in > the model broke this. Any ideas? Because auto_now_add fields are not editable. They are automatically given a value at creation time. Regards, Malcolm --~--~-~--~~~---~--~~ 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: accessing to a field value in the template
On Mon, 2008-12-22 at 17:20 -0600, GaRaGeD Style wrote: > > That particular value comes from one of three sources. In order of > > highest priority to lowest, they are: > > > >(1) Data submitted to the form (for redisplaying submitted data > >for errors). > >(2) Initial data provided to the form class > >(3) Initial data provided to the field class (when it was > >created as part of the form). > > > > The code does a semi-complex dance to pull out the right value and it's > > not something you can really emulate at the template level. That's > > something worth adding for Django 1.1. > > > So, ther is no way to access (1) data ?? I'm doing an app with > django/dojo, and I need to display fields manually, I could make them > programatically, but that would be "a lot more work", the problem I > have now is that when the user submits data with errors, I cannot > redisplay the fields with values, so there is no way to degrade > gracefully (I'm not that interested on that actually, but could be > nice). Have a look in django/forms/forms.py at the class BoundField. That is the object that is a "field" in the template. You can see there how the data value is retrieved by the code. Regards, Malcolm --~--~-~--~~~---~--~~ 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: Table inheritance and polymorphic admin forms
On Mon, 2008-12-22 at 09:42 -0800, George Sakkis wrote: [...] > Unfortunately it doesn't work for what I tried. What I am trying to do > is have the Child classes as InlineModelAdmin in some other class that > references them. Here's a sample: > > # === models.py === > class Review(models.Model): > # general fields > class Meta: > abstract = True > > class BookReview(Review): > # book-specific review fields > > class MoviewReview(Review): > # movie-specific review fields > > # === admin.py === > > class ReviewInline(admin.StackedInline): > model = models.Review > extra = 0 > > class UserReviewAdmin(admin.ModelAdmin): > inlines = [ReviewInline] > # more stuff > > admin.site.register(models.User, UserReviewAdmin) > > > This dies with "type object 'Review' has no attribute > '_default_manager'", apparently because Review is not a table-backed > model. What should I be doing differently ? I don't really understand at all why you're trying to create the admin like this. You want to edit BookReview and MovieReview objects, so create admin classes for those two models. Creating an admin class for Review is impossible (since it's abstract -- which wasn't something I realised you were doing in your original explanation) and not really necessary, since it's not Review objects that you're editing. Regards, Malcolm --~--~-~--~~~---~--~~ 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: I18n when using standalone templates
On Mon, 2008-12-22 at 05:06 -0800, Iwan wrote: > Hi there, > > We're using Django templates on their own. Usually invoked like this > (eg): > > - > t = django.template.Template(templateSource) > c = django.template.Context({}) > > print t.render(c) > - > > When you add i18n to this mix, however, how do you set the language to > be used when rendering? Can you put something into the context? You can do it this way: from django.utils import translation translation.activate(locale) where "locale" is a variable containing the name of the locale you wish to activate. You should call that as early as possible in the processing pipeline once you know the right locale value. Regards, Malcolm --~--~-~--~~~---~--~~ 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: accessing to a field value in the template
> That particular value comes from one of three sources. In order of > highest priority to lowest, they are: > >(1) Data submitted to the form (for redisplaying submitted data >for errors). >(2) Initial data provided to the form class >(3) Initial data provided to the field class (when it was >created as part of the form). > > The code does a semi-complex dance to pull out the right value and it's > not something you can really emulate at the template level. That's > something worth adding for Django 1.1. So, ther is no way to access (1) data ?? I'm doing an app with django/dojo, and I need to display fields manually, I could make them programatically, but that would be "a lot more work", the problem I have now is that when the user submits data with errors, I cannot redisplay the fields with values, so there is no way to degrade gracefully (I'm not that interested on that actually, but could be nice). Max -- $ echo "scale=100; 4*a(1)" | bc -l --~--~-~--~~~---~--~~ 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 models
Alright thanks a lot. On Dec 22, 3:06 pm, bruno desthuillierswrote: > On 22 déc, 17:10, kev wrote: > > > > > Hello, > > Im reading a django book and it adds friends to user authentication > > system by making: > > > (was .96) > > > class Friendship(models.Model): > > from_friend = models.ForeignKey( > > User, related_name='friend_set' > > ) > > to_friend = models.ForeignKey( > > User, related_name='to_friend_set' > > ) > > def __str__(self): > > return '%s, %s' % ( > > self.from_friend.username, > > self.to_friend.username > > ) > > class Admin: > > pass > > class Meta: > > unique_together = (('to_friend', 'from_friend'), ) > > > But for this to work, you have to add friendship both ways. > > Nope. You have to *query* it both ways. --~--~-~--~~~---~--~~ 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 Help with Models and Views
> .filter returns a list of the items that match the query. So > you're trying to stringify a list. That's where the '[' and > ']' are coming from. I should have mentioned that the get method (e.g. Post.objects.get(id = 1)) will return a single object, or raise a DoesNotExist error. You may want to look into the 'get_object_or_404' helper. Have fun, -- Paul Wayper SYSTEMS ENGINEER TransACT Telephone: 02 6229 8026 Mobile: 0422 392 081 PO Box 1006, Civic Square ACT 2608 www.transact.com.au --~--~-~--~~~---~--~~ 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: Post tutorial help needed - generic.create_update.create_object
OK, that definitely fixed it, but it created another problem. Here's how it looks now: *pub_date = models.DateTimeField('date published', auto_now_add=True)* Exactly as you'd suggested. However, I'm now getting the following error on all pages I hit: *ImproperlyConfigured at /polls/new/ 'PollAdmin.fieldsets[1][1]['fields']' refers to field 'pub_date' that is missing from the form.* I got it to work by commenting out a line in my admin.py file that had some custom stuff set up, per the tutorial. Here's what that code looks like: *class PollAdmin(admin.ModelAdmin): fieldsets = [ (None,{'fields': ['question']}), ** THE OFFENDING LINE LIES HITHER:::* *('Date Information',{'fields': ['pub_date'], 'classes': ['collapse']}), ] inlines = [ChoiceInline] list_display = ('question', 'last_vote_date', 'pub_date', 'was_published_today') list_filter = ['pub_date'] search_fields = ['question'] date_hierarchy = 'pub_date' * I suspect I've now moved on to a problem in a new area. The thing I don't quite get is why adding auto_now_add to the pub_date field in the model broke this. Any ideas? On Sun, Dec 21, 2008 at 9:51 PM, Malcolm Tredinnick < malc...@pointy-stick.com> wrote: > > On Sun, 2008-12-21 at 21:46 -0700, Greg Schwimer wrote: > > OK, that was very helpful, thank you. Yes, my problem is because I am > > not setting the date. Thinking it through, I don't want the user > > changing this, so it would be helpful to use the auto_now_add idea you > > suggested. However, I can't get that working. Here's my mode; > > definition for pub_date: > > > > pub_date = models.DateTimeField('date published') > > > > The docs you referred to suggest the approach might look something > > like this: > > > > pub_date = models.DateTimeField([auto_now_add=True], 'date > > published) > > The square brackets in documentation are a fairly standard way of saying > that parameter is optional. To use the parameter, type it in without the > square brackets. Thus: > >pub_date = models.DateTimeField('date published', auto_now_add=True) > > Regards, > Malcolm > > > > > > --~--~-~--~~~---~--~~ 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 Help with Models and Views
> From: Mike Albert > Subject: Newbie Help with Models and Views > > I have a couple test rows of data in my database. From the > interactive shell (manage.py shell), I can return data correctly with > Post.objects.filter(id=1). You'll notice that that data is coming back as ['row 1']. It's in a list. > When I attempt to return the same > data with my view, it does not appear to work. Here is the view: > > from django.http import HttpResponse > from board.models import Post > > def current_board(request): > posts = Post.objects.filter(id=1) > html = " %s" % posts > return HttpResponse(html) > > > The above simply prints "[ ]" Any thoughts? I'm a django > newbie with no programming experience, so I'm sure it's > something basic. Thanks in advance for the help! .filter returns a list of the items that match the query. So you're trying to stringify a list. That's where the '[' and ']' are coming from. I don't know why you're not seeing any of the items in that list, because my testing: >>> foo = [1,2,3] >>> print 'x%sx' % foo x[1, 2, 3]x shows that stringifying a list should print the list as you'd expect. But this may lead you to a solution. Hope this helps, -- Paul Wayper SYSTEMS ENGINEER TransACT Telephone: 02 6229 8026 Mobile: 0422 392 081 PO Box 1006, Civic Square ACT 2608 http://www.transact.com.au Please avoid printing this email! --~--~-~--~~~---~--~~ 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: dynamic mod wsgi
On Dec 22, 9:44 pm, Ben Eliottwrote: > Hi Graham, > I've finally managed to get back to the wildcard subdomains & mod_wsgi > today. Unfortunately the discussion thread you mentioned has > disappeared and after a few hours i still seem to be doing a good job > of getting nowhere. I can still access thread with no problems. > Although you mentioned using mod_rewrite to get hold of the url > variable, it looks like the %{SERVER} variable in mod_wsgi might take > care of this already? > > My main issue seems to be to accessing the %{SERVER} (or relevant > mod_rewrite) variable in the .wsgi script, to specify a particular > settings file. > > Within a VirtualHost i have: > WSGIApplicationGroup %{SERVER} > WSGIDaemonProcess %{SERVER} ...threads etc > WSGIProcessGroup %{SERVER} The %{SERVER} value is only magic when used with WSGIApplicationGroup directive. > So this is probably hoplessly wrong also, but if you can give some > further pointers that would be most kind. Can you post a more complete example of your Apache configuration showing what you are trying to achieve. Sorry I didn't get back to you last time, it was a hectic few weeks. Things have settled down somewhat now, so I'll go back over your original post and work out again what it is you were trying to do. Graham > Thanks and Regards, > Ben > > On 9 Dec 2008, at 10:18, Graham Dumpleton wrote: > > > > > On Dec 9, 8:05 pm, Ben Eliott wrote: > >> Graham, > >> Thank you for coming back personally to such a lowly wsgi question! I > >> started reading your email and thinking the answer was 'no', then > >> ended up thinking 'definitely maybe'. I'll keep an eye out in case > >> you > >> post more, otherwise i'll follow those links and your directions and > >> hope to report back with some progress. > > > I'll definitely try and say more later when get a chance. > > > Just do be aware of one thing. By using a single WSGI script file for > > multiple sites, you loose the ability with mod_wsgi daemon mode to > > touch the WSGI script file and cause a single site to be reloaded. One > > would normally use this as a way of reloading a single site without > > the need to restart the whole of Apache. When sharing the single WSGI > > script file across sites, touching the WSGI script file will restart > > all sites using that WSGI script file. If they share the code this may > > actually be want you want, so not a problem, but worth mentioning. > > > In this arrangement, if you did want to reload one site, for example > > because you change its settings file, you would need to use 'ps' to > > identify process(es) in that daemon process group, based on what > > display-name option was set to, and send all those processes in that > > daemon process group a SIGINT using the 'kill' command. Alternatively, > > you would need to setup a background thread which monitored something > > like the distinct settings file for each site and have the process > > itself send a SIGINT to itself. This would be a variation on > > background reloader described in: > > > http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_... > > > More later. > > > Graham > > >> Thanks and Regards, > >> Ben > > >> On 9 Dec 2008, at 08:23, Graham Dumpleton wrote: > > >>> On Dec 9, 6:53 pm, "ben.dja...@googlemail.com" > >>> wrote: > Hi, I'm converting to the excellent mod_wsgi and wondering if it's > possible to make a single httpd virtual host/wsgi file to manage > wildcard subdomains. > > Basically I have an app where i'm creating a new instance for each > client and using subdomains. So client1.example.com and > client2.example.com both point to the same app, but their own > settings.py/django instance. > > So far so fine. I've been happily converting to mod_wsgi daemons, > creating virtual hosts and independent .wsgi files for each one. > But > now just wondering whether there is some way i can make this > process > dynamic so one virtual host/.wsgi file will take care of all these > subdomains. > > I see the advice on the wsgi wiki to push domain sub-directories to > different django instances, but i'd rather keep using the > subdomains > if possible. > > It looks possible to be able to parse information about the > incoming > request in the wsgi file and push it to different settings. But i'm > not sure what this will do in terms of spawning processes etc, it > looks a little dangerous, or maybe this will work. Any advice > appreciated thanks! > > >>> Start by reading recent discussion: > > >>> http://groups.google.com/group/django-users/browse_frm/thread/dfd3521 > >>> ... > > >>> I'll post more tomorrow if have time, have to do some things tonight > >>> and then out most of the day tomorrow. > > >>> In short though, no support for dynamic
Re: problem with adding foreign key to table
On Dec 22, 9:14 pm, Anawrote: > Hello, > > I migrated my MySQL tables to Postgres. Generally, the migration was > fine with one exception. I have a table researchproj that included > two foreign keys (institution_id and contact_id). I received the > following error: > > Caught an exception while rendering: ('ascii', u'Jorge Gir\xf3n', 9, > 10, 'ordinal not in range(128)') > > when I tried to access the researchproj table through admin. If I > delete the column contact_id, the error goes away. If I add the > column back onto the table the error returns. All the tables contain > data, although I created a test researchproj table with just one > tuple. I've added, deleted and done acrobats trying to get the admin > to accept the column contact_id in the researchproj table. I have > checked the sequence numbers for all tables, and also any referential > integrity issues with all the tables. Can someone help? > > Thanks, > > Ana This is not a data integrity issue, but a character set one. The character represented by the unicode sequence \xf3 (an o with an acute accent, I think) cannot be converted into valid ASCII. You should probably be using UTF-8 as the character encoding of your tables. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Newbie Help with Models and Views
Hello, Just getting started learning django, and I'm having trouble with a view. Here is the model I've created: from django.db import models class Post (models.Model): text = models.CharField(max_length=30) def __str__(self): return self.text I have a couple test rows of data in my database. From the interactive shell (manage.py shell), I can return data correctly with Post.objects.filter(id=1) When I attempt to return the same data with my view, it does not appear to work. Here is the view: from django.http import HttpResponse from board.models import Post def current_board(request): posts = Post.objects.filter(id=1) html = " %s" % posts return HttpResponse(html) The above simply prints "[ ]" Any thoughts? I'm a django newbie with no programming experience, so I'm sure it's something basic. Thanks in advance for the help! -Mike --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
problem with adding foreign key to table
Hello, I migrated my MySQL tables to Postgres. Generally, the migration was fine with one exception. I have a table researchproj that included two foreign keys (institution_id and contact_id). I received the following error: Caught an exception while rendering: ('ascii', u'Jorge Gir\xf3n', 9, 10, 'ordinal not in range(128)') when I tried to access the researchproj table through admin. If I delete the column contact_id, the error goes away. If I add the column back onto the table the error returns. All the tables contain data, although I created a test researchproj table with just one tuple. I've added, deleted and done acrobats trying to get the admin to accept the column contact_id in the researchproj table. I have checked the sequence numbers for all tables, and also any referential integrity issues with all the tables. Can someone help? Thanks, Ana --~--~-~--~~~---~--~~ 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: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)
With my code, what are you using as "content"? I'm using: form.cleaned_data['source'].read() So my code looks something like this: PHOTO_MEDIUM_SIZE = 400,400 source_image = form.cleaned_data['source'].read() resized_image = resize_photo(source_image,PHOTO_MEDIUM_SIZE)) photos.save(image_name,resized_image) You may want to also want to check the image file you are using for testing, interlaced PNG's are not supported by PIL. http://www.pythonware.com/library/pil/handbook/format-png.htm -Brian On Dec 22, 2:46 pm, Merrickwrote: > I got the same result with brianmac44's code. I also verified that the > my resize_image() works when opening the file from the local > filesystem - so I am somehow not passing the file in a manner that > Image.open likes. > > On Dec 22, 4:45 am, brianmac44 wrote: > > > I had the same problem two weeks ago. This is what I wrote: > > > def resize_photo(self,content,size): > > img = Image.open(ContentFile(content)) > > img.thumbnail(size, Image.ANTIALIAS) > > io = StringIO.StringIO() > > img.save(io, 'PNG') > > return ContentFile(io.getvalue()) > > > Hope this helps. > > > -Brian > > > On Dec 22, 4:41 am, Merrick wrote: > > > > Thank you I tried that and I still get the same error. > > > > I spent a little more time looking at PIL / Image.py and cleaning up > > > the code. From what I can tell the Image.open method is having trouble > > > with what I am passing to it. > > > > def resize_image(file, size=(50, 50)): > > > from PIL import Image > > > from cStringIO import StringIO > > > from django.core.files.base import ContentFile > > > > image_data = StringIO(file.read()) > > > > ### this line below is where the issue is ### > > > image = Image.open(image_data) > > > > if image.mode not in ('L', 'RGB'): > > > image = image.convert('RGB') > > > image.thumbnail(size, Image.ANTIALIAS) > > > o = StringIO() > > > image.save(o, "JPEG") > > > return ContentFile(o.getvalue()) > > > > This is how I call it: > > > picture = pform.cleaned_data['picture'] > > > thumbnail_content = resize_image(picture) > > > > Thank you for looking at this. > > > > On Dec 21, 3:08 pm, "j...@zigzap.com" wrote: > > > > > From what I can tell your not wrapping the thumbnailfilein > > > > ContentFile your just returning the rawfilefrom the string IO. To > > > > use the the ImageField django provides you must provide it with afile > > > > that is in a special wrapper called ContentFile. I would suggest > > > > trying this: > > > > > from django.core.files.base import ContentFile (import this function > > > > at the top of your view or where ever you put def resize_image) > > > > > change the last line of def resize_image from "return o.getvalue()" to > > > > "return ContentFile(o.getvalue())" > > > > > I would also recommend changing "new_profile.picture.save(filename, > > > > thumbnail_content)" to "new_profile.picture.save(filename, > > > > thumbnail_content, save=False)" so that you are not hitting the > > > > database twice. --~--~-~--~~~---~--~~ 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 date filter
On Dec 22, 12:30 pm, Aldowrote: > Hi folks, > > Simple enough problem but cant find the functionality - if it exists. > > this_week = datetime.date.today() - timedelta(7) > Cars.objects.filter(created_date>this_week) > > I basically want to find all cars that were created in the last 7 > days. I have seen there are things for the month and year > created_date__year = this_week.year > created_date__month = this_week.month > What i want is > created_date__week = this_week.week > > Is there any simple way of doing this. Can you not just do: Cars.objects.filter(created_date__gte=this_week) -- DR --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django models
On 22 déc, 17:10, kevwrote: > Hello, > Im reading a django book and it adds friends to user authentication > system by making: > > (was .96) > > class Friendship(models.Model): > from_friend = models.ForeignKey( > User, related_name='friend_set' > ) > to_friend = models.ForeignKey( > User, related_name='to_friend_set' > ) > def __str__(self): > return '%s, %s' % ( > self.from_friend.username, > self.to_friend.username > ) > class Admin: > pass > class Meta: > unique_together = (('to_friend', 'from_friend'), ) > > But for this to work, you have to add friendship both ways. Nope. You have to *query* it both ways. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to set the from a ModelChoiceField?
class MyForm(...): def __init__(self, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) self.fields['myfield'].choices = City.objects.values_list('id', name_field) --~--~-~--~~~---~--~~ 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: Complete layout (template) switching.
On 22 déc, 13:34, Kurawrote: > Hey guys, I'm currently working on a content management system built > on the Django framework, currently the whole cms works on a section->page(s) > basis which is working well, we've run in to some issues with > > our designs in that the blocks for content on some pages are in > different locations and the overall layout is different, to combat > this we've added a field to the page table that tells Django which > layout template it should use, the issue is I'm not sure how to > actually make Django read that column and actually switch the whole > layouts template for that page on a project level as a replacement to > base.html while keeping base.html as default for other pages. > > Any ideas? if it's a field of the Page model object and you have a Page model instance in your context, then {% extends page.template| default:"base.html" %} should do. http://docs.djangoproject.com/en/dev/ref/templates/builtins/#extends --~--~-~--~~~---~--~~ 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: non-fields being inherited by ModelForm
On Dec 22, 4:43 pm, nbv4wrote: > I have a model which is defines kind of like this: > > MyModel(models.Model) > field1 = models.BooleanField() > field2 = models.BooleanField() > field_num = "1" > > And then I have a form thats pretty much this: > > MyModelForm(models.ModelForm) > class meta > model = MyModel > > I want to be able to access the "field_num" value from the form > object. So I can do this in a template: > > > {{form.field1 }} > {{form.field2 }} > > > How can I do this? I'm sorta new to Python/Django The attribute won't be added to the form, because it isn't a field. However, a modelform always has an 'instance' attribute, which is a reference to the model instance used to populate the form, or a blank one. So you should be able to do: {{ form.instance.field_num }} -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Session and request.FILES
I'm writing custom session based wizard (data between step is stored in sessions). One of the steps is uploading files (not the last). The problem is that i save models only after last step. So the question is how to deal with files? As i understand there is no way to store files in session --~--~-~--~~~---~--~~ 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: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)
I got the same result with brianmac44's code. I also verified that the my resize_image() works when opening the file from the local filesystem - so I am somehow not passing the file in a manner that Image.open likes. On Dec 22, 4:45 am, brianmac44wrote: > I had the same problem two weeks ago. This is what I wrote: > > def resize_photo(self,content,size): > img = Image.open(ContentFile(content)) > img.thumbnail(size, Image.ANTIALIAS) > io = StringIO.StringIO() > img.save(io, 'PNG') > return ContentFile(io.getvalue()) > > Hope this helps. > > -Brian > > On Dec 22, 4:41 am, Merrick wrote: > > > Thank you I tried that and I still get the same error. > > > I spent a little more time looking at PIL / Image.py and cleaning up > > the code. From what I can tell the Image.open method is having trouble > > with what I am passing to it. > > > def resize_image(file, size=(50, 50)): > > from PIL import Image > > from cStringIO import StringIO > > from django.core.files.base import ContentFile > > > image_data = StringIO(file.read()) > > > ### this line below is where the issue is ### > > image = Image.open(image_data) > > > if image.mode not in ('L', 'RGB'): > > image = image.convert('RGB') > > image.thumbnail(size, Image.ANTIALIAS) > > o = StringIO() > > image.save(o, "JPEG") > > return ContentFile(o.getvalue()) > > > This is how I call it: > > picture = pform.cleaned_data['picture'] > > thumbnail_content = resize_image(picture) > > > Thank you for looking at this. > > > On Dec 21, 3:08 pm, "j...@zigzap.com" wrote: > > > > From what I can tell your not wrapping the thumbnailfilein > > > ContentFile your just returning the rawfilefrom the string IO. To > > > use the the ImageField django provides you must provide it with afile > > > that is in a special wrapper called ContentFile. I would suggest > > > trying this: > > > > from django.core.files.base import ContentFile (import this function > > > at the top of your view or where ever you put def resize_image) > > > > change the last line of def resize_image from "return o.getvalue()" to > > > "return ContentFile(o.getvalue())" > > > > I would also recommend changing "new_profile.picture.save(filename, > > > thumbnail_content)" to "new_profile.picture.save(filename, > > > thumbnail_content, save=False)" so that you are not hitting the > > > database twice. --~--~-~--~~~---~--~~ 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: login_required redirects always to LOGIN_REDIRECT_URL?
Hello, You can add a hidden input named "next" where you put the value of next in the GET variable. Like this Or you can change the action variable of the form to include the current GET variables. like this If your view that handles GET and POST aren't the same you must add the "next" var in the action field on your own. The latter is the best IMHO. Hope that helps! Regards, Matias. On Mon, Dec 22, 2008 at 11:47 AM, Jarek Zgodawrote: > > I'm seeing strange behaviour of login_required decorator: any view > decorated with it first sends to login page, then to url defined in > LOGIN_REDIRECT_URL. The url to decorated view is supplied in next > parameter (/login/?next=/path/to/view/) but is never executed. > > Looking at login view code I see that the redirect is taken from > redirect_field_name field (which in my case is default "next") of > REQUEST. This works as I expect if I do GET, but this value is not set > if I issue POST request with credentials after displaying form. > > Do I have to write my own login machinery to achieve such > functionality (redirect to decorated view after login)? > > Cheers > J. > > > -- :wq --~--~-~--~~~---~--~~ 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: Is this a bug in FormWizard?
> > Your analysis is correct. It's the self.extra_context.update(*) call > in the FormWizard that simply updates the class level copy of that > variable. > > If you instead override "parse_params" as suggested by the comments in > FormWizard, you won't have this problem. To be clearer, in addition to this you will also have to wrap the FormWizard in a view that instantiates it on every request as I mentioned previously. --~--~-~--~~~---~--~~ 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: reverse foreign key lookup in extra()
Thanks a lot Malcolm for your explanatory information. I think I get the concept now :) On Dec 20, 9:36 pm, Malcolm Tredinnickwrote: > On Fri, 2008-12-19 at 11:10 -0800, Fereshteh wrote: > > Hi, > > I am trying to add a filtering functionality to my web application. I > > create a WHERE clouse text in the client side as text and post it to > > the server. > > > My Django modele lookes like this: > > class Projects(models.Model): > > id = models.AutoField(primary_key=True) > > name = models.TextField() > > class Meta: > > db_table = 'projects' > > > class Timesheet(models.Model): > > ts_id = models.AutoField(primary_key=True) > > user = models.ForeignKey(Users, db_column='ts_user', > > related_name='ts_user_child') > > project = models.ForeignKey(Projects, db_column='project', > > related_name='project_child', null='true') > > class Meta: > > db_table = 'timesheet' > > > I use the following in my Django view to retrieve the data according > > to the filtering argument received: > > filter_str = request.POST['filter_str'] > > #filter_str contains something like this: "project__name = 'Django > > supported web app'" > > Timesheet.objects.filter(user = id).extra(where = [filter_str]) > > > But it gives me the error: > > > column project__name does not exist > > > Without using extra the same query works fine so the column does > > exist. > > Your conclusion here is incorrect. There is no column in the database > table called "project__name". When you pass that string to a filter() > call, Django does a lot of processing and works out the right database > table and column name to use for the query. Have a look at the output of > > Timesheet.objects.filter(project__name="foo").query.as_sql() > > for example. You will not see any reference to a column called > "project__name" there. If you are using extra(), you need to use the > correct column names: extra() only exists as a way to write almost raw > SQL portions. > > It sounds a lot like you really want to be using a second filter() call, > not an extra() call. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: Is this a bug in FormWizard?
On Dec 19, 2:27 pm, 朱穆穆wrote: > self.extra_context is a reference of FormWizard.extra_context. > It was empty when the class define, but may not empty when > instantiate. > > class TestWizard(forms.FormWizard): > pass > > tw1 = TestWizard() > tw1(request, extra_context={'test1': 1}) > # tw1.extra_context is {'test1': 1} > > tw2 = TestWizard() > tw2(request, extra_context={'test2': 2}) > # tw1.extra_context and tw2.extra_context both are {'test1': 1, > 'test2':2} Your analysis is correct. It's the self.extra_context.update(*) call in the FormWizard that simply updates the class level copy of that variable. If you instead override "parse_params" as suggested by the comments in FormWizard, you won't have this problem. For example: def parse_params(self, request, *args, **kwargs): if 'extra_context' in kwargs: self.extra_context = kwargs['extra_context'] --~--~-~--~~~---~--~~ 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 models
I see what you are saying but there are few drawbacks: 1) 2 queries instead of one. 2) When you combine into friends_all or something, you need to keep track of which was friend vs which is user. I was thinking more on the lines of this: Each User has a UserProfile which i defined. In UserProfile define a onetomany relationship which points to a specific entry in friends relationship so that both friends would point to the same friendship entry. Im not a django or database relationships expert so im not sure if this would even work or whether it would have better performance than 2 queries (usually you select entries more than insert them). Any feedback is welcome Kevin On Dec 22, 12:28 pm, Jason Sidabraswrote: > The way I was thinking of doing it was to have two foreignkeys named > friend1 and friend2 then when you do your list you could run > (something like) > > friends = Friendship.objects.get(friend1__exact=user) > and > friends2 = Friendship.objects.get(friend2__exact=user) > > Then you have a complete instance of the friends. I'm not by a django > computer right now > to figure it out but friends and friends2 could be added together to > pass one variable. > > On Dec 22, 10:10 am, kev wrote: > > > Hello, > > Im reading a django book and it adds friends to user authentication > > system by making: > > > (was .96) > > > class Friendship(models.Model): > > from_friend = models.ForeignKey( > > User, related_name='friend_set' > > ) > > to_friend = models.ForeignKey( > > User, related_name='to_friend_set' > > ) > > def __str__(self): > > return '%s, %s' % ( > > self.from_friend.username, > > self.to_friend.username > > ) > > class Admin: > > pass > > class Meta: > > unique_together = (('to_friend', 'from_friend'), ) > > > But for this to work, you have to add friendship both ways. Ex/ user1 -> > > user2 and user2 -> user1 which means almost duplicate entries in > > > this model. And anytime you modify one friendship, you have to do the > > same to the other one. > > > Is there a better way to do this so that only one entry exists in the > > db? Any suggestions are welcome! > > > 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 -~--~~~~--~~--~--~---
Re: How to set the from a ModelChoiceField?
I suspect that bots aren't going to follow form submits like this so it doesn't matter. But if you have these GET queries coded into any html elements, thereby becoming part of the sitemap, then it probably will matter. This is a bit of a common sense punt, i'm not an SEO expert, so standing-by to be corrected! On 22 Dec 2008, at 13:06, mb0...@googlemail.com wrote: > > Hello, > > I have a ModelChoiceField getting filled up by a database queryset. > Works fine this far. > In my template the entries of the select-field look all like this: > Afghanistan > > I know that that the value between the two option tags (Afghanistan) > can be set by changing the model's __str()__-method. But is there also > a way to change the way the value-attribut (3) is set? By now it is > the unique id-field from the database, I guess. > I would like to change it, to get more SE-friendly urls (when > submitting the form with GET). Or am I wrong about this? > > > Kind regards, > Martin > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Forms and ManyToMany relationship with intermediary model
Hey there, I've been searching this group for a working example of a complex form using a ManyToMany relationship with an intermediary model. I've read this documentation to know a bit more about the ManyToMany relationship: http://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany I found these posts with a similar problem but wasn't able to make their example work: http://groups.google.com/group/django-users/browse_thread/thread/755f6338ebb623ad/22e3983079012888?lnk=gst=manytomany#22e3983079012888 http://groups.google.com/group/django-users/browse_thread/thread/30377f508e805d/fcb922a7deddc46e?lnk=gst=manytomany+form#fcb922a7deddc46e I also read about Formsets: http://docs.djangoproject.com/en/dev/topics/forms/formsets/ here are my models: http://pastebin.com/f3524b188 Basically, I have Clients and Groups. Clients can be part of multiple groups. Clients that are part of a group can use its group's free rental rate at anytime but only once. That is where the intermediary model comes in with that extra data. What I'm struggling with is saving that data using a form. here's the view: http://pastebin.com/f26256934 The highlighted line is where it dies. Please note that I'm not using the Admin interface. I don't want someone to write the code for me here. I just want to know what's wrong or what I'm forgetting in my code. any hints people? Bernard --~--~-~--~~~---~--~~ 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: Table inheritance and polymorphic admin forms
On Dec 21, 10:02 pm, Malcolm Tredinnickwrote: > On Sun, 2008-12-21 at 18:50 -0800, George Sakkis wrote: > > Hi all, > > > I have a situation which I think would best be modeled as (single) > > inheritance, involving product reviews for various kinds of products. > > Naturally, there are some fields which are common to all reviews > > (overall rating, user, review date) and some which are specific to the > > type of product. Given such an appropriate model set, I'd like to use > > the admin interface to, say, edit the reviews of a user "inline", > > where for each review the appropriate form would be rendered (i.e. > > including all the fields related to each given product). Is this > > possible, and if not, is there a workaround ? > > My inner philosopher is protesting that if there is a workaround, that > would make it possible to do something, right? So if it's not possible, > there's no workaround, pretty much by definition. :-) Well a more precise wording would be "is there a straightforward, 'correct', solution, or if not, at least an ugly kludge that at least works ?" :-) > Anyway, there are two answers to your question: (1) yes, it Just Works, > and (2) What happened when you tried it? It's not really that hard to > test this out. > > Create a simple model inheritance situation with Parent and Child, > inheriting from Parent. Give the Child and admin entry and go and add a > new child. You'll see all the Parent fields right there on the page. It > works transparently. Unfortunately it doesn't work for what I tried. What I am trying to do is have the Child classes as InlineModelAdmin in some other class that references them. Here's a sample: # === models.py === class Review(models.Model): # general fields class Meta: abstract = True class BookReview(Review): # book-specific review fields class MoviewReview(Review): # movie-specific review fields # === admin.py === class ReviewInline(admin.StackedInline): model = models.Review extra = 0 class UserReviewAdmin(admin.ModelAdmin): inlines = [ReviewInline] # more stuff admin.site.register(models.User, UserReviewAdmin) This dies with "type object 'Review' has no attribute '_default_manager'", apparently because Review is not a table-backed model. What should I be doing differently ? George --~--~-~--~~~---~--~~ 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 models
The way I was thinking of doing it was to have two foreignkeys named friend1 and friend2 then when you do your list you could run (something like) friends = Friendship.objects.get(friend1__exact=user) and friends2 = Friendship.objects.get(friend2__exact=user) Then you have a complete instance of the friends. I'm not by a django computer right now to figure it out but friends and friends2 could be added together to pass one variable. On Dec 22, 10:10 am, kevwrote: > Hello, > Im reading a django book and it adds friends to user authentication > system by making: > > (was .96) > > class Friendship(models.Model): > from_friend = models.ForeignKey( > User, related_name='friend_set' > ) > to_friend = models.ForeignKey( > User, related_name='to_friend_set' > ) > def __str__(self): > return '%s, %s' % ( > self.from_friend.username, > self.to_friend.username > ) > class Admin: > pass > class Meta: > unique_together = (('to_friend', 'from_friend'), ) > > But for this to work, you have to add friendship both ways. Ex/ user1 -> > user2 and user2 -> user1 which means almost duplicate entries in > > this model. And anytime you modify one friendship, you have to do the > same to the other one. > > Is there a better way to do this so that only one entry exists in the > db? Any suggestions are welcome! > > 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 -~--~~~~--~~--~--~---
non-fields being inherited by ModelForm
I have a model which is defines kind of like this: MyModel(models.Model) field1 = models.BooleanField() field2 = models.BooleanField() field_num = "1" And then I have a form thats pretty much this: MyModelForm(models.ModelForm) class meta model = MyModel I want to be able to access the "field_num" value from the form object. So I can do this in a template: {{form.field1 }} {{form.field2 }} How can I do this? I'm sorta new to Python/Django --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 models
Hello, Im reading a django book and it adds friends to user authentication system by making: (was .96) class Friendship(models.Model): from_friend = models.ForeignKey( User, related_name='friend_set' ) to_friend = models.ForeignKey( User, related_name='to_friend_set' ) def __str__(self): return '%s, %s' % ( self.from_friend.username, self.to_friend.username ) class Admin: pass class Meta: unique_together = (('to_friend', 'from_friend'), ) But for this to work, you have to add friendship both ways. Ex/ user1 - > user2 and user2 -> user1 which means almost duplicate entries in this model. And anytime you modify one friendship, you have to do the same to the other one. Is there a better way to do this so that only one entry exists in the db? Any suggestions are welcome! 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 -~--~~~~--~~--~--~---
Re: Problem with url tag
This is really boring :( I've restarted the server, and it doens't work again :/ also I've noticed that no urls in reparations.urls can't be called with the template tag url... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Installing django admin on apache/ mod_python
Checked two more things: - to mke sure that mod_python could compile anything it wanted to I chown'd the python distribution to apache (the user). This had and effect - various pyc files created - however, the admin app still doesn't run. - put in a symbolic link so the django distribution is visible within the mysite folder. not sure if I did this correctly and the documentation at http://docs.djangoproject.com/en/dev/howto/deployment/modpython/ doesn't clarify this. Again, this had no effect. I'd like to understand what happens when django tries to start admin. It will be looking for admin.site.root but where does it expect that to be? Also, as there is nothing in apache's error log, is there anywhere else where evidence could be found? On Dec 21, 9:31 am, paultannerwrote: > No more input on this for a while so I tried various moving the > directories around. > My supposition is that it can't find the part of the distribution > containing theadmincode. > > vhost.conf (on a subdomain) > --- > > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > PythonPath "['/var/www/test','/var/www/test/django'] + sys.path" > PythonDebug On > > > urls.py > > from django.conf.urls.defaults import * > from django.contrib importadmin > from mysite.views import current_datetimeadmin.autodiscover() > > urlpatterns = patterns('', > (r'^admin/(.*)',admin.site.root), > (r'^time/$', current_datetime), > ) > > mysite directory is at /var/www/test > django distribution is in the same place > > Is the problem with the PythonPath as: > > /time app in myuysite runs OK > /foo gives a 404 error via django debug > /adminjust hangs (blank browser - nothing appears on apache error > log.) > > Any suggestions pls? > > Paul > > On Nov 18, 12:08 pm, "Karen Tracey" wrote: > > > > > On Tue, Nov 18, 2008 at 3:39 AM, paultanner wrote: > > > > I got a fresh distribution (1.01) and installed it on RHEL4 linux/ > > > apache/mod_python(in a subdomain) > > > python is 2.3.4 > > > the trivial app /tim (from the book) works OK so most of the config > > > must be right > > > then tried to add theadmininterface, modifying settings.py and .. > > > > urls.py > > > --- > > > > from django.conf.urls.defaults import * > > > from django.contrib importadmin > > > from mysite.views import current_datetime > > >admin.autodiscover() > > > > urlpatterns = patterns('', > > > (r'^admin/(.*)',admin.site.root), > > > (r'^time/$', current_datetime), > > > ) > > > > This just hangs. Does not throw an error. An entry in the access_log > > > shows that it tried to redirect. > > > A cut-n-paste of what you're seeing the the log might be enlightening. > > > The other urlpattern you find is old, and will not work with 1.0.x > > > Karen- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TextMate Django Bundle
On 17 Dec 2008, at 23:00, felix wrote: > and thanks to whoever made this ! very useful. The maintainer is PBX / Paul Bissex -- David Reynolds da...@reynoldsfamily.org.uk --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
login_required redirects always to LOGIN_REDIRECT_URL?
I'm seeing strange behaviour of login_required decorator: any view decorated with it first sends to login page, then to url defined in LOGIN_REDIRECT_URL. The url to decorated view is supplied in next parameter (/login/?next=/path/to/view/) but is never executed. Looking at login view code I see that the redirect is taken from redirect_field_name field (which in my case is default "next") of REQUEST. This works as I expect if I do GET, but this value is not set if I issue POST request with credentials after displaying form. Do I have to write my own login machinery to achieve such functionality (redirect to decorated view after login)? Cheers 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-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: Sites
On Mon, Dec 22, 2008 at 3:43 AM, toddwrote: > I'm using the latest django release 1.0.2 and following the tutorial. > I noticed I do not have 'Sites' in my admin site. Am I missing > something to get the 'Sites' appear? > Probably you do not have 'django.contrib.sites' listed in your INSTALLED_APPS? Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Advanced Permissions and States
makka...@gmail.com wrote: >> I'm working on a big project at my work myself. >> We came to this problem last week (we did something to check it, but it >> was unmanagable). >> We wanted to move the check to the models. This is a little bit >> difficult because you basicly doesn't have the user object at in the >> __init__ function of your model. So I've written a small middleware >> which makes the request model available and handles permission denied. >> It rather simple at the moment. The __init__ function of our model calls >> a function which knows where to get the user object, and raises a >> permission denied exception when this function isn't returning True. >> > Can u explain that a little bit ? The __init__ trick .. > > The __init__ function of the model does something like this: if not permission.hasPermission(): raise permission.PermissionsError() The hasPermission function can be any function which accepts any arguments, just what you define ofcourse. The hasPermission function gets the user object and does the check which is needed, returns False when the user hasn't permission, return True when the user has permission. When you store the request object in your middleware, please make it thread-safe (look at transaction middleware and module of django for an example). >> The >> middleware picks up the exception and creates a permission denied page. >> >> > That one is a good idea > > Thanks, the middleware has the function process_exception which checks for the PermissionsError Exception, and returns a HttpResponse with the error page if it encounters that permission, otherwise it returns 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to set the from a ModelChoiceField?
Hello, I have a ModelChoiceField getting filled up by a database queryset. Works fine this far. In my template the entries of the select-field look all like this: Afghanistan I know that that the value between the two option tags (Afghanistan) can be set by changing the model's __str()__-method. But is there also a way to change the way the value-attribut (3) is set? By now it is the unique id-field from the database, I guess. I would like to change it, to get more SE-friendly urls (when submitting the form with GET). Or am I wrong about this? Kind regards, Martin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Complete layout (template) switching.
Hey guys, I'm currently working on a content management system built on the Django framework, currently the whole cms works on a section- >page(s) basis which is working well, we've run in to some issues with our designs in that the blocks for content on some pages are in different locations and the overall layout is different, to combat this we've added a field to the page table that tells Django which layout template it should use, the issue is I'm not sure how to actually make Django read that column and actually switch the whole layouts template for that page on a project level as a replacement to base.html while keeping base.html as default for other pages. Any ideas? --~--~-~--~~~---~--~~ 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: "Building you first Django app, Part 1" example not working
You're 14. You recognize that you're having a problem and you post to the Django group for help. You're not stupid at all. I would say you're very intelligent! On Dec 21, 2:43 pm, Chriswrote: > Oh shit, that's awesome! Thanks! I thought it had already created the > DB and wanted me to fill in that info... I'm so stupid sometimes. > Thanks a bunch mrtot... > > On Dec 21, 3:50 am, mrtot wrote: > > > Hi Chris, > > > maybe it's the best to just do what the error message suggest: > > > "Please fill out DATABASE_NAME in the settings module before using the > > database. " > > > Put in something like '/home/chris/projects/django-tutorial/db/db.db' > > > You can create your own name. Django just wants to know where it > > should store the database. > > No need to install MySQL for your local sandboxes :) > > > Greets, > > Martin > > > On 21 Dez., 12:40, Chris wrote: > > > > Okay... I'm on part two of the tut now and I am attemping to use > > > Python's built-in SQLite Database just to get a feel for Django. > > > However, the tutorial confuses me in part one when it defines > > > DATABASE_NAME, "The name of your database. If you're using SQLite, the > > > database will be a file on your computer; in that case, DATABASE_NAME > > > should be the full absolute path, including filename, of that file. If > > > the file doesn't exist, it will automatically be created when you > > > synchronize the database for the first time (see below)." > > > > It say, "see below," but all that is below is the reference, "If > > > you're using SQLite, you don't need to create anything beforehand - > > > the database file will be created automatically when it is needed." > > > which is wonderful, but I recieve the error shown below when I try to > > > run the admin interface, as I haven't specified the DATABASE_NAME. How > > > can I if I don't know where it was created? > > > > Anyway, here's my error. Running almost any other command at the promt > > > gives me an error ending with "ImproperlyConfigured: Please fill out > > > DATABASE_NAME in the settings module before using the database.", but > > > the error shown when I try to run the admin is included below... > > > > --- > > > > Traceback (most recent call last): > > > > File "/Library/Python/2.5/site-packages/django/core/servers/ > > > basehttp.py", line 278, in run > > > self.result = application(self.environ, self.start_response) > > > > File "/Library/Python/2.5/site-packages/django/core/servers/ > > > basehttp.py", line 635, in __call__ > > > return self.application(environ, start_response) > > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > > wsgi.py", line 243, in __call__ > > > response = middleware_method(request, response) > > > > File "/Library/Python/2.5/site-packages/django/contrib/sessions/ > > > middleware.py", line 35, in process_response > > > request.session.save() > > > > File "/Library/Python/2.5/site-packages/django/contrib/sessions/ > > > backends/db.py", line 52, in save > > > session_key = self.session_key, > > > > File "/Library/Python/2.5/site-packages/django/contrib/sessions/ > > > backends/base.py", line 152, in _get_session_key > > > self._session_key = self._get_new_session_key() > > > > File "/Library/Python/2.5/site-packages/django/contrib/sessions/ > > > backends/base.py", line 144, in _get_new_session_key > > > if not self.exists(session_key): > > > > File "/Library/Python/2.5/site-packages/django/contrib/sessions/ > > > backends/db.py", line 25, in exists > > > Session.objects.get(session_key=session_key) > > > > File "/Library/Python/2.5/site-packages/django/db/models/ > > > manager.py", line 93, in get > > > return self.get_query_set().get(*args, **kwargs) > > > > File "/Library/Python/2.5/site-packages/django/db/models/query.py", > > > line 304, in get > > > num = len(clone) > > > > File "/Library/Python/2.5/site-packages/django/db/models/query.py", > > > line 160, in __len__ > > > self._result_cache = list(self.iterator()) > > > > File "/Library/Python/2.5/site-packages/django/db/models/query.py", > > > line 275, in iterator > > > for row in self.query.results_iter(): > > > > File "/Library/Python/2.5/site-packages/django/db/models/sql/ > > > query.py", line 206, in results_iter > > > for rows in self.execute_sql(MULTI): > > > > File "/Library/Python/2.5/site-packages/django/db/models/sql/ > > > query.py", line 1733, in execute_sql > > > cursor = self.connection.cursor() > > > > File "/Library/Python/2.5/site-packages/django/db/backends/ > > > __init__.py", line 56, in cursor > > > cursor = self._cursor(settings) > > > > File "/Library/Python/2.5/site-packages/django/db/backends/sqlite3/ > > > base.py", line 139, in _cursor > >
I18n when using standalone templates
Hi there, We're using Django templates on their own. Usually invoked like this (eg): - t = django.template.Template(templateSource) c = django.template.Context({}) print t.render(c) - When you add i18n to this mix, however, how do you set the language to be used when rendering? Can you put something into the context? Thanks - Iwan --~--~-~--~~~---~--~~ 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: Advanced Permissions and States
On Monday 22 December 2008 12:18:13 pm Paul van der Linden wrote: > Hi, Hi thanks for the reply > I'm working on a big project at my work myself. > We came to this problem last week (we did something to check it, but it > was unmanagable). > We wanted to move the check to the models. This is a little bit > difficult because you basicly doesn't have the user object at in the > __init__ function of your model. So I've written a small middleware > which makes the request model available and handles permission denied. > It rather simple at the moment. The __init__ function of our model calls > a function which knows where to get the user object, and raises a > permission denied exception when this function isn't returning True. Can u explain that a little bit ? The __init__ trick .. > The > middleware picks up the exception and creates a permission denied page. > That one is a good idea > makka...@gmail.com wrote: > > Hi i'm developing an e-commerce site with Django, and have situations > > like this : > > > > - A user can execute different operations in different time-intervals if > > he has the right privileges. > > Ex : A user can edit only his products > > Ex : A user can edit only his orders when he has bought the product. > > > > The solution may seem straightforward you have a view and do these : > > > > def some_view(request): > > if not first_requirement_ok: > > raise Error > > if not second_requirement_ok: > > raise Error > > > > #all other requirements > > . > > . > > . > > . > > > > In the past i developed a forum app and did the same thing as above. > > However when put the app in production i saw that there were some > > security issues. Some users were able to edit others posts and etc. > > > > I think that time i need sth better and more dynamic. Do someone knows > > some way to do things cooler ? Some pattern or way that will let me > > manage that user privilage interaction easier. > > > > What i think for now is to write lots of security decorators and use > > them. Sth like that : > > > > @is_user_owner > > @did_he_buy_product > > > > def some_view(request): > > #do the operation > > > > > > Another way i think about is to use the State Pattern (using the state > > diagrams) and move that code somewhere else for more flexibility. For > > example: > > > > class SomeState: > > > > @is_user_owner > > @did_he_buy_product > > > > def change_state(*args): > > #do stuff > > > > > > Does some of you manage that kind of big projects and how do you manage > > it ? Any advices recommendations will be appreciated. > > --~--~-~--~~~---~--~~ 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: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)
I had the same problem two weeks ago. This is what I wrote: def resize_photo(self,content,size): img = Image.open(ContentFile(content)) img.thumbnail(size, Image.ANTIALIAS) io = StringIO.StringIO() img.save(io, 'PNG') return ContentFile(io.getvalue()) Hope this helps. -Brian On Dec 22, 4:41 am, Merrickwrote: > Thank you I tried that and I still get the same error. > > I spent a little more time looking at PIL / Image.py and cleaning up > the code. From what I can tell the Image.open method is having trouble > with what I am passing to it. > > def resize_image(file, size=(50, 50)): > from PIL import Image > from cStringIO import StringIO > from django.core.files.base import ContentFile > > image_data = StringIO(file.read()) > > ### this line below is where the issue is ### > image = Image.open(image_data) > > if image.mode not in ('L', 'RGB'): > image = image.convert('RGB') > image.thumbnail(size, Image.ANTIALIAS) > o = StringIO() > image.save(o, "JPEG") > return ContentFile(o.getvalue()) > > This is how I call it: > picture = pform.cleaned_data['picture'] > thumbnail_content = resize_image(picture) > > Thank you for looking at this. > > On Dec 21, 3:08 pm, "j...@zigzap.com" wrote: > > > From what I can tell your not wrapping the thumbnailfilein > > ContentFile your just returning the rawfilefrom the string IO. To > > use the the ImageField django provides you must provide it with afile > > that is in a special wrapper called ContentFile. I would suggest > > trying this: > > > from django.core.files.base import ContentFile (import this function > > at the top of your view or where ever you put def resize_image) > > > change the last line of def resize_image from "return o.getvalue()" to > > "return ContentFile(o.getvalue())" > > > I would also recommend changing "new_profile.picture.save(filename, > > thumbnail_content)" to "new_profile.picture.save(filename, > > thumbnail_content, save=False)" so that you are not hitting the > > database twice. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to access SplitDateTime field elements in template
I have a form with a SplitDateTimeField and cannot figure out how to access the individual date and time elements in it from my template: class Dummy1(models.Model): name = models.CharField(max_length = 100) created = models.DateTimeField(default = datetime.datetime.now()) class Dummy1Form(forms.Form): name = forms.CharField(max_length = 100) created = forms.SplitDateTimeField(widget=forms.SplitDateTimeWidget ()) class Meta: model = Dummy1 In my template: {% trans "Created:" %} {{ form.created }} will give me access to the 2 fields but if I want to do something like the old form , what syntax do I need to get at the individual elements: {% trans "Created:" %} {% trans "Date: "%}{{ form.created_date }} {% trans "Time: "%}{{ form.created_time }} I haven't found any doc on this Rgds Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django date filter
Hi folks, Simple enough problem but cant find the functionality - if it exists. this_week = datetime.date.today() - timedelta(7) Cars.objects.filter(created_date>this_week) I basically want to find all cars that were created in the last 7 days. I have seen there are things for the month and year created_date__year = this_week.year created_date__month = this_week.month What i want is created_date__week = this_week.week Is there any simple way of doing this. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
DJango +Appy Framework+ generate pdf and odt file
Dear all, I am using POD APPY framework (http://appyframework.org/) for generating reports in pdf and odt files. i am able to get reports in odt file using development server. when i tried with pdf reports, i got an error ERROR An error occurred during the conversion. Could not connect to OpenOffice on port 2002. UNO (OpenOffice API) says: Connector : couldn't connect to socket (Success). - When i googled out this error, i got a solution. SOLUTION-Run the comman in terminal -- /usr/lib/openoffice/program/soffice "- accept=socket,host=localhost,port=2002;urp;" -- then i am able to get the reports in pdf in development server. PROBLEM The problem i am facing is, i have deployed my project in apache with modpython. i can get the report in odt file with out any problem. but when i try to get the report in pdf format, i am getting an error Error is --- com.sun.star.task.ErrorCodeIOException --- i have gooogled out to solve this issue, but still i am hanging with tis error Can any one help me to solve this problem. thanks in advance :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Subprocess module in Python CGI
Hello, I have started using python recently and would like to call a short python script via browser using a CGI script, but initially I am trying to call the same python script directly through python command line. The script intends to perform a few command line in a pipe and I have written the script (a short one) as follows. I would later also like to import this application to Django. #!/usr/bin/python import cgi, string, os, sys, cgitb, commands, subprocess import posixpath, macpath #file = "x.tar.gz" #comd = "tar -xf %s" % (file) #os.system(comd) #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../') comd = [\ "tar -xf x.tar.gz", \ "cd demo", \ "cp README ../", \ ] outFile = os.path.join(os.curdir, "output.log") outptr = file(outFile, "w") errFile = os.path.join(os.curdir, "error.log") errptr = file(errFile, "w") retval = subprocess.call(comd, 0, None, None, outptr, errptr) errptr.close() outptr.close() if not retval == 0: errptr = file(errFile, "r") errData = errptr.read() errptr.close() raise Exception("Error executing command: " + repr(errData)) but after trying to execute this independently, I get the following error which I am unable to interpret : Traceback (most recent call last): File "process.py", line 18, in retval = subprocess.call(comd, 0, None, None, outptr, errptr) File "/usr/lib/python2.5/subprocess.py", line 443, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.5/subprocess.py", line 593, in __init__ errread, errwrite) File "/usr/lib/python2.5/subprocess.py", line 1135, in _execute_child raise child_exception Could someone suggest where am I going wrong and if corrected, what is the probability of this script being compatible with being called through the browser. Thanking you people in advance. Regards. --~--~-~--~~~---~--~~ 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: dynamic mod wsgi
Hi Graham, I've finally managed to get back to the wildcard subdomains & mod_wsgi today. Unfortunately the discussion thread you mentioned has disappeared and after a few hours i still seem to be doing a good job of getting nowhere. Although you mentioned using mod_rewrite to get hold of the url variable, it looks like the %{SERVER} variable in mod_wsgi might take care of this already? My main issue seems to be to accessing the %{SERVER} (or relevant mod_rewrite) variable in the .wsgi script, to specify a particular settings file. Within a VirtualHost i have: WSGIApplicationGroup %{SERVER} WSGIDaemonProcess %{SERVER} ...threads etc WSGIProcessGroup %{SERVER} So this is probably hoplessly wrong also, but if you can give some further pointers that would be most kind. Thanks and Regards, Ben On 9 Dec 2008, at 10:18, Graham Dumpleton wrote: > > > > On Dec 9, 8:05 pm, Ben Eliottwrote: >> Graham, >> Thank you for coming back personally to such a lowly wsgi question! I >> started reading your email and thinking the answer was 'no', then >> ended up thinking 'definitely maybe'. I'll keep an eye out in case >> you >> post more, otherwise i'll follow those links and your directions and >> hope to report back with some progress. > > I'll definitely try and say more later when get a chance. > > Just do be aware of one thing. By using a single WSGI script file for > multiple sites, you loose the ability with mod_wsgi daemon mode to > touch the WSGI script file and cause a single site to be reloaded. One > would normally use this as a way of reloading a single site without > the need to restart the whole of Apache. When sharing the single WSGI > script file across sites, touching the WSGI script file will restart > all sites using that WSGI script file. If they share the code this may > actually be want you want, so not a problem, but worth mentioning. > > In this arrangement, if you did want to reload one site, for example > because you change its settings file, you would need to use 'ps' to > identify process(es) in that daemon process group, based on what > display-name option was set to, and send all those processes in that > daemon process group a SIGINT using the 'kill' command. Alternatively, > you would need to setup a background thread which monitored something > like the distinct settings file for each site and have the process > itself send a SIGINT to itself. This would be a variation on > background reloader described in: > > > http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Daemon_Processes > > More later. > > Graham > >> Thanks and Regards, >> Ben >> >> On 9 Dec 2008, at 08:23, Graham Dumpleton wrote: >> >> >> >>> On Dec 9, 6:53 pm, "ben.dja...@googlemail.com" >>> wrote: Hi, I'm converting to the excellent mod_wsgi and wondering if it's possible to make a single httpd virtual host/wsgi file to manage wildcard subdomains. >> Basically I have an app where i'm creating a new instance for each client and using subdomains. So client1.example.com and client2.example.com both point to the same app, but their own settings.py/django instance. >> So far so fine. I've been happily converting to mod_wsgi daemons, creating virtual hosts and independent .wsgi files for each one. But now just wondering whether there is some way i can make this process dynamic so one virtual host/.wsgi file will take care of all these subdomains. >> I see the advice on the wsgi wiki to push domain sub-directories to different django instances, but i'd rather keep using the subdomains if possible. >> It looks possible to be able to parse information about the incoming request in the wsgi file and push it to different settings. But i'm not sure what this will do in terms of spawning processes etc, it looks a little dangerous, or maybe this will work. Any advice appreciated thanks! >> >>> Start by reading recent discussion: >> >>> http://groups.google.com/group/django-users/browse_frm/thread/dfd3521 >>> ... >> >>> I'll post more tomorrow if have time, have to do some things tonight >>> and then out most of the day tomorrow. >> >>> In short though, no support for dynamic transient daemon processes >>> yet, ie.,: >> >>> http://code.google.com/p/modwsgi/issues/detail?id=22 >> >>> so, can't get away from using WSGIDaemonProcess for each instance at >>> the moment. >> >>> One can use dynamic setting of WSGIApplicationGroup via a variable >>> set >>> by mod_rewrite to select daemon process as well as set some name >>> relevant to settings file. WSGI application wrapper can then be used >>> to override DJANGO_SETTINGS_MODULE. >> >>> So, information is in that post, you just need to adapt it to your >>> situation. That is, use SERVER_NAME rather than REMOTE_USER from >>> authentication as basis of selecting
Re: Advanced Permissions and States
Hi, I'm working on a big project at my work myself. We came to this problem last week (we did something to check it, but it was unmanagable). We wanted to move the check to the models. This is a little bit difficult because you basicly doesn't have the user object at in the __init__ function of your model. So I've written a small middleware which makes the request model available and handles permission denied. It rather simple at the moment. The __init__ function of our model calls a function which knows where to get the user object, and raises a permission denied exception when this function isn't returning True. The middleware picks up the exception and creates a permission denied page. makka...@gmail.com wrote: > Hi i'm developing an e-commerce site with Django, and have situations like > this : > > - A user can execute different operations in different time-intervals if he > has the right privileges. > Ex : A user can edit only his products > Ex : A user can edit only his orders when he has bought the product. > > The solution may seem straightforward you have a view and do these : > > def some_view(request): > if not first_requirement_ok: > raise Error > if not second_requirement_ok: > raise Error > > #all other requirements > . > . > . > . > > In the past i developed a forum app and did the same thing as above. However > when put the app in production i saw that there were some security issues. > Some users were able to edit others posts and etc. > > I think that time i need sth better and more dynamic. Do someone knows some > way to do things cooler ? Some pattern or way that will let me manage that > user privilage interaction easier. > > What i think for now is to write lots of security decorators and use them. > Sth > like that : > > @is_user_owner > @did_he_buy_product > > def some_view(request): > #do the operation > > > Another way i think about is to use the State Pattern (using the state > diagrams) and move that code somewhere else for more flexibility. For > example: > > class SomeState: > > @is_user_owner > @did_he_buy_product > > def change_state(*args): > #do stuff > > > Does some of you manage that kind of big projects and how do you manage it ? > Any advices recommendations will be appreciated. > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with url tag
What a strangeness! I edit the template removing the extend tag, and it worked, next I readded the extend and it still worked :O this is really strange :/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Model with CharField primary key, force_update=True to prevent saving other object
I'm working with a model using a CharField primary key, and want to ask whether it is appropriate to use force_update=True in a save() override on the model. I need to prevent other objects from being created/updated if save() is called with a changed pk value. class Widget(models.Model): identifier = models.CharField(primary_key=True, max_length=10) I realize that the Django ORM works best with an auto id column, and I can use that if necessary. I'm experimenting with a custom PK for two reasons: a) this key is an externally assigned alphanumeric ID that won't change over the lifetime of the object, and b) some legacy tables I'll need to work with in the future have the same layout. I first noticed this in the admin app, where edting (this Model's) pk field creates or updates a different object with that pk. Confirmed in the shell, and mentioned in the docs [1]. Thanks for any suggestions. [1] Forcing an INSERT or UPDATE http://docs.djangoproject.com/en/dev/ref/models/instances/#forcing-an-insert-or-update [2] Changing the value of the primary key http://groups.google.com/group/django-users/browse_thread/thread/6a0567912d2f035/06c503c65189fabc [3] Admin interface using CharField as a primary key http://groups.google.com/group/django-users/browse_thread/thread/50be5ff7b516bd76/e07e653d7f51c493 --~--~-~--~~~---~--~~ 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: S3Storage.py and Thumbnails using PIL (IOError / cannot identify image file)
Thank you I tried that and I still get the same error. I spent a little more time looking at PIL / Image.py and cleaning up the code. From what I can tell the Image.open method is having trouble with what I am passing to it. def resize_image(file, size=(50, 50)): from PIL import Image from cStringIO import StringIO from django.core.files.base import ContentFile image_data = StringIO(file.read()) ### this line below is where the issue is ### image = Image.open(image_data) if image.mode not in ('L', 'RGB'): image = image.convert('RGB') image.thumbnail(size, Image.ANTIALIAS) o = StringIO() image.save(o, "JPEG") return ContentFile(o.getvalue()) This is how I call it: picture = pform.cleaned_data['picture'] thumbnail_content = resize_image(picture) Thank you for looking at this. On Dec 21, 3:08 pm, "j...@zigzap.com"wrote: > From what I can tell your not wrapping the thumbnailfilein > ContentFile your just returning the rawfilefrom the string IO. To > use the the ImageField django provides you must provide it with afile > that is in a special wrapper called ContentFile. I would suggest > trying this: > > from django.core.files.base import ContentFile (import this function > at the top of your view or where ever you put def resize_image) > > change the last line of def resize_image from "return o.getvalue()" to > "return ContentFile(o.getvalue())" > > I would also recommend changing "new_profile.picture.save(filename, > thumbnail_content)" to "new_profile.picture.save(filename, > thumbnail_content, save=False)" so that you are not hitting the > database twice. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with url tag
On 22 Dic, 09:24, Malcolm Tredinnickwrote: > Okay, nothing unexpected there. If I use the same lines with a dummy > view file, things certainly seem to work. > > The confusing thing here is that the url template tag is a relatively > simple wrapper around reverse(), so there aren't many places for things > to go wrong. Still, let's see what might be happening. I'm assuming in > what follows that you're either running Django 1.0.2 or something later > from the 1.0.X branch or Django trunk. All those versions have basically > the same code in place with all the relevant fixes for reverse(). > > Add some debug printing to django/template/defaulttags.py in the URLNode > class. In particular, in the render() method where it says > > args = [arg.resolve(context) for arg in self.args] > > (line 361 in 1.0.X, line 371 in trunk). > > What I'm interested in seeing is what are the values and types of the > elements in the args list. So the output of something like > > print [(repr(x), type(x)) for x in args] > Instead of editing django core, could I create a template tag? I think it is better > would be interesting. Somehow -- and I don't know how or why, yet -- the > value of worksheet.number might not be turning out as expected. Although > the error message does make it seem like you're passing in a number > correctly. > > I'll admit I'm grasping at straws a bit here, but this is the kind of > thing that you really have to debug at the source, line by line. > Ideally, we need to work out if the exact same data, of the exact same > type is being passed into the reverse() calls for the tag version. If it > is the exact same piece of data, there's something else going on. > Somehow, when you're running under the web server, the setup is subtly > different to the shell code. That's going to be a little tougher to > debug. > > Oh ... other idea. Try some experiments like this: > > In [3]: from django.template import Template, Context > > In [4]: t = Template("{% url show_worksheet 5537 %}") > > In [5]: t.render(Context()) > Out[5]: u'/foglio/5537/' > > That shows the url tag is working in my setup when I pass in a constant > argument. Perhaps you can arrange a shell-prompt version with > worksheet.number set up exactly as in the template that is failing for > you. Would be interesting to see if you can make things fail for the url > tag at the shell prompt whilst reverse() for the same thing works. > I tried it and it worked :) also i tried with passing the WorkSheet object: >>> from django.template import Template, Context >>> from reparations.models import WorkSheet >>> w = WorkSheet.objects.get(pk=1) >>> c = Context({ 'w': w }) >>> t = Template("{% url show_worksheet w.number %}") >>> t.render(c) u'/riparazioni/foglio/5537/' > Regards, > Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Sites
Hi, I'm using the latest django release 1.0.2 and following the tutorial. I noticed I do not have 'Sites' in my admin site. Am I missing something to get the 'Sites' appear? --~--~-~--~~~---~--~~ 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: PDF to Text Coverter
Check this: http://code.activestate.com/recipes/511465/ http://pybrary.net/pyPdf/ Best regards, 2008/12/21 Harish: > > Hi Friends... > > I know this is a not a right place to ask this question. > but it is related to Python. I thought it to ask. > > Is there any python library is available to read a pdf files... ? > > Or any library to convert the pdf into text files? > > If you have any idea about above issues > > please let me know... > > Regards > Harish Bhat M -- Antoni Aloy López Blog: http://trespams.com Site: http://apsl.net --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
doc/user manual management
Hi, We are developing an Intranet product hosted on Django. It is a product which is currently installed at couple of clients and goes through monthy updates. We are developing a user manual which will be in revision almost every week. We might have a few more installations this year for the same product. We need to somehow update the app's documents every week. The code base is currenlty being updated by SVN, and we are using mysqladmin, to alter the database schemas as when required. Is there a way we can ensure that the docs change uniformly from central machine, much like svn updates code base. We would like the data/docs to be in the database Thanks -- Ramdas S +91 9342 583 065 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with url tag
On Sun, 2008-12-21 at 23:58 -0800, patrick91 wrote: > On 22 Dic, 02:17, Malcolm Tredinnickwrote: > > Certainly a bit unexpected. Can you paste the relevant lines from your > > URL Conf file, please? > > > > Regards, > > Malcolm > > Sure :) > here it is: > url(r'foglio/(?P[0-9]+)/$', views.show_worksheet, > name='show_worksheet'), Okay, nothing unexpected there. If I use the same lines with a dummy view file, things certainly seem to work. The confusing thing here is that the url template tag is a relatively simple wrapper around reverse(), so there aren't many places for things to go wrong. Still, let's see what might be happening. I'm assuming in what follows that you're either running Django 1.0.2 or something later from the 1.0.X branch or Django trunk. All those versions have basically the same code in place with all the relevant fixes for reverse(). Add some debug printing to django/template/defaulttags.py in the URLNode class. In particular, in the render() method where it says args = [arg.resolve(context) for arg in self.args] (line 361 in 1.0.X, line 371 in trunk). What I'm interested in seeing is what are the values and types of the elements in the args list. So the output of something like print [(repr(x), type(x)) for x in args] would be interesting. Somehow -- and I don't know how or why, yet -- the value of worksheet.number might not be turning out as expected. Although the error message does make it seem like you're passing in a number correctly. I'll admit I'm grasping at straws a bit here, but this is the kind of thing that you really have to debug at the source, line by line. Ideally, we need to work out if the exact same data, of the exact same type is being passed into the reverse() calls for the tag version. If it is the exact same piece of data, there's something else going on. Somehow, when you're running under the web server, the setup is subtly different to the shell code. That's going to be a little tougher to debug. Oh ... other idea. Try some experiments like this: In [3]: from django.template import Template, Context In [4]: t = Template("{% url show_worksheet 5537 %}") In [5]: t.render(Context()) Out[5]: u'/foglio/5537/' That shows the url tag is working in my setup when I pass in a constant argument. Perhaps you can arrange a shell-prompt version with worksheet.number set up exactly as in the template that is failing for you. Would be interesting to see if you can make things fail for the url tag at the shell prompt whilst reverse() for the same thing works. Regards, Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---