Re: Error when I use datetime.now()

2007-10-19 Thread Michael Newman

try datetime.now().__str__() or if you want to make it pretty try
datetime.now().strftime(YourCustomFormatHere). Look at
http://docs.python.org/lib/strftime-behavior.html#strftime-behavior

Your problem is a datetime object is a not a string. Both those above
examples turn it into a string.

On Oct 19, 11:22 pm, Greg <[EMAIL PROTECTED]> wrote:
> Hello,
> I have a class called Orders that tries to add the current date to
> it's comments field when it's saved.  Here is my code:
>
> from datetime import datetime
>
> class Order(models.Model):
> comments = models.TextField("Comments", maxlength=1000)
> etc...
>
> def save(self):
> self.comments += "This is a string - " + datetime.now() + "
> This is a string "
>
> 
>
> Whenever, I save my order class I get the following error:
>
> TypeError at /admin/plush/order/1/
> cannot concatenate 'str' and 'datetime.datetime' objects
>
> Any Suggestions?


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



Error when I use datetime.now()

2007-10-19 Thread Greg

Hello,
I have a class called Orders that tries to add the current date to
it's comments field when it's saved.  Here is my code:

from datetime import datetime

class Order(models.Model):
comments = models.TextField("Comments", maxlength=1000)
etc...

def save(self):
self.comments += "This is a string - " + datetime.now() + "
This is a string "



Whenever, I save my order class I get the following error:

TypeError at /admin/plush/order/1/
cannot concatenate 'str' and 'datetime.datetime' objects

Any Suggestions?


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



Re: How do I do this JOIN...

2007-10-19 Thread Malcolm Tredinnick

On Fri, 2007-10-19 at 15:04 -0700, Dr Stitch wrote:
> Greeting all!
> 
> CAVEAT:  I'm a Django newbie. I've spent about 3 hours searching,
> reading, hazing over all the documentation and tutorials and it's
> quite likely I have missed it or I'm way too new to Django to
> understand the simplicity of the solution for the problem I'm
> presenting.  So, feel free to "RTFURL" (provided you provide the
> URL :)  Okay, enough said.
> 
> The models.py from my app ("publications") is included at the end.  My
> end goal is to get the following:  'published.title,
> journal_names.name, journal_impact_factor.impact_factor'.
> 
> In standard SQL land, it would be something like:
> 
> SELECT published.title, journal_names.name,
> journal_impact_factor.impact_factor
> FROM published, journal_names, journal_impact_factor
> WHERE
>  published.journal_names_id=journal_names.id
>  AND
>  published.year=journal_impact_factor.year
>  AND
>  journal_impact_factor.journal_names_id=journal_names.id;
> 
> Now, I can get publication title and journal name via:
>  latest_pubs_list = published.objects.all().order_by('-date')[:10]
>  [ (p.title, p.journal_names.name) for p in latest_pubs_list]
> 
> But I'm stumped on how to bring in the
> journal_impact_factor.impact_factor.  Ideas?

You're on the right track. The key bit you're missing is that you how to
refer to reverse relations. That is described in [1].

It's also necessary to realise that the many-to-one (ForeignKey) mapping
between journal_impact_factor and journal means there can be multiple
impact factors for a single journal (the reverse of many-to-one is one
to *many*, after all). However, if you know for other reasons that
you'll only have one impact for each journal, you can do this:

[(p.title, p.journal_names.name,
   p.journal_names.journal_impact_factor_set.all()[0].impact_factor)
   for p in latest_pubs_list]

If you're going to be doing that query a lot, you might also want to
look at the select_related() method on queyrsets (see [2]), so that you
pull all the data back from the database in one query, rather than
making three separate runs to the db (one for each access to a remote
model).

[1] http://www.djangoproject.com/documentation/db-api/#backward
[2] http://www.djangoproject.com/documentation/db-api/#select-related

Regards,
Malcolm

-- 
Honk if you love peace and quiet. 
http://www.pointy-stick.com/blog/


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



Re: python mvc framework and java mvc framework

2007-10-19 Thread Kenneth Gonsalves


On 20-Oct-07, at 7:22 AM, Laszlo Marai wrote:

> You can host multiple applications in django but as far as I could see
> from the mailing list you'll have some problem if you want to have two
> different django instances running under mod_python.

not so. There have been reports of over 70 django instances running  
under mod_python in the same server. I have 12 in one server without  
problems.

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



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



Re: Problem with query on m2m relation

2007-10-19 Thread Malcolm Tredinnick

On Fri, 2007-10-19 at 08:24 -0700, web-junkie wrote:
> Hi,
> 
> I have a m2m relationship from books to authors. A book can have 0-n
> authors (yes, don't ask why there can be no authors). If I want to do
> a search where I it should match the title or authors, I just gives me
> books that have an author. Not the other matches. See here for the
> code:
> 
> http://dpaste.com/22883/
> 
> Is my query wrong? Or wouldn't be the correct behaviour to do a left
> join and alllow null values? (Bug?)

This looks like some combination of #2080, #2253 and #3592. All of those
are fixed on the queryset-refactor branch and will be merged into trunk
when the work on that branch is finished.

Regards,
Malcolm

-- 
Always try to be modest and be proud of it! 
http://www.pointy-stick.com/blog/


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



Re: python mvc framework and java mvc framework

2007-10-19 Thread Kenneth Gonsalves


On 20-Oct-07, at 7:46 AM, Laszlo Marai wrote:

>>
>> not so. There have been reports of over 70 django instances running
>> under mod_python in the same server. I have 12 in one server without
>> problems.
>
> Wasn't there a question here about mod_python a few days ago where the
> solution was to configure different interpreters for each django
> instances? I might have misunderstood the problem.

yes there was. There are several threads on this. But the conclusion  
is that these were the result of improper configuration of the  
servers in question, caches and things like that. I have not seen any  
reports of persistent problems. I had one case of two sites that were  
nearly identical - and at times in admin, fields from one site would  
appear on the index of the other. But this was when both sites were  
open at the same time in firefox tabs - so I put it down to browser  
cache. There has been no report from my users (each of whom can only  
access their sites) of any crossover.

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



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



Re: python mvc framework and java mvc framework

2007-10-19 Thread Laszlo Marai

On Sat, 20 Oct 2007 07:40:27 +0530
Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:

> > You can host multiple applications in django but as far as I could see
> > from the mailing list you'll have some problem if you want to have two
> > different django instances running under mod_python.
> 
> not so. There have been reports of over 70 django instances running  
> under mod_python in the same server. I have 12 in one server without  
> problems.

Wasn't there a question here about mod_python a few days ago where the
solution was to configure different interpreters for each django
instances? I might have misunderstood the problem.

  atleta

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



Re: python mvc framework and java mvc framework

2007-10-19 Thread James Bennett

On 10/19/07, Laszlo Marai <[EMAIL PROTECTED]> wrote:
> So the java solutions need more configuration work but they might be more
> flexible in some cases. And don't forget that you're comparing a set of
> components (java) against a full stack (django). The configuration work
> can be alleviated by pre-assembling a full stack from java components.
> There are projects that do just that (e.g. appfuse).

It's worth pointing out that in the Python world, WSGI[1] is meant to
provide a single, interoperable standard for web applications; the
idea is that no matter what framework you're using (or even if you're
not using a framework), if you speak WSGI you'll be able to run under
any WSGI-compliant web server and talk to any other WSGI applications
or use any available WSGI middlewares.

Django speaks WSGI well enough to run as a WSGI application, though
there is at least one wart I know of that we need to iron out (dealing
with SCRIPT_NAME so that Django can be arbitrarily rooted inside a
site without needing to do any special handling of URLs). I'd also
like at some point to add at least basic support for Django to act as
a WSGI server to make it easier to mix and match things (it'd be
fairly straightforward to write a generic view which hosts a WSGI
application, I think).


[1] http://www.python.org/dev/peps/pep-0333/


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

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



Re: python mvc framework and java mvc framework

2007-10-19 Thread Laszlo Marai

On Sat, 20 Oct 2007 00:53:45 -
Francis <[EMAIL PROTECTED]> wrote:

  Hi,

I'm quite new to django but have a little insight into java.

> On the other hand, java web framework look quite complicated with lot
> of xml and manual configuration with no real advantage. Java verbosity

Well, it depends. There are tons of java frameworks. Some of them need
XML configuration some of them don't but most of them will allow you to
use it. The modern ones will allow you to use annotations which is
quite terse way of expressing configuration. The main difference here is
that django uses 'convention over configuration' while the java
most frameworks don't. Then when you talk about java web frameworks it's
usually really just the web framework without persistence or
authentication, etc. So it's not a full stack. In that world you combine
the components you like into your application while django, as far as I
can see, gives you one option for all of these.

You'll need some XML for the servlet container (web application server)
which you don't really use with django. In the java world you have a
separate server that hosts all of the web applications for a given
machine. Some of them may use one framework some of them may be just
plain servlets. You can deploy them on the same server without any
problem. You can even apply independent pre/post processors (so
called servlet filters). They are like django middlewares (if I got that
right) but they're standard components and can be plugged in
without touching the application. This all needs to be wired together
somehow.

You can host multiple applications in django but as far as I could see
from the mailing list you'll have some problem if you want to have two
different django instances running under mod_python.

So the java solutions need more configuration work but they might be more
flexible in some cases. And don't forget that you're comparing a set of
components (java) against a full stack (django). The configuration work
can be alleviated by pre-assembling a full stack from java components.
There are projects that do just that (e.g. appfuse).

> and static checking may help to find bug earlier than with python.
> Python doesn't force you to include exception, assertion etc.. which
> may lead to spent more time debuging or delevering application that
> broke more often.

It's a matter of taste. I kind of like static type checking some people
don't. I also like having to declare exceptions. There is a more-or-less
valid argument that you have to write unit tests anyway, no matter if
you use a statically or dynamically typed language, and those tests are
supposed to catch (most of the) type errors.

> My question is to someone who actually try both, are they similar in
> productivity and enterprise quality?

For quality you'll need the unit tests. I'm not sure if you need to write
more tests for python to make up for the lack of static type checking or
not. I would think that you should, but I don't have enough experience
yet. But the quality can be assured by good tests and they are needed in
both cases.

I can't really tell anything about the productivity as I'm really slow in
django :) bacause I know very little yet. In java you have to use the
right tools and components to be productive and that's not an easy task.
On the other hand my feeling is that if you know your environment then
there isn't such a big difference between the two. (I know it's quite a
rebell view here :) and I'm actually using django to test this claim.)
Java frameworks have a lot to learn/steal from django to become more
productive. E.g. I don't think that there is any framework out there that
support the generic view concept of django.

If you don't have any background then you'll probably better off starting
with django because it has everything put together.

  atleta

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



Re: Custom middleware for logging

2007-10-19 Thread Jeremy Dunck

On 10/19/07, Steve Potter <[EMAIL PROTECTED]> wrote:
>
> I would like to put together a piece of code that will test the
> referer for each request and if it matches a predefined pattern it
> would log that request as well as place a cookie on the client.
>
> Is custom middleware the correct place to do this?

Yes.  It sounds like you want to use process_request, do your
matching, and either log right then, or, if you need to wait for the
response for some reason, annotate the request with an extra
attribute, which a later process_* can check for.

> Also, I'm not exactly clear how response.set_cookie() works.  If I set
> a cookie in the middleware during a request, will it be passed to the
> client on the next response?

Use response.set_cookie in process_response.  That's always the
response passed back from the resolved view.  The cookie will be set
on *that* response, which is going on the wire back to the client just
after you return.  :)

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



Custom middleware for logging

2007-10-19 Thread Steve Potter

I would like to put together a piece of code that will test the
referer for each request and if it matches a predefined pattern it
would log that request as well as place a cookie on the client.

Is custom middleware the correct place to do this?

Also, I'm not exactly clear how response.set_cookie() works.  If I set
a cookie in the middleware during a request, will it be passed to the
client on the next response?

Thanks,

Steve


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



python mvc framework and java mvc framework

2007-10-19 Thread Francis

Hi,

For personnal information and curiosity, I was looking at the
available java mvc web framework out there.

One thing that I found particular, is that the dynamic language camp
market their framework as productive environnement, easy and so. While
the java framework emphasis on the enterprise-quality application.

On the other hand, java web framework look quite complicated with lot
of xml and manual configuration with no real advantage. Java verbosity
and static checking may help to find bug earlier than with python.
Python doesn't force you to include exception, assertion etc.. which
may lead to spent more time debuging or delevering application that
broke more often.

My question is to someone who actually try both, are they similar in
productivity and enterprise quality?

Francis


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



Custom Validator inside of a Custom Manipulator

2007-10-19 Thread Michael Newman

I am so close to getting this project done. The last little bit is all
about validation. I have been following the docs pretty closely and am
really at a loss as to what is going on right now. The Error:
TypeError at /videoUploader/
__init__() got an unexpected keyword argument 'field_name'

Here is my views.py:

from django.http import HttpResponse, HttpResponseRedirect
from django import newforms as forms
from videouploader.upload.models import VideoSubmission
from django.shortcuts import render_to_response, get_object_or_404
from videouploader.upload.validator import VideoManipulator


def upload_video(request):
m = VideoManipulator()
if request.method =='POST':
new_data = request.POST.copy()
new_data.update(request.FILES)
errors = m.get_validation_errors(new_data)
m.do_html2python(new_data)
if not errors:
new_video = VideoSubmission.save(new_data)
return HttpResponseRedirect('/videoUploader/
done/%i' % new_video.id)
else:
errors = new_data = {}
form = forms.FormWrapper(m, new_data, errors)
return render_to_response('form.html',{
'form': form
})

and the validator/manipulator file:

from django.forms import Manipulator
from django import newforms as forms
from django.core import validators
from datetime import date

class VideoManipulator(Manipulator):
def __init__(self):
self.fields = (
forms.FileField( field_name = "videoupload",
validator_list = [self.isValidFile]),
forms.EmailField( field_name = "email",
validator_list = [validators.isValidEmail]),
forms.CharField( field_name = "entrantname",
validator_list = [validators.hasNoProfanities]),
forms.DateField( field_name = "entrantDOB",
vallidator_list = [self.is18]),
forms.CharField( field_name = "name",
validator_list = [validators.hasNoProfanities]),
forms.DateField( field_name = "kidDOB",
validator_list = [self.isInDateRange]),
forms.CharField( field_name = "city",
validator_list = [validators.hasNoProfanities]),
forms.TextField( field_name = "caption",
validator_list = [validators.hasNoProfanities]),
forms.BooleanField( field_name = "TOS",
validator_list = [self.mustBeTrue]),
forms.BooleanField( field_name = "parent",
validator_list = [self.mustBeTrue]),
forms.BooleanField( field_name = "waiver",
validator_list = [self.mustBeTrue]),
)


Any help would be greatly appreciated. This will keep me up tonight ;)


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



More friends more money,get friends while get paid

2007-10-19 Thread my god

More friends more money,get friends while get paid
http://groups.google.com/group/all-good-things/web/get-friends-while-get-paid


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



How do I do this JOIN...

2007-10-19 Thread Dr Stitch

Greeting all!

CAVEAT:  I'm a Django newbie. I've spent about 3 hours searching,
reading, hazing over all the documentation and tutorials and it's
quite likely I have missed it or I'm way too new to Django to
understand the simplicity of the solution for the problem I'm
presenting.  So, feel free to "RTFURL" (provided you provide the
URL :)  Okay, enough said.

The models.py from my app ("publications") is included at the end.  My
end goal is to get the following:  'published.title,
journal_names.name, journal_impact_factor.impact_factor'.

In standard SQL land, it would be something like:

SELECT published.title, journal_names.name,
journal_impact_factor.impact_factor
FROM published, journal_names, journal_impact_factor
WHERE
 published.journal_names_id=journal_names.id
 AND
 published.year=journal_impact_factor.year
 AND
 journal_impact_factor.journal_names_id=journal_names.id;

Now, I can get publication title and journal name via:
 latest_pubs_list = published.objects.all().order_by('-date')[:10]
 [ (p.title, p.journal_names.name) for p in latest_pubs_list]

But I'm stumped on how to bring in the
journal_impact_factor.impact_factor.  Ideas?  Maybe I've come about
the model construction from the wrong perspective (i.e. a pure PGSQL
as opposed to the "Django" way).  I don't know.  But I'd appreciate
any insight anyone could provide.

Oh yeah, if I've been too brief or you need more snippets, just let me
know!

Thanks!
-Tim

~ models.py
from django.db import models

# Create your models here.

class journal_names(models.Model):
 name = models.CharField(maxlength=80)
 citation = models.CharField(maxlength=80)

 class Admin:
  pass

 class Meta:
  verbose_name_plural = "journal_names"

class journal_impact_factor(models.Model):
 journal_names = models.ForeignKey(journal_names)
 year = models.PositiveSmallIntegerField()
 impact_factor = models.FloatField(max_digits=5, decimal_places=3)

 class Admin:
  pass

class published(models.Model):
 journal_names = models.ForeignKey(journal_names)
 title = models.CharField(maxlength=160)
 year = models.PositiveSmallIntegerField()

 class Admin:
  pass

 class Meta:
  verbose_name_plural = "published"


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



Re: two block template tags on after another

2007-10-19 Thread johnny

What I need to do is, get the records from the database and split
fields contents.  One of the field, has commas separated contents and
another field has - separated fields.  In my view, I just do fetchall
of database records and send to view.  From the view, I do a for loop
to go through each records, and split two of the fields contents that
have - and , separated values.

I have got it to work now.  I think splitting the field records
contents by template tags is the best solution.  Correct me if I am
wrong.



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



Re: two block template tags on after another

2007-10-19 Thread Karen Tracey
On 10/19/07, Marty Alchin <[EMAIL PROTECTED]> wrote:
>
> So instead of trying to use output.custom_format_string1(), you'd just
> do whatever your template tag needs to do.


Which brings up the question, what are you (johhny) trying to do?  I'm
unable to grasp the intent of the block tags code you've posted by looking
at it, but I have a sneaking suspicion that whatever you are trying to
accomplish may be more easily done in some simpler fashion.  If you start
with a higher-level description of what you'd like to do, someone may be
able to point towards an easier way.

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



custom field doesnot validating at admin page

2007-10-19 Thread ViX

Hi,
I am trying a custom field with a special data field have to handle.
The data is a 4 digit with or with a letter at the end. eg. 9(a),
99(a), 999(a), (a).

class CustCharField(models.CharField):
def __init__(self, *args, **kwargs):
models.CharField.__init__(self, max_length=5, *args, **kwargs)

#def to_python(self, value):
#if (not value[:-1].isdigit()) or (len(value[:-1]) > 4):
#   raise validators.ValidationError, _(u'Seq is 4 numbers max
with at most 1 letter only trailing, eg. 9(a), 99(a), 999(a),
(a)')
#if value[-1].isdigit():
#return  "%04d" % int(value)
#else:
#return "%04d%s" % (int(value[:-1]), value[-1])

def validate(self, field_data, all_data):
if (not field_data[:-1].isdigit()) or (len(field_data[:-1]) >
4):
raise validators.ValidationError, _(u'Seq is 4 numbers max
with at most 1 letter only trailing, eg. 9(a), 99(a), 999(a),
(a)')

def get_internal_type(self):
return "CharField"

class Test(models.Model):
cust = CustCharField()

When I try to use shell, it seems it works:
>>> from mysite.testapp import models
>>> c1 = models.Test()
>>> b1.cust = "a"
>>> b1.validate()
{'cust': [u'Seq is 4 numbers max with at most 1 letter only trailing,
eg. 9(a), 99(a), 999(a), (a)']}
>>>

But when I use the admin page, it doent show up an alert message
asking to change the field value, and then store it to database with
no exception. If I comment the to_python function about out. The admin
page does encouter an exception, but it halts instead of pop up alert
message.

Any clue on how this can be fix? TIA

Best,
ViX


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



Re: two block template tags on after another

2007-10-19 Thread Marty Alchin

On 10/19/07, johnny <[EMAIL PROTECTED]> wrote:
> upper() in output.upper(), I am assuming is the name of the template
> tag.  When I try to do it as in this example, I get an error:
>
> 
>
> I didn't understand the output.upper() part.  I think the
> documentation above is written for people who already know how the
> template tag works, it doesn't do any good for beginners.

It's written for people who are somewhat familiar with Python itself.
upper() is a standard method of all Python strings. It has nothing to
do with the template tag except that it's what the tag uses to make
the string all uppercase.

So instead of trying to use output.custom_format_string1(), you'd just
do whatever your template tag needs to do.

-Gul

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



Re: two block template tags on after another

2007-10-19 Thread johnny

I am looking at this documentation:
http://www.djangoproject.com/documentation/templates_python/#parsing-until-another-block-tag-and-saving-contents

It has the following code:
output = self.nodelist.render(context)
return output.upper()

upper() in output.upper(), I am assuming is the name of the template
tag.  When I try to do it as in this example, I get an error:

Exception Type: AttributeError
Exception Value:'unicode' object has no attribute
'custom_format_string1'

If I comment out #return output.custom_format_string2() and just do it
like this, it works:

#return output.custom_format_string1()
return output

I didn't understand the output.upper() part.  I think the
documentation above is written for people who already know how the
template tag works, it doesn't do any good for beginners.


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



Re: access session out of view, howto find out sessionkey?

2007-10-19 Thread Simon Oberhammer

wow, I'm glad there is a cookbook entry for this :-) thank you

On Oct 19, 3:30 pm, skam <[EMAIL PROTECTED]> wrote:
> You should be able to build a middleware similar 
> tohttp://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser,
> getting request.session instead of request.user


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



Djangonauts in Amsterdam, Prague, or Krakow?

2007-10-19 Thread Brian Luft

My wife and I are travelling through Eastern Europe for the next 2
months. (we're starting in Amsterdam though).

I'd love to meet up with any Djangonauts for a little chat.  I like
beer, wine, Django, and open source software if anyone can spare a few
minutes for a chat :)

Cheers
-Brian


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



Re: Python 2.3 deployment

2007-10-19 Thread Malcolm Tredinnick

On Fri, 2007-10-19 at 13:29 +0100, Chris Hoeppner wrote:
> Huh I lied. The django update only forced me to call that view with
> POST, and now that I'm doing, it's throwing the same traceback. I'm not
> sure what this might be. I'll check again with the system admins.

When you tested at the interactive prompt -- which doesn't involve
Django at all, did your random module contain a randint function? That
would be the first thing to establish.

Regards,
Malcolm



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



Re: two block template tags on after another

2007-10-19 Thread Karen Tracey
I suspect the template processing code is getting confused by:

{% end_custom_format_string2 %)


Which should be:

{% end_custom_format_string2 %}

That is, sqiggly brace, not paren, at the end.

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



Re: Problem with Pagination

2007-10-19 Thread Greg

Rob,
Thanks for the reply.  In looking at that link I found out about the
Paginator Tag.  Which I think is what I need.  However, in reading the
documenation about that tag.  It says 'To be used in conjunction with
the object_list generic view.'  I am not using a generic view.  I have
the following code in my view:

page = int(page) -1
posts = ObjectPaginator(request.session['test'], 1)

return render_to_response('search.htm', {
'posts':posts.get_page(page),
'page':page+1,
'next':posts.has_next_page(page),
'prev':posts.has_previous_page(page),
'start': posts.first_on_page(page),
'finish': posts.last_on_page(page),
'pages': posts.page_range}
)

//

I'm kinda lost in reading the documentation about the Paginator Tag.
I put a assert statement in my paginator function, however when I
accessed the template the assert statement never happened.  Also, what
is '{% spaceless %}'.  They say to put that in the template?

Thanks for any help

On Oct 19, 10:31 am, Rob Hudson <[EMAIL PROTECTED]> wrote:
> I don't think it's 100% to your specs but take a look at 
> this:http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-d...
>
> It's close enough for tweaking to get you 95% of the way there
> (maybe).


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



Re: Is posted data always in order?

2007-10-19 Thread Marty Alchin

On 10/19/07, Ken <[EMAIL PROTECTED]> wrote:
> Thanks for your reply.  It was a great help.  I followed up on reading
> the HTML spec and the posted data is returned in document order.  Next
> section.

Ah, so it is! Color me crazy, but when information about how browsers
should process data wasn't in a section titled "Processing form data",
I just stopped looking. Thanks for the followup.

-Gul

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



Re: two block template tags on after another

2007-10-19 Thread johnny

There is a problem with default django for loop tag {% for  %} {%
endfor%} .  Django template doesn't seem to like nested block tag
inside for loop tag.

{% for a_object in object_list %}
{% load custom_format %}
{% custom_format_string1 a_object.3 %}
{{split_string_data1}}
{% end_custom_format_string1 %)

{% custom_format_string2 a_object.4 %}
{{split_string_data2}}
{% end_custom_format_string2 %)
{% endfor %}

Does it mean I have to overwrite the way django template for loop tag
works?

Django Error:
Exception Type: TemplateSyntaxError
Exception Value:Invalid block tag: 'endfor'


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



Re: Is posted data always in order?

2007-10-19 Thread Ken

On Oct 19, 10:37 am, "Marty Alchin" <[EMAIL PROTECTED]> wrote:

> [1]http://www.w3.org/TR/html401/interact/forms.html#h-17.13.3

Thanks for your reply.  It was a great help.  I followed up on reading
the HTML spec and the posted data is returned in document order.  Next
section.

Ken

[1] http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4


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



Re: Python 2.3 deployment

2007-10-19 Thread Chris Hoeppner

Hi guys!

Thanks for those responses. So, the random.randint function does exist:
# python
Python 2.3.5 (#1, Aug 25 2005, 09:17:44) 
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> random.randint
>

And here's whar Thomas suggests:
AssertionError at /
/usr/lib/python2.3/random.pyc



El vie, 19-10-2007 a las 15:12 +0200, Thomas Guettler escribi�:
> >   File
> > "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", line
> > 19, in get_new_session_key session_key = md5.new("%s%s%s%s" %
> > (random.randint(0, sys.maxint - 1), os.getpid(), time.time(),
> > settings.SECRET_KEY)).hexdigest()
> >
> > AttributeError: 'module' object has no attribute 'randint'
> 
> You can test what random module you are using:
> 
> insert a line above: assert False, random.__file__
> 
> You can test the random module:
> 
> python /usr/lib64/python2.4/random.py
> 2000 times random
> 0.003 sec, avg 0.497669, stddev 0.288045, min 0.00160483, max 0.99949
> 2000 times normalvariate
> 
> 
> HTH,
>  Thomas
> 
> > 


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



Re: 0.96 login issue with cookies

2007-10-19 Thread web-junkie

Did you activate the cache in Django? I once discovered an issue with
that..


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



Re: Is posted data always in order?

2007-10-19 Thread Marty Alchin

I haven't done any testing on this, but I'd like to point out one
thing. The HTML spec[1] doesn't specify anything about browsers having
to assemble the data set in document order. This means that even if
Django made sure that the multivalues are put in POST in the order
they were received, there doesn't seem to be a guarantee that the
browser will get them in the right order. So we'd have to consider the
order of values "undefined" even if Django handled it as best it
could.

But, like I said, I haven't done any testing on this, so maybe all the
browsers do indeed post them in the proper order. Without it being in
the spec though, I wouldn't trust it to always be that way.

-Gul

[1] http://www.w3.org/TR/html401/interact/forms.html#h-17.13.3

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



Re: Problem with Pagination

2007-10-19 Thread Rob Hudson

I don't think it's 100% to your specs but take a look at this:
http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/

It's close enough for tweaking to get you 95% of the way there
(maybe).


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



Problem with query on m2m relation

2007-10-19 Thread web-junkie

Hi,

I have a m2m relationship from books to authors. A book can have 0-n
authors (yes, don't ask why there can be no authors). If I want to do
a search where I it should match the title or authors, I just gives me
books that have an author. Not the other matches. See here for the
code:

http://dpaste.com/22883/

Is my query wrong? Or wouldn't be the correct behaviour to do a left
join and alllow null values? (Bug?)


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



Re: Is posted data always in order?

2007-10-19 Thread Ken

I would like to add (if anyone who writes django documentation is
reading) a statement explicitly confirming or denying this in the
documentation would be nice.  The fact that django sub-classed a dict
to handle multiple values posted by a form seems to suggest that
multiple values are returned in the order they were posted.  It would
make the processing the posted data a lot easier.  If the order is not
guaranteed, the docs need to say it explicitly, so programmers using
django can use a different tack when constructing such forms.


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



Re: Is posted data always in order?

2007-10-19 Thread Ken



On Oct 18, 8:07 pm, Thejaswi Puthraya <[EMAIL PROTECTED]>
wrote:

> request.POST is a python dictionary and the keys need not be ordered.

You misunderstand.  I know dicts are not ordered in the sense lists
are.  My question is this:  Suppose I have a form that returns
multiple values for a given key, say, x.  That is

#  this is the first input; I submit the value x1

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



Re: py2app & py2ex

2007-10-19 Thread Francis Lavoie
Hi,

I though of doing something similar a couple of month ago without reading
about It, I somehow change my mind.

I really like django, but I don't think it is well suite for this kind of
use. What i decide to do is a python client application which use the web
server as a web service to update information when online.

I didn't start my project yet, but one thing I explore, is to use a html
widget into my graphical interface and generate html with a python template
system (like the one django use).

Maybe more experienced django developper have a different opinion or
solution. It would be very useful.

Francis


2007/10/19, ArqEco <[EMAIL PROTECTED]>:
>
>
> Hello friends,
>
> "The Story That Won't Go Away" comes back!
>
> I am a newcomer to Django and just read some posts from one year ago
> about creating standalone programs with Django and py2app or py2exe.
>
> What is the status of this issue now? Anyone found a solution?
>
> I need to develop a very simple issue tracker and (non-software)
> project management application to be used for a small team of up to
> five members.
>
> The application is being designed to be installed on desktop and
> notebook computers (where it will be used out of the office
> [offline]), and will have a synchronization feature.
>
> I think that even the built in Django development server would be fine
> to me.
>
> I tried a very simple py2app setup but stoped at the question of
> calling "python manage.py runserver" from my starting script.
> execfile() doesn't allow arguments ("runserver"). Any suggestion?
>
> These are newcomer questions but I am not a professional developer.
>
> Thank you for your patience :-)
>
> Márcio
>
>
> >
>

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



Re: Uploading and then accessing files ... ?

2007-10-19 Thread dbee

OK got it thanks - a redirect works fine :-)

On Oct 19, 3:14 pm, dbee <[EMAIL PROTECTED]> wrote:
> I'm using the Django alias site_media redirect to access static files
> on my server. I have an aspect to my django application whereby the
> user can upload his own files and then access those files to include
> them in newsletters etc...
>
> The problem of course is that the user will upload files to /libs/
> media/userfiles, but then when it comes to the time to access those
> files, /libs/media/userfiles/file.jpg will return a 404 because the
> file can only be accessed at /site_media/userfiles/file.jpg
>
> Httpd.conf :
>
> # The django static file redirect
> Alias /site_media /home/babo/django/mobiit/libs/media/
>
> My erstwhile solution was to use a Rewrite rule so that the user could
> access /site_media/ from /libs/media ...
>
> Httpd.conf:
>
>  RewriteEngine On
>  RewriteLog "/tmp/mobiit/rewrite.log"
>  RewriteLogLevel 9
>  RewriteRule ^/libs/media/(.*)$ /site_media/($1)
>
> Log Output:
>
> (2) init rewrite engine with requested uri /libs/media/userfiles/image/
> file.jpg
> (3) applying pattern '^/libs/media/(.*)$' to uri '/libs/media/
> userfiles/image/file.jpg'
> (2) rewrite /libs/media/userfiles/file.jpg -> /site_media/(userfiles/
> image/file.jpg)
> (2) local path result: /site_media/(userfiles/image/file.jpg)
> (2) prefixed with document_root to /home/babo/django/mobiit/site_media/
> (userfiles/file.jpg)
> (1) go-ahead with /home/babo/django/mysite/site_media/(userfiles/image/
> file.jpg) [OK]
>
> As you can see from the last line, the rewrite will add the document
> root to the file path. In my case the file path is purely fictional
> and hence there's a problem using the rewrite.
>
> So what I did at that stage was put a soft link in the /mysite
> directory that should have take the /home/babo/django/mysite/
> site_media/ to /home/babo/django/mysite/libs/media instead.
> Unfortunately this doesn't work either though 
>
> ln -s libs/media/ site_media
>
> Has anyone else encountered this problem ?
>
> Thanks


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



Uploading and then accessing files ... ?

2007-10-19 Thread dbee

I'm using the Django alias site_media redirect to access static files
on my server. I have an aspect to my django application whereby the
user can upload his own files and then access those files to include
them in newsletters etc...

The problem of course is that the user will upload files to /libs/
media/userfiles, but then when it comes to the time to access those
files, /libs/media/userfiles/file.jpg will return a 404 because the
file can only be accessed at /site_media/userfiles/file.jpg

Httpd.conf :

# The django static file redirect
Alias /site_media /home/babo/django/mobiit/libs/media/

My erstwhile solution was to use a Rewrite rule so that the user could
access /site_media/ from /libs/media ...

Httpd.conf:

 RewriteEngine On
 RewriteLog "/tmp/mobiit/rewrite.log"
 RewriteLogLevel 9
 RewriteRule ^/libs/media/(.*)$ /site_media/($1)

Log Output:

(2) init rewrite engine with requested uri /libs/media/userfiles/image/
file.jpg
(3) applying pattern '^/libs/media/(.*)$' to uri '/libs/media/
userfiles/image/file.jpg'
(2) rewrite /libs/media/userfiles/file.jpg -> /site_media/(userfiles/
image/file.jpg)
(2) local path result: /site_media/(userfiles/image/file.jpg)
(2) prefixed with document_root to /home/babo/django/mobiit/site_media/
(userfiles/file.jpg)
(1) go-ahead with /home/babo/django/mysite/site_media/(userfiles/image/
file.jpg) [OK]

As you can see from the last line, the rewrite will add the document
root to the file path. In my case the file path is purely fictional
and hence there's a problem using the rewrite.

So what I did at that stage was put a soft link in the /mysite
directory that should have take the /home/babo/django/mysite/
site_media/ to /home/babo/django/mysite/libs/media instead.
Unfortunately this doesn't work either though 

ln -s libs/media/ site_media

Has anyone else encountered this problem ?

Thanks


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



Uploading and then accessing files ... ?

2007-10-19 Thread dbee

I'm using the Django alias site_media redirect to access static files
on my server. I have an aspect to my django application whereby the
user can upload his own files and then access those files to include
them in newsletters etc...

The problem of course is that the user will upload files to /libs/
media/userfiles, but then when it comes to the time to access those
files, /libs/media/userfiles/file.jpg will return a 404 because the
file can only be accessed at /site_media/userfiles/file.jpg

Httpd.conf :

# The django static file redirect
Alias /site_media /home/babo/django/mobiit/libs/media/

My erstwhile solution was to use a Rewrite rule so that the user could
access /site_media/ from /libs/media ...

Httpd.conf:

 RewriteEngine On
 RewriteLog "/tmp/mobiit/rewrite.log"
 RewriteLogLevel 9
 RewriteRule ^/libs/media/(.*)$ /site_media/($1)

Log Output:

(2) init rewrite engine with requested uri /libs/media/userfiles/image/
file.jpg
(3) applying pattern '^/libs/media/(.*)$' to uri '/libs/media/
userfiles/image/file.jpg'
(2) rewrite /libs/media/userfiles/file.jpg -> /site_media/(userfiles/
image/file.jpg)
(2) local path result: /site_media/(userfiles/image/file.jpg)
(2) prefixed with document_root to /home/babo/django/mobiit/site_media/
(userfiles/file.jpg)
(1) go-ahead with /home/babo/django/mysite/site_media/(userfiles/image/
file.jpg) [OK]

As you can see from the last line, the rewrite will add the document
root to the file path. In my case the file path is purely fictional
and hence there's a problem using the rewrite.

So what I did at that stage was put a soft link in the /mysite
directory that should have take the /home/babo/django/mysite/
site_media/ to /home/babo/django/mysite/libs/media instead.
Unfortunately this doesn't work either though 

ln -s libs/media/ site_media

Has anyone else encountered this problem ?

Thanks


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



Re: Ordering by foreign key, class Meta

2007-10-19 Thread Malcolm Tredinnick

On Fri, 2007-10-19 at 06:54 -0700, äL wrote:
> I would like to order a list in a view by foreign key. If I try
> ordering how in the
> code below my list is ordered by 'person'. And this means that the
> list
> ist ordered by the ID of the table Person. But I need a list ordered
> by 'nameLast'.
> Thus I changed ordering 'person' into 'person.nameLast'. But then I
> got an error
> "Column not found".
> 
> Does anybody have an ideia how to order by a foreign key? I spent a
> lot of
> time for searching any solution. Unfortunatelly without success.

Ordering by related fields is a bit crufty at the moment and it doesn't
always work (e.g. ticket #2076). The general idea is that you have to
use the database table name(!) followed by a dot followed by the target
model field name (not the column name). This is actually documented at
http://www.djangoproject.com/documentation/db-api/#order-by-fields but
you have to read it carefully.

The good news is that this will shortly change so that you will be able
to write person__nameLast in your case, just like you do for filters.
That code is currently in the queryset-refactor branch and will be
merged with trunk as soon as a few more slightly tricky problems with
queries are ironed out.

By way of example and as a sneak preview, [1] and [2] (in the Meta
class) show the new syntax (that's a new test file on that branch).

[1]
http://code.djangoproject.com/browser/django/branches/queryset-refactor/tests/regressiontests/queries/models.py#L290

[2]
http://code.djangoproject.com/browser/django/branches/queryset-refactor/tests/regressiontests/queries/models.py#L62

Regards,
Malcolm

-- 
Remember that you are unique. Just like everyone else. 
http://www.pointy-stick.com/blog/


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



Anyone running mod_python for Python 2.5 on Mac OS X?

2007-10-19 Thread Ulf Kronman

Hi all,

I have severe problems to get my Apache 2 to run mod_python together
with Python 2.5 on Mac OS X 10.4.10.

This is my sad story:

I'm developing a small in-house publication database for bibliometric
purposes. I run a Ubuntu Linux-based server with Apache, Python and
PostgreSQL, but I have my development environment on my MacBook Pro,
running Mac OS X 10.4.10.

I recently installed a new Linux server with Ubuntu 7.04 and the
installation of all Django-needed software went really smooth with apt-
get. I now have Apache 2.1, Python 2.5 and PostgreSQL 8.2 running on
the server, together with Django and mod_python and psycopg2.

When I did some adjustments to my develop environment on my Mac, I
suddenly realized that I was running Python 2.5 (installed from a DMG)
as my local script environment, but the Apache server was still
running its mod_python through MacPorts Python 2.4. It was when I
decided to fix this to get my develop environment at par with my
server environment hell broke loose.

Naively, I first ran a MacPorts "sudo port install mod_python25". The
installation detected a dependency on MacPorts Python 2.5 and
installed it (fair enough), but didn't update my $PATH, so the
following installation of mod_python25 failed, complaining about a
missing "math" module. After some tweaking of paths in my .profile, I
got the mod_python25 through the installation, but Apache wouldn't run
mod_python, claiming that it still was built for Python 2.4 in its
error log, and also looking for mod_python in the wrong site-packages
directory.

To make things even worse, I stupidly tried to install psycopg2 for
running together with Python 2.5, calling command "sudo port install
py-psycopg2". This installation process started by installing MacPorts
Python 2.4 (!) and then PostgreSQL 8.1, although I already had
MacPorts PostgreSQL 8.2 running on the system. The installation
process once again didn't update my $PATH and thus failed, complaining
about a missing "math" module. I once again tweaked my path and got
psycopg2 through the installation, but the resulting package ended up
in the wrong site-packages directory.

So, now I had a situation with both MacPorts Python 2.4 and 2.5
installed, together with DMG-installed Python 2.4 and Python 2.5 and a
total confusion regarding what paths to use. I tried to read the
documentation, but couldn't really sort out what to put in my $PATH,
$PYTHONHOME and my $PYTHONPATH.

I decided to start over and go the full MacPorts way, so I cleared out
all versions of Python, together with mod_apache and psycopg2 and
tried a clean MacPorts install. The result was about the same as
before, with Python parts ending up in funny places, broken paths and
the mod_python25 installation complaining about the version problem.

Since the MacPorts way didn't work, I decided to go the other way and
installed the DMG version of Python 2.5, downloaded packages for
mod_python and psycopg2 and compiled them manually. The result was the
same as before, mod_python claiming that it was compiled for running
together with Python 2.4 and refusing to run together with Python 2.5.

After about a week of frustrating struggle, I decided to give up and
try to put the system back in the state it was before all this
started, with Apache running mod_python through Python 2.4. I once
again cleared out all versions of Python, tried to locate all
configuration files and remove all traces of Python 2.5 and rebooted
the system. Then I did an install of the DMG version of Python 2.4 and
got it working in the proper place.

After that I compiled the mod_python, pointing at the newly installed
Python 2.4 and got it through compilation, but the compiled package
ended up in this location:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.5/site-
packages/

(Notice the python2.5 in the Versions/2.4 path?! It wasn't there
before, but was actually created by the mod_python installation.)

This didn't work, since Apache and Python 2.4 was looking for
mod_python in the
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/
directory. After moving the mod_python module there, things finally
started to work.

Then I compiled the psycopg2 and it also installed itself in:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.5/site-
packages/
and had to be manually moved to:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/
to get it to start to work.

So, to end this long and sad story, I want to pose some questions:

1. Is there any hidden setting in Mac OS X that the installation
procedures read to generate this funny path? I don't have it in
my .profile (and I don't have a .bashrc) and I tried to grep the whole
system for "python2.5" and checked both my env and sudo env and I
can't find it.

2. How should the variables $PATH, $PYTHONHOME and $PYTHONPATH be set
in a properly installed Python on a Mac OS system?

3. Which is the best way to go to 

Ordering by foreign key, class Meta

2007-10-19 Thread äL

I would like to order a list in a view by foreign key. If I try
ordering how in the
code below my list is ordered by 'person'. And this means that the
list
ist ordered by the ID of the table Person. But I need a list ordered
by 'nameLast'.
Thus I changed ordering 'person' into 'person.nameLast'. But then I
got an error
"Column not found".

Does anybody have an ideia how to order by a foreign key? I spent a
lot of
time for searching any solution. Unfortunatelly without success.


### CODE ###

class Person(models.Model):
nameLast  = models.CharField ('Nachname', maxlength = 31)
nameFirst = models.CharField ('Vorname', maxlength = 31)
address   = models.CharField ('Adresse', maxlength = 63)

def __str__(self):
return "%s, %s " % (self.nameLast, self.nameFirst)

class Admin:
list_display = ('nameLast', 'nameFirst', 'address')
fields = (
('Personalien',{'fields': ('nameLast',
'nameFirst', 'address')})
)


class Meta:
ordering = ('nameLast', 'nameFirst', 'location')
verbose_name= "Person"
verbose_name_plural = "Personen"


class Karateka(models.Model):
person= models.ForeignKey   (Person, verbose_name = 'Person',
core = True)
bsc   = models.BooleanField ('BSC')
comment   = models.TextField('Bemerkung', blank = True, null =
True)

def __str__(self):
return "%s" % (self.person)

class Admin:
list_display = ('person')
fields = (
(None,   {'fields': ('person')})
)

def name_last(self):
return "%s" % (self.person.nameLast)

class Meta:
ordering= ('person')
verbose_name= 'Karateka'
verbose_name_plural = 'Karatekas'

### END CODE ###


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



py2app & py2exe

2007-10-19 Thread ArqEco

Hello friends,

"The Story That Won't Go Away" comes back!

I am a newcomer to Django and just read some posts from one year ago
about creating standalone programs with Django and py2app or py2exe.

What is the status of this issue now? Anyone found a solution?

I need to develop a very simple issue tracker and (non-software)
project management application to be used for a small team of up to
five members.

The application is being designed to be installed on desktop and
notebook computers (where it will be used out of the office
[offline]), and will have a synchronization feature.

I think that even the built in Django development server would be fine
to me.

I tried a very simple py2app setup but stoped at the question of
calling "python manage.py runserver" from my starting script.
execfile() doesn't allow arguments ("runserver"). Any suggestion?

These are newcomer questions but I am not a professional developer.

Thank you for your patience :-)

Márcio


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



Re: Getting contents of a Http Response Object

2007-10-19 Thread dbee

Aha, thanks dude :-)

On Oct 19, 12:55 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2007-10-19 at 04:32 -0700, dbee wrote:
> > I'm creating a pdf document dynamically, I need to include barchart
> > data in the document. The  bar chart data is also created dynamically
> > with report lab. I can get the barchart data at my url ...
>
> > def barchart_interests(request):
>
> > .
>
> > #get a GIF (or PNG, JPG, or
> > whatever)
> > binaryStuff = d.asString('gif')
>
> > return HttpResponse(binaryStuff, 'image/gif')
>
> > Now I want to use that barchart in my pdf ...
>
> > def dyn_pdf(request):
>
> >buffer = StringIO()
>
> > # Create the PDF object, using the StringIO object as its
> > "file."
> > p = canvas.Canvas(buffer)
>
> > # Get the HttpResponseObject
> > image = interests_barchart(request)
>
> > # Insert the image into the pdf document
> > p.drawInlineImage(image, 100,350, width=100,height=100)
>
> > p.showPage()
> > p.save()
>
> > Things that I've tried 
>
> >p.drawInlineImage(image._get_contents, 100,350,
> > width=100,height=100)
> >Attribute Error: 'function' object has no attribute 'format'
>
> >p.drawInlineImage(image.content, 100,350, width=100,height=100)
> >I/O Error: Cannot open resource "GIF87a
>
> This one is close, but you're not reading the Reportlab documentation
> correctly. drawInlineImage() takes a filename or a PIL image object as
> its first argument, where as image.content is the binary data that is in
> the HttpResponse. So you need to create an Image object from that data
> first. This should be close:
>
> from PIL import Image
> from cStringIO import StringIO
>
> ...
> img = Image.open(StringIO(image.content))
> p.drawInlineImage(img, ...)
>
> Read the PIL documentation for more possibilities.
>
> Regards,
> Malcolm


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



Re: Getting contents of a Http Response Object

2007-10-19 Thread dbee

Hi Matthew,

Thanks. The problem is though, that I'm following the docs and using
another class to 'shape' my barchart ...

# Use this one for client
signup
class interests_class(Drawing):

format = 'gif'

def __init__(self, width=400, height=250, *args, **kw):

apply(Drawing.__init__,(self,width,height)+args,kw)

# set the chart
type
self.add(VerticalBarChart(), name='chart')

#
Title
self.add(String(200,240,''), name='title')

...

if __name__=='__main__':
#use the standard 'save' method to save barchart.gif, barchart.pdf
etc
#for quick feedback while
working.
 
interests_class().save(formats=['gif','png','jpg','pdf'],outDir='.',fnRoot='barchart')

# Then I'm using the above class to create my barchart image 

def interests_barchart(request):

d = interests_class()

d.chart.data=[   ]

#  Give it a
title
if request.has_key('title'):
d.title.text = request['title']

# get a GIF (or PNG, JPG, or
whatever)
# binaryStuff = d.asString('gif')

return d

# I'd already tried your suggestion previously as in ...

## Takes the d object here
image = interests_barchart(request)

p.drawInlineImage(image, 100,350, width=100,height=100)

The problem is that the d object isn't actually a PIL object at all.
The barchart_interests function works with a Drawing PIL object, but
it doesn't inherit from it and in turn - it doesn't return a PIL
object. 'd' is a barchart_interests() object, it has no format
attribute and no convert() method. I can fake the format attribute but
I can't fake the convert method.

Strictly speaking then, d object should inherit from Drawing -
although the doc examples do it my way and not the other way. I'd
prefer not to have to rewrite the class.

The preferable solution would be to be able to get_file_contents()
from the HttpResponseObject somehow. Otherwise I'll have to write
multiple classes to output my barcharts in multiple ways. (This isn't
my only barchart).

Thanks

On Oct 19, 12:55 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2007-10-19 at 04:32 -0700, dbee wrote:
> > I'm creating a pdf document dynamically, I need to include barchart
> > data in the document. The  bar chart data is also created dynamically
> > with report lab. I can get the barchart data at my url ...
>
> > def barchart_interests(request):
>
> > .
>
> > #get a GIF (or PNG, JPG, or
> > whatever)
> > binaryStuff = d.asString('gif')
>
> > return HttpResponse(binaryStuff, 'image/gif')
>
> > Now I want to use that barchart in my pdf ...
>
> > def dyn_pdf(request):
>
> >buffer = StringIO()
>
> > # Create the PDF object, using the StringIO object as its
> > "file."
> > p = canvas.Canvas(buffer)
>
> > # Get the HttpResponseObject
> > image = interests_barchart(request)
>
> > # Insert the image into the pdf document
> > p.drawInlineImage(image, 100,350, width=100,height=100)
>
> > p.showPage()
> > p.save()
>
> > Things that I've tried 
>
> >p.drawInlineImage(image._get_contents, 100,350,
> > width=100,height=100)
> >Attribute Error: 'function' object has no attribute 'format'
>
> >p.drawInlineImage(image.content, 100,350, width=100,height=100)
> >I/O Error: Cannot open resource "GIF87a
>
> This one is close, but you're not reading the Reportlab documentation
> correctly. drawInlineImage() takes a filename or a PIL image object as
> its first argument, where as image.content is the binary data that is in
> the HttpResponse. So you need to create an Image object from that data
> first. This should be close:
>
> from PIL import Image
> from cStringIO import StringIO
>
> ...
> img = Image.open(StringIO(image.content))
> p.drawInlineImage(img, ...)
>
> Read the PIL documentation for more possibilities.
>
> Regards,
> Malcolm


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



Re: access session out of view, howto find out sessionkey?

2007-10-19 Thread skam

You should be able to build a middleware similar to
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser ,
getting request.session instead of request.user


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



Re: two block template tags on after another

2007-10-19 Thread Karen Tracey
On 10/18/07, johnny <[EMAIL PROTECTED]> wrote:
[snip]

{% custom_format_string1 a_object.3 %}


...

{% custom_format_string2 a_object.4 %}


...

@register.tag(name="custom_format_sting1")


...

@register.tag(name="custom_format_sting2")


The names you register are missing the r's in "string", but your template
code is including the r's.You need to make the names match.

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



access session out of view, howto find out sessionkey?

2007-10-19 Thread Simon Oberhammer

I need to access a session-field in a model, I found this:
http://www.djangoproject.com/documentation/sessions/#using-sessions-out-of-views

but what would be the clean way to find out the session-key? or is
there another way to get the "current" session in a model?

btw: Users are not necessarily logged in

thanks
 simon


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



Re: Python 2.3 deployment

2007-10-19 Thread Thomas Guettler

>   File
> "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", line
> 19, in get_new_session_key session_key = md5.new("%s%s%s%s" %
> (random.randint(0, sys.maxint - 1), os.getpid(), time.time(),
> settings.SECRET_KEY)).hexdigest()
>
> AttributeError: 'module' object has no attribute 'randint'

You can test what random module you are using:

insert a line above: assert False, random.__file__

You can test the random module:

python /usr/lib64/python2.4/random.py
2000 times random
0.003 sec, avg 0.497669, stddev 0.288045, min 0.00160483, max 0.99949
2000 times normalvariate


HTH,
 Thomas

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



Re: two block template tags on after another

2007-10-19 Thread johnny

Can someone help me, plz?

I have two block tags that take an argument and then sets a variable
in the template.  The two block tags are inside the template "for
loop" tags, one after another.

On Oct 18, 3:00 pm, johnny <[EMAIL PROTECTED]> wrote:
> I have  templatetags/custom_format.py, and in it I have
> do_custom_format_string1, do_custom_format_string2.  I placed the
> template tags
> one after another, insdie my html page like this:
>
> {% for a_object in object_list %}
> {% load custom_format %}
> {% custom_format_string1 a_object.3 %}
> {{split_string_data1}}
> {% end_custom_format_string1 %)
>
> {% custom_format_string2 a_object.4 %}
> {{split_string_data2}}
> {% end_custom_format_string2 %)
> {% endfor %}
>
> custom_format.py:
>
> from django import template
> #from django.template import Variable
> from django.template import resolve_variable
> register = template.Library()
>
> @register.tag(name="custom_format_sting1")
> def do_custom_format_sting1(parser, token):
> nodelist = parser.parse(('end_custom_format_sting1',))
> tag_name, data_to_split = token.split_contents()
> parser.delete_first_token()
> return CustomFormatString1Node(nodelist, data_to_split)
>
> class CustomFormatString1Node(template.Node):
> def __init__(self, nodelist, data_to_split):
> self.nodelist = nodelist
> self.data_to_split = data_to_split
> def render(self, context):
> actual_data = resolve_variable(self.data_to_split, context)
> datalist = actual_data.split(',')
> context['split_string_data1'] = "".join(datalist)
> output = self.nodelist.render(context)
> return output.custom_format_sting1()
>
> @register.tag(name="custom_format_sting2")
> def do_custom_format_sting2(parser, token):
> nodelist = parser.parse(('end_custom_format_sting2',))
> tag_name, data_to_split = token.split_contents()
> parser.delete_first_token()
> return CustomFormatString2Node(nodelist, data_to_split)
>
> class CustomFormatString2Node(template.Node):
> def __init__(self, nodelist, data_to_split):
> self.nodelist = nodelist
> self.data_to_split = data_to_split
> def render(self, context):
> actual_data = resolve_variable(self.data_to_split, context)
> datalist = actual_data.split('-')
> context['split_string_data2'] = "".join(datalist)
> output = self.nodelist.render(context)
> return output.custom_format_sting2()
>
> Error I am getting:
>
> Exception Type: TemplateSyntaxError
> Exception Value:Invalid block tag: 'custom_format_string1'
>
> error at html file:
> {% custom_format_string1 a_object.3 %}


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



Re: Python 2.3 deployment

2007-10-19 Thread Chris Hoeppner

Huh I lied. The django update only forced me to call that view with
POST, and now that I'm doing, it's throwing the same traceback. I'm not
sure what this might be. I'll check again with the system admins.


El vie, 19-10-2007 a las 21:12 +1000, Malcolm Tredinnick escribi�:
> On Fri, 2007-10-19 at 11:56 +0100, Chris Hoeppner wrote:
> > Hey guys!
> > 
> > I have no choice but deploy to this server, running CentOS 4.4, with no
> > option to upgrade python beyond 2.3, and I'm getting this:
> > 
> > Mod_python error: "PythonHandler django.core.handlers.modpython"
> > 
> > Traceback (most recent call last):
> > 
> >   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, 
> > in HandlerDispatch
> > result = object(req)
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 
> > 178, in handler
> > return ModPythonHandler()(req)
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 
> > 155, in __call__
> > response = middleware_method(request, response)
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/contrib/sessions/middleware.py", 
> > line 95, in process_response
> > obj = Session.objects.get_new_session_object()
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", line 
> > 37, in get_new_session_object
> > obj, created = 
> > self.get_or_create(session_key=self.get_new_session_key(),
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", line 
> > 19, in get_new_session_key
> > session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1), 
> > os.getpid(), time.time(), settings.SECRET_KEY)).hexdigest()
> > 
> > AttributeError: 'module' object has no attribute 'randint'
> 
> Something's a bit broken with your setup, then. Certainly
> random.randint() existedin Python 2.3 (I just tested it).
> 
> Do a quick test to confirm that it really is missing in a shell:
> 
> Python 2.3.5 (#1, Mar 11 2007, 08:55:14) 
> [GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2
> Type "help", "copyright", "credits" or "license" for more
> information.
> >>> import random
> >>> random.randint
>  0x672110>>
> 
> If that fails, your python installation is very non-standard. You could
> also try looking at the results of "rpm -qV python" to check that there
> hasn't been any inadvertent (or deliberate) changes to the installed
> rpm.
> 
> Note sure what to suggest here. The problem looks to be in your
> installation. Start asking serious questions of the sys admin.
> 
> Regards,
> Malcolm
> 
> 
> 
> > 


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



Getting contents of a Http Response Object

2007-10-19 Thread dbee

I'm creating a pdf document dynamically, I need to include barchart
data in the document. The  bar chart data is also created dynamically
with report lab. I can get the barchart data at my url ...

def barchart_interests(request):

.


#get a GIF (or PNG, JPG, or
whatever)
binaryStuff = d.asString('gif')

return HttpResponse(binaryStuff, 'image/gif')

Now I want to use that barchart in my pdf ...

def dyn_pdf(request):

   buffer = StringIO()

# Create the PDF object, using the StringIO object as its
"file."
p = canvas.Canvas(buffer)

# Get the HttpResponseObject
image = interests_barchart(request)

# Insert the image into the pdf document
p.drawInlineImage(image, 100,350, width=100,height=100)

p.showPage()
p.save()

Things that I've tried 

   p.drawInlineImage(image._get_contents, 100,350,
width=100,height=100)
   Attribute Error: 'function' object has no attribute 'format'

   p.drawInlineImage(image.content, 100,350, width=100,height=100)
   I/O Error: Cannot open resource "GIF87a

I know that PHP has a function called get_file_from_contents() or
something similar to that. I'm not entirely sure what I should be
doing here to get the .gif image from the HttpResponseObject. I can
access the barchart no problem with my browser

Thanks


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



Re: Python 2.3 deployment

2007-10-19 Thread Chris Hoeppner

Thanks, Malcolm!

For some reason, updating django to trunk solved it. My system admins
told me kindly that it's not their problem. Very nice indeed.


El vie, 19-10-2007 a las 21:12 +1000, Malcolm Tredinnick escribi�:
> On Fri, 2007-10-19 at 11:56 +0100, Chris Hoeppner wrote:
> > Hey guys!
> > 
> > I have no choice but deploy to this server, running CentOS 4.4, with no
> > option to upgrade python beyond 2.3, and I'm getting this:
> > 
> > Mod_python error: "PythonHandler django.core.handlers.modpython"
> > 
> > Traceback (most recent call last):
> > 
> >   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, 
> > in HandlerDispatch
> > result = object(req)
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 
> > 178, in handler
> > return ModPythonHandler()(req)
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", line 
> > 155, in __call__
> > response = middleware_method(request, response)
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/contrib/sessions/middleware.py", 
> > line 95, in process_response
> > obj = Session.objects.get_new_session_object()
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", line 
> > 37, in get_new_session_object
> > obj, created = 
> > self.get_or_create(session_key=self.get_new_session_key(),
> > 
> >   File 
> > "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", line 
> > 19, in get_new_session_key
> > session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1), 
> > os.getpid(), time.time(), settings.SECRET_KEY)).hexdigest()
> > 
> > AttributeError: 'module' object has no attribute 'randint'
> 
> Something's a bit broken with your setup, then. Certainly
> random.randint() existedin Python 2.3 (I just tested it).
> 
> Do a quick test to confirm that it really is missing in a shell:
> 
> Python 2.3.5 (#1, Mar 11 2007, 08:55:14) 
> [GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2
> Type "help", "copyright", "credits" or "license" for more
> information.
> >>> import random
> >>> random.randint
>  0x672110>>
> 
> If that fails, your python installation is very non-standard. You could
> also try looking at the results of "rpm -qV python" to check that there
> hasn't been any inadvertent (or deliberate) changes to the installed
> rpm.
> 
> Note sure what to suggest here. The problem looks to be in your
> installation. Start asking serious questions of the sys admin.
> 
> Regards,
> Malcolm
> 
> 
> 
> > 


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



Re: Getting contents of a Http Response Object

2007-10-19 Thread Malcolm Tredinnick

On Fri, 2007-10-19 at 04:32 -0700, dbee wrote:
> I'm creating a pdf document dynamically, I need to include barchart
> data in the document. The  bar chart data is also created dynamically
> with report lab. I can get the barchart data at my url ...
> 
> def barchart_interests(request):
> 
> .
> 
> 
> #get a GIF (or PNG, JPG, or
> whatever)
> binaryStuff = d.asString('gif')
> 
> return HttpResponse(binaryStuff, 'image/gif')
> 
> Now I want to use that barchart in my pdf ...
> 
> def dyn_pdf(request):
> 
>buffer = StringIO()
> 
> # Create the PDF object, using the StringIO object as its
> "file."
> p = canvas.Canvas(buffer)
> 
> # Get the HttpResponseObject
> image = interests_barchart(request)
> 
> # Insert the image into the pdf document
> p.drawInlineImage(image, 100,350, width=100,height=100)
> 
> p.showPage()
> p.save()
> 
> Things that I've tried 
> 
>p.drawInlineImage(image._get_contents, 100,350,
> width=100,height=100)
>Attribute Error: 'function' object has no attribute 'format'
> 
>p.drawInlineImage(image.content, 100,350, width=100,height=100)
>I/O Error: Cannot open resource "GIF87a

This one is close, but you're not reading the Reportlab documentation
correctly. drawInlineImage() takes a filename or a PIL image object as
its first argument, where as image.content is the binary data that is in
the HttpResponse. So you need to create an Image object from that data
first. This should be close:

from PIL import Image
from cStringIO import StringIO

...
img = Image.open(StringIO(image.content))
p.drawInlineImage(img, ...)

Read the PIL documentation for more possibilities.

Regards,
Malcolm


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



Re: Python 2.3 deployment

2007-10-19 Thread Malcolm Tredinnick

On Fri, 2007-10-19 at 11:56 +0100, Chris Hoeppner wrote:
> Hey guys!
> 
> I have no choice but deploy to this server, running CentOS 4.4, with no
> option to upgrade python beyond 2.3, and I'm getting this:
> 
> Mod_python error: "PythonHandler django.core.handlers.modpython"
> 
> Traceback (most recent call last):
> 
>   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in 
> HandlerDispatch
> result = object(req)
> 
>   File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", 
> line 178, in handler
> return ModPythonHandler()(req)
> 
>   File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", 
> line 155, in __call__
> response = middleware_method(request, response)
> 
>   File 
> "/usr/lib/python2.3/site-packages/django/contrib/sessions/middleware.py", 
> line 95, in process_response
> obj = Session.objects.get_new_session_object()
> 
>   File "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", 
> line 37, in get_new_session_object
> obj, created = self.get_or_create(session_key=self.get_new_session_key(),
> 
>   File "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", 
> line 19, in get_new_session_key
> session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1), 
> os.getpid(), time.time(), settings.SECRET_KEY)).hexdigest()
> 
> AttributeError: 'module' object has no attribute 'randint'

Something's a bit broken with your setup, then. Certainly
random.randint() existedin Python 2.3 (I just tested it).

Do a quick test to confirm that it really is missing in a shell:

Python 2.3.5 (#1, Mar 11 2007, 08:55:14) 
[GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> import random
>>> random.randint
>

If that fails, your python installation is very non-standard. You could
also try looking at the results of "rpm -qV python" to check that there
hasn't been any inadvertent (or deliberate) changes to the installed
rpm.

Note sure what to suggest here. The problem looks to be in your
installation. Start asking serious questions of the sys admin.

Regards,
Malcolm



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



Python 2.3 deployment

2007-10-19 Thread Chris Hoeppner

Hey guys!

I have no choice but deploy to this server, running CentOS 4.4, with no
option to upgrade python beyond 2.3, and I'm getting this:

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in 
HandlerDispatch
result = object(req)

  File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", 
line 178, in handler
return ModPythonHandler()(req)

  File "/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py", 
line 155, in __call__
response = middleware_method(request, response)

  File 
"/usr/lib/python2.3/site-packages/django/contrib/sessions/middleware.py", line 
95, in process_response
obj = Session.objects.get_new_session_object()

  File "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", 
line 37, in get_new_session_object
obj, created = self.get_or_create(session_key=self.get_new_session_key(),

  File "/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py", 
line 19, in get_new_session_key
session_key = md5.new("%s%s%s%s" % (random.randint(0, sys.maxint - 1), 
os.getpid(), time.time(), settings.SECRET_KEY)).hexdigest()

AttributeError: 'module' object has no attribute 'randint'


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



Re: Getting the right data to the template

2007-10-19 Thread Malcolm Tredinnick

On Thu, 2007-10-18 at 15:25 -0700, Mikkel Høgh wrote:
> I have a bit of a problem - I'm creating a GTD-focused task management
> app for Django, mainly for my own benefit, but it's open source if any
> one cares.
> 
> I've been trying to implement a taxonomy system like the one Drupal
> uses. Only problem is that I find it difficult to get the right data
> out into the template system.
> 
> As an example, I have a list of Task objects, which is supposed to be
> displayed to the user. These Task objects all have Term object
> associated with them (ManyToMany). The Term objects belong
> (ForeignKey) to a Vocabulary object. I want to get the Term objects by
> their Vocabulary so I can display them in different columns.
> 
> Lets say I have a Task object called 'Fix the apache configuration on
> xyz server', which has the Term objects 'Urgent' (from the Priority
> Vocabulary) and 'Work' (from the Context Vocabulary).
> 
> Currently, I have a bit of a kludge where I've put a refresh method on
> the Task object that generates a dictionary with vocabulary names as
> keys and as value a string containing a comma-separated list of all
> the terms from that Vocabulary associated with the Term object in
> question.
> 
> I would like to be able to access the Term objects directly in the
> template, so I could get the absolute URL for them in the "right" way
> or if that's not feasible, some other solution, because I need the
> aforementioned string to have links to the Term objects in question...

It's not completely clear to me what you want to do here. Is this what
you are trying to accomplish: given a Task object, find all the
associated Term objects and group them by their vocabulary attribute?

If that's the case, then I think your current code is fairly close.
However, instead of storing term.title in the dictionary, just store the
term object itself and don't both joining the items together at the end.
This way, after calling refresh(), you can do something like this in
your template:

{% for elt in task.t.items %}
   Vocabulary word is {{ elt.0 }}
   Associated terms are:
   {% for term in elt.1 %}
   {{ term.title }}
   {% endfor %}
{% endfor %}

(or anything more advanced). If you're using post-0.96 Django, you can
even write

{% for vocab, term in task.t.items %}

but that's mostly a matter of taste. The functionality is the same.

If you want to do this without the refresh() method, I suspect you're
probably out of luck. the hard part is the grouping based on the
vocabulary term -- you can't do that simply as a queryset. If it was me,
though, I wouldn't make refresh() adjust the task object. I would have
it return the dictionary, so you can do all of the above stuff as 

{% for vocab, term in task.get_vocab_and_terms %}

without having to remember to call task.refresh() in your view.

Regards,
Malcolm


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



Stub django project

2007-10-19 Thread Antoni Aloy

Hello!

I have just created a project  at
http://code.google.com/p/appfusedjango/, the idea is to have a simple
application to start with which shows and solves some of the common
questions one can have when starts a project.

Hope it helps!

-- 
Antoni Aloy López
Binissalem - Mallorca
http://www.trespams.com
Soci de Bulma - http://www.bulma.cat

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