Re: Lookup by week

2006-01-30 Thread Max Battcher


Adrian Holovaty wrote:

On 1/30/06, Jan Rademaker <[EMAIL PROTECTED]> wrote:

Would it make sense to implement such a thing? An alternative would be
to figure out at what date a week starts and ends and just use
pub_date__range, but that's not really the point. I'm just curious how
easy/hard it would be to implement.

If the above isn't going to work, what's the best/most elegant way to
go, __range?


Yeah, I'd suggest calculating the week start/end dates in your own
code and using the __range lookup. Weeks are a bit of a messy problem
-- different people have different definitions of when they start,
etc.


Then, if weeks are implemented, you start to get requests for fortnights 
and scores...


--
--Max Battcher--
http://www.worldmaker.net/


Re: Extending User

2006-01-30 Thread Roberto Aguilar

I've done this with the latter approach.  I made a person model that
had more person-specific information and made the user field a foreign
key and added the edit_inline option to have the information right
there in the user interface:

user = meta.ForeignKey(auth.User, edit_inline=meta.STACKED,
num_in_admin=1, max_num_in_admin=1)

This works pretty well for me at least.

-berto.

On 1/30/06, char <[EMAIL PROTECTED]> wrote:
>
> I've seen a couple of approaches on this mailing list for adding
> application specific fields to the User class. The first involves
> extending auth.User but this seems a little complex, and was
> specifically labeled an "advanced" method. It doesn't seem like you
> should have to break out deep black magic to do something so standard.
>
> The other method is to have a foreign key pointing to a User. This is
> easier but it makes for a messy Admin interface (resulting in both a
> User class and a separate MyUser class that needs to be associated with
> a User). What is the "canonical" way for extending atuh.User with
> application specific fields?
>
>


Re: Extending User

2006-01-30 Thread char

That did it. Thanks.



Extending User

2006-01-30 Thread char

I've seen a couple of approaches on this mailing list for adding
application specific fields to the User class. The first involves
extending auth.User but this seems a little complex, and was
specifically labeled an "advanced" method. It doesn't seem like you
should have to break out deep black magic to do something so standard.

The other method is to have a foreign key pointing to a User. This is
easier but it makes for a messy Admin interface (resulting in both a
User class and a separate MyUser class that needs to be associated with
a User). What is the "canonical" way for extending atuh.User with
application specific fields?



Re: error restoring project

2006-01-30 Thread Luke Skibinski Holt

Ah excellent - I think it's natural to presume after fixing a bunch of
errors and updating paths after restoring from backup to a new dir that
the fault is more than likely on your end than with product.

For anyone who follows, 'ordering' should be a list and look like:

class META:
ordering=['title']
...


Luke Skibinski Holt



Re: possible to validate a subset of a model's fields?

2006-01-30 Thread Julio Nobrega

  You could pickle (as in, serialize) the data and save on the
database. Then just unpickle when you need to view it.

On 1/30/06, Oliver Rutherfurd <[EMAIL PROTECTED]> wrote:

> Thanks for the suggestion, but saving to the db after every page is a
> requirement of the app.  If someone fills out a page and comes back a
> week, or even a year later, everything they previously entered should
> be in the db.

--
Julio Nobrega - http://www.inerciasensorial.com.br


Re: possible to validate a subset of a model's fields?

2006-01-30 Thread Oliver Rutherfurd

Hi Amit,

On 1/30/06, Amit Upadhyay <[EMAIL PROTECTED]> wrote:
> On 1/31/06, Oliver Rutherfurd <[EMAIL PROTECTED]> wrote:
> > The use case for this is a long registration process, where different
> > data points from individual models are split across multiple pages.
> > The application needs to save data collected after every step, so the
> > user doesn't have to start from scratch if they leave the site and
> > return later.  As a silly example, let's say that name is collected on
> > page 1, phone # on page 2.  Both are required and both live in a
> > 'person' table -- and I want to save the model after page 1.
>
> I would recommend creating your own FormManipulators, one for each page.
> Validate page level manipulator and save the content in request.session, and
> when you are done on the last page, pick out all the saved temproary states
> and insert it in the database.

Thanks for the suggestion, but saving to the db after every page is a
requirement of the app.  If someone fills out a page and comes back a
week, or even a year later, everything they previously entered should
be in the db.

-Ollie


Re: Error when relating a model to another model more than once

2006-01-30 Thread Russell Keith-Magee
On 1/31/06, Rudolph <[EMAIL PROTECTED]> wrote:
Hi,I'm using the development version of Django (trunk) and I've got twosimple classes. The Language class should contain the two letterlanguage abbreviations and the full name of the language in English.
The LanguageTranslation class should contain translated names of thelanguages:I haven't had this specific problem myself, but I think I _might_ know the cause of the problem (I don't know for sure, but it seems possible).
When Django discovers a ForeignKey in a model, it puts a  'related' field in the model that is referenced. The name that Django uses for the related field is the name of the table that is referenced (in this case, 'language'). However, if you have two foreign keys referencing the same class, you end up with colliding related fields - which Django doesn't detect.
The simple solution is to use related_name on the foreign key(s) in your model:...    namelang = meta.ForeignKey(Language, verbose_name='Language of thetranslation', related_name='namelang')...

I have recently added code to the magic-removal branch to detect this sort of model problem. In the meantime, just add the related_name.
Like I said - I haven't had this specific problem myself, but I can see how a field ambiguity like this might cause all sorts of problems in admin UIs, etc.Hope this helpsRuss Magee %-)


Re: possible to validate a subset of a model's fields?

2006-01-30 Thread Amit Upadhyay
On 1/31/06, Oliver Rutherfurd <[EMAIL PROTECTED]> wrote:
The use case for this is a long registration process, where differentdata points from individual models are split across multiple pages.The application needs to save data collected after every step, so theuser doesn't have to start from scratch if they leave the site and
return later.  As a silly example, let's say that name is collected onpage 1, phone # on page 2.  Both are required and both live in a'person' table -- and I want to save the model after page 1.
I would recommend creating your own FormManipulators, one for each page. Validate page level manipulator and save the content in request.session, and when you are done on the last page, pick out all the saved temproary states and insert it in the database.
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: Template inheritance problem

2006-01-30 Thread PythonistL

Adrian,
Thank you for your reply. I still have problems with template
inheritance
Can you please help me with the following?

I have the Index1.html
##Index1.html#
{% extends "board/test" %}
 {% block title %}Tittle from Index.html {% endblock %}
This is a text from Index1.html
 {%block mine%}Hello from Index1{%endblock%}
Text at the end
##

and a test.html file
###test.html



{% block title %}Tittle from test.html{% endblock %}



This is a text from test.html
{%block mine%}Hello from test.html {%endblock%}


I use this view with the template


def TestTemplate(request):
return render_to_response('board/Index1')


I would expect that the title should be
Tittle from test.html

but it shows still
Tittle from Index.html
Why?

Also no text( except that in block tags in Index1.html) is
printed.Why?
Thank you for help
Rregards,
la.



Oracle support?

2006-01-30 Thread Robert Hicks


On the Django site it lists the currently implemented databases and say 
"more to come soon".


Is Oracle on that list? And relatively speaking, how "soon" is soon?

Robert



Re: What is save to use in __repr__

2006-01-30 Thread Jan Rademaker

A bit of code would have clarified my problem. This is what I tried the
first time:

return "Testing %s %s %.2f" % (self.someForeignKey.someThing(),
self.somedate.strftime("%d-%m-%Y"), self.someFloat)

There were 2 problems, basically. First, I tried to access an object
instance directly and not through get_(), but that's going to be fixed
somehow, or so I've heard on #django.

Second, the date field I use has auto_now_add=True (see Maniac's
comment) that's causing problems. Would you consider this a bug? It
'feels' wrong. Right now, these kind of issues don't really bother me,
I'm just trying to find out if django is right for me, but could
something like this make it to 1.0?

Regards,

-janr



Re: FileField :: mx file size

2006-01-30 Thread Maniac


Waylan Limberg wrote:


I envision a simple script that intercepts the
upload submit, checks the actual file size against the specified limit
(perhaps in a hidden field or hard coded in script or even via an ajax
request (but why?)) and either returns an error message or submits the
upload.

No, those projects use Ajax to periodically poll the server about how 
many bytes already uploaded. This is why the server should feed data to 
the framework as soon as it receives them and not after it already have 
got everything. Then your application code on server can really know how 
much data it's going to get (from Content-Length) and the store data 
being received to some known location in memory or on disk and tell to 
parallel Ajax request the progress.


Re: What is save to use in __repr__

2006-01-30 Thread Adrian Holovaty

On 1/30/06, Jan Rademaker <[EMAIL PROTECTED]> wrote:
> What is save to use __repr__ ?
>
> I've found out that I shoud use self.get_someForeignKey().someThing()
> instead of self.someForeignKey.someThing(), but what about date fields
> and such?
>
> Because, when I use self.someDateField in __repr__ django crashes the
> moment _add_ a new object (using admin).

This isn't a Django problem; it's a basic Python rule that any
__repr__() method must return a string. For that reason, you should
make sure that __repr__() returns a string, not an object instance or
(in the case of date fields) a datetime object.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Re: What is save to use in __repr__

2006-01-30 Thread Roberto Aguilar

I ran into the same thing in a model with a ForeignKey to an auth.User
object.  In my __repr__ function I had:

self.get_user()

which would crash Django.  In this instance, I wanted the username
specifically, so I resorted to using:

self.get_user().username

I didn't try, but I think this would have worked as well:

str(self.get_user())

I think the reason it crashed is because __repr__ should return a
string, not an object, so if you explicitly "stringify" the object,
you should be fine.  In your case, try:

str(self.someForeignKey().someThing())

-berto.

On 1/30/06, Jan Rademaker <[EMAIL PROTECTED]> wrote:
>
> What is save to use __repr__ ?
>
> I've found out that I shoud use self.get_someForeignKey().someThing()
> instead of self.someForeignKey.someThing(), but what about date fields
> and such?
>
> Because, when I use self.someDateField in __repr__ django crashes the
> moment _add_ a new object (using admin).
>
> The field is declard as:
> datum = meta.DateTimeField(auto_now_add=True)
>
> Error: TemplateSyntaxError: Caught an exception while rendering.
>
> - janr
>
>


Re: FileField :: mx file size

2006-01-30 Thread Waylan Limberg

On 1/30/06, Amit Upadhyay <[EMAIL PROTECTED]> wrote:
> On 1/30/06, Maniac <[EMAIL PROTECTED]> wrote:
> >
> > Amit Upadhyay wrote:
> >
> > > It would be good to have a general django wide setting specifying the
> > > maximum length allowed for POST data, if underlying server allowed it.
> >
> > Django just doesn't control these things. Read my answer in this very
> > thread, it's http-server and browser that don't let it happen.
> >
>
> Umm.. I have not done any research on this, but if that was the case
> projects like http://sean.treadway.info/demo/upload/ and
> http://encodable.com/filechucker/ wouldn't have been
> possible. May be some webservers do not support it, and maybe there would be
> some issues related to terminating connection if file size is larger, but
> having this may be good.
>
> No time for investigating it right now, but existence of those projects
> imply its doable, even if its a hack, atleast on some servers.
>
>


True, but both of those projects use "AJAX", aka JavaScript. Remember,
your trying to test the size of a file **before** it is uploaded. That
would require doing the check on the client side - which requires
**client side code;** namely, JavaScript. I'm not to up on JS myself
and don't really know what capabilities it has in determining file
size, if any, but I envision a simple script that intercepts the
upload submit, checks the actual file size against the specified limit
(perhaps in a hidden field or hard coded in script or even via an ajax
request (but why?)) and either returns an error message or submits the
upload. Of course, you still have those people who will turn JS off to
bypass the limit, so you still want the server side code to validate
file size and throw away oversized uploads. Perhaps not ideal, but its
an inherit limit of http and (usually) for good reason.

--

Waylan Limberg
[EMAIL PROTECTED]


Re: editable in fields

2006-01-30 Thread Maniac


Tim Terlegård wrote:


To get a non-editable field you can do field = meta.CharField(editable =
False). This is meant for hiding the field, right? Not to make it
readonly in code?
 

It means (as far as I know) that default manipulators will skip it and 
won't complain about their invalidity. So in effect it means that they 
are not intended to be edited by the user but rather set manually in the 
code.


Think for example of some calculated field that can't be blank. You 
shouldn't show it to a user and want to calculate in, say, _pre_save. 
But if editable=False is not set then a manipulator would complain about 
it being empty before attempting to save it.


Re: Error when relating a model to another model more than once

2006-01-30 Thread Rudolph

To be complete, this is the Error page I get:
TypeError at /admin/reg/languages/2/
'bool' object is not callable
Request Method: GET
Request URL:http://localhost:8000/admin/reg/languages/2/
Exception Type: TypeError
Exception Value:'bool' object is not callable
Exception Location:
/usr/lib/python2.4/site-packages/django/core/meta/__init__.py in bind,
line 262

Template error

In template
/usr/lib/python2.4/site-packages/django/contrib/admin/templates/admin/change_form.html,
error at line 52

Caught an exception while rendering.
42  {% block after_field_sets %}{% endblock %}
43  {% if change %}
44  {% if bound_manipulator.ordered_objects %}
45  {% trans "Ordering" %}
46  
47  {% if form.order_.errors %}{{ form.order_.html_error_list }}{%
endif %}
48  {% trans "Order:" %} {{
form.order_ }}
49  
50  {% endif %}
51  {% endif %}
52  {% for related_object in bound_manipulator.inline_related_objects
%}{% edit_inline related_object %}{% endfor %}
53  {% block after_related_objects %}{% endblock %}
54  {% submit_row bound_manipulator %}
55  {% if add %}
56  document.getElementById("{{
bound_manipulator.first_form_field_id }}").focus();
57  {% endif %}
58  {% if bound_manipulator.auto_populated_fields %}
59  
60  {% auto_populated_field_script
bound_manipulator.auto_populated_fields change %}
61  
62  {% endif %}

Traceback (innermost last)

* /usr/lib/python2.4/site-packages/django/core/template/__init__.py
in render_node
   724.
   725. def render_node(self, node, context):
   726. return(node.render(context))
   727.
   728. class DebugNodeList(NodeList):
   729. def render_node(self, node, context):
   730. try:
   731. result = node.render(context) ...
   732. except TemplateSyntaxError, e:
   733. if not hasattr(e, 'source'):
   734. e.source = node.source
   735. raise
   736. except Exception:
   737. from sys import exc_info
  ▶ Local vars
  Variable  Value
  context
  [{}, {'forloop': {'parentloop': {}, 'last': True, 'counter': 2,
'revcounter0': 0, 'revcounter': 1, 'counter0': 1, 'first': False},
'related_object': }, {'block':  '>, , , , '>, , , , , , , , , , ,
, , , , , , , , , , , , , ,
,  '>]>}, {},
{'has_delete_permission': True, 'bound_manipulator':
, 'add': False, 'app_label': 'reg', 'form_url': '',
'change': True}, {'LANGUAGES': (('bn', 'Bengali'), ('cs', 'Czech'),
('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('en', 'English'),
('es', 'Spanish'), ('fr', 'French'), ('gl', 'Galician'), ('is',
'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('nl', 'Dutch'),
('no', 'Norwegian'), ('pt-br', 'Brazilian'), ('ro', 'Romanian'), ('ru',
'Russian'), ('sk', 'Slovak'), ('sr', 'Serbian'), ('sv', 'Swedish'),
('zh-cn', 'Simplified Chinese'), ('zh-tw', 'Traditional Chinese')),
'LANGUAGE_CODE': 'en-us'}, {}, {'perms':
,
'messages': [], 'user': rfroger}, {'is_popup': False, 'original':
English, 'object_id': '2', 'form': {'error_dict': {}, 'edit_inline':
True, '_inline_collections':
[, ], 'manipulator':
, 'order_objects': [], 'data': {'abbreviation': 'en',
'name': 'English', 'languagetranslation.0.id': None,
'languagetranslation.0.translation': '',
'languagetranslation.0.translation_language_id': None, 'id': 2},
'original': English}, 'title': 'Change language'}]
  exc_info
  
  node
  
  self
  [ '>, , , , '>, , , , , , , , , , ,
, , , , , , , , , , , , , ,
,  '>]
  wrapped
  
*
/usr/lib/python2.4/site-packages/django/core/template/defaulttags.py in
render
   104. # boolean values designating first and last times through
loop
   105. 'first': (i == 0),
   106. 'last': (i == len_values - 1),
   107. 'parentloop': parentloop,
   108. }
   109. context[self.loopvar] = item
   110. for node in self.nodelist_loop:
   111. nodelist.append(node.render(context)) ...
   112. context.pop()
   113. return nodelist.render(context)
   114.
   115. class IfChangedNode(Node):
   116. def __init__(self, nodelist):
   117. self.nodelist = nodelist
  ▶ Local vars
  Variable  Value
  context
  [{}, {'forloop': {'parentloop': {}, 'last': True, 'counter': 2,
'revcounter0': 0, 'revcounter': 1, 'counter0': 1, 'first': False},
'related_object': }, {'block':  '>, , , , '>, , , , , , , , , , ,
, , , , , , , , , , , , , ,
,  '>]>}, {},
{'has_delete_permission': True, 'bound_manipulator':
, 'add': False, 'app_label': 'reg', 'form_url': '',
'change': True}, {'LANGUAGES': (('bn', 'Bengali'), ('cs', 'Czech'),
('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('en', 'English'),
('es', 'Spanish'), ('fr', 'French'), ('gl', 'Galician'), ('is',
'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('nl', 'Dutch'),
('no', 'Norwegian'), ('pt-br', 'Brazilian'), ('ro', 'Romanian'), ('ru',
'Russian'), ('sk', 'Slovak'), ('sr', 'Serbian'), ('sv', 

Re: Lookup by week

2006-01-30 Thread Adrian Holovaty

On 1/30/06, Jan Rademaker <[EMAIL PROTECTED]> wrote:
> Would it make sense to implement such a thing? An alternative would be
> to figure out at what date a week starts and ends and just use
> pub_date__range, but that's not really the point. I'm just curious how
> easy/hard it would be to implement.
>
> If the above isn't going to work, what's the best/most elegant way to
> go, __range?

Yeah, I'd suggest calculating the week start/end dates in your own
code and using the __range lookup. Weeks are a bit of a messy problem
-- different people have different definitions of when they start,
etc.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


editable in fields

2006-01-30 Thread Tim Terlegård

To get a non-editable field you can do field = meta.CharField(editable =
False). This is meant for hiding the field, right? Not to make it
readonly in code?

To me hidden is more intuitive than editable. I thought that when so
much was renamed anyway...  :)

Tim


What is save to use in __repr__

2006-01-30 Thread Jan Rademaker

What is save to use __repr__ ?

I've found out that I shoud use self.get_someForeignKey().someThing()
instead of self.someForeignKey.someThing(), but what about date fields
and such?

Because, when I use self.someDateField in __repr__ django crashes the
moment _add_ a new object (using admin).

The field is declard as:
datum = meta.DateTimeField(auto_now_add=True)

Error: TemplateSyntaxError: Caught an exception while rendering.

- janr



Re: FileField :: mx file size

2006-01-30 Thread Maniac


Amit Upadhyay wrote:

No time for investigating it right now, but existence of those 
projects imply its doable, even if its a hack, atleast on some servers.


Hm... Yes, they do it with some patched FCGI code.


Re: FileField :: mx file size

2006-01-30 Thread Adriano Bonat

I think that this is doable, but need to be implemented by an Apache
Hook/Handler.

I've done some searches now for something related with mod_python, but
not found anything, just a link with this same problem but using Perl.

http://www.experts-exchange.com/Web/Web_Languages/CGI/Q_20862752.html

Is a nice thing to be explored :)

-Adriano Bonat

On 1/30/06, Amit Upadhyay <[EMAIL PROTECTED]> wrote:
> On 1/30/06, Maniac <[EMAIL PROTECTED]> wrote:
> >
> > Amit Upadhyay wrote:
> >
> > > It would be good to have a general django wide setting specifying the
> > > maximum length allowed for POST data, if underlying server allowed it.
> >
> > Django just doesn't control these things. Read my answer in this very
> > thread, it's http-server and browser that don't let it happen.
> >
>
> Umm.. I have not done any research on this, but if that was the case
> projects like http://sean.treadway.info/demo/upload/ and
> http://encodable.com/filechucker/ wouldn't have been
> possible. May be some webservers do not support it, and maybe there would be
> some issues related to terminating connection if file size is larger, but
> having this may be good.
>
> No time for investigating it right now, but existence of those projects
> imply its doable, even if its a hack, atleast on some servers.
>
>
> --
> Amit Upadhyay
> Blog: http://www.rootshell.be/~upadhyay
> +91-9867-359-701


Lookup by week

2006-01-30 Thread Jan Rademaker

Hello,

As far is I know it's not possible to query date fields for a cerain
week number, eg.

# Select all polls from week 5, 2006
polls.get_list(
pub_date__year=2006,
pub_date__week=5
)

Would it make sense to implement such a thing? An alternative would be
to figure out at what date a week starts and ends and just use
pub_date__range, but that's not really the point. I'm just curious how
easy/hard it would be to implement.

If the above isn't going to work, what's the best/most elegant way to
go, __range?

- janr



Re: FileField :: mx file size

2006-01-30 Thread Amit Upadhyay
On 1/30/06, Maniac <[EMAIL PROTECTED]> wrote:
Amit Upadhyay wrote:> It would be good to have a general django wide setting specifying the> maximum length allowed for POST data, if underlying server allowed it.Django just doesn't control these things. Read my answer in this very
thread, it's http-server and browser that don't let it happen.Umm.. I have not done any research on this, but if that was the case projects like 
http://sean.treadway.info/demo/upload/ and http://encodable.com/filechucker/ wouldn't have been possible. May be some webservers do not support it, and maybe there would be some issues related to terminating connection if file size is larger, but having this may be good. 
No time for investigating it right now, but existence of those projects imply its doable, even if its a hack, atleast on some servers.-- Amit UpadhyayBlog: 
http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: FileField :: mx file size

2006-01-30 Thread Maniac


Amit Upadhyay wrote:

It would be good to have a general django wide setting specifying the 
maximum length allowed for POST data, if underlying server allowed it.


Django just doesn't control these things. Read my answer in this very 
thread, it's http-server and browser that don't let it happen.


Re: error restoring project

2006-01-30 Thread Max Battcher


Luke Skibinski Holt wrote:

my hd failed the other day taking my db with it. I'm trying to restore
my project now, but I'm getting this error in the admin app:

ERROR: missing FROM-clause entry for table "auth_users" SELECT
"blogs_blogs"."user_id","blogs_blogs"."title","blogs_blogs"."desc","blogs_blogs"."entriespp","blogs_blogs"."disabled"
FROM "blogs_blogs" ORDER BY "auth_users"."username" DESC


This is a known issue (http://code.djangoproject.com/ticket/930) dealing 
with the One-To-One relationship.  The SQL is not creating the proper 
JOIN for the default ordering and you need to explicitly create an 
ordering='title' in your Meta class so that is isn't ordering based on a 
field in the other class.


I'm assuming this isn't being fixed right now because the Subclassing 
system will replace it.


--
--Max Battcher--
http://www.worldmaker.net/



Re: Template inheritance problem

2006-01-30 Thread PythonistL

Adrian,thank you for your reply.
Yes, they  both are in the same (board) directory.
So, what shall I try to find out the reason why it doesn't work?
Thank you
Regards,
L.



Re: FileField :: mx file size

2006-01-30 Thread Eric Walstad

On Sunday 29 January 2006 20:29, arthur debert wrote:
> is there a way to check for this BEFORE the file
> is uploaded?

On Monday 30 January 2006 08:15, Adrian Holovaty wrote:
> On 1/30/06, tonemcd <[EMAIL PROTECTED]> wrote:
> > So does this happen *before* the file is uploaded - I mean when the
> > submit button is pressed? It seems that Django will be getting
> > information from the browser about the length of the data to be
> > uploaded - and that's something I've always thought HTTP could not
> > do...
>
> As far as the validator I posted, it does the validation *before* the
> file is saved to the filesystem, when it is still in memory.

But that is *after* all the file bits have been sent from the browser to the 
server.  Right?  My understanding is that the op wants to keep bandwidth 
under control by refusing to allow files greater than N bytes from ever 
entering memory.  I've not yet found a way to do so; in the past, I've had to 
examine the size of the uploaded file after it has arrived at the server in 
its entirety.  It works, but the consumed bandwidth was wasted for files that 
exceeded the size limit as the bits were simply tossed.


Re: FileField :: mx file size

2006-01-30 Thread tonemcd

Cheers Adrian, that's very handy to know..

Tone



validators combined

2006-01-30 Thread Jiri Barton

I have two text input fields in a form. At least one of them is
required. My question is, how can I check for this?

class MyManipulator = (formfields.Manipulator):

def __init__(self, request=None):
self.fields = [
formfields.TextField(
field_name='apples',
length=5,
),
self.fields = [
formfields.TextField(
field_name='pears',
length=5,
),
]

The problem is, I cannot use is_required=True. I can use another field
and make it is_required=True and define another validator - this is
what I'm doing now:


self.fields =
.
formfields.TextField(
field_name='basket',
length=5,
is_required=True,
validator_list=[apples_or_pears],
),


   def apples_or_pears(self, field_data, all_data):
if not all_data.get('apples', '') and not
all_data.get('pears', ''):
raise validator.ValidationError, _('bummer - what
now?')


This is a hack and has several drawbacks, such as it does not belong to
the correct field, and is within an unexpected field's validator list.

Thank you for your suggestions.
Jiri



Re: mod_python installation problems

2006-01-30 Thread Adrian Holovaty

On 1/30/06, treelife <[EMAIL PROTECTED]> wrote:
> Firstly, Debian 3.1 does not have a python2.4 version of the software
> for Apache2.0 and when I install the 2.3 version Apache is giving me
> some ".. Segmentation fault (11)".

Try disabling the PHP Apache module. There are some known issues when
PHP and mod_python are enabled at the same time.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Re: FileField :: mx file size

2006-01-30 Thread Adrian Holovaty

On 1/30/06, tonemcd <[EMAIL PROTECTED]> wrote:
> So does this happen *before* the file is uploaded - I mean when the
> submit button is pressed? It seems that Django will be getting
> information from the browser about the length of the data to be
> uploaded - and that's something I've always thought HTTP could not
> do...

As far as the validator I posted, it does the validation *before* the
file is saved to the filesystem, when it is still in memory.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Re: assign or rename a variable in templates

2006-01-30 Thread tonemcd

Bryan,
If you can handle Zope PageTemplates, the plugin from Stefan might be
useful: http://www.zope.org/Members/shh/DjangoPageTemplates

That allows for variable creation, but of course you don't get the
django templates...

Cheers,
Tone



Re: FileField :: mx file size

2006-01-30 Thread tonemcd

Amit,
I think that's more a progress 'barber pole' widget than something
which will detect the length of a file and drop the connection if it's
over a certain size (although it's hard to tell...)

Cheers,
Tone



Re: FileField :: mx file size

2006-01-30 Thread Maniac


Adrian Holovaty wrote:


   def isSmallFile(self, field_data, all_data):
   if len(field_data["content"] > 1: # 10,000 bytes
   raise validators.ValidationError, "Please enter a smaller file."

The trick here is to operate on field_data['content'] instead of
field_data. File-upload fields are a special-case; they come across as
a dictionary of {'filename', 'content-type', 'content'}.
 

If you can do len(filed_data['content']) then this content is already 
has been uploaded on the server. At present the only way to know the 
size of data before they are uploaded is the Content-Length header sent 
by browsers. It also depends on server environment if it passes the 
control to a script before all the POST data has been received. I have 
an impression that Apache doesn't do it (thought I didn't check 
properly). And even if it did then the only way to prevent user to 
download anything is to break the connection. Which also generally 
impossible with http servers and would look ulgy in a browser that just 
sends data and doesn't expect anything sane to happen before upload 
finishes. So it would just show some network error message.


I saw some discussions about specifying content size restriction in 
future browsers on a WHAT WG list 
(http://listserver.dreamhost.com/pipermail/whatwg-whatwg.org/) but it 
didn't end up in anything yet.


Re: image field update impossible.

2006-01-30 Thread [EMAIL PROTECTED]

thank you mary !

MEDIA_ROOT = '/home/greg/Projects/woot/'
with 'postimgs' as the path in imagefield allow editing without error.



error restoring project

2006-01-30 Thread Luke Skibinski Holt

my hd failed the other day taking my db with it. I'm trying to restore
my project now, but I'm getting this error in the admin app:

ERROR: missing FROM-clause entry for table "auth_users" SELECT
"blogs_blogs"."user_id","blogs_blogs"."title","blogs_blogs"."desc","blogs_blogs"."entriespp","blogs_blogs"."disabled"
FROM "blogs_blogs" ORDER BY "auth_users"."username" DESC

I'm getting it for both of my apps installed, both having one-to-one
relationships with the user. Other models within those apps that don't
have any relationship to the user (but to other models) are not
failing.

The steps I took to restore my project were
create database
manage.py init
manage.py createsuperuser
manage.py install admin
manage.py install 

I'm using the latest revision as of this posting. Any ideas on what is
going wrong? Did I miss something or do something in the wrong order?


Luke Skibinski Holt



mod_python installation problems

2006-01-30 Thread treelife

Many people seem to have some difficulties configuring apache
mod_python, at least initially to work with Django.  I have also had
these initial configuration difficulties, but have successfully
configured it on my local box, which runs Suse 9.3.

However, I am having real difficulties just installing it on my live
web server which runs Debian 3.1 and Apache 2.0.x  ( I believe x=.54)

Firstly, Debian 3.1 does not have a python2.4 version of the software
for Apache2.0 and when I install the 2.3 version Apache is giving me
some ".. Segmentation fault (11)".

I would be grateful for any help, as I really want to get back to doing
some web development, but find myself spending all my time trying to
get the requisite software installed.

Sincerely



Re: image field update impossible.

2006-01-30 Thread mary

u have to check your media_root that is in settings.py
cause i think the problem is that he can't find the right path for your
media files
and the right path had to be media_root path+ the path of upload_to
[EMAIL PROTECTED] wrote:
> It doesn't solve the problem, i can't still override the image with a
> new one, an invalid filename error rise.
> see there http://img95.imageshack.us/img95/4536/see9za.png.