Re: question about django-pagination

2009-12-18 Thread Lakshman Prasad
> would I still be able to paginate over the entire list of 1 objects?
Or my list would be shortened to 5 objects?

Its the latter. Your query set will loop only for the size of it's length.


On Sat, Dec 19, 2009 at 12:03 PM, Continuation wrote:

> In the django-pagination, it uses the example:
> {% autopaginate object_list %}
>
> My question is does object_list have to be the **entire** list over
> which I want to paginate, or can I limit the length of object_list? If
> I limit the length of object_list, will autopaginate still go through
> the entire list?
>
> As an example, say I want to paginate over the list a.field_set.all().
> Let's say that list has 1 objects. I might not want my database to
> return such a large result set. So I might want to do something like:
>
> object_list = a.field_set()[:5]
>
> Now if I use {% autopaginate object_list %} in my template, would I
> still be able to paginate over the entire list of 1 objects? Or my
> list would be shortened to 5 objects?
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

--

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




Re: SQL transaction style in django?

2009-12-18 Thread Christophe Pettus

On Dec 18, 2009, at 9:58 PM, yummy_droid wrote:
> I read that we can overwrite the save() for any model to do something
> before/after its save. But my issue is, how can I be sure that what i
> save + what the model needs to save happen as a transaction, so if
> either fails, the whole thing fails.

Django has a reasonably complete set of transaction control  
functionality.  The official documentation is at:

http://docs.djangoproject.com/en/dev/topics/db/transactions/

I also wrote a blog entry about it:


http://thebuild.com/blog/2009/11/07/django-postgresql-and-transaction-management/

(The blog entry is with regards to PostgreSQL, but it's pretty  
generally applicable.)

None of it involved overriding .save(), I'm pleased to report.

--
-- Christophe Pettus
x...@thebuild.com

--

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




question about django-pagination

2009-12-18 Thread Continuation
In the django-pagination, it uses the example:
{% autopaginate object_list %}

My question is does object_list have to be the **entire** list over
which I want to paginate, or can I limit the length of object_list? If
I limit the length of object_list, will autopaginate still go through
the entire list?

As an example, say I want to paginate over the list a.field_set.all().
Let's say that list has 1 objects. I might not want my database to
return such a large result set. So I might want to do something like:

object_list = a.field_set()[:5]

Now if I use {% autopaginate object_list %} in my template, would I
still be able to paginate over the entire list of 1 objects? Or my
list would be shortened to 5 objects?

--

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




SQL transaction style in django?

2009-12-18 Thread yummy_droid
Hi,

I read that we can overwrite the save() for any model to do something
before/after its save. But my issue is, how can I be sure that what i
save + what the model needs to save happen as a transaction, so if
either fails, the whole thing fails.

Example. I want to keep a total inventory count in a model called
"Item". I want to then be able to add entries in model ItemEntry,
which has a count_used. When the ItemEntry model is being saved, I
want to deduct the amount from the total in corresponding "Item"
model. But if I do something like:

# forgive the syntax, I'm winging it right now
class ItemEntry(models.Model):

def save():
i = Item.objects.get(pk=5)
i.count = i.count - used_value
i.save()
self.save()

if either fails in the "save()", the data will be out of sync. Is
there a way to wrap this in a "transaction", without going into the
database itself and creating triggers, etc.?

Can I specify trigger like behaviour in the model definition? I would
like to not have changes in some other place(e.g. DB), since django's
advantage is centrally organizing things.

Thanks.

--

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




feedparser import error

2009-12-18 Thread Nick
Hello,

I've installed pydelicious and it seems to work until it imports
feedparser.py. I've installed feedparser.py, and it's in the same
directory as pydelicious. When pydelicious tries to import
feedparser.py my app crashes. I get 'No module named feedparser'. Does
anyone know why feedparser.py isn't importing? Has anyone else had
this problem? I'm using python 26 on windows xp.

Thank you,

Nick

--

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




Re: authentication security

2009-12-18 Thread James Bennett
On Fri, Dec 18, 2009 at 6:58 PM, macdd  wrote:
> plain text then it isn't very secure. Okay so https comes in. What I
> don't understand is when to use it and when not to. It seems like if
> you authenticate over https just for user credentials and then go back
> to http (like yahoo) than someone could just ease drop your cookie and
> be you, making logging in and out in any form pointless?

To be perfectly honest, I stopped caring about man-in-the-middle and
eavesdropping attacks a very long time ago.

I suppose that if I were employed by a defense or intelligence agency,
or if I were handling extremely sensitive corporate or financial data,
I might give some thought to them, because the security requirements
in those fields are so strict and the stakes are so high (US
defense/intelligence agencies, for example, go so far as to mandate
specific -- classified -- RF-emission requirements for their hardware,
in order to prevent electromagnetic eavesdropping). Even in that
situation, though, MITM would not be atop my list of priorities.

And the plain and simple truth is that I don't work in such fields. I
write software to let news companies publish things, and MITM really
isn't even on my radar. If this seems strange, consider that an
attacker -- should he or she be both motivated and determined enough
to try to obtain the credentials of one of my users -- simply has
access to far too many easier and simpler attack vectors which can
accomplish that.

First on the list, and hardest to defend, is phishing: it doesn't
matter how much security I build in to the connection between my
server and my user's browser, if the user can be fooled into typing
credentials into a form on some other site. And fooling users into
doing that is unbelievably easy.

Then there are the cross-site scripting and cross-site request forgery
attacks, both of which can be pulled off easily and in ways which are
hard to detect. XSS is the ring-0 attack of the web, and a far more
likely vector than packet sniffing or cookie replaying. And CSRF is
the terrorist hijack of the Internet, but you don't realize you've
been hijacked until it's far too late. At least they can be mitigated
and prevented, and Django provides tools which allow you to do just
that.

But there's a whole list of easy but effective tactics which goes on
and on; most involve social engineering or low-tech methods. Some are
as simple as glancing over someone's shoulder in a coffeeshop. And all
of them are far, far, far more likely to be used against you than a
frail and complex credential-sniffing man-in-the-middle attack. Like I
said, MITM just isn't even on my radar, and probably shouldn't be on
yours either.

But if you feel you must focus on unlikely and difficult threat models
rather than likely and simple ones, there's an easy answer: HTTPS for
everything. Nothing else comes close, and probably nothing else will
for the foreseeable future.

Of course, this presumes that your users know how to spot the
difference between plain unencrypted HTTP and encrypted HTTPS, or are
paying attention to the indicators their browsers give about
certificate validity, or are even bothering to look at the address bar
at all. Sadly, the answer to all of those questions is "no": your
users don't know and don't care, and if someone decides it's worth
going after them, they'll get compromised by far simpler, far
lower-tech phishing attacks just like everybody else...


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




authentication security

2009-12-18 Thread macdd
I am reading the django book. I just finished the chapter on
authentication. I get the jist of it. What I don't understand is the
overall security of authentication. If everything you do is passed as
plain text then it isn't very secure. Okay so https comes in. What I
don't understand is when to use it and when not to. It seems like if
you authenticate over https just for user credentials and then go back
to http (like yahoo) than someone could just ease drop your cookie and
be you, making logging in and out in any form pointless?

--

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




Rails-style form value deserializer?

2009-12-18 Thread Todd Blanchard
One thing I'm keenly missing from rails is the form input naming convention 
that causes the form values to be converted into a hierarchy.  For instance,




will result in the request values being stored as { 'foo'  : {'bar' : 'one', 
'baz' : 'two' }}

this is very handy when updating multiple related objects in a single form 
submit.

Is there a similar facility for django/python or will I need to write it?

-Todd Blanchard

--

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




attachments vs filebrowser

2009-12-18 Thread Todd Blanchard
I need users to attach arbitrary media files to database records.  Attachments 
seems to do what I need, except that its UI is utterly lame - it should figure 
out the media type of the file from the extension and display an appropriate 
thumbnail as well as a way to provide a viewer inline.  Also, it relies on a 
bunch of custom tags for django's template processor but I'm using jinja2.

filebrowser seems smarter this way, but seems targeted strictly at trusted 
users.  I need arbitrary users to be able to attach files.

Is there something else I ought to consider?  

--

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




Re: Problem with Meta inner class accessing its parent

2009-12-18 Thread Kevin Renskers
Thanks for the information, I will look into your suggestions. The
getLanguage design did seem to work though, as changing the language
did have an effect on the __unicode__ function: in the admin interface
the correct values (for that language) were shown. At least it did so
on the local runserver environment. I can see though that even though
__unicode__ is called every time, the ordering is probably called only
at import time, and my little plan won't work.

Have to find a solution for that problem first I guess, before I even
start to tackle the problem of how to set the ordering...


On Dec 18, 5:00 pm, Bill Freeman  wrote:
> I can't promise that it will do what you want, but your problem is
> that at the time
> you try to set the value of Meta.ordering, class Substrate does not yet exist.
> You can dig into the Substrate.objects._meta later to add ordering, probably.
>
> Your design wouldn't have worked anyway, since getLanguage would only
> have been called once, at import time, and even if that worked, it wouldn't
> follow current language as it changes (I presume) from request to request.
>
> Oh, and since you're not calling getLanguage on a class instance, it would
> have to be declared a staticmethod or classmethod, and not get the self
> argument or replace it with cls (for classmethod).  Static method would be
> the choice here (and no self)
>
> It's mildly possible that ordering is allowed to be a callable.  If
> so, you could
> assign it to a function (not a method of the not yet defined Substrate).  
> That's
> the function itself, no parentheses.  The function would return the list.
>
> If ordering can't be a callable, you could create a class that implements 
> enough
> of list behavior to satisfy the framework (a subject for research or
> experimentation,
> but iteration might be enough) and set ordering to an instance, whose apparent
> content depends on the current language.
>
> It still might not work, if the __metaclass__ processes Meta.ordering at clas
> definition time.  You have the source code.
>
> Bill
>
> On Fri, Dec 18, 2009 at 6:07 AM, Kevin Renskers  wrote:
> > Hi,
>
> > I am having a bit of a problem. I have a model with 3 name fields,
> > each for a different language. By creating an __unicode__ function
> > like below, I always get the correct name for the current language.
> > Works fine.
>
> > But, I want to change the default ordering for this model, so that in
> > each language, the correct order is used. Sadly, this doesn't work, as
> > I get the error "NameError: name 'Substrate' is not defined". Also
> > "self" and "super" don't seem to work. I just can't seem to be able to
> > access the parent class from within the Meta class.
>
> > I can't even repeat the getLanguage function into the Meta class,
> > because then I get an the error "TypeError: 'class Meta' got invalid
> > attribute(s): getLanguage".
>
> > class Substrate(models.Model):
> >    name_en = models.CharField(max_length=255)
> >    name_de = models.CharField(max_length=255, blank=True)
> >    name_nl = models.CharField(max_length=255, blank=True)
>
> >    def getLanguage(self):
> >        from django.utils import translation
> >        current_language = translation.get_language()
> >        if not current_language:
> >            current_language = 'en'
> >        return current_language
>
> >    def getName(self):
> >        current_language = self.getLanguage()
> >        name = getattr(self, 'name_'+current_language, self.name_en)
> >        if not name:
> >            name = self.name_en
>
> >        return name
>
> >    def __unicode__(self):
> >        return self.getName()
>
> >    class Meta:
> >        ordering = [('name_%s' % Substrate.getLanguage()), 'name_en']
>
> > If anyone has an idea how on to do this, I would be very happy.
> > Thanks!
>
> > Cheers,
> > Kevin
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

--

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




Re: csrf error on login and admin

2009-12-18 Thread Kenneth Gonsalves
On Wednesday 16 Dec 2009 10:45:49 am Paddy Joy wrote:
> Try 'django.middleware.csrf.CsrfMiddleware' instead of
> 'django.contrib.csrf.middleware.CsrfMiddleware'
> 

copied and pasted straight from the official docs
-- 
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Correct way to unlazify a SimpleLazyObject?

2009-12-18 Thread Hanne Moa
I recently got burned by r11626, which added SimpleLazyObject to
1.1.x. I have a templatetag that linkifies a user-object, and it
checks whether it is given a django.contrib.auth.models.User, an int
(looks up a User) or a profile (looks up the User). This check was
done with type(). Unfortunately, type(SimpleLazyObject) !=
type(User()), so I had a "fun" TemplateSyntaxError in my hands.

However, the TemplateSyntaxError never happened if there was an
instance of {{ user }} before the {% prettylinktouser user %} in the
template, thus it seems to me that just outputting a SimpleLazyObject
somehow unlazifies it. So, how can a SimpleLazyObject be unlazified
everywhere else?


HM

--

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




filter and count on multi-table inheritance?

2009-12-18 Thread Gabriel Farrell
I have the following models:

class News(models.Model):
title = models.CharField(max_length=128)
author = models.ForeignKey(User, related_name='news')

class Report(News):
subtitle = models.CharField(max_length=128)
synopsis = models.TextField()

class Post(News):
body = models.TextField()


I have a page where I list authors, and would like to include a count
of Reports and Posts from each one.  Is there a way to filter News for
Report or Post items?  I would like to add to the NewsManager so that
the template could include something as simple as
{{ author.news.report_count }}.

--

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




Re: How to deal with NULL value in template

2009-12-18 Thread Continuation
I tried

{% if field %}
   No
{% else %}
  Yes - {{ field }}
{% endif %}

And if the value of field is null, the else statement above ended up
getting executed and output was "Yes - None"

So far for me:

{% ifequal field Null %} and {% ifequal field None %} works.

But

{% if field %}

doesn't.

Did I do something wrong?


On Dec 18, 4:08 am, Daniel Roseman  wrote:
> On Dec 18, 7:12 am, Continuation  wrote:
>
>
>
> > I have a field with the null=True option
>
> > How do I test for the Null value in template?
>
> > I did something like:
>
> > {% ifequal field Null %}
> >     do something
> > {% else %}
> >     do something else
>
> > I tested it and it worked. But I want to make sure this is the proper
> > way to handle Null value in Django. The doc is a bit unclear.
>
> > Also does it matter if I type out null as "Null", "null", or "NULL" in
> > the above example?
>
> The Python equivalent of null is None - if you explicitly need to
> check for that value, that's how you should spell it.
>
> However normally the better way of doing it is just
> {% if field %}
> etc, since None is boolean false, as is False, 0 and [].
> --
> DR.

--

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




Re: Learning Django - Error going through Chapt 4 on Templates at DjangoBook.com - Probably real simple

2009-12-18 Thread bayousoft
Sorry guys.  the explanation is in the next paragraph. Please
disregard.

On Dec 18, 1:50 pm, bayousoft  wrote:
> I am brand new to Django and I'm trying to get up to speed ASAP.  I
> really like it so far.  I'm getting an error trying to create a
> template in the shell.
>
> >>> from django import template
> >>> t = template.Template('My name is {{ name }}.')
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/pymodules/python2.6/django/template/__init__.py",
> line 166, in __init__
>     if settings.TEMPLATE_DEBUG and origin is None:
>   File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line
> 269, in __getattr__
>     self._setup()
>   File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line
> 38, in _setup
>     raise ImportError("Settings cannot be imported, because
> environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
> ImportError: Settings cannot be imported, because environment variable
> DJANGO_SETTINGS_MODULE is undefined.
>
> I am using Ubuntu (Karmic Koala) and I installed from the Package
> Manager Version 1.1.1.  I'm guessing I have some sort of a path
> problem.
>
> Can anyone give me a quick fix/explanation?  I'd rather not skip this
> issue because I imagine it will come back to bite me later.

--

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




Re: Learning Django - Error going through Chapt 4 on Templates at DjangoBook.com - Probably real simple

2009-12-18 Thread bayousoft
Looking in Synaptic I'm kinda wondering if I need to install python-
jinja2 ?

On Dec 18, 1:50 pm, bayousoft  wrote:
> I am brand new to Django and I'm trying to get up to speed ASAP.  I
> really like it so far.  I'm getting an error trying to create a
> template in the shell.
>
> >>> from django import template
> >>> t = template.Template('My name is {{ name }}.')
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/pymodules/python2.6/django/template/__init__.py",
> line 166, in __init__
>     if settings.TEMPLATE_DEBUG and origin is None:
>   File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line
> 269, in __getattr__
>     self._setup()
>   File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line
> 38, in _setup
>     raise ImportError("Settings cannot be imported, because
> environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
> ImportError: Settings cannot be imported, because environment variable
> DJANGO_SETTINGS_MODULE is undefined.
>
> I am using Ubuntu (Karmic Koala) and I installed from the Package
> Manager Version 1.1.1.  I'm guessing I have some sort of a path
> problem.
>
> Can anyone give me a quick fix/explanation?  I'd rather not skip this
> issue because I imagine it will come back to bite me later.

--

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




Custom Model Field with Validation...how to hook it back to ModelForm

2009-12-18 Thread bkev
Hello...

A common occurrence I have with one particular project is that it
requires the user to enter dimensions (for width/depth/height) in Feet
and Inches. Calculations are needed to be performed on that dimension,
so I've been working on a custom field type that takes in a dimension
in Feet/Inches (eg. 1'-10") and saves it to the database as a decimal
number using a regex to parse the input. The field displays to the end-
user as feet-inches at all times (with the eventual goal of writing a
method to be able to optionally display in metric, and interact with
measure.py, and geodjango stuff). What I have so far is definitely not
DRY, but aside from that, I'm having trouble with validation at the
form level. The custom model field itself works properly (from what
I've seen), and I've written a form field clean method which should
work to validate the field. My question is how to hook that form field
back into my model form to work for all the width/depth/height fields.
I'm thinking maybe an override of the init on the modelform (a la
self.fields['depth']...) , but I'm not quite sure where to go from
here...would you help me?

DCML_PATTERN = re.compile(r'^(?P\d+)(?P\.?\d*)\'?$')
FTIN_PATTERN = re.compile(r'^(?P\d+)\'?\s*-?\s*(?P[0-9]|10|
11)?\"?$')

class FtInField(models.Field):
__metaclass__ = models.SubfieldBase

empty_strings_allowed = False

def db_type(self):
return 'double'

def get_internal_type(self):
return "FtInField"

def to_python(self,value):
if value is u'' or value is None:
return None
if isinstance(value, float):
m = FTDCML_PATTERN.match(str(value))
if m is None:
raise Exception('Must be an integer or decimal 
number')
feet = int(m.group('feet'))
dec_inch = float(m.group('dec_inch') or 0)
inch = dec_inch * 12
return "%d\'-%.0f\"" % (feet,inch)
return value

def get_db_prep_value(self,value):
if value is u'' or value is None:
return None
m = FTIN_PATTERN.match(value)
if m is None:
raise Exception('Must be in X\'-Y" Format')
feet = int(m.group('feet'))
inch = int(m.group('inch') or 0)
return (feet + (inch/float(12)))


class FtInField(forms.Field):

def clean(self,value):
super(FtInField, self).clean(value)
if value is u'' or value is None:
raise forms.ValidationError('Enter a dimension in 
X\'-Y" format')
m = FTIN_PATTERN.match(value)
if m is None:
raise forms.ValidationError('Must be in X\'-Y" Format')
feet = int(m.group('feet'))
inch = int(m.group('inch') or 0)
value = '%d\'-%.0f"' % (feet,inch)
return value

class ProductClass(models.Model):
productname = models.CharField('Product Name', max_length=60,
blank=True)
depth = FtInField('Depth (Feet/Inches)')
width = FtInField('Width (Feet/Inches)')
height = FtInField('Height (Feet/Inches)')

class ProductClassForm(forms.ModelForm):
depth = FtInField()
width = FtInField()
height = FtInField()

class Meta:
model = ProductClass

class ProductClassAdmin(admin.ModelAdmin):
form = ProductClassForm

--

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




Having trouble building a search form with proper filters

2009-12-18 Thread jlwlynn
Okay, Here's a quick look at my model layout

Contact :
  company -> ForeignKey -> Company

Company :
  type --> OneToOne --> Type

Type :
  type (character)

I'm trying to build a search that will return contacts based on
certain criteria.  Any other fields in Company that do not join to
another table work just fine (e.g. company__city__icontains=city).
But, any way I've tried to filter based on the type (e.g.
company__type__type__icontans=type) results in failure.  (I've tried
all I can think of, but cannot find a solution).  Failure (in this
case) is :

Join on field 'type' not permitted.

Any ideas would be greatly appreciated!!!

Thanks,

jason

--

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




Learning Django - Error going through Chapt 4 on Templates at DjangoBook.com - Probably real simple

2009-12-18 Thread bayousoft
I am brand new to Django and I'm trying to get up to speed ASAP.  I
really like it so far.  I'm getting an error trying to create a
template in the shell.

>>> from django import template
>>> t = template.Template('My name is {{ name }}.')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/pymodules/python2.6/django/template/__init__.py",
line 166, in __init__
if settings.TEMPLATE_DEBUG and origin is None:
  File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line
269, in __getattr__
self._setup()
  File "/usr/lib/pymodules/python2.6/django/conf/__init__.py", line
38, in _setup
raise ImportError("Settings cannot be imported, because
environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable
DJANGO_SETTINGS_MODULE is undefined.

I am using Ubuntu (Karmic Koala) and I installed from the Package
Manager Version 1.1.1.  I'm guessing I have some sort of a path
problem.

Can anyone give me a quick fix/explanation?  I'd rather not skip this
issue because I imagine it will come back to bite me later.

--

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




Re: Strange problem when starting project in Windows XP

2009-12-18 Thread dfolland
idle.pyw is the gui version of the python idle editor.  Sounds like
you've got file extension .py associated with it, instead of python.

On Dec 18, 11:59 am, OkaMthembo  wrote:
> Hi Dane,
>
> Yes, when you have to specify an absolute path to get it working, it
> definitely sounds like a PATH environ config. problem. When you check your
> PATH variables, do you see the folder to django-admin.py listed?
>
> Regards,
> Lloyd
>
>
>
> On Fri, Dec 18, 2009 at 7:27 PM, Dane  wrote:
> > It worked with 'python c:\python26\scripts\django-admin.py
> > startproject newsite'. Does that mean the PATH got messed up somehow?
>
> > On Dec 18, 7:52 am, Shawn Milochik  wrote:
> > > What happens when you type 'python django-admin.py'?
>
> > > If that doesn't work, try replacing 'python' there with the full path to
> > your Python executable in Windows. I've never heard of this problem, but it
> > sounds like it could be something odd in the environment.
>
> > > Shawn
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Regards,
> Sithembewena Lloyd Dubehttp://www.lloyddube.com

--

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




Re: problems downloading django

2009-12-18 Thread Michael K
On Dec 18, 2:13 pm, Michael K  wrote:
> Still having the same issue.  I'm on a windows machine, but even if I
> use wget on one of the Solaris machines, the TAR is reported as having
> no files and/or is corrupted.
>
> Is there another download location I can try?
>
> --
> Michael

James,

Thanks for the response on this, it made me think of something else to
try - a different web browser.  It seems Chrome beta doesn't like
something about the delivery of the tar.gz.  When I used IE, the file
opened first try.

I also realized the problem with the wget is the same as my SVN issue
- except in this case, the Solaris machines are blocked from using the
proxy server in question.  Once I changed the environment to point to
the appropriate one, I also got the file from there.

Sorry to waste the bandwidth, but hopefully someone will search for
download issues - and if they're running Chrome, they'll know what's
up.

--
Michael

PS: Chrome version is 4.0.266.0

--

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




Re: problems downloading django

2009-12-18 Thread Michael K


On Dec 18, 2:10 pm, Michael K  wrote:
> On Dec 16, 4:10 pm, James Bennett  wrote:> On Wed, Dec 
> 16, 2009 at 2:13 PM, Michael K  wrote:
> > > Should I take the silence to mean I should open a bug report?
>
> > I clicked the "download" link for Django 1.1.1, and the package
> > downloaded. On finishing the download, I was able to checksum it and
> > get the same results as the signed checksum document provided at the
> > time of the 
> > release:http://media.djangoproject.com/pgp/Django-1.1.1.checksum.txt
>
> > Thus, the problem is most likely not with anything on
> > djangoproject.com; instead, it's probably something related to your
> > own Internet connection.
> It's been a couple of days, I'll try it again.
>
> Thanks for the response!

Still having the same issue.  I'm on a windows machine, but even if I
use wget on one of the Solaris machines, the TAR is reported as having
no files and/or is corrupted.

Is there another download location I can try?

--
Michael

--

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




Re: problems downloading django

2009-12-18 Thread Michael K


On Dec 16, 4:10 pm, James Bennett  wrote:
> On Wed, Dec 16, 2009 at 2:13 PM, Michael K  wrote:
> > Should I take the silence to mean I should open a bug report?
>
> I clicked the "download" link for Django 1.1.1, and the package
> downloaded. On finishing the download, I was able to checksum it and
> get the same results as the signed checksum document provided at the
> time of the 
> release:http://media.djangoproject.com/pgp/Django-1.1.1.checksum.txt
>
> Thus, the problem is most likely not with anything on
> djangoproject.com; instead, it's probably something related to your
> own Internet connection.
>
My first assumption was that it was my network connection, but I've
had no issues downloading from any other site - just
djangoproject.com.

It's been a couple of days, I'll try it again.

Thanks for the response!

--
Michael

--

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




Re: Strange problem when starting project in Windows XP

2009-12-18 Thread OkaMthembo
Hi Dane,

Yes, when you have to specify an absolute path to get it working, it
definitely sounds like a PATH environ config. problem. When you check your
PATH variables, do you see the folder to django-admin.py listed?

Regards,
Lloyd

On Fri, Dec 18, 2009 at 7:27 PM, Dane  wrote:

> It worked with 'python c:\python26\scripts\django-admin.py
> startproject newsite'. Does that mean the PATH got messed up somehow?
>
> On Dec 18, 7:52 am, Shawn Milochik  wrote:
> > What happens when you type 'python django-admin.py'?
> >
> > If that doesn't work, try replacing 'python' there with the full path to
> your Python executable in Windows. I've never heard of this problem, but it
> sounds like it could be something odd in the environment.
> >
> > Shawn
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

--

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




Re: Strange problem when starting project in Windows XP

2009-12-18 Thread Dane
It worked with 'python c:\python26\scripts\django-admin.py
startproject newsite'. Does that mean the PATH got messed up somehow?

On Dec 18, 7:52 am, Shawn Milochik  wrote:
> What happens when you type 'python django-admin.py'?
>
> If that doesn't work, try replacing 'python' there with the full path to your 
> Python executable in Windows. I've never heard of this problem, but it sounds 
> like it could be something odd in the environment.
>
> Shawn

--

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




Re: cached_db session backend, memcached and SESSION_COOKIE_AGE > 30 days

2009-12-18 Thread Jose C
In case anyone else hits this issue, there's a patch available:
http://code.djangoproject.com/ticket/12399

--

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




Re: Error creating new project

2009-12-18 Thread Gaston
Thanks Ales, there were problems with the symlink. Deleting it and
just doing python setup.py install solved the problem. Thanks again
for your help!

-Gaston


On Dec 17, 3:08 am, Ales Zoulek  wrote:
> OK.
>
> Try:
>
> ls SITE-PACKAGES-DIR/django
>
> is there a "core", "http", "forms" dirs or dirs like examples, scripts, docs
> and "django"?
>
> If it's the second case, then you need to symlink one "django" dir deeper:
>
> unlink SITE-PACKAGES-DIR/django
> ln -s `pwd`/django-trunk/django/django SITE-PACKAGES-DIR/django
>
> Regards,
>
> Ales
> --
> Ales Zoulek
> Jabber: ales.zou...@gmail.com
> --
>
>
>
> On Thu, Dec 17, 2009 at 6:40 AM, Abhaya  wrote:
> > Hi Gaston,
>
> > I am also pretty new to python. Once I had a similar issue, it turned
> > out to be permissions on the directories. Since you are creating a
> > symlink, make sure that all the directories have appropriate
> > permissions.
>
> > Regards,
> > Abhaya
>
> > On Dec 17, 2:22 am, Gaston  wrote:
> > > I believe I'm doing that, look at the last entry in the path:
>
> > > $ python
> > > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
> > > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
> > > Type "help", "copyright", "credits" or "license" for more information.>>>
> > import sys
> > > >>> print sys.path
>
> > > ['', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
> > > site-packages/setuptools-0.6c11-py2.6.egg', '/Library/Frameworks/
> > > Python.framework/Versions/2.6/lib/python2.6/site-packages/
> > > readline-2.6.4-py2.6-macosx-10.3-fat.egg', '/Library/Frameworks/
> > > Python.framework/Versions/2.6/lib/python2.6/site-packages/pexpect-2.4-
> > > py2.6.egg', '/Library/Frameworks/Python.framework/Versions/2.6/lib/
> > > python2.6/site-packages/zope.interface-3.5.3-py2.6-macosx-10.3-
> > > fat.egg', '/Library/Frameworks/Python.framework/Versions/2.6/lib/
> > > python2.6/site-packages/Twisted-9.0.0-py2.6-macosx-10.3-fat.egg', '/
> > > Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/
> > > Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/
> > > Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-
> > > darwin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/
> > > python2.6/plat-mac', '/Library/Frameworks/Python.framework/Versions/
> > > 2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Library/Frameworks/
> > > Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/Library/
> > > Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/
> > > Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-
> > > dynload', '/Library/Frameworks/Python.framework/Versions/2.6/lib/
> > > python2.6/site-packages']
>
> > > I created the symbolic link as follows, with the appropriate
> > > replacement for SITE-PACKAGES-DIR, obviously:
>
> > > ln -s `pwd`/django-trunk/django SITE-PACKAGES-DIR/django
>
> > > Unfortunately, I'm still getting the same error.
>
> > > Thanks for your help,
>
> > > -Gaston
>
> > > On Dec 16, 3:41 pm, Ales Zoulek  wrote:
>
> > > > You need to have django installed in your pythonpath.
>
> > > > You can see the current python path by running python console and
> > > > import sys
> > > > print sys.path
>
> > > > If there's not the directory containing django sources, try adding the
> > > > directory to the PYTHONPATH system environment variable, or symlink it
> > > > somewhere to dir in sys.path
>
> > > > A.
>
> > > > --
> > > > Ales Zoulek
> > > > Jabber: ales.zou...@gmail.com
> > > > --
>
> > > > On Wed, Dec 16, 2009 at 9:07 PM, Gaston 
> > wrote:
> > > > > Hello,
>
> > > > > I'm new to Django and I'm following part 1 of the tutorial. When I
> > try
> > > > > creating a new project, the following error appears:
>
> > > > > $ ~/programming/python/django-trunk/django/bin/django-admin.py
> > > > > startproject mysite
> > > > > Traceback (most recent call last):
> > > > >  File "/Users/gafiore/programming/python/django-trunk/django/bin/
> > > > > django-admin.py", line 2, in 
> > > > >    from django.core import management
> > > > > ImportError: No module named django.core
>
> > > > > I've installed Django from SVN following the installation
> > > > > instructions, and I'm using Mac OS X.
>
> > > > > Thanks a lot for your help,
>
> > > > > -Gaston
>
> > > > > --
>
> > > > > You received this message because you are subscribed to the Google
> > Groups
> > > > > "Django users" group.
> > > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > django-users+unsubscr...@googlegroups.com > > > >  groups.com>
> > 
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/django-users?hl=en.
>
> > --
>
> > You received th

Re: LDAP-groups problem

2009-12-18 Thread Wayne
Hi,

Sorry for the late reply. Here is more info.

Django Verstion: 1.1
Oracle Version:Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit
Production
cx_oracle for Python 2.6.

Thanks for the help.

Wayne

On Dec 18, 10:26 am, Peter Herndon  wrote:
> On Dec 18, 2009, at 10:15 AM, Peter Herndon wrote:
>
>
>
> > On Dec 17, 2009, at 7:32 PM, Wayne wrote:
>
> >> Hi,
>
> > This error arises from an inconsistency between the behavior of Oracle and 
> > the behavior of PostgreSQL, as Mike noted.  It works under Postgres.  I'll 
> > check with the dev list and see if this behavior difference is known, and 
> > whether the fix is to never use unique=True on a TextField (a bug in my 
> > code), or something that needs to be smoothed over in the SQL generation 
> > for Oracle specifically (a bug in the underlying Django behavior).
>
> Hi Wayne,
>
> Can you tell me the Django version, the version of cx_Oracle, and the Oracle 
> version?  If this has been fixed for certain versions, that would make this 
> error a moot point.  And the developers are certainly going to ask.  :)
>
> Thanks,
>
> ---Peter

--

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




Re: TemplateSyntaxError: 'property' object is not iterable

2009-12-18 Thread Chris Curvey
Never mind.  Me am a moron.  Had a totally different programming error
elsewhere.  It works as is it should.

On Dec 17, 4:12 pm, Chris Curvey  wrote:
> I have my class definition that looks like
>
> class Foo:
>    def get_bars(self):
>       bars = []
>        # do something to collect bar instances
>        return bars
>    bars = property(get_bars)
>
> in my template, I'd like to do something like this:
>
> {% for bar in foo.bars %}
>   {{bar.snafu}}
> {% endfor %}
>
> But when I do that, I get "TemplateSyntaxError: 'property' object is
> not iterable."
>
> If I change it to {% for bar in foo.get_bars() %}, I get a
> TemplateSyntaxError:  could not parse the remainder"
>
> If I change it to {% for bar in foo.get_bars %}, the template runs,
> but it does not seem to be calling "get_bars"
>
> How can I do what I'm trying to do?   (Must I create a "regular" list
> attribute and pre-populate it?)

--

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




Re: Directories inside app directory

2009-12-18 Thread Bill Freeman
On Thu, Dec 17, 2009 at 5:02 AM, bruno desthuilliers
 wrote:
...
>
> [1] currently 970 LOCs, and I just have the basic models structures
> and only one custom manager defined yet, so I know there will be more
> to come. YMMV but I don't like modules growing much bigger than 1 to
> 1.5 KLOC.

In general I agree that many small files are nice.  And in the case of
view.py, forms.py, etc., django doesn't know about those names specially.
view files are referred to in your url.py, which itself is just
referred to in your
root url.py, which is referred to in your settings.py, so all their names can
change without any problem, other than making your code harder for
someone else to maintain.

But the name models is known specially by the framework.

All in all, I don't care much how many lines there are in a models.py file.
After all, I don't use notepad, with its 64kib limit,  to edit python code.
I *do* care how many lines there are in a class, since that is the unit
that I must understand.  Moving those classes into separate files doesn't
make them smaller.

I do, also, prefer small apps.  When I needed to rework the (pinax) profile
app, I was happy to only have to copy that to change, rather than having to
include django.contrib.auth, account, emailconfirmation, and who knows
what else has a close relationship with django.contrib.auth.  So I don't
care how many models are in a module, but I think that five is about as
many as I would want in an app.

--

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




Early Registration for PYCON in Atlanta Ends Jan 7

2009-12-18 Thread dartdog
See link for details
https://us.pycon.org/2010/register/default/index

--

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




Re: Django Settings File - Where is it?

2009-12-18 Thread Rafael Vieira
It is the project configuration's file, "settings.py" where you can
change project options, for example, DATABASE_NAME equals name of your
database and more...

2009/12/18 Biju Varghese :
> create a project with django-admin.py startproject project1
> and this will create a folder named project1 and check in this foder
> will have settings.py urls.py manage.py and __init__.py etc.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>



-- 
Rafael Vieira
54-91575031

--

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




Re: Django Settings File - Where is it?

2009-12-18 Thread Biju Varghese
create a project with django-admin.py startproject project1
and this will create a folder named project1 and check in this foder
will have settings.py urls.py manage.py and __init__.py etc.

--

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




Re: Problem with Meta inner class accessing its parent

2009-12-18 Thread Bill Freeman
I can't promise that it will do what you want, but your problem is
that at the time
you try to set the value of Meta.ordering, class Substrate does not yet exist.
You can dig into the Substrate.objects._meta later to add ordering, probably.

Your design wouldn't have worked anyway, since getLanguage would only
have been called once, at import time, and even if that worked, it wouldn't
follow current language as it changes (I presume) from request to request.

Oh, and since you're not calling getLanguage on a class instance, it would
have to be declared a staticmethod or classmethod, and not get the self
argument or replace it with cls (for classmethod).  Static method would be
the choice here (and no self)

It's mildly possible that ordering is allowed to be a callable.  If
so, you could
assign it to a function (not a method of the not yet defined Substrate).  That's
the function itself, no parentheses.  The function would return the list.

If ordering can't be a callable, you could create a class that implements enough
of list behavior to satisfy the framework (a subject for research or
experimentation,
but iteration might be enough) and set ordering to an instance, whose apparent
content depends on the current language.

It still might not work, if the __metaclass__ processes Meta.ordering at clas
definition time.  You have the source code.

Bill


On Fri, Dec 18, 2009 at 6:07 AM, Kevin Renskers  wrote:
> Hi,
>
> I am having a bit of a problem. I have a model with 3 name fields,
> each for a different language. By creating an __unicode__ function
> like below, I always get the correct name for the current language.
> Works fine.
>
> But, I want to change the default ordering for this model, so that in
> each language, the correct order is used. Sadly, this doesn't work, as
> I get the error "NameError: name 'Substrate' is not defined". Also
> "self" and "super" don't seem to work. I just can't seem to be able to
> access the parent class from within the Meta class.
>
> I can't even repeat the getLanguage function into the Meta class,
> because then I get an the error "TypeError: 'class Meta' got invalid
> attribute(s): getLanguage".
>
> class Substrate(models.Model):
>    name_en = models.CharField(max_length=255)
>    name_de = models.CharField(max_length=255, blank=True)
>    name_nl = models.CharField(max_length=255, blank=True)
>
>    def getLanguage(self):
>        from django.utils import translation
>        current_language = translation.get_language()
>        if not current_language:
>            current_language = 'en'
>        return current_language
>
>    def getName(self):
>        current_language = self.getLanguage()
>        name = getattr(self, 'name_'+current_language, self.name_en)
>        if not name:
>            name = self.name_en
>
>        return name
>
>    def __unicode__(self):
>        return self.getName()
>
>    class Meta:
>        ordering = [('name_%s' % Substrate.getLanguage()), 'name_en']
>
>
>
> If anyone has an idea how on to do this, I would be very happy.
> Thanks!
>
> Cheers,
> Kevin
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: LDAP-groups problem

2009-12-18 Thread Peter Herndon

On Dec 18, 2009, at 10:15 AM, Peter Herndon wrote:

> 
> On Dec 17, 2009, at 7:32 PM, Wayne wrote:
> 
>> Hi,
> 
> This error arises from an inconsistency between the behavior of Oracle and 
> the behavior of PostgreSQL, as Mike noted.  It works under Postgres.  I'll 
> check with the dev list and see if this behavior difference is known, and 
> whether the fix is to never use unique=True on a TextField (a bug in my 
> code), or something that needs to be smoothed over in the SQL generation for 
> Oracle specifically (a bug in the underlying Django behavior).
> 
Hi Wayne,

Can you tell me the Django version, the version of cx_Oracle, and the Oracle 
version?  If this has been fixed for certain versions, that would make this 
error a moot point.  And the developers are certainly going to ask.  :)

Thanks,

---Peter

--

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




Re: LDAP-groups problem

2009-12-18 Thread Peter Herndon

On Dec 17, 2009, at 7:32 PM, Wayne wrote:

> Hi,

Hi Wayne,

> 
> I tried to use djando-ldap-groups but got some errors from database
> configuration. Could somebody shed some light on the possible problems
> of my set up?

Hmm, I think I found the problem below.
> 
> Our LDAP server is Sun One Server and the site is running in the
> windows environment.

Aside: If you get all this running properly, please let me know, I've not tried 
it with Sun One and would be glad to know that it works with that particular 
LDAP server.

> AUTHENTICATION_BACKENDS = (
> 'django.contrib.auth.backends.ModelBackend',
> ) .

You will need to add one of the LDAP backends to this setting.  The eDirectory 
backend is pretty generic, and will be a better bet than the ActiveDirectory 
backend.  That's not the problem you are having, but is something you'll need 
to handle shortly.
> 
> The error message came from command: python manage.py syncdb
> Creating table ldap_groups_ldapgroup
> Traceback (most recent call last):
> 
[snip]
> cx_Oracle.DatabaseError: ORA-02329: column of datatype LOB cannot be
> unique or a
> primary key
> 

In ldap_groups/models.py, the LDAPGroup.org_unit field is a TextField, and is 
marked unique=True.  I'm thinking that the cx_Oracle backend is translating the 
TextField into a Large Object (LOB) field in Oracle, and Oracle cannot ensure 
uniqueness of a Large Object.  In short, remove the "unique=True" from the 
ldap-groups code and try again.  It should work after that.

This error arises from an inconsistency between the behavior of Oracle and the 
behavior of PostgreSQL, as Mike noted.  It works under Postgres.  I'll check 
with the dev list and see if this behavior difference is known, and whether the 
fix is to never use unique=True on a TextField (a bug in my code), or something 
that needs to be smoothed over in the SQL generation for Oracle specifically (a 
bug in the underlying Django behavior).

Let me know if you have further questions, I'm happy to assist.

Regards,

---Peter Herndon

--

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




Re: Need help inserting pdf

2009-12-18 Thread Shawn Milochik
The difference between the PDF and JPG is that the JPG has to be an 'img' tag 
and the PDF has to be an 'href' tag.

So instead of:



Try:

Download Important Stuff

Shawn


--

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




Re: Strange problem when starting project in Windows XP

2009-12-18 Thread Shawn Milochik
What happens when you type 'python django-admin.py'?

If that doesn't work, try replacing 'python' there with the full path to your 
Python executable in Windows. I've never heard of this problem, but it sounds 
like it could be something odd in the environment.

Shawn

--

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




Strange problem when starting project in Windows XP

2009-12-18 Thread Dane
Hi all,

I'm new to Django. I got through the beginner tutorial without much
trouble and I just finished the introductory chapters of The
Definitive Guide, so I decided to start work on a real project. I've
quickly run into a bizarre stumbling block however when I try to start
my new project.

I run cmd.exe to open the windows command prompt, then I navigate to
my django projects folder, then type 'django-admin.py startproject
newsite' and then I get this error in the command prompt:

'The system cannot find the file idle.pyw'.

I also get an error dialog in windows titled 'idle.pyw' that says
'Windows cannot find 'idle.pyw'. Make sure you typed the name
correctly, and then try again. To search for a file, click the Start
button, and then click Search.'

I get the same error if I simply type 'django-admin.py' into the
prompt as well.

I really have no clue what's going on here. What does idle.pyw have to
do with anything? Google has been no help. I did this exact same thing
when going through the tutorial with no problems whatsoever, and made
no changes to any of my PATH variables or anything of that kind.

Any ideas? I'm really eager to get going with Django but feeling quite
frustrated! Thanks for help.

-Dane

--

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




Problem with Meta inner class accessing its parent

2009-12-18 Thread Kevin Renskers
Hi,

I am having a bit of a problem. I have a model with 3 name fields,
each for a different language. By creating an __unicode__ function
like below, I always get the correct name for the current language.
Works fine.

But, I want to change the default ordering for this model, so that in
each language, the correct order is used. Sadly, this doesn't work, as
I get the error "NameError: name 'Substrate' is not defined". Also
"self" and "super" don't seem to work. I just can't seem to be able to
access the parent class from within the Meta class.

I can't even repeat the getLanguage function into the Meta class,
because then I get an the error "TypeError: 'class Meta' got invalid
attribute(s): getLanguage".

class Substrate(models.Model):
name_en = models.CharField(max_length=255)
name_de = models.CharField(max_length=255, blank=True)
name_nl = models.CharField(max_length=255, blank=True)

def getLanguage(self):
from django.utils import translation
current_language = translation.get_language()
if not current_language:
current_language = 'en'
return current_language

def getName(self):
current_language = self.getLanguage()
name = getattr(self, 'name_'+current_language, self.name_en)
if not name:
name = self.name_en

return name

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

class Meta:
ordering = [('name_%s' % Substrate.getLanguage()), 'name_en']



If anyone has an idea how on to do this, I would be very happy.
Thanks!

Cheers,
Kevin

--

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




format date output in mail form

2009-12-18 Thread rvandam
I saw a solution on the list to format a datefield in a template.
Unfortunately i didnt find any solution for formatting a datefield in
a mailform. I have this in my model:

  Aankomst = forms.DateField(('%d/%m/%Y',), widget=forms.DateTimeInput
(format='%d/%m/%Y', attrs={
'class':'formVeld',
'readonly':'readonly',
'size':'8'
}), required=False)

This is a part of my view:

Aankomst = form.cleaned_data['Aankomst']
aankomst = str(Aankomst)
message = aankomst

The date output in my mail is:

2010-07-30

I would like it to have it as: 03/07/2010 Is there a solution for this?

--

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




Re: Error message

2009-12-18 Thread rebus_
2009/12/18 reactosguy :
> I get this message every time I go on http://localhost:8000/ with the
> Django server running:
>
> Traceback (most recent call last):
>
>  File "C:\Python26\lib\site-packages\django\core\servers
> \basehttp.py", line 279, in run
>    self.result = application(self.environ, self.start_response)
>
>  File "C:\Python26\lib\site-packages\django\core\servers
> \basehttp.py", line 651, in __call__
>    return self.application(environ, start_response)
>
>  File "C:\Python26\lib\site-packages\django\core\handlers\wsgi.py",
> line 241, in __call__
>    response = self.get_response(request)
>
>  File "C:\Python26\lib\site-packages\django\core\handlers\base.py",
> line 122, in get_response
>    return self.handle_uncaught_exception(request, resolver,
> sys.exc_info())
>
>  File "C:\Python26\lib\site-packages\django\core\handlers\base.py",
> line 166, in handle_uncaught_exception
>    return callback(request, **param_dict)
>
>  File "C:\Python26\lib\site-packages\django\views\defaults.py", line
> 23, in server_error
>    t = loader.get_template(template_name)
>
>  File "C:\Python26\lib\site-packages\django\template\loader.py", line
> 81, in get_template
>    source, origin = find_template_source(template_name)
>
>  File "C:\Python26\lib\site-packages\django\template\loader.py", line
> 74, in find_template_source
>    raise TemplateDoesNotExist, name
>
> TemplateDoesNotExist: 500.html
>
> --

Create template with the name 500.html in your base template directory.
It tries to use 500.html on server error if you have DEBUG=False.

Davor

--

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




Re: How to deal with NULL value in template

2009-12-18 Thread Daniel Roseman
On Dec 18, 7:12 am, Continuation  wrote:
> I have a field with the null=True option
>
> How do I test for the Null value in template?
>
> I did something like:
>
> {% ifequal field Null %}
>     do something
> {% else %}
>     do something else
>
> I tested it and it worked. But I want to make sure this is the proper
> way to handle Null value in Django. The doc is a bit unclear.
>
> Also does it matter if I type out null as "Null", "null", or "NULL" in
> the above example?

The Python equivalent of null is None - if you explicitly need to
check for that value, that's how you should spell it.

However normally the better way of doing it is just
{% if field %}
etc, since None is boolean false, as is False, 0 and [].
--
DR.

--

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




Re: extend queryset field lookups for time

2009-12-18 Thread hinnack
has nobody an idea for this?
Hour and Minute itself seems to be easy - should just be added to
where.py
WhereNode class => make_atom() - but how to extend the functionality
to greater / lower?


-- Hinnack

On Nov 27, 2:53 pm, Hinnack  wrote:
> Hi,
>
> how would I extend the field lookup to get somethnng like this:
>
> SELECT ... WHERE EXTRACT('hour' FROM pub_date) > 20
> what is for MYSQL:
> SELECT ... WHERE HOUR(pub_date) > 20
> to get all entries where the timepart of pub_date is grater then 8pm
>
> and how would I change the existing of YEAR, MONTH, DAY for > and <...
>
> regards
>
> -- Hinnack

--

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




Fwd: Ticket #2417 Support for binary type fields

2009-12-18 Thread Hinnack
noone interested in this?

--

Hinnack

-- Forwarded message --
From: Hinnack 
Date: 2009/12/13
Subject: Ticket #2417 Support for binary type fields
To: Django users 


Hi,

is there a timeframe, when this will make it into TRUNC or a version?

regards

--
Hinnack

--

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




Re: InternalError -- django specific state?

2009-12-18 Thread shaunc
In fact, my code had a bug in it -- I was both rolling back and
releasing the savepoint (via a finally). Sorry about that.

For the record this *does* work: you can use savepoints and row-level
locking for synchronization between different processes, as you would
hope

Thanks.

On Dec 18, 2:03 am, shaunc  wrote:
> Can anyone help me with the following point?
>
> Does django keep internal state when psycopg throws a
> OperationalError, and how do I clear it?
>
> The situation is this: I have external processes writing into a django/
> postgres database. To avoid using semaphors, etc, I'm trying to use a
> row level lock and the "savepoint" mechanism to make sure a particular
> process is the only one modifying a certain set of table rows.
>
> When another process has beat a given one to the punch, I issue a
> "select ... for update nowait" and get an operational error. The
> "except" block does a "rollback to savepoint"... however, if I
> continue on, I still can't use django -- I get an "InternalError".
>
> I know I can clear this with "connection._rollback()" but there might
> be other things in the transaction that are perfectly good
>
> The "rollback to savepoint" should be sufficient: it works when I
> simulate with two psql processes. So django (or psycopg2?) must keep
> some extra state somewhere. Does anyone know where it is and how I
> clear it?
>
> Thanks!
>
> -- Shaun

--

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