Manuel Meyer | 1 May 2008 01:55
Picon
Favicon

Identify fieldmodel for attributes of an given object


Hey,

I want to get the Fieldmodel(Charfield, TextField, SlugField...) of  
each member of any given object.

What I have now is this:

     def search_objects_attributes(o):
         object_dir = dir(o)
         for i in object_dir:
             try:
                 current_attribute = getattr(o, i)
             except:
                 continue
             if type(current_attribute) == type(u''):
                 print i+': '+str(current_attribute.__class__)+' '+str 
(len(current_attribute))+' '+current_attribute.encode('utf-8')[:300]

This code get every member, that is represented as unicode string,  
but I'd like to know, if it was defined as TextField, CharField....

How this is possible?

Thanks, Manuel

--~--~---------~--~----~------------~-------~--~----~
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 <at> googlegroups.com
To unsubscribe from this group, send email to django-users-unsubscribe <at> googlegroups.com
(Continue reading)

Scott SA | 1 May 2008 02:20
Picon
Picon

Re: Best way to extend an existing django app


Hi Rajesh,

On 4/30/08, Rajesh Dhawan (rajesh.dhawan <at> gmail.com) wrote:

>> Is there a reasonable/accptable ot better yet "recommended" way to add 
>functionality, etc. to an app without resorting to the above points? If so, 
>what stones should I turn (via google serches, etc.) to figure this out.
>
>It depends quite a bit on how "extensibly" the said app was designed.
>Does it use Python classes, for instance? If so, you could look into
>extending these classes with your own. Does it issue or allow Django
>signals? If so, you could add your own listeners to such signals.

A quick bit of grepping shows that signals are being used internally. The majority of its classes are within
Django models.

>You can also do many other kludgy things with Python like replacing a
>class method's implementation but that's not very good practice as it
>eventually ends up with unmaintanable code.

I can't afford to develop anything short-sighted - overall a losing proposition.

>Can you tell us more about the app your are looking to extend and also
>in what ways you want to extend it?

Sure. I'm looking at Satchmo. Parts of it are close enough that I can adapt to how it is configured.
Unfortunately, the product models and client models don't fit well, esp. the product model. I posted a
similar message on the Satchmo list with greater detail but have not received any suggestions.

(Continue reading)

Jay | 1 May 2008 02:21
Picon

Passing a variable to forloop


Hi, guys.  I'm working with a paginator templatetag, and I'm trying to
apply a custom style to the current page.

In the code below, page.number renders *outside* the forloop, but not
*inside* the forloop.

{{ page.number }} << this one renders, but the next page.number does
not.
{% for page in page.object_list %}
<span class="{% ifequal page.number forloop.counter %}current{% else
%}page{% endifequal %}">
{{ forloop.counter }}
</span>
{% endfor %}

How can I get that page.number inside the loop?

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

msoulier | 1 May 2008 02:39
Picon

"data" is a reserved field in newforms?


A coworker of mine created a form with a field called "data".

ie. data = forms.CharField()

This resulted in an exception being thrown when is_valid() was called
on the form:

form error - 'dict' is not callable

The exception occurs at line 180 in
   <python install>\lib\site-packages\django\newforms\forms.py

in Django 0.96.

The reason is that the hasattr() call for "clean_data" returns true.

We're just considering "data" as a reserved word in newforms now, but
I wanted to check to see if this was known. If so, I'd expect an error
saying so, instead of the cryptic one that we received.

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

(Continue reading)

Lucas Hazel | 1 May 2008 02:41
Picon
Gravatar

Re: Passing a variable to forloop


On Wed, 30 Apr 2008 17:21:47 -0700 (PDT)
Jay <jay.jansheski <at> gmail.com> wrote:

> 
> Hi, guys.  I'm working with a paginator templatetag, and I'm trying to
> apply a custom style to the current page.
> 
> In the code below, page.number renders *outside* the forloop, but not
> *inside* the forloop.
> 
> {{ page.number }} << this one renders, but the next page.number does
> not.
> {% for page in page.object_list %}
> <span class="{% ifequal page.number forloop.counter %}current{% else
> %}page{% endifequal %}">
> {{ forloop.counter }}
> </span>
> {% endfor %}
> 
> How can I get that page.number inside the loop?
> 

It's a bit hard to tell what's going on without the template tag, but
it appears you have a name collision.

--

-- 
Lucas Hazel <lucas <at> die.net.au>

--~--~---------~--~----~------------~-------~--~----~
(Continue reading)

Brandon Taylor | 1 May 2008 02:48
Picon
Gravatar

Re: Simply can't get sessions to work - help!


Hi Karen,

Ok, I have verified that the session cookie is being set using the
WebDeveloper toolbar in Firefox, and I set up an "error" page to
redirect to if the cookie wasn't set. All that worked as intended.

So, my next stupid question is...how do I get the value of the cookie
back out to the template, if it's not the way outlined in the
documentation...?

TIA,
Brandon

On Apr 30, 3:30 pm, "Karen Tracey" <kmtra... <at> gmail.com> wrote:
> On Wed, Apr 30, 2008 at 3:40 PM, Brandon Taylor <btaylordes... <at> gmail.com>
> wrote:
>
>
>
>
>
> > Hello everyone,
>
> > I must be missing the forest for the trees, because I simply can't see
> > what I'm doing wrong here!
>
> > #in views.py
> > def find_seminar_occurrence(request, slug, id):
> >    occurrence = get_object_or_404(Occurrence, pk=id)
(Continue reading)

Jay | 1 May 2008 02:48
Picon

Re: Passing a variable to forloop


Thank you-- I meant to include that.  The template tag is here,
unchanged:

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

On Apr 30, 8:41 pm, Lucas Hazel <lu... <at> die.net.au> wrote:
> On Wed, 30 Apr 2008 17:21:47 -0700 (PDT)
>
>
>
> Jay <jay.janshe... <at> gmail.com> wrote:
>
> > Hi, guys.  I'm working with a paginator templatetag, and I'm trying to
> > apply a custom style to the current page.
>
> > In the code below, page.number renders *outside* the forloop, but not
> > *inside* the forloop.
>
> > {{ page.number }} << this one renders, but the next page.number does
> > not.
> > {% for page in page.object_list %}
> > <span class="{% ifequal page.number forloop.counter %}current{% else
> > %}page{% endifequal %}">
> > {{ forloop.counter }}
> > </span>
> > {% endfor %}
>
> > How can I get that page.number inside the loop?
>
(Continue reading)

dayvo | 1 May 2008 03:01
Picon
Favicon

Re: Hardy Upgrade And PythonPath


Thank you!  That solves my problem  I was afraid they decided to rip
out generic relationships.  I know some people don't like using a
model like that but the truth is that it's been used in practice for a
long time.  There are advantages to it in some situations.

I'll take your advice and use the SVN release.  Thanks again.

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

Brandon Taylor | 1 May 2008 03:09
Picon
Gravatar

Re: Simply can't get sessions to work - help!


I got it figured out. It wasn't anything to do with my session code at
all. It was my own fault, not matching the "thanks" view correctly.

I'm still getting used to matching routes with RegExes, but now I know
what to do next time.

Thanks,
Brandon

On Apr 30, 7:48 pm, Brandon Taylor <btaylordes... <at> gmail.com> wrote:
> Hi Karen,
>
> Ok, I have verified that the session cookie is being set using the
> WebDeveloper toolbar in Firefox, and I set up an "error" page to
> redirect to if the cookie wasn't set. All that worked as intended.
>
> So, my next stupid question is...how do I get the value of the cookie
> back out to the template, if it's not the way outlined in the
> documentation...?
>
> TIA,
> Brandon
>
> On Apr 30, 3:30 pm, "Karen Tracey" <kmtra... <at> gmail.com> wrote:
>
> > On Wed, Apr 30, 2008 at 3:40 PM, Brandon Taylor <btaylordes... <at> gmail.com>
> > wrote:
>
> > > Hello everyone,
(Continue reading)

Karen Tracey | 1 May 2008 03:18
Picon
Gravatar

Re: "data" is a reserved field in newforms?

On Wed, Apr 30, 2008 at 8:39 PM, msoulier <msoulier <at> gmail.com> wrote:


A coworker of mine created a form with a field called "data".

ie. data = forms.CharField()

This resulted in an exception being thrown when is_valid() was called
on the form:

form error - 'dict' is not callable

The exception occurs at line 180 in
  <python install>\lib\site-packages\django\newforms\forms.py

in Django 0.96.

The reason is that the hasattr() call for "clean_data" returns true.

We're just considering "data" as a reserved word in newforms now, but
I wanted to check to see if this was known. If so, I'd expect an error
saying so, instead of the cryptic one that we received.

This appears to have been found and fixed, since the problem does not occur when using a fairly recent trunk level:

Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> django.get_version()
u'0.97-pre-SVN-7501'
>>> from django import newforms as forms
>>> class DataForm(forms.Form):
...     data = forms.CharField()
...
>>> df = DataForm({'data': 'x'})
>>> df.is_valid()
True

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


Gmane