Re: Is it bad to rely on db exceptions?
Hi, On Jun 13, 2:42 am, koepkedwrote: > Is it bad practice to rely on db exceptions to indicate an attempt at > writing duplicate values to a "keyed" column? For example, in some > code I'm working on, I have the following: > > x = ContentItem(title=e_title) > > try: > x.save() > except MySQLError: > x = ContentItem.objects.get(title=e_title) In this case, get_or_create does exactly what you want. However, exceptions are almost always the right thing to use in these kinds of situations. Looking for an existing object first and then continuing after not finding one is vulnerable to race conditions. That is called the "look before you leap" approach (or LBYL), while using exceptions is called the "it's easier to ask for forgiveness than permission" (or EAFP). This mailing list thread is a good read on the subject: http://mail.python.org/pipermail/python-list/2003-May/205182.html To avoid the database-specific dependency, use django.db.IntegrityError. -Forest --~--~-~--~~~---~--~~ 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: These waters aren't so friendly after all
Hi, On Fri, Jan 18, 2008 at 10:30:53AM +0530, Kenneth Gonsalves wrote: > On 18-Jan-08, at 12:20 AM, LRP wrote: > > I'm still having a problem since my shell can't seem to find django- > > admin.py. I know it's there; found it in /usr/share/python-support/ > > python-django/django/bin. > > this will not be on your path - and why debian packagers created that > weird directory is beyond me Well the tone here is degrading rapidly. Debian supports multiple Python versions simultaneously, and every Python module installed via the package manager works with all of the installed Python versions. One of the ways it does this is with the "python-support" system. Here, Python modules are installed in /usr/share/python-support/[package name]. In this case, the package name is python-django, and the "django" directory is simply the source tree from the django release. The modules are hooked into each Python's site-packages directory via .pth files. It's actually pretty elegant, I've found, and the usual problems associated with multiple interpreter versions just don't exist on Debian machines (which is certainly not the case on the RHEL server I've dealt with). > > Then there's Kenneth Gonzales. All I can say is, "hey dude, that's not > > very friendly." > > well, I was one of the people who told you *not* to rely on debian's > apt-get for installing django - django is developing too fast for > package managers to keep up with. So, if, inspite of everything you > want to use django, please install an uptodate version without apt-get. You have to admit that, in the vast majority of open-source projects, it is not common for end users to run software straight from svn. Moreover, as a user, I don't trust upstream developers to tell me how to put software on my Debian/Ubuntu machine. They are almost always wrong because they don't know Debian. On the other hand, I know Debian really well, so I have pretty good instinct about these sorts of things. It's a tricky business at first, though, figuring out who to ignore, and when :) (That said, there is a good point here: if you don't follow upstream's installation docs, you can't expect upstream to support your installation.) Now, in this case, I do run straight from svn, but only because I've found that django makes a good exception to the norm. The development version is reasonably stable, bugs get fixed reasonably quickly, and the API is still changing in a way that I'd rather not be too far behind on. In fact, if I only use the machine for development, I keep django in ~/lib/python/django. For production, I put it in /usr/local/lib/python${version}/site-packages/django. And I understand that it is up to me to maintain my PYTHONPATH (which my .bashrc does wonderfully). -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: These waters aren't so friendly after all
Hi, On Thu, Jan 17, 2008 at 10:50:50AM -0800, LRP wrote: > django-admin.py is marked as executable, as is it's containing directory. So > now I need to find out why it's not in the search path. But this is probably > a question for another forum. Maybe a little less time writing nautical prose and a little more using the tools Debian has blessed you with ;) : 18:16 [EMAIL PROTECTED] dpkg -L python-django | grep '/usr/bin' /usr/bin /usr/bin/django-admin Not that the prose isn't cute. Anyway, if you're going to champion the distribution, you might as well have a few good reasons to do so. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: These waters aren't so friendly after all
Hi, On Thu, Jan 17, 2008 at 04:25:30PM -0600, Tim Chase wrote: > > > I'm still having a problem since my shell can't seem to find django- > > admin.py. I know it's there; found it in /usr/share/python-support/ > > python-django/django/bin. > > Just to prevent other "dunder-headed mistakes", I presume it's > truely named "django-admin.py", not just "django-admin". :) > > You might also check that > /usr/share/python-support/python-django/bin [aside: this looks > like an odd path, but whatever floats your boat :) ] is in your > system path? Not a concern. The .deb copies/links it to /usr/bin/django-admin . Just type django-admin (with no .py on the end). -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Two Django applications mixing at random
Hi, On Wed, Jan 16, 2008 at 02:40:52PM -0800, [EMAIL PROTECTED] wrote: > We have recently switched to the worker MPM. We know that while > Django says to use prefork, we've heard from others that worker works > fine in most cases, and due to the high-volume Ajax nature of our > application, worker is the only way we've found to prevent our server > from being overrun during peak use times. However, because worker is > the big thing that has changed recently, and the problem was not > observed before then, it seems a likely suspect. Seems straight-forward enough. You have two options: * Switch back to prefork and find a different way to scale your performance. * Find the code that is not thread-safe and make it thread-safe. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Raising Http Redirect
Hi, On Wed, Jan 02, 2008 at 09:35:33AM -0600, James Bennett wrote: > On Jan 2, 2008 8:20 AM, Forest Bond <[EMAIL PROTECTED]> wrote: > > I disagree. Exceptions represent "exceptional situations," not all of > > which are > > necessarily errors. For instance, SystemExit is not really an error, is it? > > What about StopIteration? > > By that analogy as well, exceptions would be the wrong choice here: > what's "exceptional" about returning a redirect? A 404 or 500 is > exceptional -- it's something outside of otherwise-routine operation. > But redirecting from one page to another *is* a part of routine > operation. StopIteration represents a routine action: the end of a loop. What is exceptional about it is the interruption in flow, much like a redirection can be thought of as an interruption in content generation (in a view). An exception means "stop what you're doing and deal with this new condition." This is probably a pointless argument, though. Clearly, you prefer to use exceptions exclusively for error conditions, and I don't mind (ab)using them for other purposes as well. I view exceptions as a more general message-passing mechanism with some advantageous properties, not just a red flag to throw when things go sour. I wouldn't use them for everything, but they do lend themselves to some "stop that and do this instead" situations. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Raising Http Redirect
On Wed, Jan 02, 2008 at 04:09:43AM -0600, James Bennett wrote: > > On Jan 2, 2008 3:49 AM, Thomas Guettler <[EMAIL PROTECTED]> wrote: > > The HTTP return codes 404 and 500 can be raised with an exception. > > > > That's very handy. Unfortunately a Http Redirect can't be raised. > > Do other django users thing this would be usefull, too? > > No. Exceptions represent "errors" in a program, and the 4xx and 5xx > status codes represent "errors" in HTTP, so that maps well. But 3xx > status codes in HTTP are not errors, so implementing them as > exceptions would feel awfully strange. I disagree. Exceptions represent "exceptional situations," not all of which are necessarily errors. For instance, SystemExit is not really an error, is it? What about StopIteration? The "error condition" semantics of exceptions are injected. More practically, in Python, exceptions provide a simple way to trigger a major state change in the application from a lower level in the call stack. This is frequently not an error. A redirection exception seems natural to me; I've implemented something like this myself in the past. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: How to modify every element in a list all at once
Hi, On Sun, Dec 16, 2007 at 10:08:14AM -0800, Greg wrote: > > Forest, > Here are my models > > class Style(models.Model): > name = models.CharField(maxlength=200, core=True) > image = models.ForeignKey(Photo) > collection = models.ForeignKey(Collection, > edit_inline=models.TABULAR, num_in_admin=1, num_extra_on_change=3) > sandp = models.ManyToManyField(Choice) > > class Choice(models.Model): > choice = models.ForeignKey(Collection, edit_inline=models.TABULAR, > num_in_admin=5) > size = models.ForeignKey(Size, core=True) > price = models.ForeignKey(Price, core=True) > orderdisplay = models.IntegerField() > > class Price(models.Model): > name = models.DecimalField(max_digits=6, decimal_places=2) > > def __str__(self,): > return str(self.name) Why is Price a separate model? That is going to make your algorithm necessarily more complicated. You might have a good reason, but it's not apparent to me. This would be simpler: class Choice(models.Model): ... price = models.DecimalField(max_digits = 6 decimal_places = 2) ... Then you could use one of the algorithms that Ned and I suggested. -Forest -- Forest Bond http://www.alittletooquiet.net > On Dec 16, 11:56 am, Forest Bond <[EMAIL PROTECTED]> wrote: > > Hi, > > > > On Sun, Dec 16, 2007 at 08:37:08AM -0800, Greg wrote: > > > I've tried the following: > > > > > for s in s2: > > > s.price *= s.price * .9 > > > > > However, I still get the following error: > > > > > TypeError at /plush/chandra/antara/108/multi/ > > > unsupported operand type(s) for *: 'Price' and 'float' > > > > Can you post your models, please? > > > > I take it price is a ForeignKey... > > > > -Forest > > -- > > Forest Bondhttp://www.alittletooquiet.net signature.asc Description: Digital signature
Re: How to modify every element in a list all at once
Hi, On Sun, Dec 16, 2007 at 08:37:08AM -0800, Greg wrote: > I've tried the following: > > for s in s2: > s.price *= s.price * .9 > > However, I still get the following error: > > TypeError at /plush/chandra/antara/108/multi/ > unsupported operand type(s) for *: 'Price' and 'float' Can you post your models, please? I take it price is a ForeignKey... -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: How to modify every element in a list all at once
Hi, On Sun, Dec 16, 2007 at 07:59:52AM -0800, Greg wrote: > I've added that code into my view. However, now I'm getting the > following error: > > TypeError at /manu/coll/style/ > unsupported operand type(s) for *=: 'Price' and 'float' > > > > I can't do a int(s.price), because then I get a 'Can't assign to > function call' error. How about: for s in s2: s.price = s.price * 0.9 Haven't tried it, but I think that will work. Maybe django's FloatField and DecimalField should support *=, but it appears that they currently don't ... ? -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Performance of a django website
Hi, On Tue, Dec 11, 2007 at 01:37:36PM -0500, Richard Coleman wrote: > Rajesh Dhawan wrote: > >> When I stress test the dynamic part of the site, I am only getting about > >> 300 requests per second on my test setup. This is using two Dell 1950's > >> (one for web, one for mysql database). These are very powerful machines > >> (3.0ghz Xeons, 8 cores each, 16 gig of ram, 15k SAS drives, etc.) > > > > - How are you running your Django app? Mod_python? FastCGI? > > - What web server are you using? > > - What's the nature of the dynamic Django request you are measuring? > > How many DB queries does it make? Is DEBUG mode off? > > - What kind of numbers do you get when you serve a simple and small > > HTML file statically from your Web server without Django? > > - What kind of numbers do you get when the Django view you are > > benchmarking goes directly to a simple template (i.e. no DB queries)? > > - Are you using memcache? > > 1. mod_python > 2. apache 2.2.4 > 3. I'm using funkload and ab to measure the requests per second of one > of the base pages within the dynamic part of the website > 4. When I hit a static page in the same way (using ab), I get 6500 > requests per second. > 5. This is without memcached, or any other caching. I'm not all that qualified to comment as I've never done this sort of testing, but I do wonder if the performance you are seeing may not be all that unreasonable, given that no caching is currently being performed? Using memcached has been known to improve performance dramatically. Profiling never hurts, but there's nothing wrong with doing the easy stuff first, right? -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: How much memory does a django instance need was Does Hostmonster support Django?
Hi, On Tue, Nov 13, 2007 at 07:41:17AM +0530, Kenneth Gonsalves wrote: > On 12-Nov-07, at 6:25 PM, Forest Bond wrote: > > Maybe you need to decrease your ServerLimit? Each forked server process > > leads to increased memory usage. For a really low volume site, you can get > > away with ServerLimit 1, although I'd be sure to host your media files in a > > different instance (webfaction has docs for doing this somewhere). > > did that > > > Make sure that Django and Python debug settings are disabled, too > > (apache2.conf PythonDebug, settings.py DEBUG). > > did all this - I am still getting around 35 MB per instance. And it > is not the fault of webfaction. The same site on my local machine > gives the same figure. This on the latest svn in both cases. The last > time I looked at these figures, it was around 12-15mb an instance. > Any other clues? This is probably normal memory usage. This is not a problem, as long as it doesn't grow much beyond that, right? I have two small sites that share a lot of code running on a webfaction account. With ServerLimit 1 and media hosted on the main apache instance (which doesn't count against me for RAM usage), I stay pretty constant at 32-35MB. I don't think it would be possible to get much lower than that. Libraries have to get loaded somewhere, afterall. I guess maybe you could try to reduce your imports. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: "You don't have permission to access /doc/lookup/ on this server."
Hi, On Fri, Nov 09, 2007 at 06:02:30AM -0800, Mason wrote: > I have a Django site that works fine on my Windows platform, but when > I ported it over Ubuntu I get the following error on just one of my > links: > > "You don't have permission to access /doc/lookup/ on this server." > > Note that /doc/lookup/ is a URL, not a folder, so there are no > permissions to set. I'm wondering if /doc might mean something special > to Apache? If not then any other ideas? > > My Apache2.conf can be viewed here: http://dpaste.com/hold/24636/ The default Ubuntu site config maps /doc to /usr/share/doc, but only allows connections over the loopback interface (or something like that). You can either disable the Ubuntu "sites" configurations by commenting lines 669-670 in your main Apache2 config file, or you can disable the default site by doing: $ sudo rm /etc/apache2/sites-enabled/default It looks like you are configuring your server to serve only your Django app, so you probably just want to comment lines 669-670. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: spam
On Tue, Nov 06, 2007 at 10:02:50AM -0800, Jeffrey Johnson wrote: > This is the ONE list where I consistently get porn spam in gmail. What gives? High demand on this list? -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: how to do something at startup
Hi, On Sat, Sep 29, 2007 at 10:06:19PM -0700, pength wrote: > well, I am doing some similiar things, for example, I want to show the > time when this Django/Apache server start, and set some "gloabl > variables" which all of my apps can use, just do like this: > I have a primary app named "city", and every other app's views.py will > add a line as "from myproject.city.models import * ". So in this > models.py, just add codes like: > SERVER_START_TIME = datetime.datetime.now() > MY_GLOBAL_VAR = (1,2,3) > #test > def my_init(): > for i in range(1,11): > print i > > my_init() Except when apache spawns multiple processes or threads you'll probably get a different answer depending on which one you happen to end up talking to. That may be acceptable, though. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: How can we map a specific HTTP error to a python exception?
Hi, On Thu, Sep 20, 2007 at 09:39:05AM -0700, shabda wrote: > Would writing a middleware for this be a good idea? Then if we get the > DNE, we just return 404 from process_exception. And during development > we can just keep our middleware out, so that no real bugs beome 404. > When we deploy, we can just switch this middleware on. That would work, but I think that you should handle bugs in production explicitly, rather than masking them. If it's a bug, you want to return HTTP 500 (internal server error) and send an e-mail to the server admin notifying him of the problem. Returning a 404 is confusing, and your 404 could be cached (!). 404s should be 404s. There are a variety of ways to turn DNE to 404. Handling DNE->404 explicitly prevents your program from masking a bug. I think that this is a good thing. Does this really save that much code? The negative impact (masking bugs) is significant. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: How can we map a specific HTTP error to a python exception?
Hi, On Thu, Sep 20, 2007 at 08:47:57AM -0700, shabda wrote: > I have a number of pages which can potentially raise the > self.model.DoesNotExist exception. Whenever this exception is raised, > it maps to a HTTP 404 for me. (That object does not exist in the > database, so I cant show this, so I want to return a 404 exception). > So apart from manually adding try-except to all my views, how can I > return a 404 response on the self.model.DoesNotExist. You probably don't want to do this in your model. How about: from django.core.exceptions import ObjectDoesNotExist from django.core.http import Http404 def 404_on_dne(wrapped): def wrapper(*args, **kwargs): try: return wrapped(*args, **kwargs) except ObjectDoesNotExist: raise Http404 return wrapper Then you can wrap your views: @404_on_dne def my_view(request, arg1, arg2): obj = Model.objects.get(...) # do something I'm not entirely sure that you shouldn't just explicitly handle these exceptions in your views (you can end up masking some DNE exceptions that are really bugs), but that's a way to do what you want. Disclaimer: I haven't tried any of this code. Might have bugs. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: ANN: Satchmo 0.5 Release
On Wed, Aug 22, 2007 at 11:37:24PM -, SamFeltus wrote: > Keep at it, Python has needed a good online store forever. And the world needs an osCommerce replacement ASAP ;) ... grumble grumble PHP grumble grumble grumble ... -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: 404 Page not found handling
Hi, On Wed, Aug 15, 2007 at 08:04:20PM -0700, TheMaTrIx wrote: > Is it, in your opinions, "nice", "appropriate" and "correct", in other > words, ethical, for an internet site to setup 404 pages so that when > for instance: > > http://www.domain.com/banana/ > > that doesn't exist, gets called, the user gets a 404 page inline with > the sites main layout + a bunch of suggestions for pages that might > fit what the user was looking for, like there are pages relevant to > banana at > > http://www.domain.com/recipies/milkshakes/banana > http://www.domain.com/gallery/dancingbanana > http://www.domain.com/music/RotterdamTerrorCorps/bananenlied > > Kinda like automated search results appended to the 404's. I've had this talk with co-workers before, too. My take on it is this: * If you don't have what the user is looking for, you should return a 404 status code. * There's nothing wrong with including additional information in the HTTP response body that may help the user find what he's looking for. * If your 404 page is overly complicated, it may not be immediately obvious to the user that an "error" condition has occured. This can be confusing, and should probably be avoided. Does that sound reasonable to other folks? -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: can't unlink, move files
Hi, On Wed, Aug 08, 2007 at 12:08:17PM -0700, Enoch wrote: > I have a question about how to manipulate files by os.unlink() and > shutil.move() [...] > I always get the error > OSError: [Errno 13] Permission denied: afile.txt' To move or unlink a file, the user your code is running as needs to have write permissions for the directory containing the file. Permissions on the file itself are inconsequential. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: startproject errors with Ubuntu
On Sun, Aug 05, 2007 at 11:46:45PM -0500, James Bennett wrote: > > On 8/5/07, john <[EMAIL PROTECTED]> wrote: > > thks - the tutorial shows the .py extension and that was giving the > > error. > > The file's name is 'django-admin.py', not 'django-admin', and the > tutorial is correct; the problem was that you did not have the > executable bit set on django-admin.py, and so you did not have > permission to execute that file from the command line. The Ubuntu package ships a django-admin executable. I'm not sure if it is just a symlink to django-admin.py, or if it is django-admin.py renamed. This is to achieve compliance with Debian policy, which (I believe) recommends against extensions like .py on commands. I could, however, be mis-remembering all of this stuff. John, you should remove the django installation in /usr/local if you have the Ubuntu package installed. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Only save if changed?
On Sat, Aug 04, 2007 at 12:09:07PM +0200, Michael Elsdoerfer wrote: > > > def save(self): > > if self.id is not None: > > old_self = self.__class__.get(id = self.id) > > if self.id is None or (old_self.city != self.city) or ( > > old_self.state != self.state): > > self.geocode = self.get_geocode() > > super(SiteUser, self).save() > > You can also monitor attribute changes via __setattr__, which will save you > an additional query. That worked fine for me so far, although I am not 100% > if there might not be some edge cases that could cause problems. I can't think of any problems with that sort of approach, excluding the usual problem of the database changing underneath you. Didn't think of it, but it's a good idea. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Only save if changed?
On Fri, Aug 03, 2007 at 08:57:10PM -, [EMAIL PROTECTED] wrote: > For anyone trying this, I had to make it > old_self = self.__class__.objects.get(id = self.id) > instead of > old_self = self.__class__.get(id = self.id) Right, that's what I meant :) -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Only save if changed?
On Fri, Aug 03, 2007 at 07:37:17PM -, [EMAIL PROTECTED] wrote: > > In my site_users model (which extends auth user), I've got: > > def save(self): > self.geocode = self.get_geocode() > super(SiteUser, self).save() # Call the "real" save() method. > > get_geocode makes a call out to google's geocoding service, gives the > city and state, and returns the geocode. Since there's a lot of > activity on site_users, updating for board post counts and all sorts > of other things, I don't want to call get_geocode unless city and > state have actually changed. def save(self): if self.id is not None: old_self = self.__class__.get(id = self.id) if self.id is None or (old_self.city != self.city) or ( old_self.state != self.state): self.geocode = self.get_geocode() super(SiteUser, self).save() -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Blog engine
On Sun, Jul 29, 2007 at 05:49:54PM -, Henrik Lied wrote: > @Forest: I agree, it should be that simple. But let's say you've got a > comment reply plugin. How would we - through a middleware - manage to > intercept our usual comment system, and modify the HTML template > source to fit the plugin? It's cases like these I see the potential > pitfalls of our way of thought. Please, enlighten me if the answer is > simple. :-) Well, extensibility is tough for exactly that reason. You have to anticipate the ways in which your application might be extended. This is an extremely difficult task, for that simple reason that it is impossible to predict the future. You really don't want to be modifying templates (or any other source files) when a new plugin is installed. What you do want is to have placeholders in your templates where plugins may contribute additional markup that will appear on the page. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Blog engine
On Sat, Jul 28, 2007 at 03:28:31PM -, Henrik Lied wrote: > > Ok, so I've been thinking some more. > > The model could be something like this: > class Plugin(models.Model): > """(Plugin description)""" > pointer = models.FilePathField() ## Could work, right? > name = models.CharField(maxlength=200) > description = models.TextField(blank=True, null=True) > url = models.URLField() > apply_to = models.ForeignKey(ContentType) > active = models.BooleanField(default=False) > > We then would have to make a standard on how the plugin-packages would > be designed. > A zip-file would probably work out OK. We would then have to get this > zip-file, run through it and copy its files into a plugins- > subdirectory. The package should have a info.txt-document, where the > plugin title would be on the first line and description on the second. > > But - I'm still not sure how we'd easily hook this into other > applications - at least not without the user having to modify the > source code... See twisted.plugin. Define your interfaces, and let twisted handle the rest. Don't pull a PHP-ism like forcing users to modify code. That is, by definition, not a plugin architecture. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: latest django version
On Wed, Jul 25, 2007 at 07:51:59PM +0100, Gerry Steele wrote: > james_027 wrote: > > I would like to use the latest django version. i am trying to use > > tortoise SVN to get the latest version, but iam always getting this > > error > > > > Error * REPORT request failed on 'http://code.djangoproject.com/svn/ > > django/trunk/django' REPORT of 'http://code.djangoproject.com/svn/ > > django/trunk/django': 400 Bad Request (http://code.djangoproject.com) > > > > is there an easy to get the latest version of django in winxp? > Might you have better luck using a unix environment on windows like > cygwin. This pretty much uses all the same commands that everyone else > on linux uses and thus might give better results. Oh, come on, Tortoise SVN is good enough to pull off a stinking check-out. I'm a *nix geek too, but that's just not helpful. See here: http://www.amitu.com/blog/2006/05/svn-report-request-failed.html Likely, using command-line Subversion under CYGWIN won't do you much good. -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Satchmo
On Sun, Jul 22, 2007 at 09:35:37PM -0700, kbochert wrote: > > Just looked that up. Perhaps that's the best option... of course that > means I have to install M$ installer, install Tortoise and start using > windows explorer. Not exactly user-friendly. Isn't this standard operating procedure for a Windows box? Double-click a few setup.exe's, open up Windows explorer ... ? -Forest -- Forest Bond http://www.alittletooquiet.net signature.asc Description: Digital signature
Re: Slug (w/o using SlugField) Problems
On Wed, Jul 18, 2007 at 07:10:27PM -, John-Scott wrote: > Next, change your urls.py like so: > > (r'^characters/(?P\d+)[-\w]+/$', object_detail, > dict(character_detail_dict)), > > This should capture the '123' and discard '-bob-and-jane'. This is a > fairly elegant solution that allows you to still have 'pretty' urls > that are human readable and google friendly while completely > sidestepping the complications of record retrieval based on reverse > engineering slugs or bothering with a slug column, opting instead for > the dead-simple and fast id lookup. Don't we all agree that unique URLs with one-to-one relationships with unique resources are a Good Thing? I sure thought we did... Multiple URLs corresponding to the same resource will actually dilute your Google rank, anyway (if someone out in space uses the non-canonical version in a link). You could do a permanent redirect to the canonical version, I guess. -Forest signature.asc Description: Digital signature
Re: method as view
On Sun, Jul 15, 2007 at 03:34:40PM -0500, Carl Karsten wrote: > Forest Bond wrote: > > I'm not even sure if this sort of thing is possible, but it might be: > > > > > > class MsgViews(object): > > > > @static_method > > def __call__(request, object_id=None): > > m=get_object_or_404(Message, pk=object_id) > > return render_to_response('message_detail.html', {'message': m}) > > > > > > error: name 'static_method' is not defined Right, that should be "staticmethod" not "static_method". Sorry about that. -Forest signature.asc Description: Digital signature
Re: method as view
On Sun, Jul 15, 2007 at 02:59:57PM -0500, Carl Karsten wrote: > > How can I use a method as a view? (so that I can subclass and extend later.) > > foo works, the other 2 give errors: > > # msg/urls.py > from django.conf.urls.defaults import * > urlpatterns = patterns('msg.views', > (r'^detail/(?P[-\w]+)/$', 'foo'), > (r'^detail/x/(?P[-\w]+)/$', 'MsgViews.message_detail'), > (r'^detail/y/(?P[-\w]+)/$', MsgViews.message_detail), > ) Try this: from django.conf.urls.defaults import * msg_views = MsgViews() urlpatterns = patterns('msg.views', (r'^detail/(?P[-\w]+)/$', 'foo'), (r'^detail/x/(?P[-\w]+)/$', msg_views.message_detail), (r'^detail/y/(?P[-\w]+)/$', msg_views.message_detail), ) Alternatively, you can make message_detail a static method: class MsgViews(object): @static_method def message_detail(request, object_id=None): m=get_object_or_404(Message, pk=object_id) return render_to_response('message_detail.html', {'message': m}) I'm not even sure if this sort of thing is possible, but it might be: class MsgViews(object): @static_method def __call__(request, object_id=None): m=get_object_or_404(Message, pk=object_id) return render_to_response('message_detail.html', {'message': m}) The only reason I can think of for doing that is that you wouldn't have to import MsgViews in your urls.py, you could just specify a string. Now, after all that, I'm still a little confused as to why you would want to do all of this? You say so that you can extend your view functions, but classes are extensible because their methods can be replaced, and you already _can_ replace plain view functions... -Forest signature.asc Description: Digital signature
Re: Generating graphs from db data and displaying results using Django?
On Wed, Jul 11, 2007 at 04:56:03PM -, [EMAIL PROTECTED] wrote: > > I would actually suggest using Django to create a web service to get > the data, and a JavaScript charting library to do the drawing client- > side. Why not create the graphs on the server? -Forest signature.asc Description: Digital signature
Re: use Django's database layer for a regular python program?
On Wed, Jun 27, 2007 at 04:53:12PM +0200, Roodie wrote: > > I worked on a console application which uses django to do some > database related tasks. > I started my code with these lines: > > --- > > #!/usr/bin/env python > import sys > sys.path.append('/Library/Frameworks/Python.framework/Versions/2.4/ > lib/python2.4/site-packages/django') > sys.path.append('/path/to/the/application/directory/') > > import os > os.environ['DJANGO_SETTINGS_MODULE'] = 'applicationname.settings' > > --- > > From this point you can continue by importing the neccessary > libraries and writing your code. > > Maybe there is a better way of doing it but works perfeclty. Have a look at django.conf.settings.configure: from django.conf import settings settings.configure( INSTALLED_APPS = ( 'myappcontainingmodels', ), DEBUG = False ) See: http://www.djangoproject.com/documentation/settings/#using-settings-without-setting-django-settings-module -Forest signature.asc Description: Digital signature
Re: Introducing DjangoSites.Org
On Sun, Jun 24, 2007 at 01:42:26AM +0200, Kai Kuehne wrote: > > It's nice but I don't really like the design. It doesn't have to be > 'beautiful', but everything on the site is very big (e.g. font size). Sorry, I have to disagree here. I'm not sure when the "small fonts = beautiful" trend started, but these days, everyone seems to be competing with CNN on this front, and I think it's a bad move. If you don't like your browser's defaults, try CTL-(minus) in Firefox. I'm not sure what the IE equivalent is. -Forest signature.asc Description: Digital signature
Re: Pagination
On Thu, Jun 21, 2007 at 11:04:40PM -, Rob Hudson wrote: > > Just following up... > > If you use the query string option, you don't need to know the current > url, you can just do this: > > {% if has_previous %} > Previous > {% endif %} Which works fine & dandy as long as you're not using GET parameters for anything else. The canonical example is a search page with paginated results. It's actually a slight pain to come up with a good way to construct the prev/next URLs without making too many assumptions about the order/presence of GET parameters. I'd be happy if django would come up with a nice solution to that problem. I'd also be happier if django's pagination template context parameters didn't pollute the template context so much. It'd be nice to stuff them all in a dict called paginator: {{paginator.next}} etc. But idunno, I guess it's not that big of a deal. In practical terms, it probably doesn't actually come up, since you can just avoid name conflicts by not naming your context variables the same as the pagination variables. -Forest signature.asc Description: Digital signature
Re: Introducing DjangoSites.Org
On Wed, Jun 20, 2007 at 03:15:58AM -0700, [EMAIL PROTECTED] wrote: > > A week ago I posted about a project I was working on, Djangosites.org. > It's intended to be a showcase of what's out there in Django Land. > > I've received some fantastic feedback, and a new website template > courtesy of maddiin. > > The site is now live and ready to be used and abused. Please, login > and submit your sites. I've added a quick blurb to the top of the > DjangoPoweredSites page directing people to the new site as well as > the existing list. > > Hopefully it proves useful to newcomers to the community. What I'd > really love is if some of the Django heavyweights could post some > sites up - it would kick ass if this can eventually replace the > DjangoPoweredsites wiki page. > > Thanks to maddiin for the site design, and to the django-users mailing > list for feedback and suggestions. If you have any feedback please > don't hesitate to email it to me and I'll take it all on board. > > Most of all, thanks to the Django community for rocking. I know you > guys will embrace this :) Hi! Site looks great. A few things: * It'd be nice if the RSS feed included the site description, not just the URL. That way, I can tell whether I want to check out the new site or not without having to go there first. * It may be a good idea to have a more prominent link to the feed in the page itself. I guess most people who use RSS know to look at the URL bar in firefox. Do all browsers provide access to feeds like that? -Forest signature.asc Description: Digital signature
Re: Captcha module Version 1.1 ready for testing
On Fri, Jun 15, 2007 at 09:48:02AM -0400, Forest Bond wrote: > Do note that it must be symmetric, since you need to be able to decrypt the > answer. Sorry, this is not true. It must not be a hash, anyway, and I don't see the benefit of using public key crypto here. To me, it makes the most sense to use a symmetric algo. -Forest signature.asc Description: Digital signature
Re: Captcha module Version 1.1 ready for testing
On Fri, Jun 15, 2007 at 09:55:30AM +0200, Martin Winkler wrote: > > Am Thu, 14 Jun 2007 15:51:10 -0400 > schrieb Forest Bond <[EMAIL PROTECTED]>: > > > You can do it without external persistence (sessions and/or database > > table) by encrypting the correct response in the image filename. > > So when the request to get the image is sent to django, we have to > decrypt the solution according to the image's URL. In my > opinion that raises some problems, because it could be decrypted by > someone else too, unless you use a private/public key encryption, > which means more work on the django server than using just hashed > filenames like my approach does. If encrypting the answer in the image filename, the encryption scheme would have to be somewhat secure (or at least obscure enough to fool bots). I should think a simple symmetric algorithm using settings.SECRET_KEY. It needn't be a strong form of encryption, since the pay-off from breaking it hardly justifies even the smallest computation time (for the bot, that is). The simpler the algorithm, the lower you server load, too. Do note that it must be symmetric, since you need to be able to decrypt the answer. > Furthermore I don't see a real reason to generate images on the > fly instead of storing them directly. My approach is quite speedy even > with auto_cleanup, when there are many captcha images sitting in the > filesystem all the time. I ran an apache benchmark test on my > development machine (not the fastest hardware) multiple times where > each of them creating 1000 captchas: [...] Performance wasn't my primary concern. Writing images to the filesystem makes scalability more challenging and increases the potential for race conditions. I avoid it as a matter of principle whenever possible. Really, though, it's your code, do things however you want. My guess is that django.contrib apps need to be a little more flexible, though. It should be possible to use the app with or without filesystem writes (which are not an option for all sites). I'm also under the impression that the django core devs are generally not huge fans of Captcha systems, but I could be making that up. -Forest signature.asc Description: Digital signature
Re: matching a hyphen '-' character in urls
On Fri, Jun 15, 2007 at 08:59:51AM +1000, Malcolm Tredinnick wrote: > > On Thu, 2007-06-14 at 18:24 -0400, Forest Bond wrote: > > On Thu, Jun 14, 2007 at 10:13:32PM -, SmileyChris wrote: > > > > What you want is "[-A-Za-z0-9_]+". > > > > > > > > The reason [-\w] doesn't work is because inside character classes > > > > ([...]), \w no longer means "alphanumeric characters". It's just a > > > > character escape. > > > > > > Alternately, make the string a "raw" one (note the r before the > > > quote): > > > r'[-\w]+' > > > > Not sure that's true. Malcolm was indicating that it is a character escape > > at > > the reg-exp level, not the Python string-parsing level. > > > > Character classes can't be merged in Python reg-exps. \w represents an > > entire > > character class, and, consequently, can't be merged with other classes by > > putting \w inside the new character class. > > Chris is right; I am clearly on drugs (again). > > In [6]: re.match(r'[-\w]+', '12-34-56').group() > Out[6]: '12-34-56' > > That was what I thought the answer was and then when I tested it before > making my reply it didn't work and the rationalisation seemed sound, so > I went with what worked. However, I must have made a typo when testing. Oh. Didn't know that you could do that, and, as a result, assumed you were right. Sorry about that. -Forest signature.asc Description: Digital signature
Re: matching a hyphen '-' character in urls
On Thu, Jun 14, 2007 at 10:13:32PM -, SmileyChris wrote: > > What you want is "[-A-Za-z0-9_]+". > > > > The reason [-\w] doesn't work is because inside character classes > > ([...]), \w no longer means "alphanumeric characters". It's just a > > character escape. > > Alternately, make the string a "raw" one (note the r before the > quote): > r'[-\w]+' Not sure that's true. Malcolm was indicating that it is a character escape at the reg-exp level, not the Python string-parsing level. Character classes can't be merged in Python reg-exps. \w represents an entire character class, and, consequently, can't be merged with other classes by putting \w inside the new character class. -Forest signature.asc Description: Digital signature
Re: Captcha module Version 1.1 ready for testing
On Thu, Jun 14, 2007 at 08:14:54PM +0200, Martin Winkler wrote: > Am Thu, 14 Jun 2007 12:00:11 +0800 > schrieb "Nimrod A. Abing" <[EMAIL PROTECTED]>: > > > Are you planning to implement a configuration to allow in-memory > > images? > > One thing that annoys me with in-memory images is that you have to > change your urls.py, and I want the CaptchaField as unobtrusive as > possible. Furthermore this method needs some kind of session data > stored somewhere, and therefore also cookies. All this annoys me a bit, > to be honest. You can do it without external persistence (sessions and/or database table) by encrypting the correct response in the image filename. But, really, these are web applications. It's not entirely unreasonable to expect people to modify their code/databases to add a feature, is it? Writing files to disk isn't exactly non-intrusive either. -Forest signature.asc Description: Digital signature
Re: sleep for 30 minutes?
On Wed, Jun 13, 2007 at 12:29:10AM -0700, MartinWinkler wrote: > > > I don't recall hearing a good argument for *not* delivering the images > > dynamically, without saving them to disk. Why not do it that way? > > Since I do not want the developer to change anything in urls.py or add > some middleware or cookies - what would be the URL of this dynamically > generated image? Well, you would have to have a line added to urls.py, that's for sure. If you really want to avoid that, I suppose you have to save the images to disk. I've found that writing things to disk from web applications often carries higher maintenance penalties than adding a line to urls.py would; that's obviously an implementation trade off, though, so I suppose it's not unreasonable that you would make that trade off differently than I would. > And how would it be possible to join this image with the form that is > being sent back? There are a variety of ways to maintain state between multiple connections, even without cookies (although that is the most straight-forward and reliable way). For this sort of thing, you could probably generate an image, store it temporarily in memory or the database, generate an ASCII hash value of the image and use that as the filename (which you write to the page), and send the correct image based on the hash value encoded in the client's request for the image file. Alternatively, you could roll the dice and try to sort-of-unique-ly identify users by IP address & hostname... It would be a heck of a lot easier to use a session variable, though. What's the reason not to? Now that I think about it, you don't even need to generate the image at form-generation time, depending on how the image generation works. You could just generate the string to be depicted by the image, and hash that. Then, generate the image when it is actually requested. This would save you from storing the image at all; you would only have to store the string (and maybe the hash, too, to avoid calculating it more than once). -Forest signature.asc Description: Digital signature
Re: sqlite3: odd slice behavior
On Mon, Jun 11, 2007 at 09:43:55PM -0400, Forest Bond wrote: > On Mon, Jun 11, 2007 at 06:18:18PM +1000, Malcolm Tredinnick wrote: > > On Sun, 2007-06-10 at 15:45 -0400, Forest Bond wrote: > > > Using the sqlite3 backend, any slice operation on a QuerySet for which > > > the slice > > > does not start at 0, a list is returned instead of a QuerySet, and the > > > slice is > > > not performed in the database, but in Python. > > > > > > Is this expected behavior? The sqlite3 docs indicate that offsets can be > > > given, > > > so I see no reason this shouldn't be performed at the DB level. > > > > I'm unable to repeat this behaviour. Whenever I construct a QuerySet and > > slice it, the LIMIT/OFFSET bits get added. The only time the slicing is > > done in Python is where I have already accessed the results of the > > QuerySet (so it has been cached). In those cases, Django knows not to do > > another round-trip to the database. > > Ok, I understand the motivation for this design decision, but shouldn't the > slice still return a QuerySet? I see no reason why the (internal) cache > status > of the QuerySet should have such critical impact on the (external) API -- type > of returned objects. Well, I finally have a more thorough characterization of the situation, as illustrated here: In [1]: from loadmonitor.models import * In [2]: all_loads = Load.objects.all() In [3]: subset = all_loads[5:10] In [4]: type(subset) Out[4]: In [5]: subset.order_by('origination_state') --- Traceback (most recent call last) /home/fab/work/software/loadmonitor/ in () /home/fab/lib/python/django/db/models/query.py in order_by(self, *field_names) 406 "Returns a new QuerySet instance with the ordering changed." 407 assert self._limit is None and self._offset is None, \ --> 408 "Cannot reorder a query once a slice has been taken." 409 return self._clone(_order_by=field_names) 410 : Cannot reorder a query once a slice has been taken. In [6]: for load in all_loads: ...: pass ...: In [7]: subset = all_loads[5:10] In [8]: type(subset) Out[8]: In [9]: My original question, to some extent, has become irrelevent, since QuerySets that are the progeny of slice operations are explicitly forbidden further QuerySet-like processing (filter, order_by). That was my original desire. However, I should point out that the sqlite3 backend should, IMO, always return a QuerySet, independent of internal object caching. However, am I crazy to wonder if filtering QuerySets with slices in their murky past should be allowed? It could be implemented as a sub-query ... -Forest signature.asc Description: Digital signature
Re: sqlite3: odd slice behavior
On Mon, Jun 11, 2007 at 06:18:18PM +1000, Malcolm Tredinnick wrote: > On Sun, 2007-06-10 at 15:45 -0400, Forest Bond wrote: > > Using the sqlite3 backend, any slice operation on a QuerySet for which the > > slice > > does not start at 0, a list is returned instead of a QuerySet, and the > > slice is > > not performed in the database, but in Python. > > > > Is this expected behavior? The sqlite3 docs indicate that offsets can be > > given, > > so I see no reason this shouldn't be performed at the DB level. > > I'm unable to repeat this behaviour. Whenever I construct a QuerySet and > slice it, the LIMIT/OFFSET bits get added. The only time the slicing is > done in Python is where I have already accessed the results of the > QuerySet (so it has been cached). In those cases, Django knows not to do > another round-trip to the database. Ok, I understand the motivation for this design decision, but shouldn't the slice still return a QuerySet? I see no reason why the (internal) cache status of the QuerySet should have such critical impact on the (external) API -- type of returned objects. I'm not sure if this is a bug or intended behavior: In [1]: from loadmonitor.models import * In [2]: q = Load.objects.all() In [3]: for load in q: ...: pass ...: In [4]: loads = q[5:10] In [5]: type(loads) Out[5]: As you suspected, I have to force the whole set to be pulled in order to trigger the issue by activating the internal cache. My issue, of course, is that I sometimes use this sort of pattern: q = Model.objects.all() if x: q = q.filter(constraint = value) if y: q = q.filter(constraint2 = value2) if z: q = q.order_by('a', 'b') q = q[0:20] # Now, is q a list or QuerySet? depends on how many rows are in the table ... # So, this might cause an exception: print q.values Thoughts? Is it a bug? I guess the odds of actually wanting to do much more after slicing are relatively low, but I _did_ actually run into this in a real-life situation. -Forest signature.asc Description: Digital signature
sqlite3: odd slice behavior
Hi, Using the sqlite3 backend, any slice operation on a QuerySet for which the slice does not start at 0, a list is returned instead of a QuerySet, and the slice is not performed in the database, but in Python. Is this expected behavior? The sqlite3 docs indicate that offsets can be given, so I see no reason this shouldn't be performed at the DB level. Any ideas? thanks, Forest signature.asc Description: Digital signature
Re: Including [django-users] in subject line?
On Sat, Jun 09, 2007 at 09:23:15PM -0400, Mike Schinkel wrote: > > Malcolm Tredinnick wrote; > > > > Outlook has had rule-based sorting into other mailboxes for a while, > > > > so I would have thought it was possible to use that. > > > > > > It does have that. And I tried that for a while, but found it to be > > > "out-of-sight, out-of-mind." It's worse than just going to the group page > > > and searching when I need something. > > > > So rather than you changing your usage patterns slightly, you > > want us to change the list appearance for over 5000 other people. > > 1.) How many people will be negatively affected? Would there really be > anybody? > 2.) Did you not read that I've tried to changing your usage patterns > slightly, and nothing works? File a bug against Outlook with MSFT, or use a different client. That is the only reasonable solution. It certainly doesn't seem reasonable to me to enforce constraints against senders simply because your client is not as powerful as many others (which have had the necessary features for *years*). -Forest signature.asc Description: Digital signature
Re: Avoiding explicit references in application files
On Fri, Jun 08, 2007 at 07:33:40AM -0700, Tipan wrote: > > I'm in the process of moving our projects onto production servers and > attempting to remove explicit references to the application name in my > files. I want to be able to run a full production and a staging > version on the same server (I've set this up with Apache VirualHosts). > Both versions will be updated via Subversion from the same repository > but I want only the settings files to be the only difference between > them. > > However, I'm struggling to get it working when I remove all explicit > project references from views.py and some other custom modules. > > For example, the two versions called Prod and Test are sitting in > separate directories, each with their own setting files. The settings > files and locations are defined in the VirtualHost definition. Both > sites work fine when I change the explicit references in both url.py > files and in the relevant views.py and modules > > >From the top level url.py I'd have: > urlpatterns = patterns('', > (r'^', include('prod.promotions.urls')), #(or > test.promotions.uls) > ... > In the url.py in promotions would be: > > from promotions.models import * > > urlpatterns = patterns('', > (r'^home/$', 'prod.promotions.views.home',),#(or > test.promotions.views.home) > > > Then in the Views.py I have to explicitly refer to:. > > from prod import settings #(or - > from test imprt settings) > from prod.promotions.models import * > from prod.promotions.form_defs import * > > I have tried to change the references to run without the prod or test. > e.g. from promotions.models import. But this results in an input > error. I've also played tunes with the PythonPath settings in Apache, > but again to no avail. Assuming you have a directory layout like: /usr/local/lib/mysite/prod /usr/local/lib/mysite/test Currently, you would have a situation kind of like this: PYTHONPATH="/usr/local/lib/mysite:other:python:path:stuff" Which means you have to do this: from prod import xyz from test import abc However, if you re-structure a little bit: /usr/local/lib/mysite_prod/mysite urls.py settings.py promotions/ ... /usr/local/lib/mysite_test/mysite urls.py settings.py promotions/ ... And then set your Python paths differently: production: PYTHONPATH="/usr/local/lib/mysite_prod" development: PYTHONPATH="/usr/local/lib/mysite_test" Then you can do: from mysite import promotions And it will work correctly in both instances. -Forest signature.asc Description: Digital signature
Re: Getting primary key value without unnecessary database query
On Fri, Jun 08, 2007 at 06:35:33AM -0700, matthew wrote: > > Hi, > > This is my model: > > class Fish(models.model): >species = models.ForeignKey('Species') > more fields > > class Species(models.Model): > key = models.SlugField(primary_key=True,maxlength=20) > more fields > > Given a Fish object, I want to be able to use the value of the > Fish.species field in a template, *without* an extra query to the > database to get the Species object. I'm only interested in the actual > value of the primary key, not any of the other fields in the Species > object. {{fish.species_id}} signature.asc Description: Digital signature
Re: wicket like templating
On Sun, Jun 03, 2007 at 10:43:12AM -0700, Ittay Dror wrote: > On Jun 3, 9:50 am, Nicola Larosa <[EMAIL PROTECTED]> wrote: > > IttayDror wrote: > > > I was wondering if anyone has thought about makingdjango'stemplating > > > system more in the concepts of wicket (there are other such templating > > > engines, this is the one i've used). > > > > That's not going to happen, as you know by now. However, using any other > > That's a shame. I like Python very much, but I don't want to inforce > it on my web designer. Then don't. Use something else. I see nothing shameful about the state of affairs. The choice of template language is yours. -Forest signature.asc Description: Digital signature
Re: SVN revision for 0.96?
On Tue, May 29, 2007 at 08:28:04PM -, Andrew wrote: > > Sorry, should have been more explicit: > > The question is what the SVN revision number is for the 0.96 release > -- (I'm assuming that things were pinned to trunk for the release, and > not released from some branch) > > We already have a local copy of the distro -- revision 4313 from > January 12 2007. Try this: $ svn log --stop-on-copy http://code.djangoproject.com/svn/django/tags/releases/0.96 Since it is a tag, there should be only one line to the log, and it will be the revision the tag was created. -Forest signature.asc Description: Digital signature
Re: OT: Resources for converting MySQL data to PostgreSQL for Django
On Tue, May 29, 2007 at 08:46:29AM -0700, Joshua D. Drake wrote: > Well, that would be because MySQL is effectively broke in many weird > ways. Your best bet is to recreate your model in postgresql, initialize > that model and move the data over relation by relation. Where "broke" means roughly "!= PostgreSQL"? ;) Seriously, though, I'm not sure if it's fair to blame SQL migration woes on MySQL being "broke". Migrating data between databases is likely to provide some challenges regardless of the source or destination databases, I would think (although I don't claim anything greater than novice status with relational databases). -Forest signature.asc Description: Digital signature
Re: Feisty-updates now contains Python-2.5.1final
On Sun, May 27, 2007 at 12:36:04AM -, Mike Axiak wrote: > Ubuntu Feisty Fawn now has Python 2.5 [1] (thanks, Matthias Klose!). > For any apt-compatible system, the following should/might work: Funny enough, you should note that Feisty _ships_ with Python 2.5 pre-installed. No further action necessary, and this has been true for as long as Feisty has been released. Python 2.5 is the default Python version for Feisty, and is what you get when you type "python" at the shell. -Forest signature.asc Description: Digital signature
Re: Making a copy of an object
On Wed, May 16, 2007 at 08:38:01PM +0300, Matti Haavikko wrote: > I have the following scenario: > - I have retrieved an object from the database > - I want to create another object based on this one, with minor modifications. This seems like a pretty common use case, doesn't it? Maybe something like my_other_instance = my_instance.copy() would be a good addition to the django core? It would be simple enough to implement. -Forest signature.asc Description: Digital signature
Re: ordinal not in range(128) + ezPyCrypto
On Mon, May 14, 2007 at 10:21:28AM -0400, Benjamin Slavin wrote: > I'd recommend doing: > def get_passport(self) > > return k.decString(base64.b64decode(self.passport)) Yes, I think I would normally approach this like: class MyModel(Model): passport = CharField(maxlength = 256) # or whatever length is appropriate def _get_unencrypted_passport(self): return k.decString(base64.b64decode(self.passport)) def _set_unencrypted_passport(self, value): self.passport = base64.b64encode(k.encString(value)) unencrypted_passport = property( _get_unencrypted_passport, _set_unencrypted_passport) Or something like that. (I'm not sure if k.encString is the right function call, so double-check that.) -Forest signature.asc Description: Digital signature
Re: ordinal not in range(128) + ezPyCrypto
On Mon, May 14, 2007 at 09:27:46AM -0400, Benjamin Slavin wrote: > Then the decryption would be: > decrypted_passport = k.decString(self.passport) > self.passport = base64.b64decode(decrypted_passport) You mean: decrypted_passport = k.decString(base64.b64decode(self.passport)) self.passport = decrypted_passport Right? -Forest signature.asc Description: Digital signature
Re: [django] Subject in posts
On Fri, May 04, 2007 at 10:53:03AM -0500, James Bennett wrote: > Consider someone who doesn't have a 2400-pixel wide maximized email > client, and who sees this set of subject lines: > > [django-users] Problem with m > [django-users] Needing help wi I'd say it's time to change your mutt config :) Unless you need to know the kb's in each and every message, that is. -Forest signature.asc Description: Digital signature
Re: [django] Subject in posts
On Fri, May 04, 2007 at 12:37:33AM -0500, Andrés Martín wrote: > This mail, is for proposing that in tha all e-mail's that send to the group, > contain the [django] subject. First, because the client mail can detect spam > en > it, and Second, for recognize each mail of mail-list. is a form of have mail > organize, and know as it is as. Every mailing list I've ever seen that uses prefixed subjects adds the prefix automatically. Users shouldn't be bothered to add a repetitive prefix to their emails. We have machines to do that sort of stuff. More over, you shouldn't expect others to accomodate what appears to be severe deficiencies in your mail clients ability to deal with SPAM and sort incoming messages (or your inability to properly configure those features). One thing that I think would be nice, however, is if MIME digests were support by Google groups. I guess you can't get everything you want. -Forest signature.asc Description: Digital signature
Re: how to connect Django to objects served over xml-rpc?
On Sun, Apr 22, 2007 at 04:43:27AM -0700, Joe wrote: > It sounds like you shouldn't be using Django, honestly. You would be > fighting against/hacking around most of the functionality of django > because django is an MVC framework and you guys basically are trying > to re-write the model architecture. If you really really really want > to use django, you should probably just stick to using the controller/ > view portion, which would suck because you couldn't use the admin > application. I don't think this is true. Django's various layers of functionality are de-coupled relatively well. I would still use Django even if my data access back-end is pure XML-RPC. I just probably wouldn't use Django's ORM. Of course, using the ORM does allow you to abstract your web code even further, but you can probably write wrapper classes around your XML-RPC calls to get som eof that. (For instance, you might implement a class that, to a limited extent, emulates the QuerySet class; I think you need this to use generic views, but correct me if I'm wrong). -Forest signature.asc Description: Digital signature
Re: how to connect Django to objects served over xml-rpc?
Hi Brandon, On Fri, Apr 20, 2007 at 01:58:48PM -0400, [EMAIL PROTECTED] wrote: > I want to try out Django for a small project, hoping to discover that > it will be the web framework of my dreams, but I need some advice. > > My project group has written an xml-rpc API in front of our database > and password stores. This means that when we want to, say, create a > campus guest account, we call xml-rpc functions like create_guest(), > set_guest_info(), and set_account_password(), and those functions do > all of the database operations (and sometimes operations on other > systems) needed to perform each operation consistently (creating a > guest requires at least six tables to be updated, for example). I think you'll find that Django meets your needs quite well, however, I wouldn't recommend at all that you try to make Django's database layer wrap your XML-RPC services. Django's database layer is an ORM, so, unless your XML-RPC services constitute a thin wrapper around your database, or provide a very database-like interface, it probably doesn't meet your requirements at a basic, conceptual model. One thing you could do is provide a set of read-only thin wrappers to your database that can live alongside your current XML-RPC implementation. Then, you could use Django's ORM as an interface to that, and be able to take advantage of things like generic views and the automatic admin interface. Since the interface would be read-only, you'd have to make direct XML-RPC calls to actually make changes to the database, but it sounds like your XML-RPC functions probably provide some enforcement of data integrity, so that's probably not very avoidable. Of course, ultimately, you are getting into a new framework with significant work to do before you can even get your first app put togther (since you'll need to implement a custom database layer). That may not be the best way to introduce yourself to Django :) If your clever, you may be able to implement a read-only DB layer with only a little code, but get some advice from some Django experts first (I am not included in that group). -Forest signature.asc Description: Digital signature
Re: object_list || didn't return an HttpResponse object
On Tue, Apr 03, 2007 at 04:42:58PM -0700, TaMeR wrote: > On Apr 3, 7:10 pm, Forest Bond <[EMAIL PROTECTED]> wrote: > > The way your view is written, if the user is not authenticated, no > > HttpResponse is returned (since no return statement is executed). You > > probably want to just raise Http404 in that case. > I am not sure what you mean > I have a HttpResponseRedirect if the user is not authenticated. > This error happens with an authenticated user. > If the user is not authenticated he/she gets redirected to the login > page and that works fine. > See: > if not request.user.is_authenticated(): > return HttpResponseRedirect('/account/login/?next=%s' % > request.path) Oh, you're right. But, all of your other code is also in that if block. So if the user is authenticated, the view doesn't return anything. Looks like you just have an indentation problem. Remember, Python code is whitespace-sensitive. -Forest signature.asc Description: Digital signature
Re: object_list || didn't return an HttpResponse object
On Tue, Apr 03, 2007 at 03:46:04PM -0700, TaMeR wrote: > This used to work and I must have done something to break the code. > The simple page view still works fine but the list view gives me this > error and I been through my code a million times and can't find > anything wrong with it. The way your view is written, if the user is not authenticated, no HttpResponse is returned (since no return statement is executed). You probably want to just raise Http404 in that case. -Forest signature.asc Description: Digital signature
Re: Python-specific question: variable scope
On Fri, Mar 30, 2007 at 08:07:51PM +0200, Aidas Bendoraitis wrote: > > Actually the was no circular import since I haven't imported a from b, > but just b from a. Sorry, mis-read your code, I thought there were only two modules. > And unfortunately your answer didn't solve the original question, > which is getting the value from the module that imports the current > module. Pardon. I mis-understood that, too. So, your goal is to make Python imports act more like PHPincludes? Wny on earth would you want to do that? There is no global namespace in Python, and for good reason. What are you really trying to achieve? -Forest signature.asc Description: Digital signature
Re: Python-specific question: variable scope
On Fri, Mar 30, 2007 at 01:43:41PM +0200, Aidas Bendoraitis wrote: > > Let's say I have the files main.py, a.py and b.py > > main.py: > --- > x="some local value" > import a > ... > > > a.py: > --- > x="some other local value" > import b > ... > > > b.py: > --- > def test(): > print x > > -- > Is it possible to access the x of the module a.py in the module b.py? > What would be the functions/statements to make it possible? Or in > general, how to access the locals of the importing ( not imported!!!) > module? Well, you have a circular import here that may cause you problems. Neither module could finish loading because it depends on the other being imported which depends on the other being imported which depends on the other being imported But, this could work: a.py: x = 'some local value' b.py: x = 'some other local value' def print_a_x(): import a print a.x # prints 'some local value' def print_x(): print x # prints 'some other local value' Hope this helps. -Forest signature.asc Description: Digital signature
Re: Managing users through Admin app
On Thu, Mar 29, 2007 at 12:42:34PM -, RajeshD wrote: > The idea with the above snippet is that when you add a user, you would > enter a valid username as well as an email address. The user can then > login by entering either the username or the email address in the > admin login screen. That login screen happily takes in an email > address. One approach I've taken to create a completely email-address-oriented authentication system without throwing out Django's auth is to simply generate a unique username by hashing the email address. Unfortunately, the username is limited to 30 chars, and you need 32 characters to save the ASCII version of an MD5 hash. So, you need to come up with your own hashing function. I haven't actually come up with a guaranteed-unique function yet, and haven't really spent much time on it. I've generally settled on simple textual transformations that are probably "good enough" in terms of uniqueness. -Forest signature.asc Description: Digital signature
Re: Database exception handling please
On Wed, Mar 21, 2007 at 04:47:35PM -0700, Gerard M wrote: > > Hello django community, I have a HUGE problem, and I would like to > know if some of you guys can help me, the problem is: Im accesing a > database and there is a big chance of not finding the item im looking > for, this is the snipplet of code im using and the "solution" that > I've implemented but it doesn't work as it should: > > from django.core.exceptions import ObjectDoesNotExist > > try: > z=Dic.objects.filter(DB_Word=worfromtext).distinct() > print z > except ObjectDoesNotExist: > print 'ERROR!' Try using Dic.objects.get( ... ) instead of filter( ... ). filter gives you a subset of the table. get gives you a single result. filter doesn't mind giving you an empty result. get assumes you wanted exactly one result, and raises an exception (Dic.DoesNotExist) if the object doesn't exist. Hope this helps. -Forest signature.asc Description: Digital signature