How do I echo template variables?

2007-07-29 Thread [EMAIL PROTECTED]

I'm coming from CakePHP and I would typically set a variable for use
in my view with a call to findAll. Since there is a lot of data in the
array, I typically do something like:





This way, I can find out what data is available in the view and figure
out how much I can scale back the recursion.

Is there any equivalent in Python/Django? I've searched and didn't
come up with anything.


--~--~-~--~~~---~--~~
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: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
Here is what I get with I use 'python manage.py shell'

>>> b = Orders.objects.get(pk=1)
>>> b.s_name
u'Bob Smith''
>>> b.timestamp
u'2007-07-29'
>>>

No errors when I access the timestamp property from within the python
shell.

On Jul 30, 12:00 am, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Here is my Orders Class:
>
> class Orders(models.Model):
> timestamp = models.DateField()
> b_name = models.CharField("Billing Name", maxlength=100)
> b_address = models.CharField("Billing Address", maxlength=100)
> b_city = models.CharField("Billing City", maxlength=100)
> b_state = models.USStateField("Billing State")
> b_zip = models.CharField("Billing Zip", maxlength=100)
> b_phone = models.CharField("Billing Phone", maxlength=100)
> b_email = models.EmailField("Billing Email")
> s_name = models.CharField("Name", maxlength=100)
> s_address = models.CharField("Shipping Address", maxlength=100)
> s_city = models.CharField("Shipping City", maxlength=100)
> s_state = models.USStateField("Shipping State")
> s_zip = models.CharField("Shipping Zip", maxlength=100)
> s_phone = models.CharField("Shipping Phone", maxlength=100)
> s_email = models.EmailField("Shipping Email")
> amount = models.CharField("Order Amount", maxlength=100)
> card_number = models.CharField("Card Number", maxlength=100)
> exp_date = models.CharField("Exp. Date", maxlength=100)
> card_code = models.CharField("Card Code", maxlength=100)
> order_status = models.ForeignKey(OrderStatus)
> voided = models.BooleanField("Has order been voided?")
> email = models.BooleanField("Has an email been sent")
> order = models.TextField("Details of Order", maxlength=1000)
> comments = models.TextField("none", maxlength=1000)
>
> class Admin:
> list_display = ('s_name', 'order_status')
>
> def __str__(self,):
> return self.s_name
>
> On Jul 29, 11:59 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > Russ,
> > Here is my traceback:
>
> > Traceback (most recent call last):
> > File "c:\Python24\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >   77. response = callback(request, *callback_args, **callback_kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \decorators.py" in _checklogin
> >   55. return view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\views\decorators\cache.py"
> > in _wrapped_view_func
> >   39. response = view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \main.py" in change_stage
> >   370. new_data = manipulator.flatten_data()
> > File "c:\Python24\lib\site-packages\django\db\models\manipulators.py"
> > in flatten_data
> >   250. new_data.update(f.flatten_data(fol, obj))
> > File "c:\Python24\lib\site-packages\django\db\models\fields
> > \__init__.py" in flatten_data
> >   514. return {self.attname: (val is not None and val.strftime("%Y-%m-
> > %d") or '')}
>
> >   AttributeError at /admin/rugs/orders/1/
> >   'unicode' object has no attribute 'strftime'
>
> > On Jul 29, 11:34 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> > wrote:
>
> > > On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > Russ,
> > > > I tried including the code that you recommended.  However, I'm still
> > > > getting the same error:
>
> > > > AttributeError at /admin/rugs/orders/1/
> > > > 'unicode' object has no attribute 'strftime'
>
> > > Just to clarify - If you create, modify and save an object at the
> > > command prompt, it works fine. You can retrieve the object using the
> > > command line using calls to filter, etc, and print out objects
> > > retrieved (e.g., print Order.objects.get(pk=1) ). However, when you
> > > view the object in the admin pages you get an error. Is this correct?
>
> > > If this is the case, it is possible that you have encountered some
> > > sort of bug with the admin views dealing with date fields; to help
> > > track this down, could you provide:
>
> > > - A full stack trace of the error you are seeing
> > > - The exact revision of Django you are using
> > > - The code for the Order model
> > > - The database backend you are using
>
> > > Thanks,
> > > 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: Using LimitRequestBody to Limit File Uploads

2007-07-29 Thread Nimrod A. Abing

On 7/30/07, Graham Dumpleton <[EMAIL PROTECTED]> wrote:
> The documentation says:
>
> """Similarly, an 'apache' subdirectory should have been created within
> the package and the script file stored there under the name
> 'django.wsgi'."""
>
> Rather than trying to launch straight into setting up Django, you
> might want to get a simple WSGI hello world application going first.
> For more basic instructions read:
>
>   http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines
>
> elsewhere on the same site.

Ok, thanks again. After going through postings on modswgi Google Group
as well as your blog, I'm sold :)

I'm looking at the docs and preparing for eventual migration to mod_wsgi now...
-- 
_nimrod_a_abing_

http://abing.gotdns.com/
http://www.preownedcar.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: DbMigration 0.04 released

2007-07-29 Thread Itai Tavor

Any management.py.patch version around that applies cleanly to django
svn (5776)?

> patching file core/management.py
> Hunk #1 FAILED at 481.
> Hunk #2 succeeded at 541 (offset 20 lines).

TIA, Itai


--~--~-~--~~~---~--~~
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: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
Here is my view:

def success(request):
f = processpay(request)
if f == 'True':
pr = theamount(request)
o = Orders()
o.timestamp = datetime.now()
o.s_name = 'Bob Smith'
o.s_address = '18sdf est 15'
o.s_city = 'New York'
o.s_state = 'NY'
o.s_zip = '44801'
o.s_phone = '123-123-1321'
o.s_email = '[EMAIL PROTECTED]'
o.b_name = 'Bob'
o.b_address = 'asdf'
o.b_city = 'adsf'
o.b_state = 'NY'
o.b_zip = '1'
o.b_phone = '123-132-1231'
o.b_email = '[EMAIL PROTECTED]'
o.amount = '200'
o.card_number = '123123123123'
o.exp_date = '0909'
o.card_code = '509'
o.order_status_id = '1'
o.voided = 'False'
o.email = 'False'
o.order = 'Order Info'
o.comments = 'Comment Info'
o.save()
odet = request.session['orderdetails']
c = request.session['cart']
p = request.session['pad']
del request.session['orderdetails']
del request.session['cart']
del request.session['pad']
request.session.modified = True
return render_to_response('result.html', {'s': odet, 'r': c, 
'spad':
p, 'p': pr})
else:
return render_to_response('result.html', {'s': 'Did not work'})

On Jul 30, 12:00 am, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Here is my Orders Class:
>
> class Orders(models.Model):
> timestamp = models.DateField()
> b_name = models.CharField("Billing Name", maxlength=100)
> b_address = models.CharField("Billing Address", maxlength=100)
> b_city = models.CharField("Billing City", maxlength=100)
> b_state = models.USStateField("Billing State")
> b_zip = models.CharField("Billing Zip", maxlength=100)
> b_phone = models.CharField("Billing Phone", maxlength=100)
> b_email = models.EmailField("Billing Email")
> s_name = models.CharField("Name", maxlength=100)
> s_address = models.CharField("Shipping Address", maxlength=100)
> s_city = models.CharField("Shipping City", maxlength=100)
> s_state = models.USStateField("Shipping State")
> s_zip = models.CharField("Shipping Zip", maxlength=100)
> s_phone = models.CharField("Shipping Phone", maxlength=100)
> s_email = models.EmailField("Shipping Email")
> amount = models.CharField("Order Amount", maxlength=100)
> card_number = models.CharField("Card Number", maxlength=100)
> exp_date = models.CharField("Exp. Date", maxlength=100)
> card_code = models.CharField("Card Code", maxlength=100)
> order_status = models.ForeignKey(OrderStatus)
> voided = models.BooleanField("Has order been voided?")
> email = models.BooleanField("Has an email been sent")
> order = models.TextField("Details of Order", maxlength=1000)
> comments = models.TextField("none", maxlength=1000)
>
> class Admin:
> list_display = ('s_name', 'order_status')
>
> def __str__(self,):
> return self.s_name
>
> On Jul 29, 11:59 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > Russ,
> > Here is my traceback:
>
> > Traceback (most recent call last):
> > File "c:\Python24\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >   77. response = callback(request, *callback_args, **callback_kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \decorators.py" in _checklogin
> >   55. return view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\views\decorators\cache.py"
> > in _wrapped_view_func
> >   39. response = view_func(request, *args, **kwargs)
> > File "c:\Python24\lib\site-packages\django\contrib\admin\views
> > \main.py" in change_stage
> >   370. new_data = manipulator.flatten_data()
> > File "c:\Python24\lib\site-packages\django\db\models\manipulators.py"
> > in flatten_data
> >   250. new_data.update(f.flatten_data(fol, obj))
> > File "c:\Python24\lib\site-packages\django\db\models\fields
> > \__init__.py" in flatten_data
> >   514. return {self.attname: (val is not None and val.strftime("%Y-%m-
> > %d") or '')}
>
> >   AttributeError at /admin/rugs/orders/1/
> >   'unicode' object has no attribute 'strftime'
>
> > On Jul 29, 11:34 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> > wrote:
>
> > > On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > Russ,
> > > > I tried including the code that you recommended.  However, I'm still
> > > > getting the same error:
>
> > > > AttributeError at /admin/rugs/orders/1/
> > > > 'unicode' object has no attribute 'strftime'
>
> > > Just to clarify - If you create, modify and save an object at the
> > > command prompt, it works 

Re: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
Here is my Orders Class:

class Orders(models.Model):
timestamp = models.DateField()
b_name = models.CharField("Billing Name", maxlength=100)
b_address = models.CharField("Billing Address", maxlength=100)
b_city = models.CharField("Billing City", maxlength=100)
b_state = models.USStateField("Billing State")
b_zip = models.CharField("Billing Zip", maxlength=100)
b_phone = models.CharField("Billing Phone", maxlength=100)
b_email = models.EmailField("Billing Email")
s_name = models.CharField("Name", maxlength=100)
s_address = models.CharField("Shipping Address", maxlength=100)
s_city = models.CharField("Shipping City", maxlength=100)
s_state = models.USStateField("Shipping State")
s_zip = models.CharField("Shipping Zip", maxlength=100)
s_phone = models.CharField("Shipping Phone", maxlength=100)
s_email = models.EmailField("Shipping Email")
amount = models.CharField("Order Amount", maxlength=100)
card_number = models.CharField("Card Number", maxlength=100)
exp_date = models.CharField("Exp. Date", maxlength=100)
card_code = models.CharField("Card Code", maxlength=100)
order_status = models.ForeignKey(OrderStatus)
voided = models.BooleanField("Has order been voided?")
email = models.BooleanField("Has an email been sent")
order = models.TextField("Details of Order", maxlength=1000)
comments = models.TextField("none", maxlength=1000)

class Admin:
list_display = ('s_name', 'order_status')

def __str__(self,):
return self.s_name

On Jul 29, 11:59 pm, Greg <[EMAIL PROTECTED]> wrote:
> Russ,
> Here is my traceback:
>
> Traceback (most recent call last):
> File "c:\Python24\lib\site-packages\django\core\handlers\base.py" in
> get_response
>   77. response = callback(request, *callback_args, **callback_kwargs)
> File "c:\Python24\lib\site-packages\django\contrib\admin\views
> \decorators.py" in _checklogin
>   55. return view_func(request, *args, **kwargs)
> File "c:\Python24\lib\site-packages\django\views\decorators\cache.py"
> in _wrapped_view_func
>   39. response = view_func(request, *args, **kwargs)
> File "c:\Python24\lib\site-packages\django\contrib\admin\views
> \main.py" in change_stage
>   370. new_data = manipulator.flatten_data()
> File "c:\Python24\lib\site-packages\django\db\models\manipulators.py"
> in flatten_data
>   250. new_data.update(f.flatten_data(fol, obj))
> File "c:\Python24\lib\site-packages\django\db\models\fields
> \__init__.py" in flatten_data
>   514. return {self.attname: (val is not None and val.strftime("%Y-%m-
> %d") or '')}
>
>   AttributeError at /admin/rugs/orders/1/
>   'unicode' object has no attribute 'strftime'
>
> On Jul 29, 11:34 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>
> > On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Russ,
> > > I tried including the code that you recommended.  However, I'm still
> > > getting the same error:
>
> > > AttributeError at /admin/rugs/orders/1/
> > > 'unicode' object has no attribute 'strftime'
>
> > Just to clarify - If you create, modify and save an object at the
> > command prompt, it works fine. You can retrieve the object using the
> > command line using calls to filter, etc, and print out objects
> > retrieved (e.g., print Order.objects.get(pk=1) ). However, when you
> > view the object in the admin pages you get an error. Is this correct?
>
> > If this is the case, it is possible that you have encountered some
> > sort of bug with the admin views dealing with date fields; to help
> > track this down, could you provide:
>
> > - A full stack trace of the error you are seeing
> > - The exact revision of Django you are using
> > - The code for the Order model
> > - The database backend you are using
>
> > Thanks,
> > 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: caching and "hello username" on each page

2007-07-29 Thread James Bennett

On 7/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote:
> I would LOVE to use caching for both anonymous and logged in users, but
> the problem is that every page on our site (http://www.splicemusic.com)
> has the typical "hello username | log out | ..." at the top of each page.

You might consider using finer-grained caching, so that you only cache
the things that are actually expensive to generate (e.g., complex
database lookups).

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: caching and "hello username" on each page

2007-07-29 Thread Doug B

You could also make your own render_to_response() function that
renders and caches the generic part of the page, and then passes that
in as a context for your base layout with the non-cacheable stuff like
the username.  Or make some of the generic stuff tags that cache
themselves using the lower level cache api.


--~--~-~--~~~---~--~~
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: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Russell Keith-Magee

On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Russ,
> I tried including the code that you recommended.  However, I'm still
> getting the same error:
>
> AttributeError at /admin/rugs/orders/1/
> 'unicode' object has no attribute 'strftime'

Just to clarify - If you create, modify and save an object at the
command prompt, it works fine. You can retrieve the object using the
command line using calls to filter, etc, and print out objects
retrieved (e.g., print Order.objects.get(pk=1) ). However, when you
view the object in the admin pages you get an error. Is this correct?

If this is the case, it is possible that you have encountered some
sort of bug with the admin views dealing with date fields; to help
track this down, could you provide:

- A full stack trace of the error you are seeing
- The exact revision of Django you are using
- The code for the Order model
- The database backend you are using

Thanks,
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: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Russ,
I tried including the code that you recommended.  However, I'm still
getting the same error:

AttributeError at /admin/rugs/orders/1/
'unicode' object has no attribute 'strftime'

///

I updated my view to include the following lines:

from datetime import datetime
...
o.timestamp = datetime.now()



When I drill down on the order from within my admin I still get the
error listed above.

Thanks

On Jul 29, 7:45 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
>
>
> > Ok,
> > I just added a Field in my Orders class.  It looks like this:
> ...
> > Do I need to put something into my timestamp field when I create the
> > Orders instance?  For example:
>
> Yes; your field is a required field, so you will need to provide
> timestamp data. DateFields store their data in datatime format; so you
> will need to do something like:
>
> >>> from datetime import datetime
> >>> o.timestamp = datetime(2007,7,30)
>
> To assist with form handling, Django also allows string inputs to date fields:
>
> >>> o.timestamp = "2007-07-30"
> > I would like to be able to create the current date when I' working
> > with the Orders instance (o.timestamp)
>
> For this one, try:
>
> >>> o.timestamp = datetime.now()
>
> 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: error on models with foreign key on each other

2007-07-29 Thread Ben Ford
It looks like your problem is that you have a ForeignKey pointing both
ways... This is unnecessary. You only need one ForeignKey, pointing from the
pointing from the 'child' to the 'parent'... I would guess from your
snippet, that one employee can have many contracts and assignments so you
need to delete these 2 lines:

   employee_contract = models.ForeignKey('EmployeeContract')
   employee_assignment = models.ForeignKey('EmployeeAssignment')

Django ORM will add two properties to your model which will return a query
set of all of an individual Employee's contracts or assignments. These
properties (they're actually descriptors) will be called something like
employeecontract_set, if you want to change this name put:

employee = models.ForeignKey(Employee, related_name='contracts')

or whatever you want to call the relationship... now you'll be able to do:

>>>emp = Employee.objects.get()
>>>emp.contracts.all()
... [.. ]

Hope this explains it OK.
Ben

On 30/07/07, James Bennett <[EMAIL PROTECTED]> wrote:
>
>
> On 7/29/07, james_027 <[EMAIL PROTECTED]> wrote:
> > D:\private\james\documents\django\ksk>python manage.py validate
> > manning.employee: Reverse query name for field 'employee_contract'
> > clashes with field 'EmployeeContr
> > act.employee'. Add a related_name argument to the definition for
> > 'employee_contract'.
> > manning.employee: Reverse query name for field 'employee_assignment'
> > clashes with field 'EmployeeAss
> > ignment.employee'. Add a related_name argument to the definition for
> > 'employee_assignment'.
> > 2 errors found.
>
> Django is telling you exactly what you need to do to resolve the
> error. Look at the model documentation for "related_name" for more
> details.
>
>
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of
> correct."
>
> >
>


-- 
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: newforms: common constraints

2007-07-29 Thread james_027

hi,

what will be the proper approach to do this? creating a custom fields
or custom field validation?

Thanks
james

On Jul 27, 10:53 pm, "Jacob Kaplan-Moss" <[EMAIL PROTECTED]>
wrote:
> On 7/27/07, james_027 <[EMAIL PROTECTED]> wrote:
>
> > but those min maxconstraintsare socommon? why not include it?
>
> Because "common" is different for any given user and/or site. I think
> *I've* only written a single form with min/max validation, FWIW.
> Designing a framework is hard; you've got to search for things that
> are as close to truly universal as possible. Otherwise you end up
> including every little pet feature that someone asks for, and that's
> known as "PHP".
>
> A good programmer will keep around his/her own library ofcommoncode
> and break it out whenever needed. If you need min/max validation
> often, you should make that the start of your own personal toolkit.
>
> Jacob


--~--~-~--~~~---~--~~
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: error on models with foreign key on each other

2007-07-29 Thread James Bennett

On 7/29/07, james_027 <[EMAIL PROTECTED]> wrote:
> D:\private\james\documents\django\ksk>python manage.py validate
> manning.employee: Reverse query name for field 'employee_contract'
> clashes with field 'EmployeeContr
> act.employee'. Add a related_name argument to the definition for
> 'employee_contract'.
> manning.employee: Reverse query name for field 'employee_assignment'
> clashes with field 'EmployeeAss
> ignment.employee'. Add a related_name argument to the definition for
> 'employee_assignment'.
> 2 errors found.

Django is telling you exactly what you need to do to resolve the
error. Look at the model documentation for "related_name" for more
details.



-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



error on models with foreign key on each other

2007-07-29 Thread james_027

Hi,

I am trying to migrate an existing application to django. I am
encountering the following problem with this models

D:\private\james\documents\django\ksk>python manage.py validate
manning.employee: Reverse query name for field 'employee_contract'
clashes with field 'EmployeeContr
act.employee'. Add a related_name argument to the definition for
'employee_contract'.
manning.employee: Reverse query name for field 'employee_assignment'
clashes with field 'EmployeeAss
ignment.employee'. Add a related_name argument to the definition for
'employee_assignment'.
2 errors found.

class Employee(models.Model):
lastname = models.CharField(maxlength=30)
firstname = models.CharField(maxlength=30)
middlename = models.CharField(blank=True, maxlength=30)
gender = models.CharField(maxlength=1)
birthday = models.DateField()
contact_no = models.CharField(blank=True, maxlength=50)
address = models.CharField(maxlength=100)
notes = models.CharField(maxlength=200)
pay_by = models.CharField(maxlength=3, choices=PAY_BY_LIST)
hour_rate = models.DecimalField(max_digits=7,
decimal_places=2)
allowance = models.DecimalField(max_digits=7,
decimal_places=2)
account_no = models.CharField(blank=True, maxlength=20)
sss = models.CharField(blank=True, maxlength=20)
phil_health = models.CharField(blank=True, maxlength=20)
pag_ibig = models.CharField(blank=True, maxlength=20)

employee_contract = models.ForeignKey('EmployeeContract')
employee_assignment = models.ForeignKey('EmployeeAssignment')

AREA_LIST = (
('CKG', 'Cooking'),
('DLY', 'Delivery'),
('DYG', 'Drying'),
('FLA', 'Flavoring'),
('FYG', 'Frying'),
('LGS', 'Logistics'),
('MXG', 'Mixing'),
('PKG', 'Packaging'),
('ROG', 'Roasting'),

)
class EmployeeAssignment(models.Model):
employee = models.ForeignKey(Employee)
assignment_from = models.DateField()
assignment_to = models.DateField()
area = models.CharField(maxlength=3, choices=AREA_LIST)
position = models.CharField(maxlength=20)
edit_by = models.ForeignKey(Profile)

EMPLOYEE_CONTRACT_STATUS_LIST = (
('ACT', 'Active'),
('FIN', 'Finnish'),
('RES', 'Resign'),
('TER', 'Terminate'),
)
class EmployeeContract(models.Model):
employee = models.ForeignKey(Employee)
contract_to = models.DateField()
contract_from = models.DateField()
notes = models.CharField(blank=True, maxlength=200)
status = models.CharField(maxlength=3,
choices=EMPLOYEE_CONTRACT_STATUS_LIST)
edit_by = models.ForeignKey(Profile)

Although this problem can be solve with just renaming some of the
fields. I wonder if when doing some django orm operation could produce
a problem.

thanks
james


--~--~-~--~~~---~--~~
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: a generic JSON serializer???

2007-07-29 Thread Empty

I have pulled together pieces to do this.  I posted about it here:

http://blog.michaeltrier.com/2007/7/30/json-generic-serializer

I don't know if it's exactly what you're looking for, but check it out.

Empty

On 7/26/07, Eric St-Jean <[EMAIL PROTECTED]> wrote:
>
> Hi,
> There does not seem to be an easy way to serialize anything to JSON:
> serializers.serialize will handle a QuerySet
> simplejson.dumps will handle normal python data structures
>
> But what about a python dict which has a django model instance in it,
> for example??? Or a Field?
>
> Sure, i can (and did) write a trivial recursive function (it was a hack,
> i should make it a proper serializer) which looks into the structure and
> loops into the elements.
> upon finding a list or dict or tuple, it calls itself.
> Finding a queryset it calls serializers.serialize
> Finding a base python type it calls simplejson.dumps
> Finding a model instance, i made a stupid quick hack to get a queryset
> which has that instance only, and then i call serializers.serialize on it.
>
> But i can hardly believe i'm the first one with this problem; did anyone
> make a generic serializer, which will handle both python stuff and
> django stuff (not just QuerySets)???
>
> >
>

--~--~-~--~~~---~--~~
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: Match from list in URLconf

2007-07-29 Thread Matt the Destroyer

I missed a quote, it should be:
(r'^(?P\w+)/$', 'project.views.user_page')

On Jul 29, 10:16 pm, Matt the Destroyer <[EMAIL PROTECTED]>
wrote:
> Perhaps try adding a URL pattern like the following:
>  (r^(?P\w+)/$', 'project.views.user_page')
>
> Your view function (called "user_page") will now accept "user_name" as
> an argument in addition to the request object.  I should warn you that
> using that regular expression could be dangerous, as it'll accept any
> string past the root url.  That having been said, I'm sure there's a
> better way to do this, but this should get you started.
>
> On Jul 29, 7:17 pm, Matt <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello list,
>
> > I was wondering if the following is possible with the URLconf:
>
> > I'd like the URL regex to match part of a URL if it exists within a
> > specific list of values. For example, if you wanted to direct users to
> > their area of your site, you might have something like this:
>
> >www.mysite.com/matt--> go to my areawww.mysite.com/jess--> go to Jess' 
> >areawww.mysite.com/mark--> go to Mark's area
>
> > In this situation you'd want a URL match for every user on your site,
> > which is obviously database driven. I'd like to be able to pull a list
> > of all the users out of the database and use a single line in my
> > URLconf to acheive the above.
>
> > This could all be acheived using another view to determine whether the
> > given name was a valid user, and if so direct you to the appropriate
> > view, but wouldn't that prevent you using Django's generic views?
>
> > Thanks,
> > Matt.- 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: Match from list in URLconf

2007-07-29 Thread Matt the Destroyer

Perhaps try adding a URL pattern like the following:
 (r^(?P\w+)/$', 'project.views.user_page')

Your view function (called "user_page") will now accept "user_name" as
an argument in addition to the request object.  I should warn you that
using that regular expression could be dangerous, as it'll accept any
string past the root url.  That having been said, I'm sure there's a
better way to do this, but this should get you started.

On Jul 29, 7:17 pm, Matt <[EMAIL PROTECTED]> wrote:
> Hello list,
>
> I was wondering if the following is possible with the URLconf:
>
> I'd like the URL regex to match part of a URL if it exists within a
> specific list of values. For example, if you wanted to direct users to
> their area of your site, you might have something like this:
>
> www.mysite.com/matt--> go to my areawww.mysite.com/jess--> go to Jess' 
> areawww.mysite.com/mark--> go to Mark's area
>
> In this situation you'd want a URL match for every user on your site,
> which is obviously database driven. I'd like to be able to pull a list
> of all the users out of the database and use a single line in my
> URLconf to acheive the above.
>
> This could all be acheived using another view to determine whether the
> given name was a valid user, and if so direct you to the appropriate
> view, but wouldn't that prevent you using Django's generic views?
>
> 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: Blog engine

2007-07-29 Thread Forest Bond
On Sun, Jul 29, 2007 at 05:49:54PM -, Henrik Lied wrote:
> @Forest: I agree, it should be that simple. But let's say you've got a
> comment reply plugin. How would we - through a middleware - manage to
> intercept our usual comment system, and modify the HTML template
> source to fit the plugin? It's cases like these I see the potential
> pitfalls of our way of thought. Please, enlighten me if the answer is
> simple. :-)

Well, extensibility is tough for exactly that reason.  You have to anticipate
the ways in which your application might be extended.  This is an extremely
difficult task, for that simple reason that it is impossible to predict the
future.

You really don't want to be modifying templates (or any other source files) when
a new plugin is installed.  What you do want is to have placeholders in your
templates where plugins may contribute additional markup that will appear on the
page.

-Forest
-- 
Forest Bond
http://www.alittletooquiet.net


signature.asc
Description: Digital signature


Re: friends table adding choices from the same database

2007-07-29 Thread [EMAIL PROTECTED]

THANK YOU!

i just got home, will try this to see if this works... i'm new to
django so thanks for the help, i'll look up what related_name works,
but it looks good.

Israel

On Jul 29, 9:41 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> If the Friend is really a user...wouldn't something like this work:
>
> class Friends(models.Model):
>  parent_user = models.ForeignKey(User, related_name="user")
>  friend_user = models.ForeignKey(User,related_name="friends")
>
> Then for the parent_user's friends...you'd do something like:
> parent_users_friends = parentuser.friends_set.all() to bring back
> a listing of all of his friends.
>
> On Jul 27, 8:05 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > i'm working on an app that has a table called friends whose model
> > looks like this:
>
> > class Friend(models.Model):
> > user = models.ForeignKey(User)
> > friend = models.CharField(maxlength=100)
> > status = models.CharField(maxlength=1,choices=FSTATUS_CHOICES)
>
> > def __str__(self):
> > return self.friend
>
> > user is the user that added the friend, while friend SHOULD be the id
> > of the user that has been added. Both fields use the user table.  I
> > cant use the same foreign key for both, this would be an error.
> > Ideally i would want a drop down box with all the username for the
> > friend field.  I thought about using choices, but cant seem to create
> > a tuple that is dynamically populated from the username field in the
> > user table.
>
> > Any ideas how i could go about this?
>
> > P.S is this a recursive relationship? i dont think so but hopefully
> > some DB guru can shed some light.


--~--~-~--~~~---~--~~
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: Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Russell Keith-Magee

On 7/30/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Ok,
> I just added a Field in my Orders class.  It looks like this:
...
> Do I need to put something into my timestamp field when I create the
> Orders instance?  For example:

Yes; your field is a required field, so you will need to provide
timestamp data. DateFields store their data in datatime format; so you
will need to do something like:

>>> from datetime import datetime
>>> o.timestamp = datetime(2007,7,30)

To assist with form handling, Django also allows string inputs to date fields:

>>> o.timestamp = "2007-07-30"

> I would like to be able to create the current date when I' working
> with the Orders instance (o.timestamp)

For this one, try:

>>> o.timestamp = datetime.now()

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: db mock for unit testing

2007-07-29 Thread Russell Keith-Magee

On 7/29/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> So what advantages are there to the mocking approach over just replacing
> the setting?

Genuine mocking (as opposed to this proposal) has one really big
advantage - it's lightning fast. All the db-calls get faked using a
cache-like setup, so it takes pretty much no time to run any db query.
The cost comes in keeping the mock data source up to date.

I've been mentally ruminating on adding a mock framework to speed up
Django's tests, with some support framework to make generating the
mock data easier. When my ideas have congealed a little bit, I might
have some code to throw around. Watch this space.

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: db mock for unit testing

2007-07-29 Thread Russell Keith-Magee

On 7/29/07, Andrey Khavryuchenko <[EMAIL PROTECTED]> wrote:
>
> I'm not using django's testing framework for several reasons:
>  - I'm using django from 0.91 days and wasn't following django-users all
>this way
>  - I use nose and twill for testing and they have no ready-to-use plugs
>into django testing (or I haven't been able to find it)

There aren't any built-in mechanisms for supporting nose or twill
tests. There are so many 'alternative' testing frameworks - we're not
going to add support for every single one of them.

However, it is very simple to add support for an external testing
mechanism - this is one of the original design considerations. See the
following for details:

http://www.djangoproject.com/documentation/testing/#using-a-different-testing-framework

> But sqlite has no concat function and straightforward approach will lead to
> an exception.  Thus
> sqlite_conn.connection.create_function('concat', 2,
>lambda *args: ''.join(args))
> in DbMock setup.

This is a workaround required by your specific SQL requirements.
Similar problems would exist if you used Postgres TSearch2 extensions
in your queries, or any other DB-specific extension. It's not really
Django's responsibility to normalize every possible SQL query across
every possible backend.

However, it probably is Django's responsibility to provide a generic
hook so that you (as an end user) can add whatever normalizations your
application may require. Any suggestions on how to approach this
problem would be greatfully accepted.

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: Template tag and combining variables & text

2007-07-29 Thread Emanuele Pucciarelli


Il giorno 29/lug/07, alle ore 22:48, Tomas Kopecek ha scritto:

> I know, it's syntactical nonsense. But does anybody know about some  
> way
> how to combine variable content with string content? Is it possible?
>
> For example, very crude way could be something like
>
> {% img %} {{BASE_URL}}/path/z.gif {% endimg %}

Maybe something like {% img base_url "path/z.gif" %}: let string  
content be surrounded by double quotes, and let the tag join  
everything for you.

Code:

from django.template import Node, TemplateSyntaxError, Library

register = Library()

class MixedNode(Node):
class Variable(object):
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
def __init__(self, args):
self.parameters = [
[self.Variable(arg), 
arg.rstrip('"').lstrip('"')][arg[0] == arg 
[-1] == '"']
for arg in args]
def get_param(self, i, context):
if isinstance(i, self.Variable):
return context[str(i)]
else:
return i
def get_string(self, context):
return ''.join([self.get_param(param, context) for param in  
self.parameters])

class ImageNode(MixedNode):
def render(self, context):
return '' % self.get_string(context)

def do_img(parser, token):
arglist = token.split_contents()
if len(arglist) < 2:
raise TemplateSyntaxError, "%r tag requires at least one 
argument"  
% token.contents.split()[0]
return ImageNode(arglist[1:])

register.tag('img', do_img)

(you can then subclass MixedNode for pretty much everything...)

Regards,

-- 
Emanuele
--~--~-~--~~~---~--~~
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 LimitRequestBody to Limit File Uploads

2007-07-29 Thread Graham Dumpleton

On Jul 30, 12:26 am, "Nimrod A. Abing" <[EMAIL PROTECTED]> wrote:
> On 7/29/07, Graham Dumpleton <[EMAIL PROTECTED]> wrote:
>
> > > I would love to try that on my development server but I can't seem to
> > > find documentation on how to do it:
>
> > >http://code.djangoproject.com/wiki/ServerArrangements
>
> > > Can someone point me in the right direction?
>
> > Available from:
>
> >  http://www.modwsgi.org
>
> > Django specific integration guide at:
>
> >  http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
>
> I'm looking at the Django integration guide but I am confused as to
> what I do with the following:
>
> > Using this function, a script file for a Django application which is 
> > compatible with mod_wsgi would be constructed as follows:
>
> > import os, sys
> > sys.path.append('/usr/local/django')
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> > import django.core.handlers.wsgi
>
> > application = django.core.handlers.wsgi.WSGIHandler()
>
> Where do I put that? views.py?

The documentation says:

"""Similarly, an 'apache' subdirectory should have been created within
the package and the script file stored there under the name
'django.wsgi'."""

Rather than trying to launch straight into setting up Django, you
might want to get a simple WSGI hello world application going first.
For more basic instructions read:

  http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines

elsewhere on the same site.

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
-~--~~~~--~~--~--~---



Match from list in URLconf

2007-07-29 Thread Matt

Hello list,

I was wondering if the following is possible with the URLconf:

I'd like the URL regex to match part of a URL if it exists within a
specific list of values. For example, if you wanted to direct users to
their area of your site, you might have something like this:

www.mysite.com/matt --> go to my area
www.mysite.com/jess --> go to Jess' area
www.mysite.com/mark --> go to Mark's area

In this situation you'd want a URL match for every user on your site,
which is obviously database driven. I'd like to be able to pull a list
of all the users out of the database and use a single line in my
URLconf to acheive the above.

This could all be acheived using another view to determine whether the
given name was a valid user, and if so direct you to the appropriate
view, but wouldn't that prevent you using Django's generic views?

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.contrib.markup problems

2007-07-29 Thread Steve

On Jul 27, 6:57 pm, "Robert Coup" <[EMAIL PROTECTED]>
wrote:
>
> I suspect whatever is hosting your site (mod_python? fcgi?) is using a
> different path or a different interpreter (like 2.4). Print the value
> of sys.path from a view and see whether it includes the right folder.
>
> The other thing is to look in the
> django/contrib/markup/templatetags/markup.py file and make sure django
> is importing the same thing you are in the shell.
>
> Rob :)

Thanks for your tips. I finally figured out that my dispatch.fcgi
wasn't settings the proper folder in sys.path.


--~--~-~--~~~---~--~~
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: Confusion over CRUD generic views and newforms

2007-07-29 Thread Matt

Thanks Phil. Seems to do exactly what it promises.

Regards,
Matt.

On Jul 29, 12:10 pm, "Phil Davis" <[EMAIL PROTECTED]> wrote:
> On 26/07/07, Matt <[EMAIL PROTECTED]> wrote:
>
> > Can you confirm that the CRUDgenericviewsare compatible with
> >newforms? I haven't seen any examples of how to do it, but I'm having
> > a hard time believing that this core functionality hasn't been
> > implemented (or even patched) fornewformsyet.
>
> You may want to look at:
>
>  http://www.djangosnippets.org/snippets/99/
>
> which is a re-implementation of create_object and 
> update_objectgenericviewsusingnewformsby danjak.
>
> I have not actually tried using the code though and it does not look
> like it supports thenewformsedit_inline stuff (not surprising as
> written before that appeared).
>
> --
> Phil


--~--~-~--~~~---~--~~
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: Is there any way to associate a view with a template?

2007-07-29 Thread Emanuele Pucciarelli <[EMAIL PROTECTED]>

Hi Dan,

> make a view for the nav.html template (which is included in all the
> page templates)? I imagine it could be done with SSI but I don't want
> to go that route unless I have no other option.

Carole's advice solves your problem just right; on the other hand, you
might want to look at the {% menu %} tag I've just shared on
djangosnippets.org: http://www.djangosnippets.org/snippets/347/ . I
don't know if it does the same thing that you're trying to do, but if
it does, it could save you time :)

Regards,

--
Emanuele




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Error: 'unicode' object has no attribute 'strftime'. Just added models.DateField

2007-07-29 Thread Greg

Ok,
I just added a Field in my Orders class.  It looks like this:

timestamp = models.DateField("Creation Date")

//

I create a new instance of the order class below:

o = Orders()
o.s_name = 'Greg Smith'
o.s_address = '123 West Main'
o.s_city = 'city'
... (And so on)
o.save()

Do I need to put something into my timestamp field when I create the
Orders instance?  For example:

o = Orders()
o.timestamp = ?? # Not sure what goes here
o.s_name = 'Bob'
o.s_address = '123 West Main'
o.s_city = 'city'
... (And so on)
o.save()

//

Currently, when I save the Orders instance it writes it to the db.  I
can view the record in my admin.  I can open the record and select
'Today' for my timestamp field and click save.  However, I get the
error ''unicode' object has no attribute 'strftime'' When I try to
open the record after I added the timestamp.

I would like to be able to create the current date when I' working
with the Orders instance (o.timestamp)

Any help would be appreciated.

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
-~--~~~~--~~--~--~---



Template tag and combining variables & text

2007-07-29 Thread Tomas Kopecek

Hello,
imagine tag, that has one parameter. Typical usage will look like this:

{% img img_url %} or {% img "http://x.y/z.gif; %}

These two cases are simple to implement, the problem arises when 
parameter would be a combination of variable content and string - 
something like this:

{% img {{BASE_URL}}/path/z.gif %}

I know, it's syntactical nonsense. But does anybody know about some way 
how to combine variable content with string content? Is it possible?

For example, very crude way could be something like

{% img %} {{BASE_URL}}/path/z.gif {% endimg %}

-- 

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
-~--~~~~--~~--~--~---



Validating custom primary key values in raw_id_admin fields

2007-07-29 Thread Brendan Arnold

ref: 
http://groups.google.com/group/django-users/browse_thread/thread/9c9b05de723877a2/41c26d973af029d5?lnk=gst=raw_id_admin=10#41c26d973af029d5

hi there,

there still seems to be this problem. i just checked out the svn about
a week ago. it appears to be a problem with validation. the databases
are geared up for accepting characters rather than integers where
appropriate.

the error message now reads 'Enter only digits separated by commas.'

brendan

On Oct 26 2006, 9:49 pm, "atlithorn" <[EMAIL PROTECTED]> wrote:
> This seems to be on the fritz again.Chgsets 785 and 790 for ticket #586
> fixed this in pre-mr. I have a foreign key related table with a
> CharField primary key. Trying to add stuff in the admin creates a list
> of primary keys but save fails with "Enter only digits separated by
> commas." 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
-~--~~~~--~~--~--~---



RE: noob problem with Unicode

2007-07-29 Thread Donald Spears

Yep that did it, gesh, I feel dumb :P

Thanks,
Paul

-Original Message-
From: django-users@googlegroups.com [mailto:[EMAIL PROTECTED]
On Behalf Of Parnell Springmeyer
Sent: Sunday, July 29, 2007 12:41 PM
To: django-users@googlegroups.com
Subject: Re: noob problem with Unicode


Make sure you are using the correct version, the documentation link
defaults to the repository code; you have to follow the 0.96 version
documentation link on the top.




--~--~-~--~~~---~--~~
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: noob problem with Unicode

2007-07-29 Thread Parnell Springmeyer

Make sure you are using the correct version, the documentation link
defaults to the repository code; you have to follow the 0.96 version
documentation link on the top.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



noob problem with Unicode

2007-07-29 Thread dpsthree


I was following the tutorial 
(http://www.djangoproject.com/documentation/tutorial01/)  and can't get the
__unicode__ function to return properly.

I have the following in my models.py

from django.db import models
import datetime

class Poll(models.Model):
question = models.CharField(maxlength=200)
pub_date = models.DateTimeField('date published')

def __unicode__(self):
return self.question

def was_published_today(self):
return self.pub_date.date() == datetime.date.today()

class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(maxlength=200)
votes = models.IntegerField()

def __unicode__(self):
return self.choice

calling Poll.objects.all() returns:
[]

expected:

[]

The function was_published_today works properly, and I have my editor setup
to show all whitespace, so I know its not a tab problem.  I can't seem to
figure it out, but I'm sure its something simple.


Thanks in advance,

Paul
-- 
View this message in context: 
http://www.nabble.com/noob-problem-with-Unicode-tf4166369.html#a11853698
Sent from the django-users mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Blog engine

2007-07-29 Thread Henrik Lied

@Forest: I agree, it should be that simple. But let's say you've got a
comment reply plugin. How would we - through a middleware - manage to
intercept our usual comment system, and modify the HTML template
source to fit the plugin? It's cases like these I see the potential
pitfalls of our way of thought. Please, enlighten me if the answer is
simple. :-)


--~--~-~--~~~---~--~~
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: friends table adding choices from the same database

2007-07-29 Thread [EMAIL PROTECTED]

If the Friend is really a user...wouldn't something like this work:

class Friends(models.Model):
 parent_user = models.ForeignKey(User, related_name="user")
 friend_user = models.ForeignKey(User,related_name="friends")

Then for the parent_user's friends...you'd do something like:
parent_users_friends = parentuser.friends_set.all() to bring back
a listing of all of his friends.



On Jul 27, 8:05 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> i'm working on an app that has a table called friends whose model
> looks like this:
>
> class Friend(models.Model):
> user = models.ForeignKey(User)
> friend = models.CharField(maxlength=100)
> status = models.CharField(maxlength=1,choices=FSTATUS_CHOICES)
>
> def __str__(self):
> return self.friend
>
> user is the user that added the friend, while friend SHOULD be the id
> of the user that has been added. Both fields use the user table.  I
> cant use the same foreign key for both, this would be an error.
> Ideally i would want a drop down box with all the username for the
> friend field.  I thought about using choices, but cant seem to create
> a tuple that is dynamically populated from the username field in the
> user table.
>
> Any ideas how i could go about this?
>
> P.S is this a recursive relationship? i dont think so but hopefully
> some DB guru can shed some light.


--~--~-~--~~~---~--~~
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 LimitRequestBody to Limit File Uploads

2007-07-29 Thread Nimrod A. Abing

On 7/29/07, Graham Dumpleton <[EMAIL PROTECTED]> wrote:
> > I would love to try that on my development server but I can't seem to
> > find documentation on how to do it:
> >
> > http://code.djangoproject.com/wiki/ServerArrangements
> >
> > Can someone point me in the right direction?
>
> Available from:
>
>   http://www.modwsgi.org
>
> Django specific integration guide at:
>
>   http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

I'm looking at the Django integration guide but I am confused as to
what I do with the following:

> Using this function, a script file for a Django application which is 
> compatible with mod_wsgi would be constructed as follows:
>
> import os, sys
> sys.path.append('/usr/local/django')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> import django.core.handlers.wsgi
>
> application = django.core.handlers.wsgi.WSGIHandler()

Where do I put that? views.py?

Thanks in advance.
-- 
_nimrod_a_abing_

http://abing.gotdns.com/
http://www.preownedcar.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Blog engine

2007-07-29 Thread Forest Bond
On Sat, Jul 28, 2007 at 03:28:31PM -, Henrik Lied wrote:
> 
> Ok, so I've been thinking some more.
> 
> The model could be something like this:
> class Plugin(models.Model):
> """(Plugin description)"""
> pointer = models.FilePathField() ## Could work, right?
> name = models.CharField(maxlength=200)
> description = models.TextField(blank=True, null=True)
> url = models.URLField()
> apply_to = models.ForeignKey(ContentType)
> active = models.BooleanField(default=False)
> 
> We then would have to make a standard on how the plugin-packages would
> be designed.
> A zip-file would probably work out OK. We would then have to get this
> zip-file, run through it and copy its files into a plugins-
> subdirectory. The package should have a info.txt-document, where the
> plugin title would be on the first line and description on the second.
> 
> But - I'm still not sure how we'd easily hook this into other
> applications - at least not without the user having to modify the
> source code...

See twisted.plugin.  Define your interfaces, and let twisted handle the rest.

Don't pull a PHP-ism like forcing users to modify code.  That is, by definition,
not a plugin architecture.

-Forest
-- 
Forest Bond
http://www.alittletooquiet.net


signature.asc
Description: Digital signature


Re: ubuntu 6.06 deployment issues

2007-07-29 Thread [EMAIL PROTECTED]

Sorry to re-awaken this thread, but it seems that people are still
having issues with this PYTHONPATH info. In an attempt to get this
sorted out, I've attached a patch to #4296 that adds a bit more info.
Can anyone add any more info to what I've got?

Thanks,
Simon G


#4296 - http://code.djangoproject.com/ticket/4296


--~--~-~--~~~---~--~~
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 LimitRequestBody to Limit File Uploads

2007-07-29 Thread Graham Dumpleton

On Jul 29, 8:35 pm, "Nimrod A. Abing" <[EMAIL PROTECTED]> wrote:
> On 7/29/07, Graham Dumpleton <[EMAIL PROTECTED]> wrote:
> > If not bound to mod_python because of need to use it for custom
> > authentication/authorisation handlers connected to Django, you might
> > also try using mod_wsgi instead, where the LimitRequestBody directive
> > isn't a problem.
>
> I would love to try that on my development server but I can't seem to
> find documentation on how to do it:
>
> http://code.djangoproject.com/wiki/ServerArrangements
>
> Can someone point me in the right direction?

Available from:

  http://www.modwsgi.org

Django specific integration guide at:

  http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

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: Filter to find closest match

2007-07-29 Thread Tim Chase

> In pure sql  we can do :
> "select min(abs(width-150)) from quote_pricelisttable where name_id =
> 1 and width >= 240-150 and width <=240+150;"
> 
> How to make it work properly from django ORM?

Did you try playing with the extra() call I included in my
previous email?  It should do what you describe, and doesn't
require a fixed window such as you describe not wanting.

While it does rely on using some SQL, it does so through the
Django ORM and it should be fairly portable SQL (the "Abs()"
function is usually the "Abs()" function on most SQL engines).
The code I included (minus any syntax errors) should have found
the items from the given table where they were the minimum
distance from the target value.

  w = 240 # target width to find the closest...comes from user
  results = PriceList.objects.extra(where=["""
  Abs(app_pricelist.width - %s) = (
 SELECT Min(Abs(pl.width - %s))
 FROM app_pricelist pl
 )
  """], params=[w, w])

The results are a Django ORM query object that can be further
filtered, sliced, sorted, and iterated over with no problems.
While it can be done in pure python/django rather than SQL, it
would require dragging the whole PriceList across the wire and
filtering locally--a much slower proposition than simply letting
the DB do the work for you and shipping you just the exact
results you want.

-tim




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Confusion over CRUD generic views and newforms

2007-07-29 Thread Phil Davis

On 26/07/07, Matt <[EMAIL PROTECTED]> wrote:
> Can you confirm that the CRUD generic views are compatible with
> newforms? I haven't seen any examples of how to do it, but I'm having
> a hard time believing that this core functionality hasn't been
> implemented (or even patched) for newforms yet.

You may want to look at:

  http://www.djangosnippets.org/snippets/99/

which is a re-implementation of create_object and update_object
generic views using newforms by danjak.

I have not actually tried using the code though and it does not look
like it supports the newforms edit_inline stuff (not surprising as
written before that appeared).

-- 
Phil

--~--~-~--~~~---~--~~
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 LimitRequestBody to Limit File Uploads

2007-07-29 Thread Nimrod A. Abing

On 7/29/07, Graham Dumpleton <[EMAIL PROTECTED]> wrote:
> We hadn't been able to come up with a way of reproducing the problem
> on demand so hadn't yet been able to investigate. Where people had
> seen this exception it was very rare and very random.

I think the following conditions trigger the exception:

1. Set LimitRequestBody to an arbitrary limit, in our case 15728640
2. Upload a file larger than LimitRequestBody using POST to a Django
app. In the test case that caused the error, the file size is 24952238
(based on our logs).

The case above is for only one file of that specific size for that
specific limit.

If I find the time I will set up a few test cases for this error and
see if I can trigger it on demand.

> I'll link this discussion to that issue as it may help finding
> underlying problem in mod_python.
>
> > I get that traceback emailed to me every time an uploaded file hits
> > the limit set by LimitRequestBody.
> >
> > I am using Django 0.96 and this is on the production server.
> >
> > Someone posted something similar on this list last December but the
> > last question by the OP was never really addressed:
> >
> > http://groups.google.com/group/django-users/browse_thread/thread/162a...
> >
> > Has any progress been made with regards to handling 413 from within Django?
>
> FWIW, how mod_python handle the Apache LimitRequestBody directive is
> wrong. I have it one of my TODO lists to log a bug against mod_python
> for it.
>
> The problem is that mod_python doesn't check whether LimitRequestBody
> would be triggered before actually calling the mod_python handler.
> Thus, that the post data exceeds the limit is only found when
> req.read() of mod_python request object is called and a Python
> exception is generated because of an unknown read error. Well at least
> it normally is an unknown read error. In your case you seem to be
> triggered this other Python bug and getting that error instead.
>
> Now, because a read error of some sort is generated, mod_python
> handlers would normally see it as an unexpected exception and it would
> propagate back and result in a 500 Internal Server Error page rather
> than a 413 error back to the client. Whether Django does anything
> different or still sends back a 500 error page I don't know.

The user reported that he just gets "Connection reset by peer."

> In comparison, in mod_wsgi where I uncovered this problem with
> LimitRequestBody, the code checks to see if LimitRequestBody would be
> triggered before calling the WSGI application. If triggered the code
> immediately returns without calling the application, returning the 413
> error. If an ErrorDocument for 413 is defined that would then be
> invoked, else the standard Apache 413 error page would be returned.
>
> In summary, mod_python LimitRequestBody handling is broken. Even when
> fixed, it would result in it being detected before Django is even
> called and thus only custom error page can be one setup using
> ErrorDocument directive of Apache. This ErrorDocument directive would
> reference a Django URL if desired.

I guess that would be an acceptable fall-back behavior.

> Only other choice when using mod_python is not to use Apache
> LimitRequestBody directive and for your actual Django URL handler to
> check Content-Length of request itself and generate an appropriate 413
> error page. You wouldn't be able to apply it in one go for whole
> Django application.

One reason we turned to using LimitRequestBody is to prevent DoS
attacks on our server. IIRC, Django keeps POST uploaded files in
memory. I don't know if this is still the case in SVN trunk, so please
correct me if I am dead wrong :)

Deferring the actual size check to a Django view would be a bit late
(and useless for our intended purpose) because by that time, Django
and mod_python would have handled the request already.

> If not bound to mod_python because of need to use it for custom
> authentication/authorisation handlers connected to Django, you might
> also try using mod_wsgi instead, where the LimitRequestBody directive
> isn't a problem.

I would love to try that on my development server but I can't seem to
find documentation on how to do it:

http://code.djangoproject.com/wiki/ServerArrangements

Can someone point me in the right direction?

> Hope this helps to explain the issue.

Very informative explanation. Thank you :)
-- 
_nimrod_a_abing_

http://abing.gotdns.com/
http://www.preownedcar.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 LimitRequestBody to Limit File Uploads

2007-07-29 Thread Graham Dumpleton

On Jul 29, 8:00 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Jul 29, 11:20 am, "Nimrod A. Abing" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello,
>
> > I have recently begun testing LimitRequestBody to limit file uploads.
> > It works but there are some issues. Whenever the uploaded file hits
> > the limit, I get "Connection reset by peer". Ideally I would like to
> > be able to redirect the user to an error page but it seems that Django
> > tries to run but it hits an exception:
>
> > Traceback (most recent call last):
>
> >  File 
> > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/base.py",
> > line 77, in get_response
> >response = callback(request, *callback_args, **callback_kwargs)
>
> >  File 
> > "/opt/ActivePython/lib/python2.4/site-packages/django/db/transaction.py",
> > line 194, in _commit_on_success
> >res = func(*args, **kw)
>
> >  File "/home/preownedcar/djangoapps/preownedcar/CoreApp/views.py",
> > line 1108, in offer_post
> >new_data = request.POST.copy()
>
> >  File 
> > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py",
> > line 69, in _get_post
> >self._load_post_and_files()
>
> >  File 
> > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py",
> > line 50, in _load_post_and_files
> >self._post, self._files =
> > http.parse_file_upload(self._req.headers_in, self.raw_post_data)
>
> >  File 
> > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py",
> > line 119, in _get_raw_post_data
> >self._raw_post_data = self._req.read()
>
> > SystemError: Objects/stringobject.c:3518: bad argument to internal function
>
> This error message possibly relates to this bug in mod_python.
>
>  https://issues.apache.org/jira/browse/MODPYTHON-234
>
> We hadn't been able to come up with a way of reproducing the problem
> on demand so hadn't yet been able to investigate. Where people had
> seen this exception it was very rare and very random.
>
> I'll link this discussion to that issue as it may help finding
> underlying problem in mod_python.
>
> > I get that traceback emailed to me every time an uploaded file hits
> > the limit set by LimitRequestBody.
>
> > I am using Django 0.96 and this is on the production server.
>
> > Someone posted something similar on this list last December but the
> > last question by the OP was never really addressed:
>
> >http://groups.google.com/group/django-users/browse_thread/thread/162a...
>
> > Has any progress been made with regards to handling 413 from within Django?
>
> FWIW, how mod_python handle the Apache LimitRequestBody directive is
> wrong. I have it one of my TODO lists to log a bug against mod_python
> for it.
>
> The problem is that mod_python doesn't check whether LimitRequestBody
> would be triggered before actually calling the mod_python handler.
> Thus, that the post data exceeds the limit is only found when
> req.read() of mod_python request object is called and a Python
> exception is generated because of an unknown read error. Well at least
> it normally is an unknown read error. In your case you seem to be
> triggered this other Python bug and getting that error instead.
>
> Now, because a read error of some sort is generated, mod_python
> handlers would normally see it as an unexpected exception and it would
> propagate back and result in a 500 Internal Server Error page rather
> than a 413 error back to the client. Whether Django does anything
> different or still sends back a 500 error page I don't know.
>
> In comparison, in mod_wsgi where I uncovered this problem with
> LimitRequestBody, the code checks to see if LimitRequestBody would be
> triggered before calling the WSGI application. If triggered the code
> immediately returns without calling the application, returning the 413
> error. If an ErrorDocument for 413 is defined that would then be
> invoked, else the standard Apache 413 error page would be returned.
>
> In summary, mod_python LimitRequestBody handling is broken. Even when
> fixed, it would result in it being detected before Django is even
> called and thus only custom error page can be one setup using
> ErrorDocument directive of Apache. This ErrorDocument directive would
> reference a Django URL if desired.
>
> Only other choice when using mod_python is not to use Apache
> LimitRequestBody directive and for your actual Django URL handler to
> check Content-Length of request itself and generate an appropriate 413
> error page. You wouldn't be able to apply it in one go for whole
> Django application.
>
> If not bound to mod_python because of need to use it for custom
> authentication/authorisation handlers connected to Django, you might
> also try using mod_wsgi instead, where the LimitRequestBody directive
> isn't a problem.
>
> Hope this helps to explain the issue.

And here is the mod_python issue I have created for the
LimitRequestBody issue.

  

Re: Using LimitRequestBody to Limit File Uploads

2007-07-29 Thread Graham Dumpleton

On Jul 29, 11:20 am, "Nimrod A. Abing" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have recently begun testing LimitRequestBody to limit file uploads.
> It works but there are some issues. Whenever the uploaded file hits
> the limit, I get "Connection reset by peer". Ideally I would like to
> be able to redirect the user to an error page but it seems that Django
> tries to run but it hits an exception:
>
> Traceback (most recent call last):
>
>  File 
> "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/base.py",
> line 77, in get_response
>response = callback(request, *callback_args, **callback_kwargs)
>
>  File 
> "/opt/ActivePython/lib/python2.4/site-packages/django/db/transaction.py",
> line 194, in _commit_on_success
>res = func(*args, **kw)
>
>  File "/home/preownedcar/djangoapps/preownedcar/CoreApp/views.py",
> line 1108, in offer_post
>new_data = request.POST.copy()
>
>  File 
> "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py",
> line 69, in _get_post
>self._load_post_and_files()
>
>  File 
> "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py",
> line 50, in _load_post_and_files
>self._post, self._files =
> http.parse_file_upload(self._req.headers_in, self.raw_post_data)
>
>  File 
> "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py",
> line 119, in _get_raw_post_data
>self._raw_post_data = self._req.read()
>
> SystemError: Objects/stringobject.c:3518: bad argument to internal function

This error message possibly relates to this bug in mod_python.

  https://issues.apache.org/jira/browse/MODPYTHON-234

We hadn't been able to come up with a way of reproducing the problem
on demand so hadn't yet been able to investigate. Where people had
seen this exception it was very rare and very random.

I'll link this discussion to that issue as it may help finding
underlying problem in mod_python.

> I get that traceback emailed to me every time an uploaded file hits
> the limit set by LimitRequestBody.
>
> I am using Django 0.96 and this is on the production server.
>
> Someone posted something similar on this list last December but the
> last question by the OP was never really addressed:
>
> http://groups.google.com/group/django-users/browse_thread/thread/162a...
>
> Has any progress been made with regards to handling 413 from within Django?

FWIW, how mod_python handle the Apache LimitRequestBody directive is
wrong. I have it one of my TODO lists to log a bug against mod_python
for it.

The problem is that mod_python doesn't check whether LimitRequestBody
would be triggered before actually calling the mod_python handler.
Thus, that the post data exceeds the limit is only found when
req.read() of mod_python request object is called and a Python
exception is generated because of an unknown read error. Well at least
it normally is an unknown read error. In your case you seem to be
triggered this other Python bug and getting that error instead.

Now, because a read error of some sort is generated, mod_python
handlers would normally see it as an unexpected exception and it would
propagate back and result in a 500 Internal Server Error page rather
than a 413 error back to the client. Whether Django does anything
different or still sends back a 500 error page I don't know.

In comparison, in mod_wsgi where I uncovered this problem with
LimitRequestBody, the code checks to see if LimitRequestBody would be
triggered before calling the WSGI application. If triggered the code
immediately returns without calling the application, returning the 413
error. If an ErrorDocument for 413 is defined that would then be
invoked, else the standard Apache 413 error page would be returned.

In summary, mod_python LimitRequestBody handling is broken. Even when
fixed, it would result in it being detected before Django is even
called and thus only custom error page can be one setup using
ErrorDocument directive of Apache. This ErrorDocument directive would
reference a Django URL if desired.

Only other choice when using mod_python is not to use Apache
LimitRequestBody directive and for your actual Django URL handler to
check Content-Length of request itself and generate an appropriate 413
error page. You wouldn't be able to apply it in one go for whole
Django application.

If not bound to mod_python because of need to use it for custom
authentication/authorisation handlers connected to Django, you might
also try using mod_wsgi instead, where the LimitRequestBody directive
isn't a problem.

Hope this helps to explain the issue.

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: Model code generator

2007-07-29 Thread James Bennett

On 7/29/07, dsinang <[EMAIL PROTECTED]> wrote:
> Is there a Django model code generator which can generate code based
> on a MySQL database schema ?

http://www.djangoproject.com/documentation/django-admin/#inspectdb

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model code generator

2007-07-29 Thread dsinang

Hello,

Am a Django newbie.

Is there a Django model code generator which can generate code based
on a MySQL database schema ?

Regards,
Danny


--~--~-~--~~~---~--~~
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: Organising django projects

2007-07-29 Thread Almad


>  Has this been discussed before? What are the dev's feelings on this?

I'd like to hear them too.

> -justin

Almad


--~--~-~--~~~---~--~~
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: db mock for unit testing

2007-07-29 Thread Andrey Khavryuchenko

Malcolm,

 MT> That isn't an answer to the question Russell asked, though. You can get
 MT> exactly the same end-effect (using in-memory SQLite) if you specify
 MT> SQLite as the database engine in the settings file you use for testing.
 MT> Deriving your testing settings file from the main settings file is just
 MT> a matter of importing and replacing the right variable.

 MT> The advantage of specifying SQLite directly (and the drawback to trying
 MT> to "fake it") is that Django won't inadvertently use any MySQL- or
 MT> PostgreSQL-specific SQL constructs under the covers when calling the
 MT> database. There are places we consider the value of
 MT> settings.DATABASE_ENGINE when constructing the SQL and we may leverage
 MT> that more in the future.

 MT> So what advantages are there to the mocking approach over just replacing
 MT> the setting?

Ok, I'll be more wordy.

I'm not using django's testing framework for several reasons:
 - I'm using django from 0.91 days and wasn't following django-users all
   this way
 - I use nose and twill for testing and they have no ready-to-use plugs
   into django testing (or I haven't been able to find it)

Also simply overriding DATABASE_ENGINE to sqlite leads to problems.
E.g. my code has 
   profiles = models.User.objects.extra(where=[
"'%s'" % identity_url + "like concat(login, '%%')"])
But sqlite has no concat function and straightforward approach will lead to
an exception.  Thus 
sqlite_conn.connection.create_function('concat', 2,
   lambda *args: ''.join(args))
in DbMock setup.

So, back to business..  

My intention was to speedup unit tests and make initial test data setup
easier.  I am not proficient in django testing framework and couldn't
utilize it with nosetests.  DbMock solves my issue.

Sure, I may be wrong and the proper way is to write nose test runner
and file patches that provide more mysql or postgresql compatability for
testing.

-- 
Andrey V Khavryuchenko
Django NewGate -  http://www.kds.com.ua/djiggit/
Development - http://www.kds.com.ua 
Call akhavr1975 on www.gizmoproject.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Filter to find closest match

2007-07-29 Thread Michael

On 7/29/07, Tim Chase <[EMAIL PROTECTED]> wrote:
>
> > currently I using filter to find closest match:
> > step=100
> > w=2000 # get it from forms.
> > value=pricelist.pricelisttable_set.filter(width__gte=w-step,width__lte=w+step)[0]
> >
> > The problem is that "step" is different for different tables so
> > sometimes getting more values or none.
> >
> > What would be the best way to find the closest match?
>
> I have no idea what the Excel logic (or lack there of) may or may
> not have been.  Without Excel on my Linux box, it's hard to test,
> and even if I did have Excel, there was no data against which to
> test and see what the above formula should have done.  :)

The same formula work on OpenOffice or Gnumeric on my linux box :)
( running Excel on wine )

The whole idea to find the value in DB which is closest to to value
which we give at request.

let say we have a table:

width, heght1, heugth2
100, 210, 310, ...
200, 250, 280, ...
350, 260, 290, ...
520, 420, 460, ...
..

Now we'geot some number let say  width=240 so the closest match in
that case will be 200.

In pure sql  we can do :
"select min(abs(width-150)) from quote_pricelisttable where name_id =
1 and width >= 240-150 and width <=240+150;"


How to make it work properly from django ORM?

-- 
--
Michael

--~--~-~--~~~---~--~~
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: Looping through my POST data?

2007-07-29 Thread Alvin

That is what programming language? Note you can name what? 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
-~--~~~~--~~--~--~---



Wrong assertion in __init__ of ValidationError?

2007-07-29 Thread Gilbert Fine

This is from django r5773:

class ValidationError(Exception):
def __init__(self, message):
"ValidationError can be passed a string or a list."
if isinstance(message, list):
self.messages = ErrorList([smart_unicode(msg) for msg in
message])
else:
assert isinstance(message, basestring), ("%s should be a
basestring" % repr(message))
message = smart_unicode(message)
self.messages = ErrorList([message])

def __str__(self):
# This is needed because, without a __str__(), printing an
exception
# instance would result in this:
# AttributeError: ValidationError instance has no attribute
'args'
# See http://www.python.org/doc/current/tut/node10.html#handling
return repr(self.messages)


I don't understand the line:
assert isinstance(message, basestring), ("%s should be a basestring" %
repr(message))

I think it should be OK if message is an instance of Promise. And
usually the message IS instance of Promise if using i18n.


--~--~-~--~~~---~--~~
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: Question about {% url %}

2007-07-29 Thread Malcolm Tredinnick

On Sun, 2007-07-29 at 06:55 +, ZhangshenPeng wrote:
> when you use url pattern [a-z]+ and named it , then use in {% url
> %} ,everything is all right .
> when I change
> [a-z]+
> into
> (title|attachment|date)
> django report error "unbalanced parenthesis".
> how to fix my code to do the right thing ?
> think
> 
> code as below
> ###
> url.py:
> 
> urlpatterns = patterns('',
> url(
>   r'^order_by_(?P-?(title|attachment|date))/(?
> P[0-9]+)/',
>   object_list,
>   name="white_paper_list"
>),
> )

I suspect this is caused by the slightly limited reverse reg-exp parsing
we have at the moment. Ticket #2977 has a patch to try and fix this.
Hopefully I'll be checking in something very close to that this week. In
the meantime, you might want to try the patch on your local system to
see if it does handle that case.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Question about {% url %}

2007-07-29 Thread ZhangshenPeng

when you use url pattern [a-z]+ and named it , then use in {% url
%} ,everything is all right .
when I change
[a-z]+
into
(title|attachment|date)
django report error "unbalanced parenthesis".
how to fix my code to do the right thing ?
think

code as below
###
url.py:

urlpatterns = patterns('',
url(
r'^order_by_(?P-?(title|attachment|date))/(?
P[0-9]+)/',
object_list,
name="white_paper_list"
 ),
)

template.htm:

update

error message:

Traceback (most recent call last):
File "" in ?

  error at /white_paper/order_by_date/1/
  unbalanced parenthesis


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---