Re: Row level security
On Aug 20, 2007, at 6:41 PM, Catriona wrote: > > Hello > > Is there a way to implement row level security where a user can > determine who can do what to particular records - ie invoices? The > default would be full access only to the creater. > > I am looking at implementing a ContactInvoiveRole table but wonder if > this is the way to go. > Personally, I would add a "creator" to the invoice model and check is user == creator before allowing any writes. Keep it simple and all that. Besides, you probably want to know the creator anyways. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Row level security
Hello Thanks for that Catriona On Aug 21, 12:07 pm, "Kai Kuehne" <[EMAIL PROTECTED]> wrote: > Hi, > > On 8/21/07, Catriona <[EMAIL PROTECTED]> wrote: > > > Is there a way to implement row level security where a user can > > determine who can do what to particular records - ie invoices? The > > default would be full access only to the creater. > > > I am looking at implementing a ContactInvoiveRole table but wonder if > > this is the way to go. > > Sorry, tired. Only and > url:http://code.djangoproject.com/wiki/RowLevelPermissions > > > > > > > Thanks > > > Catriona- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Odd 404 error on Textdrive with Lighty
On Aug 20, 7:53 pm, "David Merwin" <[EMAIL PROTECTED]> wrote: > http://stpaulswired.org/media/audio/2007/aug/05/straight-from-t/is > teh main one and then derivitaves of the same: > > http://stpaulswired.org/media/audio/2007/aug/05/http://stpaulswired.org/media/audio/2007/aug/ > > Thanks so much for the help. It looks like, in your lighttpd config, /media/* is mapped directly to the filesystem. That's why it's not going through Django's URL config when you use the /media/* URLs. You should check your lighttpd config (or paste it, if you'd like some help with it.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can Django be combined with a more powerful ORM?
I had some success mapping SQLAlchemy Table objects to django models, but as Malcolm said if you're starting from scratch, unless you have a really compelling reason to use django models, why not use SA directly? Also, and forgive the tone of this, it's not meant to sound rude, why do you want to stay close to original code that looks like this: >p[d[series][game]["f"][ixb]["owner"]]["kills"]++; Regards, Ben On 21/08/07, Aidas Bendoraitis <[EMAIL PROTECTED]> wrote: > > > You can minimize the amount of code writing some special methods for > your Player model, i.e.: > > player = Player.objects.get(...) > player.increase("kills", 1) > > where > > class Player(..): > ... > def increase(self, attribute, by_value): > current_value = getattr(self, attribute, 0) > setattr(self, attribute, current_value + by_value) > self.save() > > Good luck! > Aidas Bendoraitis [aka Archatas] > > > > On 8/20/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > > On Mon, 2007-08-20 at 15:48 +0200, Stefan Matthias Aust wrote: > > [...] > > > I'd like to freely modify database objects once loaded into memory and > > > then put everything that was modified with just one command back to > > > the database. Most ORMs work that way, I think. Objects are loaded > > > once within a transaction, know whether they are modified, dependent > > > objects can be automatically added or deleted and all modifications of > > > the database take place in one bulk operation at the end of the > > > transaction. > > > > > > Has anybody extended Django's ORM in such a way? Can it be replaced > > > with some other mapper? I recently heard about Storm, a new mapper > > > written by the Ubuntu guys... I'd prefer to not have to write my own > > > ORM. I've done that more than once in other language :) > > > > The answer to your main question is "yes", it's possible. The answer to > > the secondary question of "how hard is it?" is "it depends on what you > > really want to do". > > > > Ask yourself what features of Django you really want to keep and use > > here. It sounds like it would be most faithful to the original code to > > just not use Django's models at all. So you keep the template, view and > > URL dispatching (if that's what you like to use) and manage the data > > storage and structures yourself or with your particular > > Python-to-database mapping tool of choice. > > > > Things like keeping track of what has changed and automatically saving > > (which are a feature of some, but definitely not all persistent storage > > layers; there are drawbacks as well as advantages to that approach for > > shared data), means you need to find a storage layer that does that for > > you. It's not really a Django issue, as much as technical decision about > > how you want to persist your data and what Python interface it presents > > to you. From the examples you gave, Django's query set notation doesn't > > help you. So don't use it. Pick a replacement persistence layer. > > > > Trying to replace just the ORM portion (the "mapper" between Python > > objects and database relations) is almost certainly the wrong level to > > be customising unless you're deeply in love with the Django model > > syntax. > > > > Regards, > > Malcolm > > > > -- > > What if there were no hypothetical questions? > > http://www.pointy-stick.com/blog/ > > > > > > > > > > > > > -- Regards, Ben Ford [EMAIL PROTECTED] +628111880346 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Row level security
Hi, On 8/21/07, Catriona <[EMAIL PROTECTED]> wrote: > Is there a way to implement row level security where a user can > determine who can do what to particular records - ie invoices? The > default would be full access only to the creater. > > I am looking at implementing a ContactInvoiveRole table but wonder if > this is the way to go. Sorry, tired. Only and url: http://code.djangoproject.com/wiki/RowLevelPermissions > > Thanks > > Catriona --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Lighttpd conf
Does this conf file look right? In particular the fcgi statement fastcgi.server = ( "/mysite.fcgi" => and fastcgi.server = ( "/mysite.fcgi" => ( "main" => ( each is a different django project using a different fastcgi socket. $HTTP["host"] =~ "(www|projects).somesite.com" { server.document-root = "/web1/httpd/htdocs/" fastcgi.server = ( "/mysite.fcgi" => ( "main" => ( # Use host / port instead of socket for TCP fastcgi # "host" => "127.0.0.1", # "port" => 3033, "socket" => "/usr1/local/oper/ mysite.sock", "min-procs" => 1, "max-procs" => 25, "idle-timeout" => 30, "max-load-per-proc" => 5, "check-local" => "disable", "bin-environment" => ( "TZ" => "America/Los_Angeles" ) ) ), ) } # for classifieds $HTTP["host"] == "anywhere.somesite.com" { server.document-root = "/web1/httpd/htdocs/" fastcgi.server = ( "/mysite.fcgi" => ( "main" => ( # Use host / port instead of socket for TCP fastcgi # "host" => "127.0.0.1", # "port" => 3033, "socket" => "/usr1/local/oper/ class.sock", "min-procs" => 1, "max-procs" => 6, "idle-timeout" => 60, #"max-load-per-proc" => 5, "check-local" => "disable", "bin-environment" => ( "TZ" => "America/Los_Angeles" ) ) ), ) } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Row level security
Hello Is there a way to implement row level security where a user can determine who can do what to particular records - ie invoices? The default would be full access only to the creater. I am looking at implementing a ContactInvoiveRole table but wonder if this is the way to go. Thanks Catriona --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using the DB Package Outside of Django
Thanks for the help. A little tip for anyone else who wants to do this: put models.py in a package. You can't have models.py in the same directory as the script because django is hard coded to get the model's package at django.db.models.base.py", line 52, in __new___. On Aug 20, 4:57 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On 8/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > I've looked around and haven't found anything on it. Is there a quick > > way of creating a settings.py file and calling Django's DB API to > > connect to the database and start using my models? Thanks. > > Yes: > > http://www.djangoproject.com/documentation/settings/#using-settings-w... > > 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-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
HOT HOT HOT!! nude and on cam right now!!!
Local people looking for sex. Talk with them live right now at www.420.irio.net --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Serving large files through HttpResponse
If using mod_python, you might also look at Tramline: http://infrae.com/products/tramline This allows a response to set a special header which is then picked up by an Apache output filter, with the output filter then inserting the file contents direct into the output stream. Using Python to do this sort of Apache filter will still incur some overhead, but better than sending the file yourself. I imagine there must be a C module for Apache for doing this sort of stuff as well which would make it even more efficient. Graham On Aug 20, 11:53 pm, Simon Willison <[EMAIL PROTECTED]> wrote: > On Aug 20, 1:12 pm, Ceph <[EMAIL PROTECTED]> wrote: > > > The only other option I see to serving large files securely is > > trickery using dynamically created sym links to the true static file > > and then redirecting the user to those URLs and letting Apache serve > > them. This isn't as secure, though, and permits multiple downloads > > without them being recorded in my Django apps. > > Lighttpd and nginx both have a clever way of dealing with this > problem. You can store the real file somewhere that is readable by the > web server but NOT exposed as a public URL. Then your Django > application can (having authenticated the request) respond with a > magical header which tells the nginx/lighttpd server to serve up the > file from that location. > > Here's how to do it with nginx: > > http://wiki.codemongers.com/NginxXSendfile > > If your app is all about serving large files, it may well be worth > putting it behind an nginx proxy purely to gain access to this > feature. nginx is a really neat reverse proxy - I run > simonwillison.net as nginx proxying through tomod_python/Apache for > the dynamic pages and it's been working great for months. > > Hope that helps, > > Simon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using the DB Package Outside of Django
On 8/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I've looked around and haven't found anything on it. Is there a quick > way of creating a settings.py file and calling Django's DB API to > connect to the database and start using my models? Thanks. Yes: http://www.djangoproject.com/documentation/settings/#using-settings-without-setting-django-settings-module 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-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Odd 404 error on Textdrive with Lighty
http://stpaulswired.org/media/audio/2007/aug/05/straight-from-t/ is teh main one and then derivitaves of the same: http://stpaulswired.org/media/audio/2007/aug/05/ http://stpaulswired.org/media/audio/2007/aug/ Thanks so much for the help. On 8/20/07, RajeshD <[EMAIL PROTECTED]> wrote: > > > > On Aug 20, 6:11 pm, "David Merwin" <[EMAIL PROTECTED]> wrote: > > Fixed the 404 template and 500 templates. > > > > Here is the site wide URLS:http://dpaste.com/hold/17376/ > > > > Here is the object URLS:http://dpaste.com/hold/17375/ > > A couple of URLs that give you the 404 error? > > > > > -- Dave Merwin http://www.purebluedesign.com http://www.davemerwin.com http://www.betachurch.org cell: 541.335.1832 My Profile: http://www.linkedin.com/in/merwin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom primary key using Oracle 10g
Hi Ian Sorry for taking a while to get back to you but I've been away. Thanks for your advice. I will log a bug. I have also found a couple of other issues and will report those as well. Regards Catriona On Aug 16, 3:44 pm, Ian <[EMAIL PROTECTED]> wrote: > On Aug 15, 9:43 pm, Catriona <[EMAIL PROTECTED]> wrote: > > > Hi Ian > > > Sorry I wasn't really clear in what I want to achieve. I really just > > want to call my primary key, in this case, employee_id and have it > > incremented automatically. > > Sorry I misunderstood you. The code you tried appears to be correct, > but you've found a bug: the trigger code seems to be blindly assuming > that the AutoField will be named "id". Would you please submit a bug > report so that we don't lose track of it? > > Until this is fixed, consider supplying your primary key with the > db_column="id" option as a workaround. That will cause the underlying > column to be named ID, so the trigger should work, but the Django name > for the field will still be the one that you pick for it. > > Hope that helps! > > -Ian > > > > > > > I tried the following: > > > from django.db import models > > > class Employee(models.Model): > > employee_id = models.AutoField(max_length=10, primary_key=True) > > first_name = models.CharField(max_length=20) > > last_name = models.CharField(max_length=20) > > > and got this output - the table and sequence were created but not the > > trigger. > > > C:\DjangoTraining\PK>python manage.py validate > > 0 errors found. > > > C:\DjangoTraining\PK>python manage.py sql test > > CREATE TABLE "TEST_EMPLOYEE" ( > > "EMPLOYEE_ID" NUMBER(11) NOT NULL PRIMARY KEY, > > "FIRST_NAME" NVARCHAR2(20) NULL, > > "LAST_NAME" NVARCHAR2(20) NULL > > ) > > ; > > CREATE SEQUENCE TEST_EMPLOYEE_SQ; > > CREATE OR REPLACE TRIGGER TEST_EMPLOYEE_TR > > BEFORE INSERT ON "TEST_EMPLOYEE" > > FOR EACH ROW > > WHEN (new.id IS NULL) > > BEGIN > > SELECT TEST_EMPLOYEE_SQ.nextval INTO :new.id FROM dual; > > END; > > / > > COMMIT; > > > C:\DjangoTraining\PK>python manage.py syncdb > > Creating table test_employee > > Traceback (most recent call last): > > File "manage.py", line 11, in ? > > execute_manager(settings) > > File "C:\Python24\Lib\site-packages\django\core\management.py", line > > 1730, in > > execute_manager > > execute_from_command_line(action_mapping, argv) > > File "C:\Python24\Lib\site-packages\django\core\management.py", line > > 1621, in > > execute_from_command_line > > action_mapping[action](int(options.verbosity), > > options.interactive) > > File "C:\Python24\Lib\site-packages\django\core\management.py", line > > 554, in s > > yncdb > > cursor.execute(statement) > > File "C:\Python24\Lib\site-packages\django\db\backends\util.py", > > line 19, in e > > xecute > > return self.cursor.execute(sql, params) > > File "C:\Python24\Lib\site-packages\django\db\backends\oracle > > \base.py", line 1 > > 22, in execute > > return Database.Cursor.execute(self, query, params) > > cx_Oracle.DatabaseError: ORA-00904: "ID": invalid identifier > > > Sorry if I'm missing something really basic here but I am a bit > > confused. > > > Thanks > > > Catriona > > > On Aug 15, 6:09 pm, Ian <[EMAIL PROTECTED]> wrote: > > > > Catriona, > > > > Only AutoFields are auto-incrementing in Django. If you want to use a > > > custom primary key that isn't an AutoField, you will need to populate > > > the primary key yourself (or else create a custom trigger for it), > > > just as you would for any other column that is both NOT NULL and > > > UNIQUE. This is true across all the backends, not just Oracle. > > > > -Ian > > > > On Aug 14, 5:34 pm, Catriona <[EMAIL PROTECTED]> wrote: > > > > > Hi Jon > > > > > Thanks for your reply. I read the article but with Oracle, a sequence > > > > and trigger needs to be created for autogenerated primary keys. If I > > > > try the code that you gave me, neither the sequence nor trigger are > > > > created- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Dynamically changing newforms
You could build a builder function that does what you want (totally untested, rough example). The form_for_model functions are good working examples if I screwed something up here. def form_builder(question_instance): base_fields={'text': forms.CharField(widget=forms.Textarea, help_text=question_instance.exampleAnswer, verbose_name=question_instance.questionText) } return type('QAForm', (forms.BaseForm), {'base_fields': base_fields}) def form_set_builder(question_set,postdata=None): form_set=[] valid=True for q in question_set: Form=form_builder(q) # will use question pk id as prefix to differentiate the forms from one another if postdata: # bound form if request.POST passed in as postdata form=Form(postdata,prefix=q._get_pk_val()) valid=form.is_valid() else: # unbound form form=Form(prefix=q._get_pk_val()) form_set.append(form) return form_set, valid def view(request): qs = Question.objects if request.POST: form_set,valid=form_set_builder(qs,request.POST) if valid: #loop through and save else: return with errors else: form_set,throwaway=form_set_builder(qs) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Odd 404 error on Textdrive with Lighty
On Aug 20, 6:11 pm, "David Merwin" <[EMAIL PROTECTED]> wrote: > Fixed the 404 template and 500 templates. > > Here is the site wide URLS:http://dpaste.com/hold/17376/ > > Here is the object URLS:http://dpaste.com/hold/17375/ A couple of URLs that give you the 404 error? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Using the DB Package Outside of Django
I've used the template engine of Django in many scripts and I was wondering if there's a simple way of doing the with django.db package. I've already invested a lot of time learning Django's DB API and really like it so it would be great if I can make a models.py file and use those classes in my scripts instead of having to resort to SQL. I've looked around and haven't found anything on it. Is there a quick way of creating a settings.py file and calling Django's DB API to connect to the database and start using my models? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Apache does not serve static files from document root
On 8/20/07, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > Have you read the mod_python documentation on Django site? It gives an > example, which modified for your case would be: > > > SetHandler None > > > The important bit is the SetHandler directive. Have you done that? Yes, I did. Setting handler to default-handler has the same effect as setting it to None. I tried both values. > Post what your Apache configuration snippet for setting up Django > looks like. SOLVED. My friend has localized a problem: The reason was misinterpretation of Apache's manual sentence: " directives are processed in the order they appear in the configuration file" It does not mean I should put a *before* mod_python's , but *behind* it, because first, "/" locations is evaluated as matched, next the "/wssmedia" is matched and overrides first one. Hence the working httpd.conf snippet looks like: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE bizweb.server_settings PythonDebug On PythonPath "[r'C:\\.WKS-PF\\PRJ\\ECLIPSE\\Django\\src'] + sys.path" SetHandler default-handler Thank you for your help and I hope this off-topic thread would be usefull for somebody else who meets the similiar problems on Apache side. Peter --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Odd 404 error on Textdrive with Lighty
Fixed the 404 template and 500 templates. Here is the site wide URLS: http://dpaste.com/hold/17376/ Here is the object URLS: http://dpaste.com/hold/17375/ Lemme know what you see. Just emailed, textdrive. They do not think it is memory related. Thanks, Dave On 8/20/07, RajeshD <[EMAIL PROTECTED]> wrote: > > Hi Dave, > > > line 72, in find_template_source > > raise TemplateDoesNotExist, name > > TemplateDoesNotExist: 404.html > > This is really saying that you do not have a 404.html template > defined. Just create a simple 404.html file at the base of your > template dir path and add a simple message to it. > > This won't solve the problem of why you are getting that 404 error in > the first place, but at least you won't be distracted by the confusing > message. > > Also, it's likely that the request is never matching any of your URL > conf patterns causing the 404 error. So, perhaps post another message > here detailing all urls.py that come into action during this > particular request. > > -Rajesh > > > > > -- Dave Merwin http://www.purebluedesign.com http://www.davemerwin.com http://www.betachurch.org cell: 541.335.1832 My Profile: http://www.linkedin.com/in/merwin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ugettext vs. ugettext_lazy
Hello, I've been playing with these functions and finally I've become totally confused. I've expected that there would be some difference in behaviour, but I was not able to create such use case in which these two functions produces different results. More precisely, I haven't find place where would be better to use ugettext_lazy. In documentation is said to use this function in models.py everywhere. But for me it looks that ugettext makes the same work. All text marked to translation is translated accordingly to locale set by user via browser with both of them. Furthermore i was not able to use template strings and stay in __proxy__ mode. anything like ugettext_lazy('xyz %s') % 'some_text' comes to unicode string representation immediately. So, it looks there is no way to use template strings with *_lazy. From my view it is little bit painful to use it. But I think I must be completely missing something important in this area. Can anybody enlighten me, please? -- Tomas Kopecek e-mail: permonik at mesias.brnonet.cz ICQ: 114483784 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Odd behavior of filtering
Hi My model is: class Tag(models.Model): name = models.CharField(maxlength=30) class Snippet(models.Model): name = models.CharField(maxlength=30) tags = models.ManyToManyField(Tag,filter_interface=models.HORIZONTAL) My aim to filter snippets according to multiple tag constraints simultaneously. However, the overlap of two sets just doesn't get filtered properly. E.g.: In [96]: Snippet.objects.filter(tags__name="home") Out[96]: [, ] In [97]: Snippet.objects.filter(tags__name="email") Out[97]: [, ] In [98]: Snippet.objects.filter(tags__name="home").filter(tags__name="email") # SHOULD return [] Out[98]: [] I tried the exact same idea by using .filter(Q(..),Q(..)) and also with the Q(..)&Q(..) option, as well as by dividing the process into stages and inspecting the first filter's result on the way (it's valid). Everything just ends up with the same empty list... Any ideas? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
GoFlow: a workflow engine for django
Hi, I'm just starting a workflow engine for django, based on Zope2 openflow product. Home: http://django-goflow.blogspot.com/ (in french) Dev trac: https://opensvn.csie.org/traccgi/openflow Take a look, your comments and ideas are welcome. Miloz --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
db-api optimization
Hello, I'm preparing a search form to perform searches against the db (Postgre ). well, Imagine the form with a category field, and a words field. My view is something similar to this: def my_view( request ): items = a_model.objects.all() if request.GET: ... if form.is_valid(): ... words = data['words'].split() for word in words: items = items.filter( title__icontains = word) items = items.filter( description__icontains = word) if data['category']: items = items.filter( category = data['category'] ) Well, I know that since full-text is not available, this way is quite intensive for the db.This code, search the words in the title and the description, and if the category is defined, refines the result to that category, if not, all categories are shown. I have read in the docs, that chaining filters doesn't hit the database. Is this a good way of chaining filters or perhaps there is other more effective? Is there any way I can see the final generated sql clause? Thank you! (I'm really looking forward to postgre 8.3 with full-text in the core) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What's possible in the admin?
Thanks for both of the great replies, Malcolm and oggie rob. Much appreciated. -Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Float Field not displaying the two zeros at the end of a price
Jake and Zerek, I will able to fix the problem thanks to your suggestions. It turns out that instead of using 'a.price' I have to use 'a.price.name'. Below is my model code: class Price(models.Model): name = models.DecimalField(max_digits=6, decimal_places=2) price_cat = models.ForeignKey(PriceCategory) def __str__(self,): return str(self.name) class Admin: pass 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) / My for loop in my template contained all of my choices that fit the criteria. Notice how 'price' is a ForeignKey to the Price class. We'll when I did a 'a.price' I guess that was returning a string based on 'def __str__(self,): return str(self.name)'. So in my template I changed it to a.price.name and it works. The two zeros now appear. Thanks for your help On Aug 20, 2:14 pm, jake <[EMAIL PROTECTED]> wrote: > hi greg, > > Greg wrote: > > Jake, > > I've made the change to where both of my fields are now of type > > DecimalField. However, I'm getting the same error: > > > TypeError > > float() argument must be a string or a number > > Here is what I have is my models file: > > > models.DecimalField(max_digits=6, decimal_places=2) > > it looks to me like your 'price' field is passing a None to the filter. > this can easily happen if you have a null value in the price column. > the model specification you gave here wouldn't allow that, but have you > been altering the actual database records & table structure to keep up > with your model changes? the template may be trying to render null data > from an insert prior to your model change. > > -jake --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Odd 404 error on Textdrive with Lighty
Hi Dave, > line 72, in find_template_source > raise TemplateDoesNotExist, name > TemplateDoesNotExist: 404.html This is really saying that you do not have a 404.html template defined. Just create a simple 404.html file at the base of your template dir path and add a simple message to it. This won't solve the problem of why you are getting that 404 error in the first place, but at least you won't be distracted by the confusing message. Also, it's likely that the request is never matching any of your URL conf patterns causing the 404 error. So, perhaps post another message here detailing all urls.py that come into action during this particular request. -Rajesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Apache does not serve static files from document root
On Aug 21, 3:21 am, "Peter Melvyn" <[EMAIL PROTECTED]> wrote: > On 8/20/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > Not really Django related, so I'll do this briefly... > > Yes, I know. I appreciate your prompt reply. Thanks. > > > In this case you'll probably want to add another Location section before > > this one to handle things to WWW-ROOT/bizweb explicitly (whatever URL is > > meant to map to that filesystem location). Note (read the Apache docs) > > that Location sections are processed in order from top to bottom in the > > config file. > > Yes, I would. I played with Apache httpd.conf almost all afternoon to > do achieve this, but with no success: once there is or > setting handler tomod_python, all requests > are routed to it and it seems that all precedent are > ignored. > > If I changedmod_python's, precedent take > effect, but it break functionality of Django app. > > ### > > Regardless of Apache config problem, how to handle following URLs by > Django > application:http://www.mysite.comhttp://www.mysite.com/http://www.mysite.com/index.htmhttp://www.mysite.com/index.htmlhttp://www.mysite.com/wss/.*$ > > Currently I route different url patterns of home page to the same view > - there is no problem. With development server as well. > > But I don't know how to config Apache this way: > if URL starts with "/wssmedia/": > use default_handler > else: > usemod_python(Django) Have you read the mod_python documentation on Django site? It gives an example, which modified for your case would be: SetHandler None The important bit is the SetHandler directive. Have you done that? Post what your Apache configuration snippet for setting up Django looks like. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Odd 404 error on Textdrive with Lighty
I have textdrive account with lightty and flup running. The blog section works great. No problems. However, the audio media (and I suspect other elemets of the same app) generic views are throwing an odd 404 error. It seems that the system is not getting to the django debug. However, it is showing that I do not have a template in place. Which, you guessed it, I do. Here is the log entry: 2007-08-20 15:52:38: (mod_fastcgi.c.2551) FastCGI-stderr: Traceback (most recent call last): File "/users/home/stpauls/local/flup/server/fcgi_base.py", line 558, in run protocolStatus, appStatus = self.server.handler(self) File "/users/home/stpauls/local/flup/server/fcgi_base.py", line 1112, in handler result = self.application(environ, start_response) File "/users/home/stpauls/local/django_src/django/core/handlers/wsgi.py", line 189, in __call__ response = self.get_response(request) File "/users/home/stpauls/local/django_src/django/core/handlers/base.py", line 103, in get_response return callback(request, **param_dict) File "/users/home/stpauls/local/django_src/django/views/defaults.py", line 78, in page_not_found t = loader.get_template(template_name) # You need to create a 404.html template. File "/users/home/stpauls/local/django_src/django/template/loader.py", line 79, in get_template source, origin = find_template_source(template_name) File "/users/home/stpauls/local/django_src/django/template/loader.py", line 72, in find_template_source raise TemplateDoesNotExist, name TemplateDoesNotExist: 404.html So I am completely stumped. What I have done so far: Updated Flup Removed all logic from the template. Still errors. Any thought on how to troubleshoot would be awesome. The models.py in question is here: http://dpaste.com/hold/17357/ The urls.py in question is here: http://dpaste.com/hold/17356/ Thanks. -- Dave Merwin http://www.purebluedesign.com http://www.davemerwin.com http://www.betachurch.org cell: 541.335.1832 My Profile: http://www.linkedin.com/in/merwin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Manytomany relation with additional data
Sounds like you need to add a Recipes model (table) with a M2M field for the ingredient and a separate column for the percentage. Then your Product table actually has the ability to have more than once recipe for each product. -- Austin Govella Thinking & Making: IA, UX, and IxD http://thinkingandmaking.com [EMAIL PROTECTED] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Float Field not displaying the two zeros at the end of a price
hi greg, Greg wrote: > Jake, > I've made the change to where both of my fields are now of type > DecimalField. However, I'm getting the same error: > > TypeError > float() argument must be a string or a number > Here is what I have is my models file: > > models.DecimalField(max_digits=6, decimal_places=2) it looks to me like your 'price' field is passing a None to the filter. this can easily happen if you have a null value in the price column. the model specification you gave here wouldn't allow that, but have you been altering the actual database records & table structure to keep up with your model changes? the template may be trying to render null data from an insert prior to your model change. -jake --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ImageField via admin
Grigory Fateyev wrote: > Hello Carl Karsten! > On Sun, 19 Aug 2007 21:39:31 -0500 you wrote: > >> Grigory Fateyev wrote: >>> Hello! >>> >>> I have simple class with ImageField, but cann't add any object: >>> >>> class Book(models.Model): >>> name = models.CharField(_('Book Title'), maxlength=200) >>> book_number = models.IntegerField() >>> image = models.ImageField(upload_to='%Y/%m/%d/', core=True, >>> blank=True) >>> comment = models.TextField(_('Book Comment'), blank=True, >>>null=True) >>> author = models.CharField(_('Author'), maxlength=100, >>> blank=True) >>> year_rate = models.IntegerField() >>> >>> class Meta: >>> verbose_name = _('Book') >>> verbose_name_plural = _('Books') >>> >>> class Admin: >>> list_display = ('book_number', 'name', 'year_rate') >>> >>> def __unicode__(self): >>> return u"%s %s %s" % (self.book_number, self.name, >>> self.year_rate) >>> >>> the error: >>> >>> Traceback (most recent call last): >>> File >>> "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in >>> get_response 77. response = callback(request, *callback_args, >>> **callback_kwargs) File >>> "/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py" >>> in _checklogin 51. if 'post_data' in request.POST: File >>> "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in >>> _get_post 135. self._load_post_and_files() >>> File "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in >>> _load_post_and_files 113. self._post, self._files = >>> http.parse_file_upload(self.environ['wsgi.input'], self.environ) >>> File "/usr/lib/python2.4/site-packages/django/http/__init__.py" in >>> parse_file_upload 71. raw_message = '\r\n'.join(['%s:%s' % pair for >>> pair in header_dict.items()]) >>> >>> AttributeError at /admin/books/book/add/ >>> '_fileobject' object has no attribute 'items' >>> >>> What the problem it can be? >>> >> I just made a project with just that model. works for me. >> I would start by looking at these lines: >> >> [EMAIL PROTECTED]:~/django/foo/foot$ grep static * >> settings.py:# settings.py:MEDIA_ROOT = BASE_DIR+'/static/' >> settings.py:MEDIA_URL = '/static/' >> urls.py:(r'^static/(?P.*)$', 'django.views.static.serve', >> {'document_root': settings.BASE_DIR+'/static/', 'show_indexes': >> True}), >> >> What version of django? I am using current svn. >> >> Carl K >> > > settings.py:MEDIA_ROOT = BASE_DIR+'/media/' > settings.py:MEDIA_URL = '/site_media/' > urls.py:(r'^site_media/(?P.*)$', 'django.views.static.serve', > {'document_root': settings.BASE_DIR+'/media/', 'show_indexes':True}), > > Revision: 5946 > I used your settings, no problem. Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [EMAIL PROTECTED]:~/django/django_src$ svn up Updated to revision 5988. Carl K --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
how to change admin output of fields in editmode?
i want to change how fields are displayed in admin mode in the edit view. for example: if i use a ImageField, on editmode it says: > Derzeit: images/2007/08/17/preview/preview1.png but i want it to display the image, instead of the path and a link to the image how would one do that? is there a method which manages the output of the admin edit mode which i could overwrite? thanx for any help --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Dynamically changing newforms
Hello group, I'm trying to build a fairly complicated form submission using newforms, which requires that the form is modified based on information in the model. For example, I've got a couple of models which look like this: class Question(models.Model): questionText = models.CharField(maxlength=255, verbose_name="question text") classification = models.ForeignKey('Classification') exampleAnswer = models.CharField(maxlength=255, verbose_name="example answer") required = models.BooleanField(verbose_name="compulsory question?") class Answer(models.Model): question= models.ForeignKey('Question') classification = models.ForeignKey('Classification') job = models.ForeignKey('Job') answerText= models.TextField() The basic premise is that each Classification has a set of Questions associated with it, some of which are required. So the form is really simple - there's only one editable field so the user can answer the question: class QuestionAnswerForm(forms.Form): text = forms.CharField(widget=forms.Textarea, help_text="replace me with the example answer", verbose_name="replace me with the question") I'd like to set the verbose_name on that CharField to be the question to be answered, and the help_text to be the example answer; similarly for whether the field is required or not. This can be done by modifying form.fields['fieldname'], but unfortunately the changes don't remain after the forms have been POSTed, which I think is because the form is rebuilt from the POSTed information. You can also modify form.base_fields, but those changes are applied on a class-wide (as opposed to per-instance) basis, which doesn't help me because I have multiple Question forms on each page. Short of including the extra context information (example answer, required etc.) inside the form in hidden fields, I'm stuck. Can anyone suggest a better way of doing what I'm trying to achieve? Many thanks, Matt. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django with cmemcache extension issues
On Aug 19, 12:18 am, Sasha Weberov <[EMAIL PROTECTED]> wrote: > On Aug 18, 10:01 pm, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote: > > > On 8/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > ... > > > > however, upon enabled the middlwear with memcached using > > > cmemcached... I've tried > > > cacheing with the file system as the source and its fine. > > > With respect, you may have better luck asking people directly involved > > withcmemcache. > > I will do so - I figured there are many people who usecmemcache/ > memcache with Django. anyone? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Money
www.mirko-banner.5ub.de www.mirko-homepage.5ub.de www.mirko-search.5ub.de --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can Django be combined with a more powerful ORM?
You can minimize the amount of code writing some special methods for your Player model, i.e.: player = Player.objects.get(...) player.increase("kills", 1) where class Player(..): ... def increase(self, attribute, by_value): current_value = getattr(self, attribute, 0) setattr(self, attribute, current_value + by_value) self.save() Good luck! Aidas Bendoraitis [aka Archatas] On 8/20/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Mon, 2007-08-20 at 15:48 +0200, Stefan Matthias Aust wrote: > [...] > > I'd like to freely modify database objects once loaded into memory and > > then put everything that was modified with just one command back to > > the database. Most ORMs work that way, I think. Objects are loaded > > once within a transaction, know whether they are modified, dependent > > objects can be automatically added or deleted and all modifications of > > the database take place in one bulk operation at the end of the > > transaction. > > > > Has anybody extended Django's ORM in such a way? Can it be replaced > > with some other mapper? I recently heard about Storm, a new mapper > > written by the Ubuntu guys... I'd prefer to not have to write my own > > ORM. I've done that more than once in other language :) > > The answer to your main question is "yes", it's possible. The answer to > the secondary question of "how hard is it?" is "it depends on what you > really want to do". > > Ask yourself what features of Django you really want to keep and use > here. It sounds like it would be most faithful to the original code to > just not use Django's models at all. So you keep the template, view and > URL dispatching (if that's what you like to use) and manage the data > storage and structures yourself or with your particular > Python-to-database mapping tool of choice. > > Things like keeping track of what has changed and automatically saving > (which are a feature of some, but definitely not all persistent storage > layers; there are drawbacks as well as advantages to that approach for > shared data), means you need to find a storage layer that does that for > you. It's not really a Django issue, as much as technical decision about > how you want to persist your data and what Python interface it presents > to you. From the examples you gave, Django's query set notation doesn't > help you. So don't use it. Pick a replacement persistence layer. > > Trying to replace just the ORM portion (the "mapper" between Python > objects and database relations) is almost certainly the wrong level to > be customising unless you're deeply in love with the Django model > syntax. > > Regards, > Malcolm > > -- > What if there were no hypothetical questions? > http://www.pointy-stick.com/blog/ > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Unicode question
Hi Rob. After the unicode branch merge django expects and produces unicodes objects throughout. A detail how to port guide is here: http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsTheQuickChecklist In this specific case, you can call "lower" directly on your unicode object: "cur_month.lower()" instead of "str.lower(cur_month)" Cheers Arthur --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Ajax Form Submission Trouble
On Aug 19, 3:11 am, Thejaswi Puthraya <[EMAIL PROTECTED]> wrote: > > Thanks a bunch, but would that go into the markup or into the > > comments.js file? I'm a js newb (really bad one). I'm guessing into > > the js file, the submit button doesn't have an id. Here is my current > > comments.js filehttp://dpaste.com/17243/ > > It would go into your template and not into your js file...it is > recommended that you have an id for your submit button. > > Cheers > Thejaswi Puthraya still doesn't work, even with an ID. :( --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Apache does not serve static files from document root
On 8/20/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > Not really Django related, so I'll do this briefly... Yes, I know. I appreciate your prompt reply. Thanks. > In this case you'll probably want to add another Location section before > this one to handle things to WWW-ROOT/bizweb explicitly (whatever URL is > meant to map to that filesystem location). Note (read the Apache docs) > that Location sections are processed in order from top to bottom in the > config file. Yes, I would. I played with Apache httpd.conf almost all afternoon to do achieve this, but with no success: once there is or setting handler to mod_python, all requests are routed to it and it seems that all precedent are ignored. If I changed mod_python's , precedent take effect, but it break functionality of Django app. ### Regardless of Apache config problem, how to handle following URLs by Django application: http://www.mysite.com http://www.mysite.com/ http://www.mysite.com/index.htm http://www.mysite.com/index.html http://www.mysite.com/wss/.*$ Currently I route different url patterns of home page to the same view - there is no problem. With development server as well. But I don't know how to config Apache this way: if URL starts with "/wssmedia/": use default_handler else: use mod_python (Django) Peter --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: url issue giving me grief
Dude, thanx, it just clicked what you were saying. On Aug 20, 7:08 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2007-08-20 at 14:00 +, wheresdave wrote: > > [...] > > > > > urls.py > > > from django.conf.urls.defaults import * > > > urlpatterns = patterns('', > > (r'^network/$', 'social.network.views.index'), > >(r'^accounts/', include('registration.urls')), > >(r'^admin/', include('django.contrib.admin.urls')), > > > ) > > > Now, when i go tohttp://127.0.0.1:8000/blog orhttp://127.0.0.1/index/ > > I get the following error message. > > Request Method:GET > > Request URL: http://127.0.0.1:8000/index/ > > > Using the URLconf defined in social.urls, Django tried these URL > > patterns, in this order: > > >1. ^network/$ > >2. ^accounts/ > >3. ^admin/ > > > The current URL, index/, didn't match any of these. > > > Anybody have any ideas on what I might be doing wrong? > > It tells you right there in the error message. You have only configured > your url patterns to look for things starting with network, accounts or > admin. So passing it a URL starting with "index" isn't going to match > anything. Why do you expect those requests to return anything? > > Regards, > Malcolm > > -- > A clear conscience is usually the sign of a bad > memory.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: (1040, 'Too many connections')
Hi guys, First, thanks for the great help. I read your recomendations and fall on 2 solutions: 1) Upgrade django to version 0.96. I see some people run into problems with mysql (postgresql too), the recomended revision is [5511]. I don ´t work on this project (the site I´m keeping) from the starting, I got it in the middle. It seems my django checkout is [3754] from 2006-12-09. On the same thread, the problem seems to be raised on the [5482] django release, this way I think the problem isn´t with my django instalation. I didn´t upgraded my django version because I planning to upgrade/rewrite my whole project using newforms/newforms-admin, I don ´t know if there will be any side effect migrating to 0.96, so I focused my efforts to another points. Anyway, running a `mysqladmin proc` tells that the connections are closed properly, almost anytime I run the command, it shows me only the mysqladmin connection. 2) Upgrade MySQLdb lib. I had problems with newer versions of this lib (problems with unicode), I used webware+sqlobject. Do you think this will really solve my problem? I just wonder if I will solve a problem and raise another one (with character encoding :-P) Thanks for all help! Best regards, --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
how to change admin output of fields in editmode?
i want to change how fields are displayed in admin mode in the edit view. for example: if i use a ImageField, on editmode it says: > Derzeit: images/2007/08/17/preview/preview1.png but i want it to display the image, instead of the path and a link to the image how would one do that? is there a method which manages the output of the admin edit mode which i could overwrite? thanx for any help --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Arama yaparak para kazan!
Arama yaparak para kazan! Hergün google'da yüzlerce kelime aratıyoruz! Google'da arama yaparken bi yandanda para kazanmak istemisiniz! oturduğunuz yerde arama yapmaktan başka bi ekstrası olmadan para kazanmak 2 tık kadar kolay!!! http://www.search-earn.com/shadowspain --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to change admin output of fields in editmode?
the only solution I could think about is using js: 1. detect all image-input-fields 2. extract the value 3. build the image-tag 4. use DOM-manipulation to add the image-tag after the input-field patrick On 20 Aug., 17:07, "G.o.D" <[EMAIL PROTECTED]> wrote: > i want to change how fields are displayed in admin mode in the edit > view. > > for example: if i use a ImageField, on editmode it says: > > > Derzeit: images/2007/08/17/preview/preview1.png > > but i want it to display the image, instead of the path and a link to > the image > > how would one do that? > > is there a method which manages the output of the admin edit mode > which i could overwrite? > > thanx for any help --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Unicode question
After moving to the latest version of Django one of the functions I wrote fails to work. I'll drop the code... def year_cal(sectie, req_year = None, req_month=None): cur_year= str(datetime.datetime.now().year) cur_month= datetime.datetime.now().strftime("%b") all_month_list = ['jan', 'feb', 'maa', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'] month_list = [] if req_year is None: req_year = cur_year req_month= cur_month else: if int(req_year) > int(cur_year): req_year = cur_year if req_month is None: req_month = trans_month('jan') else: req_month = trans_month(req_month) prev_year_url = sectie.get_absolute_url() + str(int(req_year) - 1) + '/' + req_month next_year_url = sectie.get_absolute_url() + str(int(req_year) + 1) + '/' + req_month if int(req_year) == int(cur_year): next_year_url = False toggle_latest = False for month in all_month_list: if trans_month(month) == str.lower(req_month): current = True else: current = False if trans_month(month) == str.lower(cur_month): url = sectie.get_absolute_url() + str(req_year) + '/' + month toggle_latest = True else: if(toggle_latest): url = False else: url = sectie.get_absolute_url() + str(req_year) + '/' + month month_dict = { 'url' : url, 'caption' : month, 'current' : current, } month_list.append(month_dict) else: for month in all_month_list: url = sectie.get_absolute_url() + str(req_year) + '/' + month if trans_month(month) == str.lower(req_month): current = True else: current = False month_dict = { 'url' : url, 'caption' : month, 'current' : current, } month_list.append(month_dict) return {'prev_year_url': prev_year_url, 'req_year': req_year, 'next_year_url': next_year_url, 'month_list': month_list } register.inclusion_tag('year_cal.html')(year_cal) The first error I get is about the line str.lower(cur_month) because str expects a str but gets a unicode. Can some of you please give some simple tricks about moving from str to unicode? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Manytomany relation with additional data
Hi all! I think the subject is self explaining. I already know in this case I need to define an intermediary table with two foreign keys and the needed additional fields. Let's imagine this situation: 1) a product table 2) an ingredient table 3) need to link many ingredients (with its percentage) to a single product For example: Product table contents: - bread - biscuit Ingredient table contents: - flour - water - salt - sugar - butter Product - Ingredient table contents: - bread - flour - 50% - bread - water - 49% - bread - salt - 1% - biscuit - flour - 45% - biscuit - sugar - 35% - biscuit - butter - 20% The problem is that you cannot say that one table is "more important" than the other one. For example in this case I would like to choose a product ("bread") and insert all ingredient ("flour", "water", "salt") with each percentage. Moreover I would like to see and/or edit all the ingredients for one product in a tabular way to check that all percentages sum up to 100 (not more not less). Any ideas or hints? Thanks. Ciao. Marco. P.S. I imagine this is an hell to manage so at least I would like to be able to pre-populate product field with the last product inserted. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: url issue giving me grief
well, according to the tutorial i am following (r'^polls/$', 'mysite.polls.views.index'), should not work either. Cause in the tutorial mysite is the project and polls is the application. Just like with mine where Social is the project and network is the application. On Aug 20, 7:08 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2007-08-20 at 14:00 +, wheresdave wrote: > > [...] > > > > > urls.py > > > from django.conf.urls.defaults import * > > > urlpatterns = patterns('', > > (r'^network/$', 'social.network.views.index'), > >(r'^accounts/', include('registration.urls')), > >(r'^admin/', include('django.contrib.admin.urls')), > > > ) > > > Now, when i go tohttp://127.0.0.1:8000/blog orhttp://127.0.0.1/index/ > > I get the following error message. > > Request Method:GET > > Request URL: http://127.0.0.1:8000/index/ > > > Using the URLconf defined in social.urls, Django tried these URL > > patterns, in this order: > > >1. ^network/$ > >2. ^accounts/ > >3. ^admin/ > > > The current URL, index/, didn't match any of these. > > > Anybody have any ideas on what I might be doing wrong? > > It tells you right there in the error message. You have only configured > your url patterns to look for things starting with network, accounts or > admin. So passing it a URL starting with "index" isn't going to match > anything. Why do you expect those requests to return anything? > > Regards, > Malcolm > > -- > A clear conscience is usually the sign of a bad > memory.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: url issue giving me grief
On Mon, 2007-08-20 at 14:00 +, wheresdave wrote: [...] > urls.py > > from django.conf.urls.defaults import * > > urlpatterns = patterns('', > (r'^network/$', 'social.network.views.index'), >(r'^accounts/', include('registration.urls')), >(r'^admin/', include('django.contrib.admin.urls')), > > > ) > > > Now, when i go to http://127.0.0.1:8000/blog or http://127.0.0.1/index/ > I get the following error message. > Request Method: GET > Request URL: http://127.0.0.1:8000/index/ > > Using the URLconf defined in social.urls, Django tried these URL > patterns, in this order: > >1. ^network/$ >2. ^accounts/ >3. ^admin/ > > The current URL, index/, didn't match any of these. > > > > Anybody have any ideas on what I might be doing wrong? It tells you right there in the error message. You have only configured your url patterns to look for things starting with network, accounts or admin. So passing it a URL starting with "index" isn't going to match anything. Why do you expect those requests to return anything? Regards, Malcolm -- A clear conscience is usually the sign of a bad memory. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can Django be combined with a more powerful ORM?
On Mon, 2007-08-20 at 15:48 +0200, Stefan Matthias Aust wrote: [...] > I'd like to freely modify database objects once loaded into memory and > then put everything that was modified with just one command back to > the database. Most ORMs work that way, I think. Objects are loaded > once within a transaction, know whether they are modified, dependent > objects can be automatically added or deleted and all modifications of > the database take place in one bulk operation at the end of the > transaction. > > Has anybody extended Django's ORM in such a way? Can it be replaced > with some other mapper? I recently heard about Storm, a new mapper > written by the Ubuntu guys... I'd prefer to not have to write my own > ORM. I've done that more than once in other language :) The answer to your main question is "yes", it's possible. The answer to the secondary question of "how hard is it?" is "it depends on what you really want to do". Ask yourself what features of Django you really want to keep and use here. It sounds like it would be most faithful to the original code to just not use Django's models at all. So you keep the template, view and URL dispatching (if that's what you like to use) and manage the data storage and structures yourself or with your particular Python-to-database mapping tool of choice. Things like keeping track of what has changed and automatically saving (which are a feature of some, but definitely not all persistent storage layers; there are drawbacks as well as advantages to that approach for shared data), means you need to find a storage layer that does that for you. It's not really a Django issue, as much as technical decision about how you want to persist your data and what Python interface it presents to you. From the examples you gave, Django's query set notation doesn't help you. So don't use it. Pick a replacement persistence layer. Trying to replace just the ORM portion (the "mapper" between Python objects and database relations) is almost certainly the wrong level to be customising unless you're deeply in love with the Django model syntax. Regards, Malcolm -- What if there were no hypothetical questions? http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
url issue giving me grief
I am going through the tutorial from the site, however I have named my files a bit different. My project is named Social and my application is named Network. settings.py ROOT_URLCONF = 'social.urls' TEMPLATE_DIRS = ( "C:/python25/scripts/social/network/templates/admin", "C:/python25/scripts/social/network/templates/registration", urls.py from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^network/$', 'social.network.views.index'), (r'^accounts/', include('registration.urls')), (r'^admin/', include('django.contrib.admin.urls')), ) Now, when i go to http://127.0.0.1:8000/blog or http://127.0.0.1/index/ I get the following error message. Request Method: GET Request URL:http://127.0.0.1:8000/index/ Using the URLconf defined in social.urls, Django tried these URL patterns, in this order: 1. ^network/$ 2. ^accounts/ 3. ^admin/ The current URL, index/, didn't match any of these. Anybody have any ideas on what I might be doing wrong? I have gone over this, and talked about in #django on IRC, no one has any ideas what I am doin wrong here. Thanx, Dave --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Float Field not displaying the two zeros at the end of a price
Greg napisał(a): > Jake, > No I didn't. When I tried the 'floatformat:2' I made sure that my > model fields were of type FloatField. When I do use the 'floatformat: > 3' and view the template. I notice that in my error message my for > statement is highlighted: > > TypeError at /rugs/milliken/border/ionica/ > float() argument must be a string or a number > > {% for a in thespinfo %} # This line is highlighted red > 27 > 28 > 29 > 30 > 31{{ a.size }} > 32${{ a.price|floatformat:2 }} > 33 > > Also, here is my floatfield in my models.py file. This is the field > that I'm doing the 'floatformat:2' on. > > name = models.FloatField() Should it really be "name"? You refer to "price" in your template... -- Jarek Zgoda Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101 "We read Knuth so you don't have to." (Tim Peters) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Serving large files through HttpResponse
On Aug 20, 1:12 pm, Ceph <[EMAIL PROTECTED]> wrote: > The only other option I see to serving large files securely is > trickery using dynamically created sym links to the true static file > and then redirecting the user to those URLs and letting Apache serve > them. This isn't as secure, though, and permits multiple downloads > without them being recorded in my Django apps. Lighttpd and nginx both have a clever way of dealing with this problem. You can store the real file somewhere that is readable by the web server but NOT exposed as a public URL. Then your Django application can (having authenticated the request) respond with a magical header which tells the nginx/lighttpd server to serve up the file from that location. Here's how to do it with nginx: http://wiki.codemongers.com/NginxXSendfile If your app is all about serving large files, it may well be worth putting it behind an nginx proxy purely to gain access to this feature. nginx is a really neat reverse proxy - I run simonwillison.net as nginx proxying through to mod_python/Apache for the dynamic pages and it's been working great for months. Hope that helps, Simon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Can Django be combined with a more powerful ORM?
As a side-project I tried to port Stellar Crisis 2.2 (a 15 year old browser game written in the C-like langage Pike for the Roxen server) to Django. So far, unfortunately, I failed. It seems, Django isn't the right tool to create such kind of application :( SC keeps all persistent data two global dicts that contain other dicts containing more dicts and arrays. I tried to map the data onto database tables but doing this, most of the elegance of Python seems to vanish. My code is actually worse than the original Pike code. Here's an example (Pike): p[d[series][game]["f"][ixb]["owner"]]["kills"]++; "p" is the global dict of players (all player data are kept in another dict). "d" is the global dict of all other game data. Games are instances of series and "f" probably means fleet and stands for a dict of all ships. A ship is owned by a player and the server stores how many other players a player has beaten. The Django equivalent seems to be: g = Series.objects.get(name=series).game_set.get(no=game) p = Player.objects.get(name=g.fleet_set.get(no=ixb).owner) p.kills += 1 p.save() I want to stay close to the original source code (even if I do not consider it the best style) to make porting the code more straight forward. Therefore, I added helper methods to the models so that I can use [] to access a series' game. The resulting code looks like is: player = p[d[series][game].f(ixb).owner] player.kills += 1 player.save() However, I still need three lines of code where the original just used one line because I have to explicitly save the state change. The original Pike code contains all game logic in one very large function (~800 lines of code) that does a lot of modifications. Adding explicit save() methods all over the place seems to be a bad (and inefficient) way to add persistence. I'd like to freely modify database objects once loaded into memory and then put everything that was modified with just one command back to the database. Most ORMs work that way, I think. Objects are loaded once within a transaction, know whether they are modified, dependent objects can be automatically added or deleted and all modifications of the database take place in one bulk operation at the end of the transaction. Has anybody extended Django's ORM in such a way? Can it be replaced with some other mapper? I recently heard about Storm, a new mapper written by the Ubuntu guys... I'd prefer to not have to write my own ORM. I've done that more than once in other language :) My ad hoc idea is to add a __setattr__ method to all models after their post_init signal and that method would register the model object as modified with some transaction context. However, because Django's ORM doesn't honor object identity, things get very inefficient very soon. I'd also need to overwrite delete() to make sure that I do not save deleted objects. But then, it seems that each time I ask a game for its fleets or systems, a new database query is executed and I have to cache them manually and reset the cache manually if I add new ships or systems. I'm afraid, I over-bend Django's ORM here... -- Stefan Matthias Aust --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
FileField: changing file names
Hello everyone, I have an application where users can upload files, mostly photos. I wish to avoid the problem of people sending photos with the same name and ending up with a "polluted" directory like this: dscn0001.jpg dscn0001_.jpg dscn0001__.jpg dscn0001___.jpg dscn0001.jpg dscn0001_.jpg dscn0001__.jpg dscn0001___.jpg dscn0001.jpg dscn0001_.jpg I could override the save() method to save the files under / , but that would make the get_FOO_url and others fail. Has anyone done something like this that they could share? Vincent. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ImageField via admin
Hello Carl Karsten! On Sun, 19 Aug 2007 21:39:31 -0500 you wrote: > > Grigory Fateyev wrote: > > Hello! > > > > I have simple class with ImageField, but cann't add any object: > > > > class Book(models.Model): > > name = models.CharField(_('Book Title'), maxlength=200) > > book_number = models.IntegerField() > > image = models.ImageField(upload_to='%Y/%m/%d/', core=True, > > blank=True) > > comment = models.TextField(_('Book Comment'), blank=True, > >null=True) > > author = models.CharField(_('Author'), maxlength=100, > > blank=True) > > year_rate = models.IntegerField() > > > > class Meta: > > verbose_name = _('Book') > > verbose_name_plural = _('Books') > > > > class Admin: > > list_display = ('book_number', 'name', 'year_rate') > > > > def __unicode__(self): > > return u"%s %s %s" % (self.book_number, self.name, > > self.year_rate) > > > > the error: > > > > Traceback (most recent call last): > > File > > "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in > > get_response 77. response = callback(request, *callback_args, > > **callback_kwargs) File > > "/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py" > > in _checklogin 51. if 'post_data' in request.POST: File > > "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in > > _get_post 135. self._load_post_and_files() File > > "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in > > _load_post_and_files 113. self._post, self._files = > > http.parse_file_upload(self.environ['wsgi.input'], self.environ) > > File "/usr/lib/python2.4/site-packages/django/http/__init__.py" in > > parse_file_upload 71. raw_message = '\r\n'.join(['%s:%s' % pair for > > pair in header_dict.items()]) > > > > AttributeError at /admin/books/book/add/ > > '_fileobject' object has no attribute 'items' > > > > What the problem it can be? > > > > I just made a project with just that model. works for me. > I would start by looking at these lines: > > [EMAIL PROTECTED]:~/django/foo/foot$ grep static * > settings.py:# settings.py:MEDIA_ROOT = BASE_DIR+'/static/' > settings.py:MEDIA_URL = '/static/' > urls.py:(r'^static/(?P.*)$', 'django.views.static.serve', > {'document_root': settings.BASE_DIR+'/static/', 'show_indexes': > True}), > > What version of django? I am using current svn. > > Carl K > settings.py:MEDIA_ROOT = BASE_DIR+'/media/' settings.py:MEDIA_URL = '/site_media/' urls.py:(r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.BASE_DIR+'/media/', 'show_indexes':True}), Revision: 5946 the same error. -- Всего наилучшего! Григорий greg [at] anastasia [dot] ru Письмо отправлено: 2007/08/20 17:22 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Float Field not displaying the two zeros at the end of a price
Jake, I've made the change to where both of my fields are now of type DecimalField. However, I'm getting the same error: TypeError float() argument must be a string or a number Caught an exception while rendering: float() argument must be a string or a number 26 {% for a in thespinfo %} # This is the line that is red 27 28 29 30 31 {{ a.size }} 32 ${{ a.price|floatformat:2 }} Here is what I have is my models file: models.DecimalField(max_digits=6, decimal_places=2) / Thanks On Aug 20, 12:04 am, jake <[EMAIL PROTECTED]> wrote: > greg, > > Greg wrote: > > Jake, > > No I didn't. When I tried the 'floatformat:2' I made sure that my > > model fields were of type FloatField. > > i have used DecimalField in my model and |floatformat:2 in my template > and gotten the behavior you're looking for; that's probably the > combination you want here. > > best > jake --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: truncate string after x characters
{{ post.subject|slice:":15"|escape }} does the job. On Aug 20, 6:55 am, patrickk <[EMAIL PROTECTED]> wrote: > thanks. > > since truncatewords and truncatewords_html are predefined filters, I > guess that truncate should also be one (just my opinion). > > patrick > > On 20 Aug., 12:33, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > On Mon, 2007-08-20 at 11:52 +0200, patrickk wrote: > > > how do I truncate a string (in the template) after a certain amount > > > of characters? > > > I know there´s a truncate-filter, but it works with words and not > > > characters. > > > There's #5025 in Trac. > > > This shouldn't be seen as any endorsement for that ticket, since I'm not > > convinced it belongs in core and haven't really worried about making any > > kind of decision. But you can try it out for your own purposes (use it > > to create a filter in your app, for example). > > > Regards, > > Malcolm > > > -- > > The early bird may get the worm, but the second mouse gets the > > cheese.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: fs directory representation
On Mon, 2007-08-20 at 12:46 +, imgrey wrote: > First of all i would like to know if it is exists a way to represent > filenames in different encodings with django. > Seems i've tried everything, but cannot get rid of UnicodeDecodeError/ > UnicodeEncodeError messages. You need to know the encoding of strings returned by os.listdir() on your system. It looks like they aren't utf-8. So find out the encoding and you can pass that to smart_unicode as the second parameter (called "encoding"). The errors you are seeing are just saying that the default of utf-8 isn't correct. Fortunately, once you know the right value, you can control that. By the way, for things where you know they are strings and you actually know even more -- they are bytestrings in a particular encoding -- smart_unicode() might be more than you need. You could just call unicode(my_string, encoding), with the right value for 'encoding'. If you have a look at the internals of smart_unicode(), you'll see that it has a lot of machinery for dealing with objects or things that might already be unicode, etc. In your case, you don't need all this extra protection. But, still, it won't hurt anything and it's not a bad habit; it'll just be very fractionally slower. Regards, Malcolm -- If you think nobody cares, try missing a couple of payments. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
fs directory representation
First of all i would like to know if it is exists a way to represent filenames in different encodings with django. Seems i've tried everything, but cannot get rid of UnicodeDecodeError/ UnicodeEncodeError messages. There is my view: from django.shortcuts import render_to_response from django.utils.encoding import smart_unicode import os def tst(request): return render_to_response('index.html', {'ls': [smart_unicode(x) for x in os.listdir('/home/ftp/grey')],}) template: {%for i in ls%}{{i}}{%endfor%} error: Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response 77. response = callback(request, *callback_args, **callback_kwargs) File "/home/grey/src/df/fs/views.py" in tst 6. return render_to_response('index.html', {'ls': [smart_unicode(x) for x in os.listdir('/home/ftp/grey')],}) File "/usr/lib/python2.4/site-packages/django/utils/encoding.py" in smart_unicode 24. return force_unicode(s, encoding, strings_only, errors) File "/usr/lib/python2.4/site-packages/django/utils/encoding.py" in force_unicode 41. s = unicode(s, encoding, errors) UnicodeDecodeError at /ftp/ 'utf8' codec can't decode bytes in position 0-1: invalid data --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Serving large files through HttpResponse
I'm serving rather large, static files through Django. I'd rather not use renaming trickery to serve them, but I don't know what the best way to serve them through HttpResponse is. I used to use this: response = HttpResponse(iter(open(file_path, "rb"))) return response in my view. That stopped working in the previous week or two. I'm not sure why, exactly. Is this method no longer supported? I am not even sure if it is doing what I hoped it was doing. =) The only other option I see to serving large files securely is trickery using dynamically created sym links to the true static file and then redirecting the user to those URLs and letting Apache serve them. This isn't as secure, though, and permits multiple downloads without them being recorded in my Django apps. The files range in size from a few hundred KB up through about 50 MB, mostly hefty print-ready PDFs. Any suggestions? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: emulating an existing session in tests
If I am not missing something, it looks like I have solved the problem. This is hack: >>> from django.http import SimpleCookie >>> from django.test.client import Client >>> c = Client() >>> cookies = SimpleCookie() >>> cookies['sessionid'] = '8a3dd9235b8e718c3f7e890106180528' >>> c.cookies = cookies >>> c.get('/messages/') Thanks... On 20 Ağustos, 13:52, omat <[EMAIL PROTECTED]> wrote: > I am using the api via shell (i.e.: python manage.py shell) as > follows: > > >>> from django.contrib.sessions.middleware import SessionWrapper > >>> from django.test.client import Client > >>> c = Client() > >>> s = SessionWrapper('8a3dd9235b8e718c3f7e890106180528') > >>> c.session = s._session > >>> c.session > > {'_auth_user_id': 840, '_auth_user_backend': > 'django.contrib.auth.backends.ModelBackend'}>>> c.get('/messages/') > > > > The last line says the request is not considered as being form an > authenticated user because HttpResponseForbidden is returned when an > anonymous user tries to access /messages/. > > I am supplying the data in the session, so I think it must be ok. Am I > thinking wrong? > > Thanks, > oMat > > On 20 Ağustos, 13:14, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > On Mon, 2007-08-20 at 09:57 +, omat wrote: > > > Thanks for the reply... > > > > I used the existing database instead of the test database to hook to > > > the user's session like this: > > > > from django.test.client import Client > > > from django.contrib.sessions.models import Session > > > > client = Client() > > > client.session = Session.objects.get(session_key = key_from_traceback) > > > > but did not work. > > > If you're using the test framework, it doesn't talk to the production > > database. It creates it's own testing database (read the testing docs > > for more information). So your above query is talking to an empty table > > unless you have populated it yourself. > > > Regards, > > Malcolm > > > -- > > No one is listening until you make a > > mistake.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Mod_Python and Apache
On Aug 20, 5:13 pm, Sasha Weberov <[EMAIL PROTECTED]> wrote: > On Aug 20, 12:13 am, Graham Dumpleton <[EMAIL PROTECTED]> > wrote: > > > > > On Aug 20, 3:01 pm, Sasha Weberov <[EMAIL PROTECTED]> wrote: > > > > Is it normal to experience a sudden sharp spike in cpu and memory > > > usage for about a minute or so after a start/stop and restart? I'm > > > running the pre-fork mpm, FreeBSD 6.2, and latest mod_python. I've > > > tried disableing mod_python and it went away, so it's clearly mod > > > python. I know that the pre-fork mpm has dummy connections to signal > > > processes to die off and that's evident in logs, can it be causing the > > > spike because it's hitting " / "? I've tried the rewrites and all, but > > > notta. > > > > Any suggestions would be greatly appreciated. > > > Do you see the spike as soon as you start Apache but before you even > > try and access your Python web application, or does it only occur when > > you first access the Python web application? If the latter, have you > > tried a simple 'mptest' example as per mod_python documentation and > > does it exhibit the same problem? Ie., eliminate it being anything to > > do with Django, in which case you would be better off asking on the > > mod_python mailing list. > > > Other things to look at are whether your Python has been built to use > > shared libraries or not. If it hasn't and your mod_python.so is large > > because it incorporates Python library, you will potentially be stuck > > with private copy of Python library in every process and if you are > > running with minimal memory on your system with lots of prefork > > processes, you may well be running out of main memory and the box is > > busily swapping to disk. How big are your Apache child processes on > > initial startup and then subsequently after you have accessed your > > Python web application? How big is your mod_python.so module file. > > > Graham > > It happens as soon as Apache is started, or restarted. average are 15-30mb. What other non standard Apache modules do you have loaded? That is quite a lot of memory being used before anything actually happens, although not entirely clear whether you are stating the whole virtual memory of the processes or only resident memory. > I have both mod_php and mod_python loaded. After > the 1-2 minute initial startup the system has lots of free memory > 700-900mb free and cpu usage is very minimal. How complicated is your Apache configuration. Do you do anything out of the ordinary like define lots of VirtualHost containers? Do you use PythonImport directive in your Apache configuration? > mod_python.so in /usr/ > local/libexec/apache22 is 119k, libphp5 on the other hand is 2.5mb. > I've tried commenting out php and it still happens so the culprit is > Django/Mod_Python. Do you know whether your Apache web server is compiled with --enable- threads? Running: httpd -V may or may not tell you. Is your Python compiled with threads? You can tell by trying to import 'threading' from interpreter. $ python Python 2.3.5 (#1, Mar 20 2005, 20:38:20) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import threading FreeBSD still appears to have various problems with its threading when using Apache. If Python is using threading and Apache isn't, there may be a clash in terms of which threading libraries are used. I know people who simply haven't been able to get threaded Apache to work at all on FreeBSD. You might want to take this whole issue over to the mod_python mailing list as it would appear not to be Django specific, unless you are using PythonImport to import a module which is in turn import Django at Apache startup rather than first request. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: truncate string after x characters
thanks. since truncatewords and truncatewords_html are predefined filters, I guess that truncate should also be one (just my opinion). patrick On 20 Aug., 12:33, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2007-08-20 at 11:52 +0200, patrickk wrote: > > how do I truncate a string (in the template) after a certain amount > > of characters? > > I know there´s a truncate-filter, but it works with words and not > > characters. > > There's #5025 in Trac. > > This shouldn't be seen as any endorsement for that ticket, since I'm not > convinced it belongs in core and haven't really worried about making any > kind of decision. But you can try it out for your own purposes (use it > to create a filter in your app, for example). > > Regards, > Malcolm > > -- > The early bird may get the worm, but the second mouse gets the > cheese.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: emulating an existing session in tests
I am using the api via shell (i.e.: python manage.py shell) as follows: >>> from django.contrib.sessions.middleware import SessionWrapper >>> from django.test.client import Client >>> c = Client() >>> s = SessionWrapper('8a3dd9235b8e718c3f7e890106180528') >>> c.session = s._session >>> c.session {'_auth_user_id': 840, '_auth_user_backend': 'django.contrib.auth.backends.ModelBackend'} >>> c.get('/messages/') The last line says the request is not considered as being form an authenticated user because HttpResponseForbidden is returned when an anonymous user tries to access /messages/. I am supplying the data in the session, so I think it must be ok. Am I thinking wrong? Thanks, oMat On 20 Ağustos, 13:14, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2007-08-20 at 09:57 +, omat wrote: > > Thanks for the reply... > > > I used the existing database instead of the test database to hook to > > the user's session like this: > > > from django.test.client import Client > > from django.contrib.sessions.models import Session > > > client = Client() > > client.session = Session.objects.get(session_key = key_from_traceback) > > > but did not work. > > If you're using the test framework, it doesn't talk to the production > database. It creates it's own testing database (read the testing docs > for more information). So your above query is talking to an empty table > unless you have populated it yourself. > > Regards, > Malcolm > > -- > No one is listening until you make a mistake.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: truncate string after x characters
On Mon, 2007-08-20 at 11:52 +0200, patrickk wrote: > how do I truncate a string (in the template) after a certain amount > of characters? > I know there´s a truncate-filter, but it works with words and not > characters. There's #5025 in Trac. This shouldn't be seen as any endorsement for that ticket, since I'm not convinced it belongs in core and haven't really worried about making any kind of decision. But you can try it out for your own purposes (use it to create a filter in your app, for example). Regards, Malcolm -- The early bird may get the worm, but the second mouse gets the cheese. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Apache does not serve static files from document root
On Mon, 2007-08-20 at 12:17 +0200, Peter Melvyn wrote: > Hi all, > > I'm trying to migrate my Django project from dev. server to Apache on > the same machine running Windows. Content generated by Django is OK, > but no static file from DocumentRoot is served. > > My Apache & mod-python is configured this way: > > Not really Django related, so I'll do this briefly... This says that this location block will be serving *everything* for this website. That is, everything starting with '/' will be processed by whatever is in the Location block. You clearly don't want this in your case. In particular, the contents of this Location block say that everything under this URL should be give to the mod_python handler, which is exactly what is happening. In this case you'll probably want to add another Location section before this one to handle things to WWW-ROOT/bizweb explicitly (whatever URL is meant to map to that filesystem location). Note (read the Apache docs) that Location sections are processed in order from top to bottom in the config file. > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE bizweb.server_settings > PythonDebug On > PythonPath "[r'C:\\.WKS-PF\\PRJ\\ECLIPSE\\Django\\src'] + sys.path" > Regards, Malcolm -- Why can't you be a non-conformist like everyone else? http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: truncate string after x characters
2007/8/20, patrickk <[EMAIL PROTECTED]>: > how do I truncate a string (in the template) after a certain amount > of characters? It's not difficult to create custom filters. For example from django.template import Library register = Library() @register.filter def truncate(value, arg): try: return value[:int(arg)] except ValueError: return value -- Stefan Matthias Aust --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Apache does not serve static files from document root
Hi all, I'm trying to migrate my Django project from dev. server to Apache on the same machine running Windows. Content generated by Django is OK, but no static file from DocumentRoot is served. My Apache & mod-python is configured this way: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE bizweb.server_settings PythonDebug On PythonPath "[r'C:\\.WKS-PF\\PRJ\\ECLIPSE\\Django\\src'] + sys.path" DocumentRoot "V:/WWW-ROOT/bizweb" Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all ### If I tried navigate to particular file, eg. http://localhost/wssmedia/css/img/arr0_blue.gif and I got mod_python error: [...] DocumentRoot: 'V:/WWW-ROOT/bizweb' URI:'/wssmedia/css/img/arr0_blue.gif' Location: '/' Directory: None Filename: 'V:/WWW-ROOT/bizweb/wssmedia/css/img/arr0_blue.gif' PathInfo: '' Phase: 'PythonHandler' Handler:'django.core.handlers.modpython' [...] Traceback (most recent call last): [...] AttributeError: 'module' object has no attribute 'handler404' Filename V:/WWW-ROOT/bizweb/wssmedia/css/img/arr0_blue.gif is correct and the file *does* exist, but Apache did not serve it - it looks like the Apache routes all /wssmedia/ requests to mod_python, instead serving them itself. ### Please, could anybody advice what is wrong in my Apache and/or Django settings? Thanks in advance, Peter --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: emulating an existing session in tests
On Mon, 2007-08-20 at 09:57 +, omat wrote: > Thanks for the reply... > > I used the existing database instead of the test database to hook to > the user's session like this: > > from django.test.client import Client > from django.contrib.sessions.models import Session > > client = Client() > client.session = Session.objects.get(session_key = key_from_traceback) > > > but did not work. If you're using the test framework, it doesn't talk to the production database. It creates it's own testing database (read the testing docs for more information). So your above query is talking to an empty table unless you have populated it yourself. Regards, Malcolm -- No one is listening until you make a mistake. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: emulating an existing session in tests
Thanks for the reply... I used the existing database instead of the test database to hook to the user's session like this: from django.test.client import Client from django.contrib.sessions.models import Session client = Client() client.session = Session.objects.get(session_key = key_from_traceback) but did not work. Will it work, if I build a cookie back from the session and initialize the Client() with it? On 20 Ağustos, 12:19, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2007-08-20 at 09:13 +, omat wrote: > > There is an error that occurs occasionally and I suspect that it may > > be user specific (i.e. for users with certain credentials). > > > I need to run tests in the user's context, thus, I need to emulate the > > existing session of the user to test this. > > > I have the session id of the user that faced the error from the > > traceback that was mailed to me. > > > I have tried modifying the cookies and session attributes of the test > > client instance but I couldn't succeed. > > > How can I achieve this? > > The session id is just a key used to look up the session data from the > Sessions table. The data is stored in that table in pickled form (see > contrib.sessions for the details). So you don't just need the session > id. You also would need to pull out the appropriate session data and > store that in the test database that is created. Part of your test setup > would need to be putting data into the sessions table. > > Regards, > Malcolm > > -- > Two wrongs are only the beginning.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
truncate string after x characters
how do I truncate a string (in the template) after a certain amount of characters? I know there´s a truncate-filter, but it works with words and not characters. thanks, patrick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: emulating an existing session in tests
On Mon, 2007-08-20 at 09:13 +, omat wrote: > There is an error that occurs occasionally and I suspect that it may > be user specific (i.e. for users with certain credentials). > > I need to run tests in the user's context, thus, I need to emulate the > existing session of the user to test this. > > I have the session id of the user that faced the error from the > traceback that was mailed to me. > > I have tried modifying the cookies and session attributes of the test > client instance but I couldn't succeed. > > How can I achieve this? The session id is just a key used to look up the session data from the Sessions table. The data is stored in that table in pickled form (see contrib.sessions for the details). So you don't just need the session id. You also would need to pull out the appropriate session data and store that in the test database that is created. Part of your test setup would need to be putting data into the sessions table. Regards, Malcolm -- Two wrongs are only the beginning. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
emulating an existing session in tests
There is an error that occurs occasionally and I suspect that it may be user specific (i.e. for users with certain credentials). I need to run tests in the user's context, thus, I need to emulate the existing session of the user to test this. I have the session id of the user that faced the error from the traceback that was mailed to me. I have tried modifying the cookies and session attributes of the test client instance but I couldn't succeed. How can I achieve this? Thanks, oMat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Attribute Error
Guys I spent quite a while yesterday reading through the newforms section of the docs, and thought I'd taken everything in. As a python novice, I wrote a test script and couldn't replicate the error, so was beginning to wonder whether I was cracking up! After reading Malcolm's (comprehensive) response, it does make alot more sense and I feel to have a better understanding of how the newforms library hinges together. I've got to say as someone new to django I'm really impressed at the level of support you guys have got going on. On Aug 20, 6:54 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Sun, 2007-08-19 at 14:30 -0700, MikeHowarth wrote: > > I'll take a look at that. > > > Even commenting that line out and attempting to access self.title I'm > > still getting an attribute error thrown: 'Register' object has no > > attribute 'title' > > Doug Ballanc has explained how you should be writing your save() method. > I thought I might just add something about why what you're doing doesn't > seem to work, despite looking like perfectly valid Python code. > > The newforms Form class has a specialised __new__ method, which is what > is responsible for attaching attributes to the object you get back from > calling Form(). In the default case (i.e. pretty much always), what this > method does is *not* creating attributes for anything that is a > newforms.fields.Field subclass. Rather, those fields are put into an > attribute called "base_fields" (which is copied to an attribute called > "fields" in __init__). > > All this metaclass stuff happens in DeclarativeFieldsMetaclass in > newforms.forms. Replacing the metaclass with something elase to populate > the base_fields leaves open some interesting possibilities about how to > initialise form classes for those with imagination. > > This might look very strange and, in a way, it is unusual. When I was > wondering, early on in newforms life, why this was done (I think my > initial mental question was "what was he smoking?"), I realised there > isn't a completely natural thing to store in those attributes. Do they > hold the normalized, cleaned data? The original value? Both, depending > upon whether clean has been called? If the attribute is None, does that > mean we don't have that value? We haven't set it yet? Or that the form's > normalized value is None (possible for some fields)? How would you know > which fields had errors in them and what would prevent you accidentally > accessing those attributes and treating the values as real values? > > To some extent, it reduces confusion by not having attributes at all for > fields. Instead, you initialise a form with the raw, submitted data. > Then you access "cleaned_data" or is_valid() or "errors" whenever you > like and the raw data is cleaned and normalized (where possible) and > sent to two dictionaries: Form.cleaned_data and Form.errors. > > So, whilst what you were attempting might seem logical on one level, > hopefully I've explained why it could, in many cases, be more confusing > and error-prone than convenient. So the design uses a slightly different > approach from providing access to the form data and errors. > > Best wishes, > Malcolm > > -- > Borrow from a pessimist - they don't expect it > back.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Mod_Python and Apache
On Aug 20, 12:13 am, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > On Aug 20, 3:01 pm, Sasha Weberov <[EMAIL PROTECTED]> wrote: > > > Is it normal to experience a sudden sharp spike in cpu and memory > > usage for about a minute or so after a start/stop and restart? I'm > > running the pre-fork mpm, FreeBSD 6.2, and latest mod_python. I've > > tried disableing mod_python and it went away, so it's clearly mod > > python. I know that the pre-fork mpm has dummy connections to signal > > processes to die off and that's evident in logs, can it be causing the > > spike because it's hitting " / "? I've tried the rewrites and all, but > > notta. > > > Any suggestions would be greatly appreciated. > > Do you see the spike as soon as you start Apache but before you even > try and access your Python web application, or does it only occur when > you first access the Python web application? If the latter, have you > tried a simple 'mptest' example as per mod_python documentation and > does it exhibit the same problem? Ie., eliminate it being anything to > do with Django, in which case you would be better off asking on the > mod_python mailing list. > > Other things to look at are whether your Python has been built to use > shared libraries or not. If it hasn't and your mod_python.so is large > because it incorporates Python library, you will potentially be stuck > with private copy of Python library in every process and if you are > running with minimal memory on your system with lots of prefork > processes, you may well be running out of main memory and the box is > busily swapping to disk. How big are your Apache child processes on > initial startup and then subsequently after you have accessed your > Python web application? How big is your mod_python.so module file. > > Graham It happens as soon as Apache is started, or restarted. http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---