Re: Django + Cherokee Web Server

2009-11-26 Thread Jarek Zgoda
Wiadomość napisana w dniu 2009-11-27, o godz. 00:31, przez  
hcarvalhoalves:

> I'm able to configure Cherokee to run my Django project correctly,
> using the included wizard. The problem is, if an exception is thrown,
> Cherokee just shows a "Unhandled Exception" page. I figured out that
> if I run fcgi with debug=true, then I get a stacktrace from Flup, but
> I wanted the default Django behaviour (showing debug pages when
> DEBUG=TRUE on settings.py), similar to Apache or the development
> server.


This is not the response from web server, nor Django - this page is  
served by Flup. This indicates the error at the stage of loading  
Django machinery (eg. some problem with settings.py) and can not be  
passed to Django's error handling because Django is simply not yet  
loaded or not initialized properly. The only possible way to get any  
debugging information is to turn on FastCGI debug.

-- 
Artificial intelligence stands no chance against natural stupidity

Jarek Zgoda, R&D, Redefine
jarek.zg...@redefine.pl

--

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




Re: Error when generating PDF

2009-11-26 Thread Skylar Saveland
>    Paragraph(rack.nick, normalstyle, bulletText=None),

Yep, rack.nick is None here it would seem.  Like Karen said, don't
have nullable CharField if you can help it;  blank=True is good and
then and empty will be "".  I have a dirty hack for you that should
'work'.

Paragraph(  rack.nick if rack.nick else "", normalstyle,
bulletText=None )

but avoid using null, 
http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.null
for a CharField if that's what led to this.

--

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




Setting a fontName in a style

2009-11-26 Thread adelaide_mike
One final question if I may (well I hope its the last).

In my  standard report generating view I need to use Arial font (for
example).

I have studied the reportlab docs (Paragraphs chapter) for hours and
tried all sorts of guesses as to how to do it.  Nothing I have tried
works. My fault.  Now insightful enough.

I have the following in my report generating view (which works a
treat) and I am sure there is a simple alteration that will change the
font.  But there is no example in the docs AFAIK.

stylesheet = getSampleStyleSheet()
normalstyle = stylesheet['Normal']

Any offers?

Mike

--

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




Re: Newbie: is it possible to re-render a tag/filter after adding it to the web page as string

2009-11-26 Thread Skylar Saveland

>
> I'm reading a string value that is stored in my database. This string
> the main content of my webpage and it contains contents like
> javascript, css styling, and django template tags/filters.
>
> After I load string value by {{ stringValue|safe }} filter, everything
> is added to the page just as text; Javascript, css styling, template
> tags/filters all show up on the page.
>
> Can anyone tell me how I can load the content and execute/render the
> javascript, css styling, template tags/filters?

+1 for this sounding pretty weird.  But you might do the rendering and
manipulation in the view before rendering it to the template and get
what you want.

http://docs.djangoproject.com/en/dev/ref/templates/api/#compiling-a-string

Also, the little autoescape filter might help you prevent Django from
preventing you from blasting your foot off ;).
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape

bon voyage!

--

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




Re: Write debug error to file

2009-11-26 Thread akonsu
hello,

if you set the admin email address and the necessary email parameters
in your config file then django will send an email with all the
details to the admin when an exception is thrown. would this be
sufficient?

konstantin

On Nov 26, 11:15 am, Gabriel Rossetti 
wrote:
> Hello everyone,
>
> I'd like to write the django error page (when debug == true) to a file
> and return a page with that link instead of the actual page. The reason
> I'd like to do this is to be able to debug a facebook app because fb
> seams to filter/block the error page. Does anyone know how to do that?
>
> Thanks,
> Gabriel

--

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




Re: Show field labels instead of names in form error lists

2009-11-26 Thread Skylar Saveland

On Nov 27, 1:27 am, Yang Zhang  wrote:
> What's the easiest way to have error lists describe fields using their
> labels instead of their names? Thanks in advance.

I don't think that I understand your question.  Is there something to
it that isn't covered in 
http://docs.djangoproject.com/en/dev/topics/forms/#customizing-the-form-template
?

--

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




Re: admin for "regular" users - still a bad idea?

2009-11-26 Thread Skylar Saveland
> each user has their own table in the
> db for transactions, and they can do whatever they want to their own
> data. i wouldn't want them to be able to touch anyone else's tables,
> but it seems like django has a permissions system to restrict that.

ha, reading lists on mobile ... I didn't even see that you said that
each user has their own table (still hard to see exactly how this is
efficient/possible/done though).  I think it's still a bad idea.
Don't let untrusted users log into the admin is a general rule that
I've seen tossed around.

--

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




Re: admin for "regular" users - still a bad idea?

2009-11-26 Thread Skylar Saveland
> I don't
> believe you can do inline formsets with generic views, which is
> unfortunate, but it's not hard with a simple custom view.

well, perhaps not automagically, but you can just send extra_context
and then do a little bit of custom work ``if request.method == POST``.

--

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




Re: admin for "regular" users - still a bad idea?

2009-11-26 Thread Eric Abrahamsen


On Nov 27, 11:50 am, Count László de Almásy  wrote:
> ok, fair enough. does generic views have the machinery to replicate
> the admin interface?

Generic views take most of the pain out of CRUD, and also take care of
producing and validating forms. You can also steal some of the nice
javascript widgets out of the admin code. You've still got to do the
templating yourself, though, which means that most of the
functionality that you can presently put into admin.py (things like
how the changelists are displayed and filtered, how the forms are laid
out, not to mention admin actions) you'll have to do yourself. I don't
believe you can do inline formsets with generic views, which is
unfortunate, but it's not hard with a simple custom view.

All in all, I've found that doing my own admin functionality really
isn't hard at all, and you suddenly have a huge amount of freedom; the
only real pain in the ass is that you're starting from scratch with
the html and css. Boring!

Eric

>
> On Nov 26, 7:28 pm, Skylar Saveland  wrote:
>
>
>
> > Yep, still a bad idea.  Permissions are by table not by row.  Use
> > generic views for basic CRUD.
>
> > Count László de Almásy wrote:
>
> > > i've seen notes in some django documentation that implies that using /
> > > admin/ for non-trusted users is not a good idea. which is unfortunate
> > > since it seems like the admin interface is about 95% of what i want
> > > for my users to be able to view and manipulate their sales
> > > transactions data over the web. each user has their own table in the
> > > db for transactions, and they can do whatever they want to their own
> > > data. i wouldn't want them to be able to touch anyone else's tables,
> > > but it seems like django has a permissions system to restrict that.
>
> > > with the latest django, is it still considered a bad idea to do this?
> > > if so, what is the alternative, writing custom views to mimic what the
> > > admin interface does?

--

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




Show field labels instead of names in form error lists

2009-11-26 Thread Yang Zhang
What's the easiest way to have error lists describe fields using their
labels instead of their names? Thanks in advance.
-- 
Yang Zhang
http://www.mit.edu/~y_z/

--

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




Re: Newbie: is it possible to re-render a tag/filter after adding it to the web page as string

2009-11-26 Thread Andy McKay

> Can anyone tell me how I can load the content and execute/render the
> javascript, css styling, template tags/filters?

You really shouldn't be doing this. One string is everything on your  
page? You can use the Template library to re-render a template and  
that's discussed in the templating docs - but I wonder why you are  
doing that in the first place.

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

--

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




Re: Error when generating PDF

2009-11-26 Thread Andy McKay
You are passing through None to reportlab, not a string. Follow the  
traceback and you will find the line in your code where the error  
occurs.

--
   Andy McKay
   www.clearwind.ca

On 2009-11-26, at 5:40 AM, adelaide_mike   
wrote:

> In my report generating view I have this (snip):
>
> if tablename == 'Area':
>areas = Area.objects.all()
>data.append(['Code','Name','Description'])
>for area in areas:
>data.append([
>Paragraph(area.area, normalstyle, bulletText=None),
>Paragraph(area.nick, normalstyle, bulletText=None),
>Paragraph(area.desc, normalstyle, bulletText=None)
>])
>table = Table(data, 1*[0.75*inch]+1*[2.0*inch]+1*[4.0*inch],
> style=ts)
>
> elif tablename == 'Rack':
>racks = Rack.objects.all()
>data.append(['Code','Name', 'Description'])
>for rack in racks:
>data.append([
>Paragraph(rack.rack, normalstyle, bulletText=None),
>Paragraph(rack.nick, normalstyle, bulletText=None),  #
> thats line 108
>Paragraph(rack.desc, normalstyle, bulletText=None)
>])
>table = Table(data, 1*[1.25*inch]+1*[2.0*inch]+1*[4.0*inch],
> style=ts)
>
> When tablename = "Area" the .pdf is generated without error.  Wnen it
> is "Rack" this error is raised:
>
> Traceback (most recent call last):
>
> File "/home/mrowan/django/django/core/handlers/base.py", line 86, in
> get_response
>   response = callback(request, *callback_args, **callback_kwargs)
>
> File "/home/mrowan/projects/cbm/djcbm/cbm/reports.py", line 108, in
> print_list
>   Paragraph(rack.nick, normalstyle, bulletText=None),
>
> File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 523, in __init__
>   self._setup(text, style, bulletText, frags, cleanBlockQuotedText)
>
> File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 543, in _setup
>   text = cleaner(text)
>
> File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 61, in cleanBlockQuotedText
>   L=filter(truth,map(_lineClean, split(text, '\n')))
>
> File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 23, in split
>   return [uword.encode('utf8') for uword in text.split(delim)]
>
> AttributeError: 'NoneType' object has no attribute 'split'
>
> What does the error message mean?  Can someone translate please? TIA
>
> Mike
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en 
> .
>
>

--

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




Re: Write debug error to file

2009-11-26 Thread Andy McKay
You should take a look at Arecibo which has been used by a few  
Facebook apps for that very readson. It has full Django libraries and  
if you don't use it a full example of how to use middleware to process  
an error.

http://areciboapp.com

--
   Andy McKay
   www.clearwind.ca

On 2009-11-26, at 8:15 AM, Gabriel Rossetti  
 wrote:

> Hello everyone,
>
> I'd like to write the django error page (when debug == true) to a file
> and return a page with that link instead of the actual page. The  
> reason
> I'd like to do this is to be able to debug a facebook app because fb
> seams to filter/block the error page. Does anyone know how to do that?
>
> Thanks,
> Gabriel
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en 
> .
>
>

--

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




Re: admin for "regular" users - still a bad idea?

2009-11-26 Thread Count László de Almásy
ok, fair enough. does generic views have the machinery to replicate
the admin interface?

On Nov 26, 7:28 pm, Skylar Saveland  wrote:
> Yep, still a bad idea.  Permissions are by table not by row.  Use
> generic views for basic CRUD.
>
> Count László de Almásy wrote:
>
>
>
> > i've seen notes in some django documentation that implies that using /
> > admin/ for non-trusted users is not a good idea. which is unfortunate
> > since it seems like the admin interface is about 95% of what i want
> > for my users to be able to view and manipulate their sales
> > transactions data over the web. each user has their own table in the
> > db for transactions, and they can do whatever they want to their own
> > data. i wouldn't want them to be able to touch anyone else's tables,
> > but it seems like django has a permissions system to restrict that.
>
> > with the latest django, is it still considered a bad idea to do this?
> > if so, what is the alternative, writing custom views to mimic what the
> > admin interface does?

--

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




Re: better error handling in templatetags?

2009-11-26 Thread Karen Tracey
On Thu, Nov 26, 2009 at 6:02 PM, KONTRA, Gergely wrote:

> My problem is the error handling of django in templatetags, not the
> specific dummy error, which I programmed:
>
> @register.simple_tag
> def current_time():
>1/0
>return unicode(datetime.datetime.now())
>
> What annoys me, that you cannot find the line number of the error,
> just a message, that somewhere there is an error rendering the
> current_time tag.
>
>
With DEBUG=True, TEMPLATE_DEBUG=DEBUG, I get a TemplateSyntaxError debug
page with exception value:

Caught an exception while rendering: integer division or modulo by zero

Original Traceback (most recent call last):
  File "d:\u\kmt\django\trunk\django\template\debug.py", line 71, in
render_node
result = node.render(context)
  File "d:\u\kmt\django\trunk\django\template\__init__.py", line 909, in
render
return func(*resolved_vars)
  File "D:\u\kmt\software\web\playground\ttt\templatetags\tstuff.py", line
6, in current_time
1/0
ZeroDivisionError: integer division or modulo by zero

So I am seeing the line number of the error reported.  It's (somewhat
annoyingly) not actually in the traceback portion of the page, but it is on
the page.  Are you seeing something different?

Karen

--

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




Newbie: is it possible to re-render a tag/filter after adding it to the web page as string

2009-11-26 Thread Allen
Hi.. I'm a newbie and I have a question about rendering webpage and
executing a tag/filter

I'm reading a string value that is stored in my database. This string
the main content of my webpage and it contains contents like
javascript, css styling, and django template tags/filters.

After I load string value by {{ stringValue|safe }} filter, everything
is added to the page just as text; Javascript, css styling, template
tags/filters all show up on the page.

Can anyone tell me how I can load the content and execute/render the
javascript, css styling, template tags/filters?

Allen

--

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




Re: admin for "regular" users - still a bad idea?

2009-11-26 Thread Skylar Saveland
Yep, still a bad idea.  Permissions are by table not by row.  Use
generic views for basic CRUD.

Count László de Almásy wrote:
> i've seen notes in some django documentation that implies that using /
> admin/ for non-trusted users is not a good idea. which is unfortunate
> since it seems like the admin interface is about 95% of what i want
> for my users to be able to view and manipulate their sales
> transactions data over the web. each user has their own table in the
> db for transactions, and they can do whatever they want to their own
> data. i wouldn't want them to be able to touch anyone else's tables,
> but it seems like django has a permissions system to restrict that.
>
> with the latest django, is it still considered a bad idea to do this?
> if so, what is the alternative, writing custom views to mimic what the
> admin interface does?

--

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




admin for "regular" users - still a bad idea?

2009-11-26 Thread Count László de Almásy
i've seen notes in some django documentation that implies that using /
admin/ for non-trusted users is not a good idea. which is unfortunate
since it seems like the admin interface is about 95% of what i want
for my users to be able to view and manipulate their sales
transactions data over the web. each user has their own table in the
db for transactions, and they can do whatever they want to their own
data. i wouldn't want them to be able to touch anyone else's tables,
but it seems like django has a permissions system to restrict that.

with the latest django, is it still considered a bad idea to do this?
if so, what is the alternative, writing custom views to mimic what the
admin interface does?

--

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




Django + Cherokee Web Server

2009-11-26 Thread hcarvalhoalves
I'm able to configure Cherokee to run my Django project correctly,
using the included wizard. The problem is, if an exception is thrown,
Cherokee just shows a "Unhandled Exception" page. I figured out that
if I run fcgi with debug=true, then I get a stacktrace from Flup, but
I wanted the default Django behaviour (showing debug pages when
DEBUG=TRUE on settings.py), similar to Apache or the development
server.

Anyone knows how to do it?

--

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




Re: How can I change the values of select options created by a ModelForm?

2009-11-26 Thread Skylar Saveland
You're primary question is a little tough, ther are a couple of ways
to go.  I just wanted to mention that your slug might not be unique
the way you have it and you could get IntegrityError.  Also, your
get_absolute_url would be better served with permalink.  Your primary
question, well, I'm just arriving at thanksgiving dinner 


jul wrote:
> hi,
>
> I'm generating, using ModelForm, a form from a Restaurant model, which
> has a Country field.
> Country has a 'code' and a 'name' fields.
> When the form is created in my template, the values of the select
> options are the Country ids. How can I replace them by the Country
> 'code' values. Is it possible to choose which field is used as the
> value by overriding the Country field in the ModelForm?
>
> thanks
>
>
> I have that:
>
> Country:  id="id_country">
> -
> Andorra
> United Arab Emirates
> Afghanistan
>
> and I want that:
>
> Country:  id="id_country">
> -
> Andorra
> United Arab Emirates
> Afghanistan
>
>
> Models and ModelForm:
>
> class Country(models.Model):
> code = models.CharField(max_length=5, unique=True)
> name = models.CharField(max_length=100, unique=True)
>
> class Meta:
> verbose_name_plural = 'Countries'
>
> def __unicode__(self):
> return self.name
>
>
>
> class Restaurant(models.Model):
>
> name = models.CharField(max_length=100)
> country=models.ForeignKey(Country)
> city=models.ForeignKey(City)
> street=models.CharField(max_length=100)
> street_number=models.PositiveSmallIntegerField()
> phone_number=models.CharField(max_length=16, blank=True,
> null=True)
> price_range=models.PositiveSmallIntegerField(blank=True,
> null=True)
> category=models.ManyToManyField(Category, blank=True,
> null=True)
> tag=models.ManyToManyField(Tag, blank=True, null=True)
> slug = models.SlugField(unique=True)
>
> def get_absolute_url(self):
> return "/restaurant/%s/" % self.slug
>
> def __unicode__(self):
> return self.name
>
> def save(self):
> self.slug = slugify(self.name)
> super(Restaurant, self).save()
>
>
> class AddRestaurantForm(ModelForm):
>
> class Meta:
> model = Restaurant
> exclude = ('slug')

--

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




ORM aggregation and group by

2009-11-26 Thread severb
Greetings,

I have two tables: Student and Grade in a one to many relationship.
The Grade table has a field named "grade" which has integers from 0 to
5.
I want to count how many grades of each type each Student has. For
this I'm using a query similar to:
Students.objects.order_by('grades__grade').annotate(n=Count('grades'))
This SQL query does a group by Student.id and Grade.grade and orders
the results by Grade.grade. The result set is something like:
student1  2
student2  4
student3  6
student2  5
student1  3
student2  4
student3  7
As you can see there is no way of telling what grade the count was
for. What I would like is something more like:
student1  2  2
student2  4  2
student3  6  3
student2  5  3
student1  3  4
student2  4  4
student3  7  4
This means I would like somehow to add to the results the column used
in the group by statement.
A hack-ish solution is to use this query instead:
Students.objects.order_by('grades__grade').annotate(n=Count
('grades')).annotate(g=Avg('grades'))
but it doesn't feel right. I've also tried to do a .values
('grades_grade') but values() doesn't seem to work across relations.

Is there a better way to do this using the ORM?
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: better error handling in templatetags?

2009-11-26 Thread KONTRA, Gergely
My problem is the error handling of django in templatetags, not the
specific dummy error, which I programmed:

@register.simple_tag
def current_time():
1/0
return unicode(datetime.datetime.now())

What annoys me, that you cannot find the line number of the error,
just a message, that somewhere there is an error rendering the
current_time tag.

+-[ Gergely Kontra  ]--+
|   |
| Mobile:(+36 20)356 9656   |
|   |
+- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+



On Thu, Nov 26, 2009 at 17:35, Karen Tracey  wrote:
> On Thu, Nov 26, 2009 at 9:09 AM, pihentagy  wrote:
>>
>> Isn't it a known thing, that template tags are hard to debug? Did I
>> miss something?
>
> I don't know, but your original message makes it a little too hard to try to
> help probably.  You say the actual location of the error is missing, but in
> order to see what you are seeing people have to download a zip file from
> somewhere and go to some trouble to unzip and install and figure out what to
> run to recreate the problem, etc.  Why not just post the traceback you are
> getting, along with whatever snippets of the associated code that are
> relevant? You might get better feedback from that.
>
> Karen
>
>>
>>
>>
>> On Nov 11, 11:13 am, pihentagy  wrote:
>> > Hi all!
>> >
>> > I am not satisfied with the error handling inside custom template
>> > tags.
>> > To demonstrate it, I cooked a mini useless app, which can be
>> > downloaded here:
>> >
>> > What I miss from the error screen is the actual location of the error.
>> >
>> > http://cid-a93120a1b42a9e7f.skydrive.live.com/self.aspx/.Public/djang...
>> >
>> > Or did I do something wrong, that I miss the error message?
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--

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




Re: Chart tool

2009-11-26 Thread Skylar Saveland
You might also check out pycha?


S.Selvam wrote:
> On Thu, Nov 26, 2009 at 2:01 AM, Javier Guerra  wrote:
>
> > On Wed, Nov 25, 2009 at 3:07 PM, S.Selvam  wrote:
> > > I need to show some data as a chart.
> > >
> > > I would like to achieve a high quality rendering.
> > >
> > > Is reportlab or matplotlib enough ?
> >
> > reportlab allows you to generate PDFs, which can be as high quality as
> > you want; but if you want to display them on a webpage it's far from
> > the best.
> >
> > matplotlib is nice, being python.  the biggest drawback is that being
> > a server-side task, so you have to deal with the processing time
> > and/or storage/deletion of (old) images.
> >
> > for in-page charts, you can use flot (http://code.google.com/p/flot/),
> > or Google Charts (http://code.google.com/apis/chart/).  the first one
> > is a jQuery plugin, the other is an API that basically lets you
> > construct an URL for a PNG that's rendered on Google servers.  in both
> > cases, you simply put (some of) your data on the page and let either
> > the client (if using flot) or somebody else (if using Google charts)
> > deal with the heavy tasks.
> >
>
>
> Thanks Javier,
>It helped me a lot.
>
>   I have been trying with matplotlib by drawing the resultant chart to
> canvas and attaching it with response.(Hence i dont save the image as a temp
> file ).
>
>
>
> >
> > --
> > Javier
> >
> > --
> >
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
> >
> >
>
>
> --
> Yours,
> S.Selvam

--

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




Re: is_valid error/bug when unique_together fields are both ForeignKey fields

2009-11-26 Thread Nick Arnett
On Thu, Nov 26, 2009 at 9:37 AM, cerberos  wrote:

> I have a model that has two fields (Django 1.1.1)
>
> class FooBar(models.Model):
>foo = models.ForeignKey('Foo')
>bar = models.ForeignKey('Bar')
>
>class Meta:
>unique_together = (('foo','bar'),)
>
> When is_valid is called in my view and the combination of fields
> already exists (eg unique_together is false) the error returned is
> "Foo bar with this None and None already exists."
>
> "None and None" seems like a bug to me, but I'm not sure.


I've seen that kind of error, too and found various references to it when I
searched.  In my case, the problem was an extraneous comma in the code,
which wasn't picked up as a syntax error... which bothers me.  Django seems
to fail to surface some syntax errors and either produces no results or some
other error.

What I think this generally means is that in your view, the object isn't
getting initialized for some reason.  I'm assuming that you get the error
when you try to save.  I'd carefully go over whatever initializes or sets
the data.

Nick

--

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




Re: Ordering over ManyToMany relationship omits records

2009-11-26 Thread David
P.S. id == 6 disappears in ascending and id == 3 disappears in
descending.

It's not a surprise that id == 5 is duplicated because it is the only
Listing__book which has a relationship with two courses, the rest have
a relationship with only one. That part does look suspicious to me
though, as if the duplicate id "swallowing up" the missing records. I
have no clue why though... hope these details help clarify my problem.

On Nov 26, 1:31 pm, David  wrote:
> When I order over a ManyToMany relationship, certain records will not
> appear. The record which disappears changes depending  on the order by
> which I sort it. Specifically:
>
> >>> Listing.objects.order_by("book__courses")
>
> gives me Listings with id's (5, 1, 3, 5, 2, 4), and
>
> >>> Listing.objects.order_by("-book__courses")
>
> gives me Listings with id's (6, 4, 5, 2, 5,1)
>
> There is nothing wrong with the ordering. The problem is that a record
> is disappearing in the ordering process. My pertinent models are
> below. Any clues?
>
> ---
> class Course(models.Model):
>     """
>     Basic course data
>     """
>     division = models.CharField(max_length=5)
>     number = models.CharField(max_length=4)
>     title = models.CharField(max_length=250)
>
>     class Meta:
>         ordering = ('division', 'number')
>
>     def code(self):
>         return "%s %s" % (self.division, self.number)
>
>     def __unicode__(self):
>         return self.code()
>
> class Book(models.Model):
>     """
>     Information on a book (as opposed to a particular copy of it)
>     The attributes should be self-explanatory
>     """
>     title = models.CharField(max_length=250)
>     author = models.CharField(max_length=70)
>     barcode = models.CharField(max_length=50)
>     edition = models.PositiveSmallIntegerField()
>     courses = models.ManyToManyField(Course)
>
>     def __unicode__(self):
>         return self.title
>
>     def course_codes(self):
>         """
>         returns a list of courses in the form
>         course1, course2, course3
>         """
>         course_list = ""
>         for course in self.courses.all():
>             course_list += "%s, " % course.code()
>         # [:-2] takes off the trailing comma and space
>         return course_list[:-2]
>     def title_list(self):
>         return self.author
>
> class Listing(models.Model):
>     """
>     For when a student lists a particular copy of a book.
>     Keeps track of
>         * when and who listed (is selling) it
>         * if and who is currently holding it
>         * when it was last put on hold
>     * when it finally got sold
>     * whether the listing is flagged for deletion or not
>     """
>     STATUS_CHOICES = (
>         (u'F', u'For Sale'),
>         (u'M', u'Missing'),
>         (u'O', u'On Hold'),
>         (u'P', u'Seller Paid'),
>         (u'S', u'Sold'),
>         (u'T', u'To Be Deleted'),
>         (u'D', u'Deleted'),
>     )
>
>     book = models.ForeignKey(Book)
>     list_date = models.DateTimeField('Date Listed', auto_now_add=True)
>     seller = models.ForeignKey(User, related_name="selling")
>     sell_date = models.DateTimeField('Date Sold', blank=True,
> null=True)
>     holder = models.ForeignKey(User, related_name="holding",
>                                blank=True, null=True)
>     hold_date = models.DateTimeField('Date Held', blank=True,
> null=True)
>     price = models.DecimalField(max_digits=7, decimal_places=2)
>     status = models.CharField(max_length=1, choices=STATUS_CHOICES)

--

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




Ordering over ManyToMany relationship omits records

2009-11-26 Thread David
When I order over a ManyToMany relationship, certain records will not
appear. The record which disappears changes depending  on the order by
which I sort it. Specifically:

>>> Listing.objects.order_by("book__courses")

gives me Listings with id's (5, 1, 3, 5, 2, 4), and

>>> Listing.objects.order_by("-book__courses")

gives me Listings with id's (6, 4, 5, 2, 5,1)

There is nothing wrong with the ordering. The problem is that a record
is disappearing in the ordering process. My pertinent models are
below. Any clues?

---
class Course(models.Model):
"""
Basic course data
"""
division = models.CharField(max_length=5)
number = models.CharField(max_length=4)
title = models.CharField(max_length=250)

class Meta:
ordering = ('division', 'number')

def code(self):
return "%s %s" % (self.division, self.number)

def __unicode__(self):
return self.code()

class Book(models.Model):
"""
Information on a book (as opposed to a particular copy of it)
The attributes should be self-explanatory
"""
title = models.CharField(max_length=250)
author = models.CharField(max_length=70)
barcode = models.CharField(max_length=50)
edition = models.PositiveSmallIntegerField()
courses = models.ManyToManyField(Course)

def __unicode__(self):
return self.title

def course_codes(self):
"""
returns a list of courses in the form
course1, course2, course3
"""
course_list = ""
for course in self.courses.all():
course_list += "%s, " % course.code()
# [:-2] takes off the trailing comma and space
return course_list[:-2]
def title_list(self):
return self.author

class Listing(models.Model):
"""
For when a student lists a particular copy of a book.
Keeps track of
* when and who listed (is selling) it
* if and who is currently holding it
* when it was last put on hold
* when it finally got sold
* whether the listing is flagged for deletion or not
"""
STATUS_CHOICES = (
(u'F', u'For Sale'),
(u'M', u'Missing'),
(u'O', u'On Hold'),
(u'P', u'Seller Paid'),
(u'S', u'Sold'),
(u'T', u'To Be Deleted'),
(u'D', u'Deleted'),
)

book = models.ForeignKey(Book)
list_date = models.DateTimeField('Date Listed', auto_now_add=True)
seller = models.ForeignKey(User, related_name="selling")
sell_date = models.DateTimeField('Date Sold', blank=True,
null=True)
holder = models.ForeignKey(User, related_name="holding",
   blank=True, null=True)
hold_date = models.DateTimeField('Date Held', blank=True,
null=True)
price = models.DecimalField(max_digits=7, decimal_places=2)
status = models.CharField(max_length=1, choices=STATUS_CHOICES)

--

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




Re: Django tag cloud

2009-11-26 Thread Nick Arnett
On Sat, Nov 21, 2009 at 7:09 AM, Carlos Ricardo Santos <
carlosricardosan...@gmail.com> wrote:

>
>
>>
>> Obviously I can't use that number in font-size (150pt is too big) and
>> I have to make a proportion (150 -> 20pt, 1 -> 5pt, 50 ~>10pt and so
>> on).
>>
>> How can I accomplish that?
>>
>>
What you need is called data normalization - fitting data to a desired scale
- in statistics and analysis.

Here's a general page about normalization:

http://www.qsarworld.com/qsar-statistics-normalization.php

I'd imagine that there's a Python library or module that will do this for
you, but it's not hard to write your own.

Nick

--

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




Re: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread Todd Blanchard
OK, this did lead me to the solution though.

It seems that, for the ForeignKeyField the initial value should be the primary 
key of the record and not the object referenced.  So changing

>> form = IncidentForm(initial={
>>'reporter': request.user,


to 

>> form = IncidentForm(initial={
>>'reporter': request.user.id,


makes it work OK.  Seems counter-intuitive given the the ForeignKeyField wants 
to work with objects rather than keys though.



On Nov 26, 2009, at 12:33 PM, Todd Blanchard wrote:

> I want it to be possible to be changed.  But I also want the initial 
> selection to be the current user.
> 
> So this isn't really a solution.  Thanks anyway.
> 
> On Nov 26, 2009, at 10:27 AM, esatterwh...@wi.rr.com wrote:
> 
>> in your IncidentForm definition set reporter to a ModelChoiceField
>> (User.objects.all(), widget=forms.HiddenInput())
>> 
>> then it should work out ok. I usually hide fk fields to a user if i
>> want the current request.user object, because I don't want to allow
>> the possibility for it to be changed.
>> 
>> On Nov 25, 10:32 pm, Todd Blanchard  wrote:
>>> I have a (simplified) model
>>> 
>>> class Incident(models.Model):
>>>title = models.CharField(max_length=128)
>>>when_reported = models.DateTimeField(auto_now_add=True)
>>>reporter = models.ForeignKey(User)
>>> 
>>> Where User is from auth.  When used with a ModelForm, this creates a popup 
>>> button with a list of users.  I want it to default to the currently logged 
>>> in user so in my view I have:
>>> 
>>> def new_incident(request):
>>>   form = IncidentForm(initial={
>>>'reporter': request.user,
>>>'title': 'New Incident',
>>>'when_reported' : datetime.now(),
>>>})
>>> 
>>>media = form.media
>>>return render_to_response('incidents/new.html',{'form': form, 'media': 
>>> media},context_instance=RequestContext(request))
>>> 
>>> However the popup button's selection is never set to the current logged in 
>>> user.  I have rendered the current logged in user's name elsewhere on the 
>>> page, it is set.  But the popup selector isn't getting its selection set 
>>> right.  Any tips?  
>>> 
>>> -Todd Blanchard
>> 
>> --
>> 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>> 
>> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

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




Re: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread Todd Blanchard
I want it to be possible to be changed.  But I also want the initial selection 
to be the current user.

So this isn't really a solution.  Thanks anyway.

On Nov 26, 2009, at 10:27 AM, esatterwh...@wi.rr.com wrote:

> in your IncidentForm definition set reporter to a ModelChoiceField
> (User.objects.all(), widget=forms.HiddenInput())
> 
> then it should work out ok. I usually hide fk fields to a user if i
> want the current request.user object, because I don't want to allow
> the possibility for it to be changed.
> 
> On Nov 25, 10:32 pm, Todd Blanchard  wrote:
>> I have a (simplified) model
>> 
>> class Incident(models.Model):
>> title = models.CharField(max_length=128)
>> when_reported = models.DateTimeField(auto_now_add=True)
>> reporter = models.ForeignKey(User)
>> 
>> Where User is from auth.  When used with a ModelForm, this creates a popup 
>> button with a list of users.  I want it to default to the currently logged 
>> in user so in my view I have:
>> 
>> def new_incident(request):
>>form = IncidentForm(initial={
>> 'reporter': request.user,
>> 'title': 'New Incident',
>> 'when_reported' : datetime.now(),
>> })
>> 
>> media = form.media
>> return render_to_response('incidents/new.html',{'form': form, 'media': 
>> media},context_instance=RequestContext(request))
>> 
>> However the popup button's selection is never set to the current logged in 
>> user.  I have rendered the current logged in user's name elsewhere on the 
>> page, it is set.  But the popup selector isn't getting its selection set 
>> right.  Any tips?  
>> 
>> -Todd Blanchard
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

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




Re: Unexpected OSError when deleting an image

2009-11-26 Thread philip.bar...@impaerospace.com


On Nov 26, 11:19 am, David De La Harpe Golden
 wrote:
> philip.bar...@impaerospace.com wrote:
> > -rwxrwxrwt 1 ase idmsaccess 480836 2009-09-29 09:45 J0484_-
> > _2009-03-04_006.jpg
> > drwsrwsrwt 3 ase idmsaccess  12288 2009-09-11 02:58 dar
>
> > To me it looks like both the file and the directory are set to give
> > everyone (owner, group, and others) write access.
>
> See the t? it matters:http://en.wikipedia.org/wiki/Sticky_bit

That was the problem. Removing the sticky bit allowed things to
function.

Thank you for your help, it was much appreciated.

-Philip

--

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




Re: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread esatterwh...@wi.rr.com
in your IncidentForm definition set reporter to a ModelChoiceField
(User.objects.all(), widget=forms.HiddenInput())

then it should work out ok. I usually hide fk fields to a user if i
want the current request.user object, because I don't want to allow
the possibility for it to be changed.

On Nov 25, 10:32 pm, Todd Blanchard  wrote:
> I have a (simplified) model
>
> class Incident(models.Model):
>     title = models.CharField(max_length=128)
>     when_reported = models.DateTimeField(auto_now_add=True)
>     reporter = models.ForeignKey(User)
>
> Where User is from auth.  When used with a ModelForm, this creates a popup 
> button with a list of users.  I want it to default to the currently logged in 
> user so in my view I have:
>
> def new_incident(request):
>    form = IncidentForm(initial={
>             'reporter': request.user,
>             'title': 'New Incident',
>             'when_reported' : datetime.now(),
>             })
>
>     media = form.media
>     return render_to_response('incidents/new.html',{'form': form, 'media': 
> media},context_instance=RequestContext(request))
>
> However the popup button's selection is never set to the current logged in 
> user.  I have rendered the current logged in user's name elsewhere on the 
> page, it is set.  But the popup selector isn't getting its selection set 
> right.  Any tips?  
>
> -Todd Blanchard

--

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




Re: is_valid error/bug when unique_together fields are both ForeignKey fields

2009-11-26 Thread Karen Tracey
On Thu, Nov 26, 2009 at 12:37 PM, cerberos  wrote:

> I have a model that has two fields (Django 1.1.1)
>
> class FooBar(models.Model):
>foo = models.ForeignKey('Foo')
>bar = models.ForeignKey('Bar')
>
>class Meta:
>unique_together = (('foo','bar'),)
>
> When is_valid is called in my view and the combination of fields
> already exists (eg unique_together is false) the error returned is
> "Foo bar with this None and None already exists."
>
> "None and None" seems like a bug to me, but I'm not sure.
>
>
Using these models (making up my own specs for Foo and Bar since they are
referenced but not described by what you posted):

class Foo(models.Model):
f = models.IntegerField()
def __unicode__(self):
return 'Foo with f = %d' % self.f

class Bar(models.Model):
b = models.IntegerField()
def __unicode__(self):
return 'Bar with b = %d' % self.b

class FooBar(models.Model):
   foo = models.ForeignKey('Foo')
   bar = models.ForeignKey('Bar')

   class Meta:
   unique_together = (('foo','bar'),)

and the admin app, the message I get when attempting to add a FooBar that
violates the unique constraint is:

Foo bar with this Foo and Bar already exists.

So there seems to be something left out of the description of what you are
doing that may be leading to the None and None in your message, but I'm not
sure what that might be.

Karen

--

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




is_valid error/bug when unique_together fields are both ForeignKey fields

2009-11-26 Thread cerberos
I have a model that has two fields (Django 1.1.1)

class FooBar(models.Model):
foo = models.ForeignKey('Foo')
bar = models.ForeignKey('Bar')

class Meta:
unique_together = (('foo','bar'),)

When is_valid is called in my view and the combination of fields
already exists (eg unique_together is false) the error returned is
"Foo bar with this None and None already exists."

"None and None" seems like a bug to me, but I'm not sure.

--

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




How can I change the values of select options created by a ModelForm?

2009-11-26 Thread jul
hi,

I'm generating, using ModelForm, a form from a Restaurant model, which
has a Country field.
Country has a 'code' and a 'name' fields.
When the form is created in my template, the values of the select
options are the Country ids. How can I replace them by the Country
'code' values. Is it possible to choose which field is used as the
value by overriding the Country field in the ModelForm?

thanks


I have that:

Country: 
-
Andorra
United Arab Emirates
Afghanistan

and I want that:

Country: 
-
Andorra
United Arab Emirates
Afghanistan


Models and ModelForm:

class Country(models.Model):
code = models.CharField(max_length=5, unique=True)
name = models.CharField(max_length=100, unique=True)

class Meta:
verbose_name_plural = 'Countries'

def __unicode__(self):
return self.name



class Restaurant(models.Model):

name = models.CharField(max_length=100)
country=models.ForeignKey(Country)
city=models.ForeignKey(City)
street=models.CharField(max_length=100)
street_number=models.PositiveSmallIntegerField()
phone_number=models.CharField(max_length=16, blank=True,
null=True)
price_range=models.PositiveSmallIntegerField(blank=True,
null=True)
category=models.ManyToManyField(Category, blank=True,
null=True)
tag=models.ManyToManyField(Tag, blank=True, null=True)
slug = models.SlugField(unique=True)

def get_absolute_url(self):
return "/restaurant/%s/" % self.slug

def __unicode__(self):
return self.name

def save(self):
self.slug = slugify(self.name)
super(Restaurant, self).save()


class AddRestaurantForm(ModelForm):

class Meta:
model = Restaurant
exclude = ('slug')

--

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




Re: Unexpected OSError when deleting an image

2009-11-26 Thread David De La Harpe Golden
philip.bar...@impaerospace.com wrote:
> I ran 'ps aux | grep apache' which showed that apache was running
> under the www-data user account.

Okay. (Aside: Note that you can use something like mod_wsgi in daemon
mode or mod_fcgid to run django processes under a separate user account
to the main apache user)

Rest is not really django:

> The following is a line from  /etc/group
> idmsaccess:x:1003:ase,www-data,mysql,klog,syslog,daemon,avahi
> I am under the impression that means that www-data is a member of the
> group idmsaccess

Yes, though you may have to restart apache if you haven't since making
that group for the session to pick it up. (Aside: doubt it makes sense
to have all those users in that group...)

> -rwxrwxrwt 1 ase idmsaccess 480836 2009-09-29 09:45 J0484_-
> _2009-03-04_006.jpg
> drwsrwsrwt 3 ase idmsaccess  12288 2009-09-11 02:58 dar
> 
> To me it looks like both the file and the directory are set to give
> everyone (owner, group, and others) write access.
>

See the t? it matters:
http://en.wikipedia.org/wiki/Sticky_bit
This is used to make world-writable directories like /tmp a bit safer on
unix or linux systems.  However, in this case means only "ase" can
delete the file, since the sticky bit special case handling applies via
the user (the "owner" of the file/directory) not group, and "ase" owns
both the file and the directory.

This is a Feature. Only the owner of a sticky-bit directory can delete
as normal within it, and other people can only delete the files they
themselves own within the sticky-bit directory.

http://tldp.org/LDP/intro-linux/html/sect_03_04.html

You could remove the sticky bit, but you would be strongly advised
to remove the world-writable bit too if you do that...

(aside: the s matters too, but what it is doing is setting the group
of files created in the directory to idmsaccess, whic is probably
something you want)












--

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




Should generic views accept lists in template_name?

2009-11-26 Thread Enrico
Unlike the render_to_response shortcut, generic views only accepts a
single template name, not a list of templates.

These views could be improved by accepting multiple templates and the
compatibility wouldn't be affected.

One reason that this could be useful: having a categorized news
listing that may need different templates for each category or
fallback to a default template if the custom isn't found. Something
like this:

from django.views.generic.list_detail import object_list
from news.models import Entry

def news_by_category(request, slug, **kwargs):
kwargs['template_name'] = ('news/%s/entry_list.html' % slug, 'news/
entry_list.html')
kwargs['queryset'] = Entry.objects.filter(category__slug=category)
return object_list(request, **kwargs)

Does anyone have interest on this?
Django 1.2 will have class-based generic views, should they accept
multiple templates?

--

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




Re: better error handling in templatetags?

2009-11-26 Thread Karen Tracey
On Thu, Nov 26, 2009 at 9:09 AM, pihentagy  wrote:

> Isn't it a known thing, that template tags are hard to debug? Did I
> miss something?
>

I don't know, but your original message makes it a little too hard to try to
help probably.  You say the actual location of the error is missing, but in
order to see what you are seeing people have to download a zip file from
somewhere and go to some trouble to unzip and install and figure out what to
run to recreate the problem, etc.  Why not just post the traceback you are
getting, along with whatever snippets of the associated code that are
relevant? You might get better feedback from that.

Karen


>
>
On Nov 11, 11:13 am, pihentagy  wrote:
> > Hi all!
> >
> > I am not satisfied with the error handling inside custom template
> > tags.
> > To demonstrate it, I cooked a mini useless app, which can be
> > downloaded here:
> >
> > What I miss from the error screen is the actual location of the error.
> >
> > http://cid-a93120a1b42a9e7f.skydrive.live.com/self.aspx/.Public/djang...
> >
> > Or did I do something wrong, that I miss the error message?
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: Error when generating PDF

2009-11-26 Thread Karen Tracey
On Thu, Nov 26, 2009 at 8:40 AM, adelaide_mike
wrote:

> In my report generating view I have this (snip):
>
> if tablename == 'Area':
>areas = Area.objects.all()
>data.append(['Code','Name','Description'])
>for area in areas:
>data.append([
>Paragraph(area.area, normalstyle, bulletText=None),
>Paragraph(area.nick, normalstyle, bulletText=None),
>Paragraph(area.desc, normalstyle, bulletText=None)
>])
>table = Table(data, 1*[0.75*inch]+1*[2.0*inch]+1*[4.0*inch],
> style=ts)
>
> elif tablename == 'Rack':
>racks = Rack.objects.all()
>data.append(['Code','Name', 'Description'])
>for rack in racks:
>data.append([
>Paragraph(rack.rack, normalstyle, bulletText=None),
>Paragraph(rack.nick, normalstyle, bulletText=None),  #
> thats line 108
>Paragraph(rack.desc, normalstyle, bulletText=None)
>])
>table = Table(data, 1*[1.25*inch]+1*[2.0*inch]+1*[4.0*inch],
> style=ts)
>
> When tablename = "Area" the .pdf is generated without error.  Wnen it
> is "Rack" this error is raised:
>
> Traceback (most recent call last):
>
>  File "/home/mrowan/django/django/core/handlers/base.py", line 86, in
> get_response
>   response = callback(request, *callback_args, **callback_kwargs)
>
>  File "/home/mrowan/projects/cbm/djcbm/cbm/reports.py", line 108, in
> print_list
>   Paragraph(rack.nick, normalstyle, bulletText=None),
>
>  File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 523, in __init__
>   self._setup(text, style, bulletText, frags, cleanBlockQuotedText)
>
>  File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 543, in _setup
>   text = cleaner(text)
>
>  File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 61, in cleanBlockQuotedText
>   L=filter(truth,map(_lineClean, split(text, '\n')))
>
>  File "/usr/lib/python2.5/site-packages/reportlab/platypus/
> paragraph.py", line 23, in split
>   return [uword.encode('utf8') for uword in text.split(delim)]
>
> AttributeError: 'NoneType' object has no attribute 'split'
>
> What does the error message mean?  Can someone translate please? TIA
>

It's saying the specified line is trying to call the split method on an
object that has no such method.  Specifically the object that it is trying
to call split on is None, so the value of text on that line is None.  That
would seem to imply (assuing text is the first argument to Paragraph and it
hasn't been set to None between the time the initial __init__ for Paragraph
was entered and the time the error is raised), that there is a Rack in the
db where rack.nick is None.  Which seems odd -- assuming nick is a
CharField, unless you have it declared with null=True, an "empty" nick ought
to be an empty string, not None.

Karen

--

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




Re: Request POST String

2009-11-26 Thread Chris
Awesome, that looks like it. Thanks.

On Nov 26, 4:01 pm, Masklinn  wrote:
> On 26 Nov 2009, at 16:55 , Chris wrote:
>
> > Hi all,
>
> > Sorry for bothering you with something that is probably fairly
> > straight forward but I cant seem to find the solution myself.
>
> > I am using Google Checkout on my site. It calls one of my pages after
> > processing an order. It posts XML. Django seems to evaluate the XML
> > into a QueryDict, with rather silly results. For example:
>
> > blah
>
> > looks something like:
>
> > { 'blah']}
>
> > where ' > list containing the rest of the XML.
>
> > As you can see, this is wildly not what I am after. I need to access
> > the POST string directly without Django interpreting it as a
> > dictionary. How do I go about doing this? I'm open to other
> > suggestions but keep in mind I can't change the way in which the data
> > is posted, as it comes from Google Checkout.
>
> I think you 
> wanthttp://docs.djangoproject.com/en/dev/ref/request-response/#django.htt...

--

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




Re: Request POST String

2009-11-26 Thread Masklinn
On 26 Nov 2009, at 16:55 , Chris wrote:
> Hi all,
> 
> Sorry for bothering you with something that is probably fairly
> straight forward but I cant seem to find the solution myself.
> 
> I am using Google Checkout on my site. It calls one of my pages after
> processing an order. It posts XML. Django seems to evaluate the XML
> into a QueryDict, with rather silly results. For example:
> 
> blah
> 
> looks something like:
> 
> { 'blah']}
> 
> where ' list containing the rest of the XML.
> 
> As you can see, this is wildly not what I am after. I need to access
> the POST string directly without Django interpreting it as a
> dictionary. How do I go about doing this? I'm open to other
> suggestions but keep in mind I can't change the way in which the data
> is posted, as it comes from Google Checkout.
I think you want 
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.raw_post_data

--

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




Re: Unexpected OSError when deleting an image

2009-11-26 Thread philip.bar...@impaerospace.com
I ran 'ps aux | grep apache' which showed that apache was running
under the www-data user account.

I granted the idmsaccess group create and delete permission for both
the file in question and the directory containing it.

The following is a line from  /etc/group
idmsaccess:x:1003:ase,www-data,mysql,klog,syslog,daemon,avahi
I am under the impression that means that www-data is a member of the
group idmsaccess

This didn't solve the problem.

I ran ls -l to get the permissions on the file in question:

a...@djangoonedevb:~/Desktop/idms_project/idms/media/dar$ ls -l J0484_-
_2009-03-04_006.jpg
-rwxrwxrwt 1 ase idmsaccess 480836 2009-09-29 09:45 J0484_-
_2009-03-04_006.jpg

And the directory containing it:

a...@djangoonedevb:~/Desktop/idms_project/idms/media$ ls -l
total 500
drwsrwsrwt 3 ase idmsaccess  12288 2009-09-11 02:58 dar

To me it looks like both the file and the directory are set to give
everyone (owner, group, and others) write access.



On Nov 26, 7:26 am, David De La Harpe Golden
 wrote:
> philip.bar...@impaerospace.com wrote:
> > I tried editing django/core/files/storage.py to output the results of
> > an os.access() check to show that I did have write access to the image
> > file immediately before attempting the os.remove. It showed that I had
> > write access to the image file.
>
> You user account or the user account the web server is running as? They
> may not be the same thing depending on your setup.
>
> Also remember that removal requires write permissions on the directory,
> removing a file is removing it /from a directory/, so you need write
> permission on the directory the file is in as you're changing the
> directory to remove the file, not changing the file's
> contents (which is what write access to the file itself is about).

--

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




Re: Request POST String

2009-11-26 Thread Chris
Yes, I did mean '=' rather than ':'. I have been doing too much JSON
lately...

Here is an example of the output from 'str(request.POST)':

\r\nhttp://checkout.google.com/schema/2";
serial-number="707751054951378-5-1">\r\n  NEW\r\n  CHARGEABLE\r\n  NEW\r\n
REVIEWING\r\n  2009-11-26T14:39:21.900Z\r\n
707751054951378\r\n\r\n\r\n']}>

Sorry about the lack of formatting but trying to format a mix of
object notation and XML looks rather weird however you do it.

'request.POST.items()' will give you much the same nonsense. I need to
get at POST before Django tries to interpret it.

Thanks.

On Nov 26, 4:05 pm, Daniel Roseman  wrote:
> On Nov 26, 3:55 pm, Chris  wrote:
>
> > Hi all,
>
> > Sorry for bothering you with something that is probably fairly
> > straight forward but I cant seem to find the solution myself.
>
> > I am using Google Checkout on my site. It calls one of my pages after
> > processing an order. It posts XML. Django seems to evaluate the XML
> > into a QueryDict, with rather silly results. For example:
>
> > blah
>
> This isn't valid XML. Do you mean:
>     blah
>
> > looks something like:
>
> > { 'blah']}
>
> > where ' > list containing the rest of the XML.
>
> > As you can see, this is wildly not what I am after. I need to access
> > the POST string directly without Django interpreting it as a
> > dictionary. How do I go about doing this? I'm open to other
> > suggestions but keep in mind I can't change the way in which the data
> > is posted, as it comes from Google Checkout.
>
> > Thanks.
>
> Can you post some code showing how you are getting the data from the
> POST and what you are doing with it?
> --
> DR.

--

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




Write debug error to file

2009-11-26 Thread Gabriel Rossetti
Hello everyone,

I'd like to write the django error page (when debug == true) to a file 
and return a page with that link instead of the actual page. The reason 
I'd like to do this is to be able to debug a facebook app because fb 
seams to filter/block the error page. Does anyone know how to do that?

Thanks,
Gabriel

--

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




Re: Form validation

2009-11-26 Thread Karen Tracey
On Thu, Nov 26, 2009 at 5:49 AM, pinco  wrote:

> Hi there.
>
> I’m not able to figure out how to solve in a simple and clean way the
> following problem.
> Basically what I want to do is to edit the instances of the following
> model:
>
> Models.py
> class Seller(models.Model):
>brand = models.CharField(max_length=250)
>  ...
>slug = models.SlugField(unique=True)
>
> The form is generated using the following code. The validator should
> ensure that the entered brand is unique among the registered users. I
> would use the same form both to create and to edit Seller instances.
>

If you add unique=True to the brand model field (see
http://docs.djangoproject.com/en/dev/ref/models/fields/#unique) then a model
form created for that model will automatically do the uniqueness checking
for you.

Karen

--

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




Re: Request POST String

2009-11-26 Thread Daniel Roseman
On Nov 26, 3:55 pm, Chris  wrote:
> Hi all,
>
> Sorry for bothering you with something that is probably fairly
> straight forward but I cant seem to find the solution myself.
>
> I am using Google Checkout on my site. It calls one of my pages after
> processing an order. It posts XML. Django seems to evaluate the XML
> into a QueryDict, with rather silly results. For example:
>
> blah

This isn't valid XML. Do you mean:
blah


> looks something like:
>
> { 'blah']}
>
> where ' list containing the rest of the XML.
>
> As you can see, this is wildly not what I am after. I need to access
> the POST string directly without Django interpreting it as a
> dictionary. How do I go about doing this? I'm open to other
> suggestions but keep in mind I can't change the way in which the data
> is posted, as it comes from Google Checkout.
>
> Thanks.

Can you post some code showing how you are getting the data from the
POST and what you are doing with it?
--
DR.

--

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




Request POST String

2009-11-26 Thread Chris
Hi all,

Sorry for bothering you with something that is probably fairly
straight forward but I cant seem to find the solution myself.

I am using Google Checkout on my site. It calls one of my pages after
processing an order. It posts XML. Django seems to evaluate the XML
into a QueryDict, with rather silly results. For example:

blah

looks something like:

{ 'blah']}

where 'http://groups.google.com/group/django-users?hl=en.




Re: german umlaute on search querys

2009-11-26 Thread Karen Tracey
On Thu, Nov 26, 2009 at 7:03 AM, Hinnack wrote:

> Hi Karen,
>
> thanks again for your reply.
> I use Aptana with pydev extension.
> Debugging the app shows the following for search:
> dict: {u'caption': u'f\\xfcr', u'showold': False}
>
>
That's confusing to me, because other than having an extra \ (which could be
an artifact of how it's being displayed), that looks like a correctly-built
unicode object für.

and for qs:
> str: für
> although it seems to be � instead of ASCII 252 - but this could be,
> because I am sitting on a MAC
> while debugging.
>

Using python manage.py shell might shed more light, I fear the tool here is
assuming an incorrect bytestring encoding and getting in the way.

I cannot recreate anything like what you are seeing.  I have a model Thing
stored in a MySQL DB (using a utf-8 encoded table) with CharField name.
There are two instances of this Thing in the DB that contain für in the
name.  From a python manage.py shell, using Django 1.1.1:

>>> from ttt.models import Thing
>>> import django
>>> django.get_version()
'1.1.1'
>>> ufur = u'f\u00fcr'
>>> print ufur
für
>>> ufur
u'f\xfcr'
>>> ufur.encode('utf-8')
'f\xc3\xbcr'
>>> ufur.encode('iso-8859-1')
'f\xfcr'

small-u with umlaut is U+00FC, encoded in utf-8 that takes 2 bytes C3BC,
encoded in iso-8859-1 it is the 1 byte FC.

Filtering with icontains, using either the Unicode object or the utf-8
encode bytestring version, works properly:

>>> Thing.objects.filter(name__icontains=ufur)
[, ]
>>> Thing.objects.filter(name__icontains=ufur.encode('utf-8'))
[, ]

Attempting to filter with an iso-8859-1 encoded bytestring raises an error:

>>> Thing.objects.filter(name__icontains=ufur.encode('iso-8859-1'))
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line
129, in filter
return self.get_query_set().filter(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
498, in filter
return self._filter_or_exclude(False, *args, **kwargs)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
516, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py",
line 1675, in add_q
can_reuse=used_aliases)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py",
line 1614, in add_filter
connector)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/where.py",
line 56, in add
obj, params = obj.process(lookup_type, value)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/where.py",
line 269, in process
params = self.field.get_db_prep_lookup(lookup_type, value)
  File
"/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py", line
214, in get_db_prep_lookup
return ["%%%s%%" % connection.ops.prep_for_like_query(value)]
  File "/usr/lib/python2.5/site-packages/django/db/backends/__init__.py",
line 364, in prep_for_like_query
return smart_unicode(x).replace("\\", "").replace("%",
"\%").replace("_", "\_")
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 44,
in smart_unicode
return force_unicode(s, encoding, strings_only, errors)
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 92,
in force_unicode
raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-2:
unexpected end of data. You passed in 'f\xfcr' ()

This is because Django assumes the bytestring is utf-8 encoded, and runs
into trouble attempting to convert to unicode specifying utf-8 as the
string's encoding, since it is not valid utf-8 data.

The only way I have been able to recreate anything like what you are
describing is to incorrectly construct the original unicode object from a
utf-8 bytestring assuming a iso-8859-1 encoding:

>>> badufur = ufur.encode('utf-8').decode('iso-8859-1')
>>> badufur
u'f\xc3\xbcr'
>>> print badufur
für
>>> print badufur.encode('utf-8')
für
>>> print badufur.encode('iso-8859-1')
für

Using that unicode object doesn't produce any hits in the DB:

>>> Thing.objects.filter(name__icontains=badufur)
[]

But encoding it to iso-8859-1 does, because that has the effect of restoring
the original utf-8 bytestring:

>>> Thing.objects.filter(name__icontains=badufur.encode('iso-8859-1'))
[, ]

However, the debug info you show above doesn't show an incorrectly-built
unicode object, so I'm very confused by it.

Karen

--

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




Re: db_index = True on BooleanField (MySQL)

2009-11-26 Thread Tom Evans
On Thu, Nov 26, 2009 at 2:35 PM, chefsmart  wrote:

> I had a fruitless discussion with a fellow coder today. Summarily, we
> have a model for students that will keep growing with time. I mean to
> say the number of records in the database will keep growing, and no
> rows are going to be deleted.
>
> Now, students fall in one category or the other, and this is marked by
> a BooleanField.
>
> We are using MySQL. Is it advisable to index that BooleanField (that
> is db_index = True in Django)? All queries on the model will 'almost
> always' include a check on that BooleanField, that is
> Student.object.filter(categorized=False) or Student.object.filter
> (categorized=True)
>
> I have spent a lot of time on the MySQL forums to find out an answer
> to this, but am as lost as before. Some even said an index on a
> Boolean in such a case would degrade performance.
>
>
The answer is 'it depends'. Remember that MySQL will only use one index from
each table in a query. and that a boolean field has a cardinality of 2, so
it potentially doesn't reduce the number of rows to examine.

Furthermore, if (say) 95% of your Students are categorized, and you are
looking at Student.objects.filter(categorized=True), then MySQL would ignore
your index anyway, and do a full table scan. I'm unsure of exactly what
percentage of rows before MySQL does this though..

The only correct answer is to fill your database with sample data, and
analyze each of your queries in MySQL, and create appropriate composite keys
that reduce cardinality appropriately for your queries.

Cheers

Tom

--

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




Re: string-based fields and null

2009-11-26 Thread Tom Evans
On Thu, Nov 26, 2009 at 2:25 PM, chefsmart  wrote:

> Those are good points. I am inclined to think the Django developers
> think along the same lines (that is why they suggest to "Avoid using
> null on string-based fields such as CharField and TextField unless you
> have an excellent reason")
>
> Thus I am also inclined to think that CharField, ImageField etc would
> be treating an empty string "" and a database NULL as same in their
> code. I am trying to locate that code to know for sure, but haven't
> been able to yet.
>
> Regards.
>
>
I wouldn't have thought that would be true. Unless you specify 'null=True'
on a CharField, django will do its best to stop you ending up with a NULL
value in the database. Eg, in MySQL it will create the field with the
modifier 'NOT NULL'.

Empty string and NULL/None are different values, both in the database and
django. By disallowing NULLs, you just get a more consistent definition of
empty string.

For example, one of my models has an ImageField defined as:

  logo = models.ImageField( upload_to="uploads/logos", blank=True )

The db field that this corresponds to looks like this in MySQL (hope you are
using a proportional font):
+--+--+--+-+-++
| Field| Type | Null | Key | Default |
Extra  |
+--+--+--+-+-++
| logo | varchar(100) | NO   | | NULL
||

If I look at a model that has a blank logo field, then it looks like so:

>>> m.logo


If you are interested in knowing how ImageFields behave, perhaps try
creating a few models with ImageFields, with various options and test how
they behave? Might be a bit more promising than speculating.

Cheers

Tom

--

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




Re: Django tag cloud

2009-11-26 Thread Alessandro Ronchi
On Sat, Nov 21, 2009 at 4:09 PM, Carlos Ricardo Santos <
carlosricardosan...@gmail.com> wrote:

> I used this approach, was explained on "Learning website development with
> Django book", give a look there:
> *
> *
> *
> *
> *style.css *file:
> *
> *
> .tag-cloud-0 { font-size: 100%; }
> .tag-cloud-1 { font-size: 120%; }
> .tag-cloud-2 { font-size: 140%; }
> .tag-cloud-3 { font-size: 160%; }
> .tag-cloud-4 { font-size: 180%; }
>  .tag-cloud-5 { font-size: 200%; }
>
> And generated the tag number dynamically counting the objects that has that
> tag.
>
>
But in that way I must add some code to the model, wjere I can write exactly
the font-size.
I need something similar to widthratio but with a minimum value (or maybe
there is a way to make the littler sets not to 0 font-size).



-- 
Alessandro Ronchi

SOASI
Sviluppo Software e Sistemi Open Source
http://www.soasi.com
http://www.linkedin.com/in/ronchialessandro

--

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




db_index = True on BooleanField (MySQL)

2009-11-26 Thread chefsmart
I had a fruitless discussion with a fellow coder today. Summarily, we
have a model for students that will keep growing with time. I mean to
say the number of records in the database will keep growing, and no
rows are going to be deleted.

Now, students fall in one category or the other, and this is marked by
a BooleanField.

We are using MySQL. Is it advisable to index that BooleanField (that
is db_index = True in Django)? All queries on the model will 'almost
always' include a check on that BooleanField, that is
Student.object.filter(categorized=False) or Student.object.filter
(categorized=True)

I have spent a lot of time on the MySQL forums to find out an answer
to this, but am as lost as before. Some even said an index on a
Boolean in such a case would degrade performance.

--

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




Re: Best UI for letting users select an item from a large selection of records?

2009-11-26 Thread David De La Harpe Golden
Stodge wrote:

> Offering the user a drop
> down combo box of requirements to choose from isn't the best option.

Rant: combo box /means/ a text entry widget plus dropdown menu "combo".
 For some reason web developers in particular seem prone to using it to
mean a dropdown alone (html forms sadly lack built-in combo boxes, of
course)
http://en.wikipedia.org/wiki/Combo_box

> I suppose I could create an auto-complete text box widget that offers
> a list of requirements that matches what they typed. But that's a lot
> of work for someone who doesn't know Javascript (though I do have
> JQuery plugged into my app) 

If you're using jquery there are quite a few ready-made jquery plugins
that mean you can make a combo box (for various ideas of what
a combo box is or should be) quickly. Kinda one of the points of jquery
is the large array of plugins, though with the usual problems of plugins
- variable quality and design.

Here's a couple of examples:
http://phone.witamean.net/sexy-combo/examples/index.html
http://www.fairwaytech.com/Technology/FlexBoxDemo.aspx#demo8
see the jquery plugins list:
http://plugins.jquery.com/
search for "combo" or "autocomplete" or "autosuggest".

OTOH, a combo box might still be a cramped interface. One could
e.g. present a filterable table with the likes of dataTables.
http://www.datatables.net/






--

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




Re: string-based fields and null

2009-11-26 Thread chefsmart
Those are good points. I am inclined to think the Django developers
think along the same lines (that is why they suggest to "Avoid using
null on string-based fields such as CharField and TextField unless you
have an excellent reason")

Thus I am also inclined to think that CharField, ImageField etc would
be treating an empty string "" and a database NULL as same in their
code. I am trying to locate that code to know for sure, but haven't
been able to yet.

Regards.

On Nov 25, 9:43 pm, Tim Valenta  wrote:
> In most cases, any string field should be allowed to be blank, and can
> easily survive WITHOUT "null=True".  As stated before me, this is
> preferable.  For instance, you asked about FileField, among others.
> This is perfectly fine to only use "blank=True".
>
> You'll primarily only be using "null=True" on fields that cannot
> actually be blank in the database.  A Date/DateTime field, for
> instance.  an empty string isn't a valid value in MySQL, therefore you
> must also use "null=True", to achieve the blank effect.  The same goes
> for a BooleanField in Django.  Again, a blank string isn't a valid
> boolean value, so null=True is required.
>
> In short, always try to make "blank=True" work out, and only pair it
> up with "null=True" when you're dealing with database fields that
> actually cannot legally have a blank string as a value.
>
> Tim
>
> On Nov 25, 8:58 am, Bill Freeman  wrote:
>
> > The major problem that I see with NULL in strings is that there may be 
> > databases
> > out there that don't distinguish between NULL and "", that is that store 
> > them
> > the same way.
>
> > "" is just as good in most cases.  It behaves like False in python and
> > template tag
> > tests.  And it has the advantage that if you go ahead and apply a
> > string operation
> > to it without checking first, it won't raise an exception because the
> > operation isn't
> > applicable to the None object.  You can't test for it by using ISNULL
> > in SQL, but
> > unless NULL has a different meaning for you than "empty", who cares?
>
> > There are certainly cases where you might, for example, want to
> > distinguish between
> > "never been set" or "is unset", and "displays as no characters", and you 
> > could
> > encode the former states as NULL.  But you could also use a separate 
> > boolean.
> > Think about which code is going to be easier to maintain, especially
> > if by someone
> > else when they don't have you to talk to.  If this table will have
> > billions of rows, then
> > it might be worth thinking about the memory consumed for that boolean,
> >   But then
> > in an year and a half, hard drives will be twice as big.
>
> > Still, python (and lisp and C) programmers are used to thinking about
> > the possibility
> > of None (or nil or (void *)0), so experienced programmers may have an easy 
> > time
> > with maintenance or a NULL flag design.
>
> > So, it's not a hard and fast rule.  I still think that inconsistent
> > backend support is the
> > major factor.
>
> > Bill
>
> > On Tue, Nov 24, 2009 at 1:08 AM,chefsmart wrote:
> > > The Django docs suggest "Avoid using null on string-based fields such
> > > as CharField and TextField unless you have an excellent reason."
>
> > > ImageField, EmailField, FileField, FilePathField, IPAddressField,
> > > SlugField, URLField, XMLField are also a string-based fields at the db
> > > level, so am I right in assuming that null=True is best avoided in
> > > these case also, "unless you have an excellent reason."?
>
> > > I am hoping Django has code to deal with the empty string value in
> > > these fields. For example, I am hoping that Django understands that an
> > > empty string in an ImageField means there is no corresponding image.
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.

--

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




Re: Best UI for letting users select an item from a large selection of records?

2009-11-26 Thread Stodge
Thanks. No, I'm not talking about the admin interface - sorry I should
have made that clear. I'm talking about the front end UI.

On Nov 26, 9:11 am, Michel Thadeu Sabchuk  wrote:
> Hi,
>
> > I have a Ticket model that has a Requirement foreign key. The problem
> > is, there could be hundreds of requirements. Offering the user a drop
> > down combo box of requirements to choose from isn't the best option.
> > So how would you let the user select one record from a large
> > selection? What UI widget(s) would you use?
>
> Do you talking about admin interface? You can use raw_id_fields on the
> ModelAdmin class and this way, your user may inform the ID of the
> foreign key he wants, but it have a link to a popup list of item the
> user can filter.
>
> > I suppose I could create an auto-complete text box widget that offers
> > a list of requirements that matches what they typed. But that's a lot
> > of work for someone who doesn't know Javascript (though I do have
> > JQuery plugged into my app) and I don't want to spend hours coding it
> > to find out it's not the best solution. Any suggestions appreciated.
>
> I like the raw_id_fields approach for general use, it offer a great
> flexibility with less code. Anyway, a widget that shows choices as the
> users digits is easier for the user.
>
> I did something on this approach on a brazilian classifieds portal:
>
> http://portaldoclassificado.com/
>
> You can take a look on his javascript code (it do not use jquery). The
> script filter a hidden ul subitens as the user digits on a input
> field.
>
> Best regards!
>
> PS: sorry any language mistakes.
>
> --
> Michel Sabchuk
> Curitiba / Brasil

--

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




Re: Best UI for letting users select an item from a large selection of records?

2009-11-26 Thread Michel Thadeu Sabchuk
Hi,

> I have a Ticket model that has a Requirement foreign key. The problem
> is, there could be hundreds of requirements. Offering the user a drop
> down combo box of requirements to choose from isn't the best option.
> So how would you let the user select one record from a large
> selection? What UI widget(s) would you use?

Do you talking about admin interface? You can use raw_id_fields on the
ModelAdmin class and this way, your user may inform the ID of the
foreign key he wants, but it have a link to a popup list of item the
user can filter.

> I suppose I could create an auto-complete text box widget that offers
> a list of requirements that matches what they typed. But that's a lot
> of work for someone who doesn't know Javascript (though I do have
> JQuery plugged into my app) and I don't want to spend hours coding it
> to find out it's not the best solution. Any suggestions appreciated.

I like the raw_id_fields approach for general use, it offer a great
flexibility with less code. Anyway, a widget that shows choices as the
users digits is easier for the user.

I did something on this approach on a brazilian classifieds portal:

http://portaldoclassificado.com/

You can take a look on his javascript code (it do not use jquery). The
script filter a hidden ul subitens as the user digits on a input
field.

Best regards!

PS: sorry any language mistakes.

--
Michel Sabchuk
Curitiba / Brasil

--

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




Re: better error handling in templatetags?

2009-11-26 Thread pihentagy
Isn't it a known thing, that template tags are hard to debug? Did I
miss something?

On Nov 11, 11:13 am, pihentagy  wrote:
> Hi all!
>
> I am not satisfied with the error handling inside custom template
> tags.
> To demonstrate it, I cooked a mini useless app, which can be
> downloaded here:
>
> What I miss from the error screen is the actual location of the error.
>
> http://cid-a93120a1b42a9e7f.skydrive.live.com/self.aspx/.Public/djang...
>
> Or did I do something wrong, that I miss the error message?

--

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




distinct related objects

2009-11-26 Thread andreas schmid
hi,

i have a question about retrieving related objects avoiding double entries.
actually i have 3 models:
topics
projects
technologies

the projects model has foreignkeys to topics and technologies. i have a
view for the topic detail like this:

def topic_detail(request, slug):
topic = get_object_or_404(Topic, slug=slug)
return object_list(request,
   queryset=topic.project_set.all(),
   paginate_by=20,
   template_name='FSlabs/topic_detail.html',
   extra_context={ 'topic': topic })

in the template i can loop trough the projects and  get those  assigned
to this topic.
but im having problems to retrieve the technologies used by those
projects without having double entries.

i tried this in the template with a list for every project
assigned...which of course is not what i want:

{% for project in object_list  %}
{% for technology in project.technologies.distinct %}
{{
technology.title }}
{% if forloop.last %}{% else %}
{% ifequal forloop.revcounter0 1 %}and {% else %}, {%
endifequal %}
{% endif %}
{% endfor %}
{% endfor %}

can somebody point me to the right way to get what i need?

thx

--

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




Best UI for letting users select an item from a large selection of records?

2009-11-26 Thread Stodge
I have a Ticket model that has a Requirement foreign key. The problem
is, there could be hundreds of requirements. Offering the user a drop
down combo box of requirements to choose from isn't the best option.
So how would you let the user select one record from a large
selection? What UI widget(s) would you use?

I suppose I could create an auto-complete text box widget that offers
a list of requirements that matches what they typed. But that's a lot
of work for someone who doesn't know Javascript (though I do have
JQuery plugged into my app) and I don't want to spend hours coding it
to find out it's not the best solution. Any suggestions 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Error when generating PDF

2009-11-26 Thread adelaide_mike
In my report generating view I have this (snip):

if tablename == 'Area':
areas = Area.objects.all()
data.append(['Code','Name','Description'])
for area in areas:
data.append([
Paragraph(area.area, normalstyle, bulletText=None),
Paragraph(area.nick, normalstyle, bulletText=None),
Paragraph(area.desc, normalstyle, bulletText=None)
])
table = Table(data, 1*[0.75*inch]+1*[2.0*inch]+1*[4.0*inch],
style=ts)

elif tablename == 'Rack':
racks = Rack.objects.all()
data.append(['Code','Name', 'Description'])
for rack in racks:
data.append([
Paragraph(rack.rack, normalstyle, bulletText=None),
Paragraph(rack.nick, normalstyle, bulletText=None),  #
thats line 108
Paragraph(rack.desc, normalstyle, bulletText=None)
])
table = Table(data, 1*[1.25*inch]+1*[2.0*inch]+1*[4.0*inch],
style=ts)

When tablename = "Area" the .pdf is generated without error.  Wnen it
is "Rack" this error is raised:

Traceback (most recent call last):

 File "/home/mrowan/django/django/core/handlers/base.py", line 86, in
get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/home/mrowan/projects/cbm/djcbm/cbm/reports.py", line 108, in
print_list
   Paragraph(rack.nick, normalstyle, bulletText=None),

 File "/usr/lib/python2.5/site-packages/reportlab/platypus/
paragraph.py", line 523, in __init__
   self._setup(text, style, bulletText, frags, cleanBlockQuotedText)

 File "/usr/lib/python2.5/site-packages/reportlab/platypus/
paragraph.py", line 543, in _setup
   text = cleaner(text)

 File "/usr/lib/python2.5/site-packages/reportlab/platypus/
paragraph.py", line 61, in cleanBlockQuotedText
   L=filter(truth,map(_lineClean, split(text, '\n')))

 File "/usr/lib/python2.5/site-packages/reportlab/platypus/
paragraph.py", line 23, in split
   return [uword.encode('utf8') for uword in text.split(delim)]

AttributeError: 'NoneType' object has no attribute 'split'

What does the error message mean?  Can someone translate please? TIA

Mike

--

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




Re: Unexpected OSError when deleting an image

2009-11-26 Thread David De La Harpe Golden
philip.bar...@impaerospace.com wrote:

> I tried editing django/core/files/storage.py to output the results of
> an os.access() check to show that I did have write access to the image
> file immediately before attempting the os.remove. It showed that I had
> write access to the image file.
> 

You user account or the user account the web server is running as? They
may not be the same thing depending on your setup.

Also remember that removal requires write permissions on the directory,
removing a file is removing it /from a directory/, so you need write
permission on the directory the file is in as you're changing the
directory to remove the file, not changing the file's
contents (which is what write access to the file itself is about).







--

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




Re: Unexpected OSError when deleting an image

2009-11-26 Thread Tim Chase
> When I try to delete an image (specifically I'm deleting an instance
> of a photo model that contains an imagefield) I get an OSError,
> "[Errno 1] Operation not permitted"
> 
> The first thing I tried was checking the permissions in Ubuntu,
> they're set to allow write access for everyone.
> 
> I tried to deleting the image file from an Ubuntu command line and
> discovered that I could do so.
> 
> I tried deleting the image file from python using os.remove, that
> worked fine.
> 
> I tried using 'python manage.py shell' and using os.remove to delete
> the file, that worked fine.


You've tried most of the basic stuff -- my first thought would be 
"are you running as you, but is your server running as somebody 
else"?  It would help to have the output of

   ls -l /path/to/media/files/file_in_question.jpg
   ls -l /path/to/media/ | grep files

to see the ownership and permissions on the file and its 
containing directory, and then output

   from getpass import getuser
   print getuser()

in both your "python manage.py shell" or dev server (well, duh, 
this should obviously be you...from your traceback, I'm guessing 
it's "ase") and output it from your production 
(apache/lighttpd/whatever) server (might have to render it into 
some page).  This might be something like 'www' or 'wwwdata', or 
it might be you ("ase"), or it might be something completely 
different.

Armed with that info, it might help track down the issue.

-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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Module ho.pis can not be found when running on apache

2009-11-26 Thread philip.bar...@impaerospace.com
As it turned out, I hadn't managed to get mod_python to work with
Python 2.5 properly.

I found these instructions 
http://www.briggs.net.nz/log/2007/04/20/mod_python-and-python25/
for going from 2.4 to 2.5 and adapted them for going from 2.6 to 2.5.

After that, the python version began showing up as 2.5.4 and ho.pisa
could be found.

Brad, Tim, thank you for your input.

-Philip

--

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




Unexpected OSError when deleting an image

2009-11-26 Thread philip.bar...@impaerospace.com
I'm using Django 1.0.3, Apache 2.2, Python 2.5 and Ubuntu 9.04 (a
recent upgrade).

When I try to delete an image (specifically I'm deleting an instance
of a photo model that contains an imagefield) I get an OSError,
"[Errno 1] Operation not permitted"

The first thing I tried was checking the permissions in Ubuntu,
they're set to allow write access for everyone.

I tried to deleting the image file from an Ubuntu command line and
discovered that I could do so.

I tried deleting the image file from python using os.remove, that
worked fine.

I tried using 'python manage.py shell' and using os.remove to delete
the file, that worked fine.

I tried editing django/core/files/storage.py to output the results of
an os.access() check to show that I did have write access to the image
file immediately before attempting the os.remove. It showed that I had
write access to the image file.

I tried editing django/core/files/storage.py to use fcntl.lock to lock
the image file (to make sure no other process had locked the image
file) and it showed that the image file was not locked.

I tried editing django/core/files/storage.py to use os.chmod to grant
write access to the image file and got the same error message as
before, only now it occured at the os.chmod() rather than at the
os.remove().

I'm guessing that this problem has something to do with my recent
upgrade to Django 9.04, but that's just a guess as I can't even figure
out exactly what is going wrong.

I would appreciate any suggestions as to what to try next. Thank you
for your input.

Full error message follows:

OSError at /dar/repair/delete/1864/

[Errno 1] Operation not permitted: '/home/ase/Desktop/idms_project/
idms/media/dar/J0484_-_2009-03-04_008.jpg'

Request Method: POST
Request URL:http://localhost/dar/repair/delete/1864/
Exception Type: OSError
Exception Value:

[Errno 1] Operation not permitted: '/home/ase/Desktop/idms_project/
idms/media/dar/J0484_-_2009-03-04_008.jpg'

Exception Location: /usr/lib/python2.5/site-packages/django/core/
files/storage.py in delete, line 199
Python Executable:  /usr/bin/python
Python Version: 2.5.4
Python Path:['/usr/lib/python2.5/site-packages', '/home/ase/Desktop/
idms_project', '/home/ase/Desktop/idms_project/idms', '/usr/lib/
python2.5/site-packages/setuptools-0.6c11-py2.5.egg', '/usr/lib/
python2.5/site-packages/pisa-3.0.32-py2.5.egg', '/usr/lib/python2.5',
'/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/
lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages',
'/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/
Numeric', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/
site-packages/gst-0.10', '/usr/lib/pymodules/python2.5', '/usr/lib/
python2.5/site-packages/gtk-2.0', '/usr/lib/pymodules/python2.5/
gtk-2.0', '/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode']
Server time:Wed, 25 Nov 2009 21:48:48 +

Environment:

Request Method: POST
Request URL: http://localhost/dar/repair/delete/1864/
Django Version: 1.0.3
Python Version: 2.5.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'idms.general',
 'idms.ipl',
 'idms.doc',
 'idms.ssi',
 'idms.fsr',
 'idms.dar',
 'idms.dmm',
 'idms.tdm',
 'idms.ssir',
 'idms.nsr',
 'idms.ssir.templatetags',
 'idms.ffd']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.middleware.transaction.TransactionMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  91. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/auth/
decorators.py" in __call__
  78. return self.view_func(request, *args, **kwargs)
File "/home/ase/Desktop/idms_project/idms/dar/views.py" in
repair_delete
  284. repair.delete()
File "/home/ase/Desktop/idms_project/idms/../idms/dar/models.py" in
delete
  192. super(Repair,self).delete()
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
delete
  476. delete_objects(seen_objs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in
delete_objects
  909. signals.post_delete.send(sender=cls,
instance=instance)
File "/usr/lib/python2.5/site-packages/django/dispatch/dispatcher.py"
in send
  166. response = receiver(signal=self, sender=sender,
**named)
File "/usr/lib/python2.5/site-packages/django/db/models/fields/
files.py" in delete_file
  183. file.delete(save=False)
File "/usr/lib/python2.5/site-packages/django/db/models/fields/
files.py" in delete
  230. super(ImageFieldFile, self).delete(save)
File "/usr/lib/py

Re: applying a patch

2009-11-26 Thread Tim Chase
rebus_ wrote:
>> diff --git a/django/contrib/admin/media/js/admin/
>> RelatedObjectLookups.js b/django/contrib/admin/media/js/admin/
>> RelatedObjectLookups.js
>> index 1bc78f8..3941752 100644
>> --- a/django/contrib/admin/media/js/admin/RelatedObjectLookups.js
>> +++ b/django/contrib/admin/media/js/admin/RelatedObjectLookups.js
>>
>> so I guess that explains it, but I thought django used used svn!
> 
> Django uses SVN as the official repository, but AFAIK git is often
> used for development of new features etc cos it is not centralized and
> it is very simple to create branches in it and so on.
> 
> For patching on windows you could use either gnuwin32 [1] or unxutils
> [2] for comand line, both of which should be able to use patch files
> produced by any diff (svn, git or just diff) like Tim said:
> 
> patch -p0 < /path/to/patch.diff


TortoiseSVN has an option for "Apply Patch" that should behave 
similarly.

-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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: german umlaute on search querys

2009-11-26 Thread Hinnack
Hi Karen,

thanks again for your reply.
I use Aptana with pydev extension.
Debugging the app shows the following for search:
dict: {u'caption': u'f\\xfcr', u'showold': False}

and for qs:
str: für
although it seems to be � instead of ASCII 252 - but this could be,
because I am sitting on a MAC
while debugging.
(the search problem itself stays the same on MAC and LINUX debian)

regards
-- Hinnack

2009/11/26 Karen Tracey 

> On Wed, Nov 25, 2009 at 1:54 AM, Hinnack wrote:
>
>> Hi Karen,
>>
>> thanks for your reply
>>
>> it means so far I must do a:
>> qs = search[query].encode('iso-8859-1')
>>
>> before I add the qs to a Q object of a queryset. Only in this case I get
>> results.
>>
>> the full codepart looks like:
>>
>> decoder = simplejson.JSONDecoder()
>> search = decoder.decode(request.POST['search'])
>> qs = search['caption'].encode('iso-8859-1')
>>
>> searchstr = urllib.unquote_plus(qs).strip('=!~')
>>
>> basic.filter( Q(evid__caption__icontains=searchstr) )
>>
>>
>> I do have no DATABASE_OPTIONS set. Maybe that's it?
>>
>
> No, there's nothing you need to set specially to get this to work.
>
> It would be interesting to see the repr of search['caption'] before and
> after you do the encode('iso-8859-1').
>
> I suspect search['caption'] is originally a Unicode object that was
> (incorrectly) constructed from a utf-8 bytestring assuming iso-8859-1
> encoding.  That would explain the results you are getting, since encoding
> such an incorrectly constructed object to iso-8859-1 will restore it to a
> utf-8 bytestring. Django, when handed a bytestring, assumes it is utf-8
> encoded and speaks utf-8 to the database, so all works.  If on the other
> hand you pass such an incorrectly built unicode object as a unicode object,
> Django will encode it using utf-8, which results in two levels utf-8
> encoding having been done, and the result won't match actual utf-8 data in
> the database.
>
> But it's also just possible that the problem is the data values in the
> database, maybe.  Confirmation of where the problem is would come from
> knowing the repr of search['caption'] before and after the encode to
> iso-8859-1.  Then we'd be sure whether to look more closely at the way in
> which search['caption'] is getting built or the database itself.
>
> Karen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--

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




Re: applying a patch

2009-11-26 Thread rebus_
2009/11/26 paulh :
> Thank's for the reply. I do use tortoise and I tried what you
> suggested: nothing happened. Now I look at the patch file I think
> maybe it was generated by git (which I am not familiar with). The
> first few lines of the patch file (downloaded from django source) are:
>
> diff --git a/django/contrib/admin/media/js/admin/
> RelatedObjectLookups.js b/django/contrib/admin/media/js/admin/
> RelatedObjectLookups.js
> index 1bc78f8..3941752 100644
> --- a/django/contrib/admin/media/js/admin/RelatedObjectLookups.js
> +++ b/django/contrib/admin/media/js/admin/RelatedObjectLookups.js
>
> so I guess that explains it, but I thought django used used svn!
>
> Paul Hide
>

Django uses SVN as the official repository, but AFAIK git is often
used for development of new features etc cos it is not centralized and
it is very simple to create branches in it and so on.

For patching on windows you could use either gnuwin32 [1] or unxutils
[2] for comand line, both of which should be able to use patch files
produced by any diff (svn, git or just diff) like Tim said:

patch -p0 < /path/to/patch.diff

If your are fan of GUI apps then there are TortoiseSVN or  Eclipse but
i am not too sure how to apply patches with them, though a quick
google search would answer that question probably.

[1] http://gnuwin32.sourceforge.net/packages/patch.htm
[2] http://sourceforge.net/projects/unxutils/

Davor

--

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




how to activate a custom tag or filter in a string

2009-11-26 Thread swap0
Can someone help me out with this. Is this possible?

I have created a simple custom tag that replace the tag with a
javascript.

My tag look like this {{ " "|putMap:".."}}. It takes
only argument and will replace the tag with GoogleMapAPI.


--
from django import template

register = template.Library()

def putMap(value, arg):
..
..
..
..
..
return '''...'''
sayHi.is_safe=True;

register.filter('putMap', putMap)
--

The problem is this. I want uses to input this tag in a . My
result of my first attempt tells me that if I put this tag in
 it will just be a normal text string and tag function will
not activate.

So is it possible to put a custom tag in a textarea,
 save the text string to database,
   and when I retrieve this string later and the
tag will still work?

--

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




Re: Application naming and project directory layout

2009-11-26 Thread Marcus Weseloh
On Thu, 26 Nov 2009 10:18:44 +0100
Marcus Weseloh  wrote:

> [...] but are there other areas in Django that rely on
> applications having unique names? Do I need to ditch the Python-style
> namespacing and resort to module1_app1, module2_app1 application names?

Answering my own question: at least the permission system (permission
names) and the django-admin.py tool also expect applications to have
unique names.

I guess I have to rethink my project layout.

Cheers,

Marcus

--

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




Re: import twice when run test

2009-11-26 Thread Tom Evans
On Thu, Nov 26, 2009 at 2:35 AM, fallhunter  wrote:

> i have this code in my tests.py:
>
> from models import *
>
> and in the models.py I have a signal handler and register it with
>
> post_save.connect( post_save_note, sender=Note )
>
> and when i run test with ./manage.py test main
>
> I found the signal handler was registered twice and executed twice,
> and I found it's because the models was imported twice.
>
> can't i put "from models import *" in the test code? what should i do?
>
>
This happens if you import the same file using two different names. Eg, here
you are importing it as 'from models import *'. In some other part of your
code, you probably have 'from foo.models import *'. Python treats them as
two different files, and hence the signal is attached twice.

Remove/rework the spurious import, and everything will work.

Cheers

Tom

--

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




Form validation

2009-11-26 Thread pinco
Hi there.

I’m not able to figure out how to solve in a simple and clean way the
following problem.
Basically what I want to do is to edit the instances of the following
model:

Models.py
class Seller(models.Model):
brand = models.CharField(max_length=250)
 ...
slug = models.SlugField(unique=True)

The form is generated using the following code. The validator should
ensure that the entered brand is unique among the registered users. I
would use the same form both to create and to edit Seller instances.

Forms.py
class SellerForm(ModelForm):

class Meta:
model = Seller

def clean_brand(self):
try:
Seller.objects.get(brand=self.cleaned_data['brand'])
except Seller.DoesNotExist:
return self.cleaned_data['brand']
raise forms.ValidationError("This brand is already used.
Please choose another.")

Finally, the view for editing a Seller instance is the following:

Views.py
def edit(request):
if 'seller' in request.session:
this_seller = get_object_or_404(Seller, pk=request.session
['seller'])
else:
return render_to_response('default.html', {'notice': "Seller
must be logged in to edit the profile"})
if request.method == 'POST':
form = EditForm(request.POST, instance = this_seller)
if form.is_valid():
new_seller = form.save()
return render_to_response('default.html', {'notice':
"Seller profile has been updated"})
else:
return render_to_response('edit.html', {'edit_form':form})
else:
form = EditForm(instance = this_seller)
return render_to_response('edit.html', {'edit_form':form})

The problem I’m facing is the clean_brand validator. As a matter of
fact I want the brand to be unique for each user. The code works fine
when I firstly create a new brand. However when editing an existing
brand with the above code, a validation error is generated if the
brand is not modified, since the brand already exists in the
database.
Is there a simple way to solve this problem?

--

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




Re: Is there any way of model cross reference placed in different files but in one app?

2009-11-26 Thread Denis Cheremisov
Oh, thanks, that works!

On 26 ноя, 13:03, Daniel Roseman  wrote:
> On Nov 26, 10:01 am, Denis Cheremisov 
> wrote:
>
> > I have models directory with several files in it (models/__init__.py,
> > models/main.py, ...)
> > I have basic "Article" model and many models derived from it. So, I
> > would like to place them into separate file: models/article.py
> > But I also have several models ("Image" and "Section") which contain
> > ForeignKey(Article,...) and, on the  other hand, Article also has
> > ForeingKey on them. I tried to use ".models.main.Image" and
> > ".models.main.Section" as model name, but it didnt' work.
> > Is there any way to place Article and Article-based models into
> > separate file
>
> As long as your __init__.py is importing all the models from the
> various files, you can just refer to them as appname.Image,
> appname.Section etc.
> --
> DR.

--

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




Re: applying a patch

2009-11-26 Thread paulh
Thank's for the reply. I do use tortoise and I tried what you
suggested: nothing happened. Now I look at the patch file I think
maybe it was generated by git (which I am not familiar with). The
first few lines of the patch file (downloaded from django source) are:

diff --git a/django/contrib/admin/media/js/admin/
RelatedObjectLookups.js b/django/contrib/admin/media/js/admin/
RelatedObjectLookups.js
index 1bc78f8..3941752 100644
--- a/django/contrib/admin/media/js/admin/RelatedObjectLookups.js
+++ b/django/contrib/admin/media/js/admin/RelatedObjectLookups.js

so I guess that explains it, but I thought django used used svn!

Paul Hide



On Nov 25, 7:43 pm, Tim Valenta  wrote:
> It's meant to be done through an SVN checkout, since that's the format
> that the Django development repository is kept.
>
> If you haven't got SVN, I'd start there.  If you're on Windows, the
> "nicest" solution is "tortoisesvn", which integrates pretty simply
> into the Windows shell for easy right-click controls.  If you've got
> some form of Unix, then you'll have to decide if you've already got
> the commandline client program.
>
> If you've got SVN under your belt, then you're pretty much already
> almost there.  If you're using the command line, you'll have to
> navigate to your repository, and then use:
>
>     patch -p0 < /path/to/patch.diff
>
> If you're using that Windows "TortoiseSVN", you can right-click the
> repository folder, and use the menus to find the "Apply patch"
> command.  Just locate it and it should be done.
>
> There are some complications with command line patching where file
> renames are involved.  Hopefully your patch is pretty simple.  There's
> quite a bit of info in the blog circles about this stuff, so you can
> find more specifics by searching online.
>
> Tim
>
> On Nov 25, 12:12 pm, paulh  wrote:
>
> > I am interested in applying patch 7028, but I don't know what to apply
> > it to.
> > Any help would be appreciated.
>
> > Paul Hide

--

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




Prepopulate comment form from request?

2009-11-26 Thread Anselm Lingnau
I'm using the standard Django comment framework on Django 1.1. My
template uses »render_comment_form for ...« to display a comment form.
What I'd like to do is to prepopulate the name and email fields on the
form from request.user iff the request is authenticated, but I don't
see how to get at the form to pass it an »initial« dict.

Is there a way to do this that doesn't involve rewriting the
render_comment_form tag and its underlying infrastructure?

--

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




Re: Is there any way of model cross reference placed in different files but in one app?

2009-11-26 Thread Daniel Roseman
On Nov 26, 10:01 am, Denis Cheremisov 
wrote:
> I have models directory with several files in it (models/__init__.py,
> models/main.py, ...)
> I have basic "Article" model and many models derived from it. So, I
> would like to place them into separate file: models/article.py
> But I also have several models ("Image" and "Section") which contain
> ForeignKey(Article,...) and, on the  other hand, Article also has
> ForeingKey on them. I tried to use ".models.main.Image" and
> ".models.main.Section" as model name, but it didnt' work.
> Is there any way to place Article and Article-based models into
> separate file

As long as your __init__.py is importing all the models from the
various files, you can just refer to them as appname.Image,
appname.Section etc.
--
DR.

--

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




Is there any way of model cross reference placed in different files but in one app?

2009-11-26 Thread Denis Cheremisov
I have models directory with several files in it (models/__init__.py,
models/main.py, ...)
I have basic "Article" model and many models derived from it. So, I
would like to place them into separate file: models/article.py
But I also have several models ("Image" and "Section") which contain
ForeignKey(Article,...) and, on the  other hand, Article also has
ForeingKey on them. I tried to use ".models.main.Image" and
".models.main.Section" as model name, but it didnt' work.
Is there any way to place Article and Article-based models into
separate file

--

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




add permission by name instead of number

2009-11-26 Thread Adonis
Hi,

I have been going through the permission documentation and i know i
can assign users with permissions like this,

*
request.user.user_permissions.add(1)
*

But having 100 or more permissions i find this method a bit weird. Is
not there a way to say,

*
request.user.user_permissions.add('auth.delete_permission') or what i
found in an other post,
*

*
def get_permission_object(perm_label):
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission
app_label,perm_code_name = perm_label.split('.')
content_type = ContentType.objects.get(app_label=app_label)
perm = Permission.objects.get
(content_type=content_type,codename=perm_code_name)
return perm

def add_perm_to_user(user,perm_label):
user.user_permissions.add(get_permission_object(perm_label))
user.save()
return user
*

Any suggestions?
Thanks in advance!

--

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




DecimalField / floatField format

2009-11-26 Thread Benjamin Wolf
Hi there,

I need another decimalField / floatField format (',' instaed of '.')
I've found this: 
http://groups.google.com/group/django-users/browse_thread/thread/9ff4db80932d334f
But I ask myself if there isn't a simpler method for such a common task. 
(Like setting the input format for a datefield)
Perhaps the time/date/currency/float formats should get adapted to the 
language set in the langauge_code in the settings, or not?


Thanks for your help,
ben

--

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




Re: Chart tool

2009-11-26 Thread S.Selvam
On Thu, Nov 26, 2009 at 2:01 AM, Javier Guerra  wrote:

> On Wed, Nov 25, 2009 at 3:07 PM, S.Selvam  wrote:
> > I need to show some data as a chart.
> >
> > I would like to achieve a high quality rendering.
> >
> > Is reportlab or matplotlib enough ?
>
> reportlab allows you to generate PDFs, which can be as high quality as
> you want; but if you want to display them on a webpage it's far from
> the best.
>
> matplotlib is nice, being python.  the biggest drawback is that being
> a server-side task, so you have to deal with the processing time
> and/or storage/deletion of (old) images.
>
> for in-page charts, you can use flot (http://code.google.com/p/flot/),
> or Google Charts (http://code.google.com/apis/chart/).  the first one
> is a jQuery plugin, the other is an API that basically lets you
> construct an URL for a PNG that's rendered on Google servers.  in both
> cases, you simply put (some of) your data on the page and let either
> the client (if using flot) or somebody else (if using Google charts)
> deal with the heavy tasks.
>


Thanks Javier,
   It helped me a lot.

  I have been trying with matplotlib by drawing the resultant chart to
canvas and attaching it with response.(Hence i dont save the image as a temp
file ).



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


-- 
Yours,
S.Selvam

--

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




Re: Why are collapsed fieldsets expanded on submit in the admin?

2009-11-26 Thread Benjamin Wohlwend
Hi,

On 25 Nov., 16:14, Tom Evans  wrote:
> On Mon, Nov 23, 2009 at 3:57 PM, Benjamin Wohlwend wrote:
>
> > From a
> > technical view, both the client and the server couldn't care less if
> > the form fields are visible or not, they process them all the same.
>
> If that was true, then you would be right. However it isn't true. Some
> browsers will not submit non hidden form elements if they are not rendered.
> Admittedly, only crap old browsers[1].

oh, wow, I didn't know that. I thought I have seen it all with respect
to stupid browser bugs... Do you (or somebody else) know which
browsers beside the ancient Netscape 6 and Opera 7 expose bugs of this
kind?

Regards,
Benjamin

>
> Cheers
>
> Tom
>
> [1]http://bytes.com/topic/javascript/answers/89759-problems-form-element...

--

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




Re: strange style difference between development and production

2009-11-26 Thread andreas schmid
rebus_ wrote:
> 2009/11/26 andreas schmid :
>   
>> hi,
>>
>> i just noticed that the css is interpreted differently between my
>> development environment on my local machine and the deployment on the
>> server.
>>
>> locally i run the django project trough runserver and on production im
>> using wsgi with apache.
>>
>> the proportions are all right but everything is bigger if i look at
>> online site. i use the same browser to look at it.
>>
>> how is that possible?
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>> 
> This may sound silly, but are you sure you haven't used zoom in
> firefox for you production server? Try hitting Crtl+0 ?
>
> Davor
>
>   
it sounds silly and it is!! i cant explain it!

even pictures inserted in an  without resizing them trough css are
rendered bigger on production.
if i go to view image on the browser both are the same size and if i
look at the img properties with the web developer toolbar the with and
height is the same... so i really have no idea how this is possible.

--

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




Re: Creating dynamic models?

2009-11-26 Thread Kevin Renskers
Hi Matthias ,

Thank you, I went for option 1 and it works perfectly!

Funny, the add_to_class function basically does "setattr(cls, name,
value)". So I had the right solution, only you have to do this after
class creation, not inside its __init__ function. Good to know, will
blog about this :)

Again, thank you very much.

Cheers,
Kevin


On Nov 26, 10:14 am, Matthias Kestenholz
 wrote:
> On Thu, Nov 26, 2009 at 9:56 AM, Kevin Renskers  wrote:
> > Just a small update: the DynamicModels way as described on the wiki
> > doesn't work (it also says that it only works in Django 0.96, so
> > yeah..).
>
> > If anyone has any idea how to do this, I would be very thankful!
>
> > On Nov 24, 2:35 pm, Kevin Renskers  wrote:
> >> Hi all,
>
> >> In my Django project I want to have a model that is dynamically
> >> created. I tried using the __init__ function for this,  something like
> >> so:
>
> >> fields = ['field_a', 'field_b', 'field_c']
>
> >> class MyModel(models.Model):
> >>     def __init__(self, *args, **kwargs):
> >>         for field in fields:
> >>             setattr(self, field, models.DecimalField(decimal_places=4,
> >> max_digits=10))
>
> >> Sadly, this doesn't work. The columns don't get created when you run
> >> the syncdb command, and even something like
> >> MyModel._meta.get_all_field_names() doesn't return the dynamic fields.
>
> >> So, is there a way I can create a "dynamic" model? I did come 
> >> acrosshttp://code.djangoproject.com/wiki/DynamicModelsbutI don't really
> >> get that. It looks so much different then normal models, it seems like
> >> I would loose a lot of functionality or would have to change a lot of
> >> code somewhere else in my application?
>
> >> Hopefully there is an easy way to do this :)
>
> I can see two ways to achieve what you seem to want:
>
> 1. Add fields after the model has been created
>
> This method uses an only unofficially documented feature[1] of
> Django's model field classes.
>
> class MyModel(models.Model):
>     # a few fields
>
> for field in fields:
>     MyModel.add_to_class(field, models.DecimalField(decimal_places=4,
> max_digits=10))
>
> 2. Construct a new type dynamically
>
> class Meta:
>     verbose_name = _('my model')
>
> attrs = {
>     '__module__': 'mymodule',
>     'Meta': Meta,
>     'method1': method1,
>     # ... more fields and methods
>
> }
>
> for field in fields:
>     attrs[field] = models.DecimalField(...)
>
> MyModel = type('MyModel', (models.Model,), attrs)
>
> Of course, the usual caveats apply. It might make your code harder to
> read and understand, and harder to debug too, because it is not clear
> what model fields exist by simply looking at the model code (that
> applies especially to method 1)
>
> Matthias
>
> [1]: It's documented in Marty Alchin's excellent Pro Django book. I
> think we can assume that this method won't go away without very good
> reasons(tm).

--

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




Application naming and project directory layout

2009-11-26 Thread Marcus Weseloh
Hi,

I'm developing an application with several services/modules, every module
is structured into several apps. I'm planning to use the following
directory structure:

project/
  module1/
 app1 (!)
 app2
 app3
  module2/
 app1 (!)
 app4
 app5

Both modules contain an application called app1, and I would like
module1.app1 and module2.app1 to both contain models of the same name.
This will obviously fail, as Django only uses the "app1" part as a
table prefix. I can fix that by distinquishing the models using
"app_label", but are there other areas in Django that rely on applications
having unique names? Do I need to ditch the Python-style namespacing
and resort to module1_app1, module2_app1 application names?

Cheers,

Marcus

--

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




Re: Creating dynamic models?

2009-11-26 Thread Matthias Kestenholz
On Thu, Nov 26, 2009 at 9:56 AM, Kevin Renskers  wrote:
> Just a small update: the DynamicModels way as described on the wiki
> doesn't work (it also says that it only works in Django 0.96, so
> yeah..).
>
> If anyone has any idea how to do this, I would be very thankful!
>
>
> On Nov 24, 2:35 pm, Kevin Renskers  wrote:
>> Hi all,
>>
>> In my Django project I want to have a model that is dynamically
>> created. I tried using the __init__ function for this,  something like
>> so:
>>
>> fields = ['field_a', 'field_b', 'field_c']
>>
>> class MyModel(models.Model):
>>     def __init__(self, *args, **kwargs):
>>         for field in fields:
>>             setattr(self, field, models.DecimalField(decimal_places=4,
>> max_digits=10))
>>
>> Sadly, this doesn't work. The columns don't get created when you run
>> the syncdb command, and even something like
>> MyModel._meta.get_all_field_names() doesn't return the dynamic fields.
>>
>> So, is there a way I can create a "dynamic" model? I did come 
>> acrosshttp://code.djangoproject.com/wiki/DynamicModelsbut I don't really
>> get that. It looks so much different then normal models, it seems like
>> I would loose a lot of functionality or would have to change a lot of
>> code somewhere else in my application?
>>
>> Hopefully there is an easy way to do this :)
>>

I can see two ways to achieve what you seem to want:

1. Add fields after the model has been created

This method uses an only unofficially documented feature[1] of
Django's model field classes.

class MyModel(models.Model):
# a few fields

for field in fields:
MyModel.add_to_class(field, models.DecimalField(decimal_places=4,
max_digits=10))



2. Construct a new type dynamically

class Meta:
verbose_name = _('my model')

attrs = {
'__module__': 'mymodule',
'Meta': Meta,
'method1': method1,
# ... more fields and methods
}

for field in fields:
attrs[field] = models.DecimalField(...)

MyModel = type('MyModel', (models.Model,), attrs)




Of course, the usual caveats apply. It might make your code harder to
read and understand, and harder to debug too, because it is not clear
what model fields exist by simply looking at the model code (that
applies especially to method 1)


Matthias

[1]: It's documented in Marty Alchin's excellent Pro Django book. I
think we can assume that this method won't go away without very good
reasons(tm).

--

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




Re: Creating dynamic models?

2009-11-26 Thread Kevin Renskers
Just a small update: the DynamicModels way as described on the wiki
doesn't work (it also says that it only works in Django 0.96, so
yeah..).

If anyone has any idea how to do this, I would be very thankful!


On Nov 24, 2:35 pm, Kevin Renskers  wrote:
> Hi all,
>
> In my Django project I want to have a model that is dynamically
> created. I tried using the __init__ function for this,  something like
> so:
>
> fields = ['field_a', 'field_b', 'field_c']
>
> class MyModel(models.Model):
>     def __init__(self, *args, **kwargs):
>         for field in fields:
>             setattr(self, field, models.DecimalField(decimal_places=4,
> max_digits=10))
>
> Sadly, this doesn't work. The columns don't get created when you run
> the syncdb command, and even something like
> MyModel._meta.get_all_field_names() doesn't return the dynamic fields.
>
> So, is there a way I can create a "dynamic" model? I did come 
> acrosshttp://code.djangoproject.com/wiki/DynamicModelsbut I don't really
> get that. It looks so much different then normal models, it seems like
> I would loose a lot of functionality or would have to change a lot of
> code somewhere else in my application?
>
> Hopefully there is an easy way to do this :)
>
> Cheers,
> Kevin

--

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




Re: strange style difference between development and production

2009-11-26 Thread rebus_
2009/11/26 andreas schmid :
> hi,
>
> i just noticed that the css is interpreted differently between my
> development environment on my local machine and the deployment on the
> server.
>
> locally i run the django project trough runserver and on production im
> using wsgi with apache.
>
> the proportions are all right but everything is bigger if i look at
> online site. i use the same browser to look at it.
>
> how is that possible?
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>
This may sound silly, but are you sure you haven't used zoom in
firefox for you production server? Try hitting Crtl+0 ?

Davor

--

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




strange style difference between development and production

2009-11-26 Thread andreas schmid
hi,

i just noticed that the css is interpreted differently between my
development environment on my local machine and the deployment on the
server.

locally i run the django project trough runserver and on production im
using wsgi with apache.

the proportions are all right but everything is bigger if i look at
online site. i use the same browser to look at it.

how is that possible?

--

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