Re: Possible bug in model validation
Las try or I will report it as a bug as I think it is. 2011/1/28 Miguel Araujo <muchoch...@gmail.com> > Well, > > I'm just trying to figure out if this should be reported. > > Thanks, regards > > > Miguel Araujo > @maraujop > > 2011/1/22 Miguel Araujo <muchoch...@gmail.com> > > Hi everyone, >> >> I have a model A that has a overwritten save method that updates a model >> B's field. Both (A & B) have model validation using full_clean method. >> Problem is that B model's validation fails when updating the field, because >> it raises an IntegrityError saying the primary key already exits, >> obviously. >> >> To fix this within my save method I have done: >> >> if kwargs.get('force_update') is False: >> self.full_clean() >> >> If this is the desired behavior, then just let me know, I don't think the >> primary key on an update should be validated this way. >> >> Thanks, best regards >> >> >> Miguel Araujo >> @maraujop >> > > -- 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: weird behavior in select_related
I didn't know that, that's why it was happening. I didn't post my models, as I wasn't sure that would help. Thanks for your help Daniel, Miguel Araujo @maraujop 2011/1/28 Daniel Roseman <dan...@roseman.org.uk> > On Saturday, January 22, 2011 1:38:22 PM UTC, maraujop wrote: >> >> Hi everyone, >> >> I have been working on reducing DB queries in my project with great >> results. But I have realized that select_related in one of my models doesn't >> preload all the ForeignKeys and OneToOneFields, it preloads 3 out of 5. >> Actually the 3 preloaded are ForeignKeys and the other 2 are OneToOneFields. >> Before trying to reproduce this problem in a simplified schema, I need >> someone to confirm this is unusual. >> >> If I do a select_related('names', 'of', 'the', 'five', 'fks') everything >> is loaded. Last thing I can say is that those OneToOneFields point models >> that reference back to model pointing at them, for performance reasons. I >> reckon this can be a bug. >> >> Thanks, best regards >> >> >> Miguel Araujo >> @maraujop >> > > It would have helped if you'd posted your model. If your relationships are > defined as null=True, then select_related() doesn't follow them unless you > specify them explicitly. > -- > 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<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: weird behavior in select_related
Hi, Please anyone confirm if this is normal, so I can report it or not. Thanks, regards Miguel Araujo @maraujop 2011/1/22 Miguel Araujo <muchoch...@gmail.com> > Hi everyone, > > I have been working on reducing DB queries in my project with great > results. But I have realized that select_related in one of my models doesn't > preload all the ForeignKeys and OneToOneFields, it preloads 3 out of 5. > Actually the 3 preloaded are ForeignKeys and the other 2 are OneToOneFields. > Before trying to reproduce this problem in a simplified schema, I need > someone to confirm this is unusual. > > If I do a select_related('names', 'of', 'the', 'five', 'fks') everything is > loaded. Last thing I can say is that those OneToOneFields point models that > reference back to model pointing at them, for performance reasons. I reckon > this can be a bug. > > Thanks, best regards > > > Miguel Araujo > @maraujop > -- 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: Possible bug in model validation
Well, I'm just trying to figure out if this should be reported. Thanks, regards Miguel Araujo @maraujop 2011/1/22 Miguel Araujo <muchoch...@gmail.com> > Hi everyone, > > I have a model A that has a overwritten save method that updates a model > B's field. Both (A & B) have model validation using full_clean method. > Problem is that B model's validation fails when updating the field, because > it raises an IntegrityError saying the primary key already exits, > obviously. > > To fix this within my save method I have done: > > if kwargs.get('force_update') is False: > self.full_clean() > > If this is the desired behavior, then just let me know, I don't think the > primary key on an update should be validated this way. > > Thanks, best regards > > > Miguel Araujo > @maraujop > -- 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.
Possible bug in model validation
Hi everyone, I have a model A that has a overwritten save method that updates a model B's field. Both (A & B) have model validation using full_clean method. Problem is that B model's validation fails when updating the field, because it raises an IntegrityError saying the primary key already exits, obviously. To fix this within my save method I have done: if kwargs.get('force_update') is False: self.full_clean() If this is the desired behavior, then just let me know, I don't think the primary key on an update should be validated this way. Thanks, best regards ---- Miguel Araujo @maraujop -- 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.
weird behavior in select_related
Hi everyone, I have been working on reducing DB queries in my project with great results. But I have realized that select_related in one of my models doesn't preload all the ForeignKeys and OneToOneFields, it preloads 3 out of 5. Actually the 3 preloaded are ForeignKeys and the other 2 are OneToOneFields. Before trying to reproduce this problem in a simplified schema, I need someone to confirm this is unusual. If I do a select_related('names', 'of', 'the', 'five', 'fks') everything is loaded. Last thing I can say is that those OneToOneFields point models that reference back to model pointing at them, for performance reasons. I reckon this can be a bug. Thanks, best regards Miguel Araujo @maraujop -- 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 do I filter/exclude custom queryset fields created by .extra()?
Hi, Try always not to think SQL and not to use extra. Most of the times there is an alternative without extra. Extra is advanced. class Node(Model): widgets = ForeignKey(Widget) This query will give you all the different nodes that have the foreign key widgets set to something different than null: Node.objects.filter(widgets__isnull = False).distinct() As your ForeignKey widgets can not be null, all nodes in the table will point to at least one widget. So it's the same as if you do: Node.objects.all().distinct() Maybe you want to do this: class Node(Model): widgets = ForeignKey(Widget, null=True) Regards, Miguel Araujo 2010/10/29 Jumpfroggy <rocketmonk...@gmail.com> > From a raw SQL standpoint, I've figured out that these constraints > need to be in the HAVING clause, not the WHERE clause. But it looks > like HAVING is not exposed through the .extra() function, which would > seems logical. It appears you can create extra fields, but due to > this lack you can't filter on them. Is there another way to customize > the HAVING 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Today I released my first Django-app
Hi everyone! I hope this message is not seen as spam. Today I released my first Django-app as Open Source on Github. It's called django-rules. It's an authorization backend that you can use to flexibly manage per object permissions in your Django projects. I find it very useful and I'm sending this notice here, so you get to know about it. Project's website is: http://github.com/maraujop/django-rules Best regards, Miguel Araujo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Forms in a Workflow for Related Models
Hi, You will need to go step by step. First you ask the user for the reviewer with a form. Then the user has to submit the form. You manage your input form and see if the data for that reviewer already exists, if it does, then you load initial data in the second form. Now you redirect the user to the second form, empty or loaded. This is the usual HTML web application flow, not related to Django. If you want things to happen dynamically, you will have to use AJAX, you can use any JS library you like. Best regards, Miguel 2010/10/29 ghachey> Hi, > > I think I have a particular case. I could not find an easy way to do > this going carefully through all the documentation. I also couldn't > find anything close enough in these archives to help me out with my > limited experience so I am resorting to asking you. > > I have a Paper model which records research paper information > (references for a given paper). And, I have a Questionnaire model > which records a questionnaire instance for a given paper instance. > They look like this, > > class Paper(models.Model): > author = models.CharField(max_length=256) > title = models.CharField(max_length=256) > . > . > > class Questionnaire(models.Model): > paper = models.ForeignKey(Paper, > db_column='paper_fk',blank=True,null=True) > reviewer = models.CharField( >verbose_name="Who is the reviewer?", >max_length=5,choices=REVIEWERS,unique=True) > question1 = models.CharField(max_length=256) > . > . > > I have a view that pulls all paper instances (for a particular > research) showing the title and the abstract only on a page. I would > like to be able to click on the title of any one of the papers opening > a new browser window in which I could complete a questionnaire for > that particular paper. > > Ideally, it would ask first which *reviewer* would like to submit (or > update) a questionnaire for that paper (see the Questionnaire model). > Subsequently, it would show an empty Questionnaire form (if reviewer > has not submitted a questionnaire for that paper yet) or the > previously submitted instance of that questionnaire for that paper by > that reviewer. > > I simply cannot find an easy way of achieving this. I have looked at > inline formset (with online one inline), a combination of forms, etc. > but none of those seem to do what I want easily. > > Any ideas would be greatly appreciated, even telling me to do this in > a completely different way. > > Thank you, > > -- > GH > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Model Inheritance.
Hi Tom, You might want to have a look at inheritanceCastModel from django-model-utils by Carl Meyer http://github.com/carljm/django-model-utils Best regards, Miguel Araujo 2010/10/29 David De La Harpe Golden <david.delaharpe.gol...@ichec.ie> > On 29/10/10 00:04, Tom Eastman wrote: > > That's correct, but I want to take a 'Place' object, that doesn't have a >> 'restaurant', and turn it *in to* a 'Restaurant' by adding the >> corresponding row to the Restaurant table. >> > > > So you have a place. > > p = Place(name="3rd Circle of Hell") > p.save() > > This should work: > > r = Restaurant(serves_hot_dogs=True) > r.place_ptr = p > r.save() > > If you then want an r that has picked up the now-should-be-inherited place > attrs, you'll have to do something like: > > r = Restaurant.objects.get(pk=r.pk) > > print r.name > 3rd Circle of Hell > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: possible bug in joining on a geo field
Should I report it? who should I contact? Anyone can confirm this is a bug? 2010/10/23 Miguel Araujo <muchoch...@gmail.com> > Thanks Karen, you are right. But I missed the underscore for sending this, > although I was trying here with double underscore: > > So If I do it right: > > Item.objects.filter(location__point__distance__lte = (point, D(km=10))) > > I get: > > FieldError: Join on field 'point' not permitted. Did you misspell > 'distance' for the lookup type? > > So it's still not working. > > Regards, > Miguel Araujo > > 2010/10/23 Karen Tracey <kmtra...@gmail.com> > > On Sat, Oct 23, 2010 at 1:07 PM, Miguel Araujo <muchoch...@gmail.com>wrote: >> >>> Item.objects.filter(location__point__distance_lte = (point, D(km=10))) >>> >> >> Looks like you are missing an underscore in distance__lte >> >> Karen >> -- >> http://tracey.org/kmt/ >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: inheriting User class
Thanks Rob, I'm using the same approach here, but I don't really like to access some of my fields in the template doing `user.get_profile.field` I would simply love to do `user.field`. Also Sometimes I'm pointing to my profile instead of User, to access the extra information so queries become more obscure and less elegant if I need to access User though my Profile `userprofile__user__username__exact` If there is no better option, I will try to wrap everything in some helpers, Regards, Miguel Araujo 2010/10/25 Rob <robert.osbo...@gmail.com> > Probably most of us are using the separate profile model, as > recommended. > > I actually have multiple models associated with users on one project: > > User (from auth) > UserInfo (things rarely accessed such as address, emergency contact > info, etc.) > UserProfile (my application specific profile) > > I'm going to break UserProfile into EmployeeProfile and StudentProfile > at some point or keep UserProfile add the other two profile types. > Depends on how looking into Django model polymorphism goes :-) > > I prefer the separation of profile and login in my case. Many > students do not want or need logins to the system. > > > > > On Oct 24, 6:32 am, Miguel Araujo <muchoch...@gmail.com> wrote: > > ¿no one knows anything about this? > > > > Thanks, regards > > Miguel Araujo > > > > 2010/10/22 Miguel Araujo <muchoch...@gmail.com> > > > > > > > > > > > > > > > > > Hello everyone, > > > > > I'm not very aware about what's the direction Django is taking about > the > > > User model and making it swappable. Meanwhile I would like to ask if > > > inheriting the User class is advisable or not. As I have read many > places > > > obscure bugs can happen and my code will be in production. > > > > > I'm using now an AUTH_PROFILE_MODULE at the moment, but I don't realy > like > > > this approach, as it makes my class hierarchy more complicated. > > > > > Thanks, best regards > > > Miguel Araujo > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Users table
Hi, Django has a built in User model, If you put in your INSTALLED_APPS 'django.contrib.auth' you will activate Django's built-in user management app. Then if you want to have registration, I recommend you look at django-registration by James Bennett: http://bitbucket.org/ubernostrum/django-registration/ Regards, Miguel Araujo 2010/10/24 miksayer <miksa...@gmail.com> > Hello! I'm newbie in Django. And I have few questions. For learning > Django I decided to develop simple todo-service(where you can note > your current deals). > I started new project "todo" and immediately I have a question. Where > can I put users table model? Must I create new application and put it > there in models.py? > I don't ask 'how can I do it?', I ask 'how must I do it?'(i.e. 'how > to?'). > P.S. sorry for my bad English. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: inheriting User class
¿no one knows anything about this? Thanks, regards Miguel Araujo 2010/10/22 Miguel Araujo <muchoch...@gmail.com> > Hello everyone, > > I'm not very aware about what's the direction Django is taking about the > User model and making it swappable. Meanwhile I would like to ask if > inheriting the User class is advisable or not. As I have read many places > obscure bugs can happen and my code will be in production. > > I'm using now an AUTH_PROFILE_MODULE at the moment, but I don't realy like > this approach, as it makes my class hierarchy more complicated. > > Thanks, best regards > Miguel Araujo > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: possible bug in joining on a geo field
Thanks Karen, you are right. But I missed the underscore for sending this, although I was trying here with double underscore: So If I do it right: Item.objects.filter(location__point__distance__lte = (point, D(km=10))) I get: FieldError: Join on field 'point' not permitted. Did you misspell 'distance' for the lookup type? So it's still not working. Regards, Miguel Araujo 2010/10/23 Karen Tracey <kmtra...@gmail.com> > On Sat, Oct 23, 2010 at 1:07 PM, Miguel Araujo <muchoch...@gmail.com>wrote: > >> Item.objects.filter(location__point__distance_lte = (point, D(km=10))) >> > > Looks like you are missing an underscore in distance__lte > > Karen > -- > http://tracey.org/kmt/ > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
possible bug in joining on a geo field
Hi everyone, I'm trying to do a join on geo field. I have two models like these ones (simplified): from django.contrib.gis.db import models class Spot(models.Model): point = models.PointField(spatial_index = True, srid = 4326, geography = True) objects = models.GeoManager() from django.db import models class Item(models.Model): location = models.ForeignKey(Spot) description = models.CharField(max_length=100) I'm trying to execute this query: from django.contrib.gis.geos import Point point = Point(4, 5) Item.objects.filter(location__point__distance_lte = (point, D(km=10))) And I'm getting: FieldError: Join on field 'point' not permitted. Did you misspell 'distance_lte' for the lookup type? is this a bug? should I report it in a ticket? am I doing anything wrong? Thanks, regards Miguel Araujo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
inheriting User class
Hello everyone, I'm not very aware about what's the direction Django is taking about the User model and making it swappable. Meanwhile I would like to ask if inheriting the User class is advisable or not. As I have read many places obscure bugs can happen and my code will be in production. I'm using now an AUTH_PROFILE_MODULE at the moment, but I don't realy like this approach, as it makes my class hierarchy more complicated. Thanks, best regards Miguel Araujo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: dump sqlite to file when testing
Thanks Russ, I couldn't find it in the documentation, IMHO I think it's a little bit hidden. Best regards, Miguel Araujo 2010/10/21 Russell Keith-Magee <russ...@keith-magee.com> > On Wed, Oct 20, 2010 at 10:33 PM, Miguel Araujo <muchoch...@gmail.com> > wrote: > > Hi everyone, > > Is there any way to force sqlite3 to use a file instead of RAM when > running > > tests? I would like to access the DB somehow to check some fields. This > is > > the only DB engine I have in this machine. > > Yes - set the TEST_NAME (or DATABASE_TEST_NAME if you're using pre 1.2 > style database settings) to a specific file name [1]. This will > override the default behavior of using :memory: as the test database > name. > > [1] http://docs.djangoproject.com/en/dev/ref/settings/#test-name > > Yours, > Russ Magee %-) > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
dump sqlite to file when testing
Hi everyone, Is there any way to force sqlite3 to use a file instead of RAM when running tests? I would like to access the DB somehow to check some fields. This is the only DB engine I have in this machine. Thanks, Best regards Miguel Araujo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: trying to get a cache per request
Thanks again Doug, I understand your method. I think the problem is that it might be too much overhead for what I can gain using a cache, so I might drop the idea of adding one. In any case, your explanation will be probably worth in future projects :) Regards, Miguel 2010/10/10 Doug> Look around for python docs on threading.local, which lets you set a > 'global' variable for just that thread. Since a request is only going > to happen in a single thread, that lets you have a per-request global > that can be used for cache storage. With middleware to set the > threading local instance up, and remove it at the end of the request. > I think it will do what you want. One bit of weirdness I noticed was > that you always need to import the global in exactly the same way > everywhere you want it, otherwise you may not be referring to the same > variable. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: trying to get a cache per request
Thanks Doug, In my Django-app where I want to create a cache, I don't have a request parameter and I can not add it because I need to be compatible with a part of the framework itself. I don't need to access that cache in the templates anywhere. I would like that my objects persists only per request, if that is possible. Thanks, regards Miguel 2010/10/9 Doug> Why not just stick it on the request object? > > def myview(request): >request.mycache=MyCacheClass() > > then it's available everywhere the request object is. If you are > wanting something that can be used in a template tag without > explicitly passing the request object (or your cache object) in, you > probably want thread locals and a middleware to reset after each > time. I've had to do this a couple of times, and regretted in in all > but one (a template loader - we serve many sites from one fastcgi > instance and that was the only way I could think to map templates for > different sites). > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Need opinion for an object permission rule backend
Thanks, I already got that :) I misunderstood the license, regards Miguel Araujo 2010/9/30 Steve Holden <holden...@gmail.com> > On 9/30/2010 1:55 PM, Miguel Araujo wrote: > > Hi Michael, > > > > I have been looking at your project, django.extauth and I have to say I > > really like its architecture and permission handling. I have to say that > > my rule system is kind of the same thing of your role system, except > > mine is less flexible. I'm going to look a little bit the code, install > > it and see if I can help you with anything. > > > > Only thing that cached my eye is that code is Copyrighted. Why not using > > an Open-source license? > > > There is a copyright on Python itself. This doesn't stop it being > distributed under an open source license. > > regards > Steve > -- > DjangoCon US 2010 September 7-9 http://djangocon.us/ > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Need opinion for an object permission rule backend
Sorry, I misunderstood it. Then everything looks great 2010/9/30 mhall119 <mhall...@gmail.com> > The license is a 3-clause BSD style license, it's compatible with > Django's license as far as I know. > > On Sep 30, 1:55 pm, Miguel Araujo <muchoch...@gmail.com> wrote: > > Hi Michael, > > > > I have been looking at your project, django.extauth and I have to say I > > really like its architecture and permission handling. I have to say that > my > > rule system is kind of the same thing of your role system, except mine is > > less flexible. I'm going to look a little bit the code, install it and > see > > if I can help you with anything. > > > > Only thing that cached my eye is that code is Copyrighted. Why not using > an > > Open-source license? > > > > Thanks for your mail, regards > > Miguel Araujo > > > > 2010/9/30 mhall119 <mhall...@gmail.com> > > > > > > > > > I've recently open-sourced some code that I developed for my work > > > projects that may do at least part of what you need: > > >http://bitbucket.org/mhall119/django-extauth/wiki/Home > > > > > The basic idea is that you define a "role" that is a relationship > > > between a user and an instance of a given Model. With your example, > > > you would created an "owner" role for your model, that somehow links > > > the user instance to the model instance. Usually you do this directly > > > via a ForeignKey in your model, but they can be as complex as you want > > > them to be. > > > > > On Sep 30, 9:50 am, Miguel Araujo <muchoch...@gmail.com> wrote: > > > > Hi everyone, > > > > > > I have been recently thinking about an object permission system. > After > > > > reviewing Florian Apolloner (apollo13) patch for ticket > > > > #11010<http://code.djangoproject.com/ticket/11010> and > > > > reading his article at Django > > > > Advent<http://djangoadvent.com/1.2/object-permissions/>. > > > > I though about creating an Object Permission Rule Backend. The > purpose of > > > > this message is explain you my idea, so I can receive feedback from > > > Django > > > > users and developers. This way I would like to discern if it's worth > > > coding > > > > it or if it's a good approach to a reusable solution. > > > > > > I will reuse apollo's code to elaborate my idea. My Backend would > look > > > > similar to: > > > > > > class ObjectPermBackend(object): > > > > supports_object_permissions = True > > > > supports_anonymous_user = True > > > > > > def authenticate(self, username, password): > > > > return None > > > > > > def has_perm(self, user_obj, perm, obj=None): > > > > if not user_obj.is_authenticated(): > > > > user_obj = > User.objects.get(pk=settings.ANONYMOUS_USER_ID) > > > > > > if obj is None: > > > > return False > > > > > > ct = ContentType.objects.get_for_model(obj) > > > > > > try: > > > > perm = perm.split('.')[-1].split('_')[0] > > > > except IndexError: > > > > return False > > > > > > # Simplified rule system > > > > # Of course objects should extend an interface > > > > if (perm == "ownage") > > > > return obj.is_owned_by(user_obj) > > > > > > elif (perm == "edit") > > > > return obj.can_be_edited_by(user_obj) > > > > > > # Here be Dragons > > > > > > As I love decorators, I would like to create a permission_required > > > decorator > > > > that accepted more than a parameter, so: > > > > > > @permission_required('app.code_name') would > > > > become @permission_required('app.code_name', FLAG) > > > > > > If the FLAG is set the decorator searches in the model associated to > the > > > > content type of the permission, for the name of the field for the PK. > For > > > > the example imagine idArticle. Now it instantiates an object of that > > > model > > > > with Model.objects.get(pk=request.idArticle). So it would be > necessary to > > > > match request parameters to model fileds (This is the best idea I've > come > > > up > > > > with). Once it has
Re: Need opinion for an object permission rule backend
Hi Michael, I have been looking at your project, django.extauth and I have to say I really like its architecture and permission handling. I have to say that my rule system is kind of the same thing of your role system, except mine is less flexible. I'm going to look a little bit the code, install it and see if I can help you with anything. Only thing that cached my eye is that code is Copyrighted. Why not using an Open-source license? Thanks for your mail, regards Miguel Araujo 2010/9/30 mhall119 <mhall...@gmail.com> > I've recently open-sourced some code that I developed for my work > projects that may do at least part of what you need: > http://bitbucket.org/mhall119/django-extauth/wiki/Home > > The basic idea is that you define a "role" that is a relationship > between a user and an instance of a given Model. With your example, > you would created an "owner" role for your model, that somehow links > the user instance to the model instance. Usually you do this directly > via a ForeignKey in your model, but they can be as complex as you want > them to be. > > On Sep 30, 9:50 am, Miguel Araujo <muchoch...@gmail.com> wrote: > > Hi everyone, > > > > I have been recently thinking about an object permission system. After > > reviewing Florian Apolloner (apollo13) patch for ticket > > #11010<http://code.djangoproject.com/ticket/11010> and > > reading his article at Django > > Advent<http://djangoadvent.com/1.2/object-permissions/>. > > I though about creating an Object Permission Rule Backend. The purpose of > > this message is explain you my idea, so I can receive feedback from > Django > > users and developers. This way I would like to discern if it's worth > coding > > it or if it's a good approach to a reusable solution. > > > > I will reuse apollo's code to elaborate my idea. My Backend would look > > similar to: > > > > class ObjectPermBackend(object): > > supports_object_permissions = True > > supports_anonymous_user = True > > > > def authenticate(self, username, password): > > return None > > > > def has_perm(self, user_obj, perm, obj=None): > > if not user_obj.is_authenticated(): > > user_obj = User.objects.get(pk=settings.ANONYMOUS_USER_ID) > > > > if obj is None: > > return False > > > > ct = ContentType.objects.get_for_model(obj) > > > > try: > > perm = perm.split('.')[-1].split('_')[0] > > except IndexError: > > return False > > > > # Simplified rule system > > # Of course objects should extend an interface > > if (perm == "ownage") > > return obj.is_owned_by(user_obj) > > > > elif (perm == "edit") > > return obj.can_be_edited_by(user_obj) > > > > # Here be Dragons > > > > As I love decorators, I would like to create a permission_required > decorator > > that accepted more than a parameter, so: > > > > @permission_required('app.code_name') would > > become @permission_required('app.code_name', FLAG) > > > > If the FLAG is set the decorator searches in the model associated to the > > content type of the permission, for the name of the field for the PK. For > > the example imagine idArticle. Now it instantiates an object of that > model > > with Model.objects.get(pk=request.idArticle). So it would be necessary to > > match request parameters to model fileds (This is the best idea I've come > up > > with). Once it has the right object, it passes it to the backend for > > permission checks. > > > > I know I could do a decorator like @own_article but I'm looking for a > more > > reusable solution, that I would make open source and release at Github. > > > > What do you think? Is it feasible and well laid out? > > > > Thanks, best regards > > Miguel Araujo > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Need opinion for an object permission rule backend
Hi everyone, I have been recently thinking about an object permission system. After reviewing Florian Apolloner (apollo13) patch for ticket #11010<http://code.djangoproject.com/ticket/11010> and reading his article at Django Advent<http://djangoadvent.com/1.2/object-permissions/>. I though about creating an Object Permission Rule Backend. The purpose of this message is explain you my idea, so I can receive feedback from Django users and developers. This way I would like to discern if it's worth coding it or if it's a good approach to a reusable solution. I will reuse apollo's code to elaborate my idea. My Backend would look similar to: class ObjectPermBackend(object): supports_object_permissions = True supports_anonymous_user = True def authenticate(self, username, password): return None def has_perm(self, user_obj, perm, obj=None): if not user_obj.is_authenticated(): user_obj = User.objects.get(pk=settings.ANONYMOUS_USER_ID) if obj is None: return False ct = ContentType.objects.get_for_model(obj) try: perm = perm.split('.')[-1].split('_')[0] except IndexError: return False # Simplified rule system # Of course objects should extend an interface if (perm == "ownage") return obj.is_owned_by(user_obj) elif (perm == "edit") return obj.can_be_edited_by(user_obj) # Here be Dragons As I love decorators, I would like to create a permission_required decorator that accepted more than a parameter, so: @permission_required('app.code_name') would become @permission_required('app.code_name', FLAG) If the FLAG is set the decorator searches in the model associated to the content type of the permission, for the name of the field for the PK. For the example imagine idArticle. Now it instantiates an object of that model with Model.objects.get(pk=request.idArticle). So it would be necessary to match request parameters to model fileds (This is the best idea I've come up with). Once it has the right object, it passes it to the backend for permission checks. I know I could do a decorator like @own_article but I'm looking for a more reusable solution, that I would make open source and release at Github. What do you think? Is it feasible and well laid out? Thanks, best regards Miguel Araujo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: google projection GeoDjango question
After 3 days trying to solve this, I found that geopy returns latitude/longitude and GEOS expects coordinates in reversed order. This fixes my issue with the maps. Thanks though, Miguel Araujo 2010/8/27 maraujop <muchoch...@gmail.com> > Hi everyone, > > I'm new to GeoDjango. After installing it and test it. I have created > a model called Spot which gas a Geography SRID 4326 PointField. > > class Spot(models.Model): >point = models.PointField(spatial_index = True, >srid = 4326, >geography = True) > >objects = models.GeoManager() > > I have activated Open Street Maps admin interface. The points I get > come from Google geocode API, I'm using geopy library for this. So I > guess they are in 900913. My problem is that points like (40,-3) that > are in Spain are being showed in the cost of Kenya. So I guess I'm > doing something wrong. I was not sure if this map supported 900913 so > I tried this: > http://taylanpince.com/blog/posts/adding-geolocation-support-to-geodjango-admin/#comments > > But it kept doing the same thing. Any help on this? > > Thanks, best regards > Miguel Araujo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.