Re: django setting problem on windows

2009-05-02 Thread Malcolm Tredinnick

On Sat, 2009-05-02 at 22:24 -0700, online wrote:
> I have mod_python set working fine with apache.
> 
> I have django setting as following at apache
> 
> 
> ServerAdmin webmas...@dummy-host2.li
> DocumentRoot "C:/depot/projects/web/"
> ServerName web
> ServerAlias *.web
> ErrorLog "logs/dummy-host2.li-error_log"
> CustomLog "logs/dummy-host2.li-access_log" common
> 
> 
> 

I'm surprised you get the error you do, because this line should pretty
much be a showstopper for having anything inside it ever being used by
an incoming request. Go back to the documentation for Apache again. You
haven't given the Location directive a URL. You've given it a directory
path.

I would also suspect you're going to need to set the PythonPath option,
based on the file paths you've mentioned here, since they won't be on
the default Python path.

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



django setting problem on windows

2009-05-02 Thread online

I have mod_python set working fine with apache.

I have django setting as following at apache


ServerAdmin webmas...@dummy-host2.li
DocumentRoot "C:/depot/projects/web/"
ServerName web
ServerAlias *.web
ErrorLog "logs/dummy-host2.li-error_log"
CustomLog "logs/dummy-host2.li-access_log" common



SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE web.settings
PythonOption django.root "C:/depot/projects/web/"
PythonDebug On


  
SetHandler None
  

  
SetHandler None
  


-

But I always got error

"ImportError: Settings cannot be imported, because environment
variable DJANGO_SETTINGS_MODULE is undefined.
"

Thanks for any help!




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



Re: passing current datetime to generic view archive_year in a decoupled url

2009-05-02 Thread Malcolm Tredinnick

On Sat, 2009-05-02 at 21:00 -0700, josebrwn wrote:
> Hi, I'm trying to pass the current year the date based view
> archive_year using the "url" template tag, and I'm stuck trying to get
> the current time to resolve.  this works just fine:
> 
> {% now
> "Y" %}
> 
> but this (as well as many variations)
> 
> {% now "Y"
> %}
> 
> gets:
> 
> NoReverseMatch: Reverse for 'cms.coltrane_entry_archive_year' with
> arguments '()' and keyword arguments '{'year': ''}' not found.
> 
> do I need to write a view for this?

It looks like you didn't pass a variable called "now" into the
template's context. So it was resolved to the empty string, as noted in
the error message.

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



passing current datetime to generic view archive_year in a decoupled url

2009-05-02 Thread josebrwn

Hi, I'm trying to pass the current year the date based view
archive_year using the "url" template tag, and I'm stuck trying to get
the current time to resolve.  this works just fine:

{% now
"Y" %}

but this (as well as many variations)

{% now "Y"
%}

gets:

NoReverseMatch: Reverse for 'cms.coltrane_entry_archive_year' with
arguments '()' and keyword arguments '{'year': ''}' not found.

do I need to write a view for this?

Thanks
Joe

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



Re: print_r() in Django & SQL debug output

2009-05-02 Thread Malcolm Tredinnick

On Sun, 2009-05-03 at 09:48 +0700, Okto Silaban wrote:
> On Sun, May 3, 2009 at 9:27 AM, Malcolm Tredinnick
>  wrote:
> 
> 
> 
> How are you rendering that template? The only thing I can
> think of that
> will go wrong here is if you do not pass a RequestContext to
> render_to_response() -- or whatever rendering method you are
> using.
> Context processors only run if the context is a
> RequestContext, not
> simply a Context object.
> 
> See this documentation (esp. the "note" callout):
> http://docs.djangoproject.com/en/dev/ref/templates/api/#id1 
> 
> Thanx.. You're right, I forgot to add this as the third parameter :
> context_instance=RequestContext(request)
> 
> And, how about my first question ? 
> 
> 1. What Django template tags can I use to replace print_r() /
> var_dump() in PHP?

There are no direct equivalents, because Django templates are at a
different level and provide different functionality to PHP files.
However, there are a few things you can do for viewing the context and
seeing things in "pretty printed" format. Here are a bunch of ideas I
wrote up recently:
http://www.pointy-stick.com/blog/2009/02/03/some-simple-django-debugging-tools/

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



Re: print_r() in Django & SQL debug output

2009-05-02 Thread Okto Silaban
On Sun, May 3, 2009 at 9:27 AM, Malcolm Tredinnick  wrote:

>
> How are you rendering that template? The only thing I can think of that
> will go wrong here is if you do not pass a RequestContext to
> render_to_response() -- or whatever rendering method you are using.
> Context processors only run if the context is a RequestContext, not
> simply a Context object.
>
> See this documentation (esp. the "note" callout):
> http://docs.djangoproject.com/en/dev/ref/templates/api/#id1
>

Thanx.. You're right, I forgot to add this as the third parameter :
context_instance=RequestContext(request)

And, how about my first question ?

1. What Django template tags can I use to replace print_r() / var_dump() in
PHP?

regards,
okto.silaban.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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: print_r() in Django & SQL debug output

2009-05-02 Thread Malcolm Tredinnick

On Sun, 2009-05-03 at 07:47 +0700, Okto Silaban wrote:
> 
> 
> On Sun, May 3, 2009 at 7:04 AM, George Song  wrote:
> 
> 
> Django has extensive documentation. It's advisable that you
> look it up
> first before asking:
> 
> 
> 
> 
> Default :
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG 
> 
> 
> And I've added this in settings.py :
> 
> TEMPLATE_CONTEXT_PROCESSORS = (
> "django.core.context_processors.auth",
> "django.core.context_processors.debug",
> "django.core.context_processors.i18n"
> )
> 
> INTERNAL_IPS = ('127.0.0.1',)
> 
> And added these lines in my template file  :
> 
> 
>   Queries
>   
> {{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }}
> {% ifnotequal sql_queries|length 0 %}
> (Show)
> {% endifnotequal %}
>   
>   
> 
> 
> 
> 
> 
>   #
>   SQL
>   Time
> 
> 
> 
> {% for query in sql_queries %}
>   {{ forloop.counter }}
>   {{ query.sql|escape }}
>   {{ query.time }}
> {% endfor %}
> 
>   
> 
> 
> This is the output : 
> Queries
> 0 Query (Show) 

How are you rendering that template? The only thing I can think of that
will go wrong here is if you do not pass a RequestContext to
render_to_response() -- or whatever rendering method you are using.
Context processors only run if the context is a RequestContext, not
simply a Context object.

See this documentation (esp. the "note" callout):
http://docs.djangoproject.com/en/dev/ref/templates/api/#id1

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



Re: Avatars in comments

2009-05-02 Thread Malcolm Tredinnick

On Sat, 2009-05-02 at 15:22 -0700, trancos123 wrote:
> [Sorry for my poor english]
> Hi
> I'm using a django.contrib.comments for my application (with django-
> profile), and i want to add the user avatar
> in every comment.
> How can i do this?
> I'm searching for a tutorial about this, but i can't find nothing.

This shouldn't be too hard. There are two pieces to the solution:
storing the data about the avatar in the database and displaying the
avatar information when you display a comment.

The basic information you need to know is in the custom comments
documentation:
http://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/#ref-contrib-comments-custom

The comment models (in django/contrib/comments/models.py) are designed
to be subclassable. So you would create a subclass of the Comment model,
adding a new field to store the avatar image (or perhaps the username at
an avatar service, if you're using something like gravatars from
Wordpress).

As far as entering and displaying comments goes, that should all work
normally if you've set things up as in the above documentation. I have a
suspicion a lot of that functionality was only fixed up in Django 1.1
and so it might not all work in Django 1.0.2. However, give it a try and
see what happens (since there are no markers in the docs saying it's
"new in Django development version"). But just be prepared -- you might
have to use the Django 1.1-beta for all that work; I'm not sure.

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



Re: Altering database object

2009-05-02 Thread Michael
On Sat, May 2, 2009 at 9:37 PM, George Song  wrote:

> I think the easiest solution for you is to write a custom method on your
> Score model:
>


You might also want to look at writing a template tag or filter. In this
case a simple filter would be:

from django import template

registry = template.Library()

@register.filter
def fr_date(value):
return DateFr(value)


and in your templates you just do a filter call like so:

{{ s.moment|fr_date }}


Simple and easy.
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/

Hope that helps,

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-users@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: Loading a filter module for all templates: possible?

2009-05-02 Thread Michael
On Sat, May 2, 2009 at 8:44 PM, Rex  wrote:

>
> I have a module called myfilters.py that contains my custom filters.
> Is there some way around putting the command "{% load myfilters %}" in
> every template I want to use a custom filter in? I tried putting the
> load command in a base template, but templates that inherit from this
> one don't appear to inherit the filters that get loaded. Is this
> correct?
>

Yes this is correct. The way the templates work is that each block is a
separate node and the context that they are rendered in is separate as well.

If you wish to add a group of filters or template tags to built ins, there
is a hook that lets you do this. django.template.add_to_builtins lets you
add a module to built in template tags and filters in every template. I
wouldn't recommend this however, because it does slow down performance a
touch, on load time and every time a tag needs to be looked at and if there
happens to be an error in the tags that you added to built ins every
template on every page will throw an error instead of just the ones you
imported that library in.

You might also want to look at context processors, they allow you to place
variables in the context that you might want on every template.

Hope that helps,

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-users@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: Altering database object

2009-05-02 Thread George Song

On 5/2/2009 6:24 PM, Vedlen wrote:
> I've got multiple tuples, and I need all the fields.
> I just need to pass all the "moment" fields from the tuples, into my
> function.
> 
> Here is what my template looks like :
> 
> 
> {{ for s in Score }}
> {{ s.moment }}{{ s.someOtherField }}
> {{ endfor }}
> 
> 
> 
> It's like I'd need to do this :
> 
> 
> {{ for s in Score }}
> {{ DateFr(s.moment) }}{{ s.someOtherField }} tr>
> {{ endfor }}
> 
> 
> but it doesn't work since you can't call functions in templates :( so
> I need to alter the "moment" fields before getting to the template
> thing, you know what I mean. It's a pretty basic task when you know
> Django pretty well though, but I don't :)

I think the easiest solution for you is to write a custom method on your 
Score model:

{{{
class Score(models.Model):
 

 def date_fr_moment(self):
 return DateFr(self.moment)
}}}

In your template, you can just access it with s.date_fr_moment.

-- 
George


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



Re: Altering database object

2009-05-02 Thread Vedlen

I've got multiple tuples, and I need all the fields.
I just need to pass all the "moment" fields from the tuples, into my
function.

Here is what my template looks like :


{{ for s in Score }}
{{ s.moment }}{{ s.someOtherField }}
{{ endfor }}



It's like I'd need to do this :


{{ for s in Score }}
{{ DateFr(s.moment) }}{{ s.someOtherField }}
{{ endfor }}


but it doesn't work since you can't call functions in templates :( so
I need to alter the "moment" fields before getting to the template
thing, you know what I mean. It's a pretty basic task when you know
Django pretty well though, but I don't :)


Thank you for your help

On May 2, 8:02 pm, Daniel Roseman 
wrote:
> On May 2, 3:39 pm, Vedlen  wrote:
>
>
>
>
>
> > Hi everybody,
>
> > I started working with Django very recently and I'm basically a PHP
> > developer so I'm pretty much confused with lots of different things
> > right now as I'm getting used to Django ;)
>
> > Here's my problem :
>
> > First off, I fetch values from my database :
> > s = Score.objects.filter(blablabla).order_by(blablabla)
>
> > but among the fields returned above there's this one field called
> > "moment" for which I need all occurences to be passed through a
> > function called "DateFr()". However I can't call a function in the
> > template, and I'm somehow not able to perform a "for ... in s" as
> > Django returns " 'Score' object is unsubscriptable "
>
> > Could anyone help me out with this?
>
> > Thank you very much :]
>
> > Vedlen
>
> I think you might need to post some more code, as the line you have
> posted has 'filter' and that always returns a queryset, but you
> somehow seem to have got a single Score instead.
>
> However, if you're sure you only need the 'moment' field and none of
> the others, you might try this:
> moments = Score.objects.filter(blablah).order_by(blahblah).values_list
> ('moment', flat=True)
> which just returns a list of all the moment fields.
> --
> 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-users@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: print_r() in Django & SQL debug output

2009-05-02 Thread Okto Silaban
On Sun, May 3, 2009 at 7:04 AM, George Song  wrote:

Django has extensive documentation. It's advisable that you look it up
> first before asking:
>
> <
> http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-debug
> >


Default :
DEBUG = True
TEMPLATE_DEBUG = DEBUG

And I've added this in settings.py :

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n"
)

INTERNAL_IPS = ('127.0.0.1',)

And added these lines in my template file  :


  Queries
  
{{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }}
{% ifnotequal sql_queries|length 0 %}
(Show)
{% endifnotequal %}
  
  





  #
  SQL
  Time



{% for query in sql_queries %}
  {{ forloop.counter }}
  {{ query.sql|escape }}
  {{ query.time }}
{% endfor %}

  


This is the output :
Queries
0 Query (Show)

Meanwhile, it does do query.. As these lines show correct DB output :


{% for item in items %}


{{item.nominal}} :

{{ item.category.name }}
 -
{{item.info}}
{% if item.location.location %}
@{{ item.location.location }}
{% endif %}
[3:53]

[x]



 {% endfor %}


regards,
Okto.silaban.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Loading a filter module for all templates: possible?

2009-05-02 Thread Rex

I have a module called myfilters.py that contains my custom filters.
Is there some way around putting the command "{% load myfilters %}" in
every template I want to use a custom filter in? I tried putting the
load command in a base template, but templates that inherit from this
one don't appear to inherit the filters that get loaded. Is this
correct?

Thanks,

Rex
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: print_r() in Django & SQL debug output

2009-05-02 Thread George Song

On 5/2/2009 4:53 PM, Okto Silaban wrote:
> Ok, I know this is not a PHP mailing list.. I just want to make the 
> question simpler.
> 
> I'm coming from CakePHP background.
> 
> 1. What Django template tags can I use to replace print_r() / var_dump() 
> in PHP?
> 2. How can I display SQL debug output?
> 
> *in cakePHP I can use debug() function to show the SQL debug. So I can 
> see what SQL query it runs
> 
> debug output example :
> 
> SELECT * FROM myapp_entry

Django has extensive documentation. It's advisable that you look it up 
first before asking:



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



print_r() in Django & SQL debug output

2009-05-02 Thread Okto Silaban
Ok, I know this is not a PHP mailing list.. I just want to make the question
simpler.

I'm coming from CakePHP background.

1. What Django template tags can I use to replace print_r() / var_dump() in
PHP?
2. How can I display SQL debug output?

*in cakePHP I can use debug() function to show the SQL debug. So I can see
what SQL query it runs

debug output example :

SELECT * FROM myapp_entry


Sorry for my English..

regards,
okto.silaban.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Avatars in comments

2009-05-02 Thread trancos123

[Sorry for my poor english]
Hi
I'm using a django.contrib.comments for my application (with django-
profile), and i want to add the user avatar
in every comment.
How can i do this?
I'm searching for a tutorial about this, but i can't find nothing.

Thanks for your help

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



Re: Help beginner again: templatetags.

2009-05-02 Thread zayatzz

Ohwell..

In the process of learning django i have this project that pretty much
does nothing.

at first i used development server to test-run it, then i installed
apache and other required stuff and moved my project into another
folder.

I set up my httpd.conf to read from the new folder and i thought it
was doing that, but apparently i had not changed my template path in
settings.py.

How stupid of me...

Lesson for all beginners - when you move your project around, make
sure you check and doublecheck your settings.py :)

Alan

On May 2, 9:28 pm, Michael Newman  wrote:
> On May 2, 2009, at 1:58 PM, zayatzz  wrote:
>
>
>
> > No matter. i figured out the cause, but now i have different how...
> > not one suitable for this thread
>
> Alan;
>
> Glad you got it figured out. It would be helpful to the people who  
> might be of will be following this thread to hear what the ultimate  
> solution was or how you got there no matter how silly it might be.  
> Also to clear up some of your comments about magic and caching, which  
> were not the case.
>
> Good to hear you got it worked out,
>
> 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-users@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
-~--~~~~--~~--~--~---



Job opening: Software Architect/Developer in Emeryville - Photo Imaging web leader

2009-05-02 Thread Mark Liebman, Pictopia

Hi, I am the founder/president of Pictopia.com, the internet's leading
"photo commerce" fulfillment provider. We help market the photography
of major media organizations directly to consumers. We have over 800
partners' photo archives including The Washington Post, The AP,
Reuters, and National Geographic. Our production capabilities include
the super-high end of fine-art/museum grade technology, materials and
techniques.

We have an opening now for an expert Python/Django developer to join
our company. If you or someone you know would be a great match, please
apply for this position. My email address is the link under my name on
our About Us page: Mark Liebman   http://pictopia.com/pub2/people.html


Company: Pictopia.com
Located in Emeryville, California
May 2, 2009

Position:  Python: Senior Development Architect/Engineer

Description:  The Senior Development Architect is the sole individual
responsible for managing and further evolving Pictopia’s software-
directed systems.  As for our photo fulfillment systems, the
operations include production, image gallery, and transaction
processing.  At the corporate level, these include internet hosting
and monitoring, search indexing, and database management, among
others. The successful candidate will be an expert in the following
standards and languages / systems:
•   Python, optimally with Django 1.x
•   Perl
•   MYSQL including table and query optimization

Additional Qualifications/requirements:
•   5 years minimum real world experience engineering web solutions for
LAMP stacks
•   PHP, Javascript, XSLT, XML
•   Strong relational DB knowledge (table optimization, query
optimization)
•   Ability to prioritize and lead multiple simultaneous projects
effectively
•   Enthusiasm for architecting and implementing solid, scalable,
extensible solutions
•   Strong verbal, written, analytical and communication skills

This position reports directly to the company’s President and is part
of Pictopia’s senior management team.  It is a CTO-track position with
the real chance for advancement as the company grows. The ideal
candidate will be a dedicated, hands on professional who is a self-
starter and proficient with managing details while keeping the big
picture in mind.  We value positive attitudes and professionals who
can successfully navigate through ambiguous and challenging
situations.

We offer an exciting and unique opportunity for the ambitious
developer who wants to play a large part in one of the net’s next e-
commerce sensations!

Compensation is comprised of both salary and equity incentives.

About the Company
Pictopia.com, located in Emeryville, California, provides highest
quality photo prints to consumers via purchases made at its own web
site and at the sites of its partners. Over 800 of the world’s top
media companies including National Geographic, The Associated Press,
Gannett, The Washington Post, AOL, and Yahoo, have partnered with
Pictopia to monetize their vast image holdings via sales to the
public.  By taking the partners image archives and feeds direct to the
public, Pictopia creates brand-promotion opportunities and revenue
streams that have not previously existed.  As an example of how we
work today, if you are browsing the Washington Post web-site and see a
picture you want to own for yourself, when you click to “buy” the
picture, it takes you to our web-site and we handle all the
transaction order and fulfillment.

We are a privately funded entrepreneurial venture which has recently
made a strategic and management restructuring.  At this new stage of
our growth, we are very excited to be advancing to the next level in
our company’s development!

Culture:  At Pictopia we have a relaxed, intimate and informal
environment.  As a growing dot com we work hard but like to have fun
doing it.  Every team member is a valuable contributor to achieving
the company’s objectives.  Our flat corporate hierarchy supports team
players, not strong egos.

Benefits: Pictopia provides many big-company benefits in a small
company setting including:
•   Medical, Dental, Vision and prescription coverage
•   Health care Flexible Spending Account
•   Employee Assistance Program (EAP)
•   Basic Life and Personal Accident Insurance
•   401K and 529 College Savings Plans
•   Professional training and development

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



Re: Help beginner again: templatetags.

2009-05-02 Thread Michael Newman


On May 2, 2009, at 1:58 PM, zayatzz  wrote:

>
> No matter. i figured out the cause, but now i have different how...
> not one suitable for this thread
>>
>>
>>
>>
>>
>>

Alan;

Glad you got it figured out. It would be helpful to the people who  
might be of will be following this thread to hear what the ultimate  
solution was or how you got there no matter how silly it might be.  
Also to clear up some of your comments about magic and caching, which  
were not the case.

Good to hear you got it worked out,

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-users@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: Help beginner again: templatetags.

2009-05-02 Thread zayatzz

Yup i was.

The problem was that somehow my httpd.conf was loading wrong project
at all... Because of i put django install directory into my httpd.conf
pythonpath line.

All fixed now. And i can report that the templatetag is fixed too.

Sorry for causing such a mess...

kinda blushing now...

Alan.

On May 2, 8:57 pm, Daniel Roseman 
wrote:
> On May 2, 6:52 pm, zayatzz  wrote:
>
>
>
> > this must be some kind of magic, cause:
>
> > The time is {% current_time "%Y-%m-%d %I:%M %p" %}.
>
> > is all what my arts.html contains now.
>
> > But i
> > 1) cleared firefox cache
> > 2) disabled caching from ff's web developer toolbar
> > 3) disabled firebug just in case
> > 4) restarted computer
>
> > and i still get the same markup plus the lorem ipsum text changes with
> > each reload. Just like it should, but i dont have lorem ipsum tag in
> > my template... HOW?
>
> > Alan
>
> Silly suggestion, but are you actually loading the 'arts.html' and not
> 'index.html' in your view?
> --
> 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-users@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: Help beginner again: templatetags.

2009-05-02 Thread zayatzz

Yup i was.

The problem was that somehow my httpd.conf was loading wrong project
at all... Because of i put django install directory into my httpd.conf
pythonpath line.

All fixed now. And i can report that the templatetag is fixed too.

Sorry for causing such a mess...

kinda blushing now...

Alan.

On May 2, 8:57 pm, Daniel Roseman 
wrote:
> On May 2, 6:52 pm, zayatzz  wrote:
>
>
>
> > this must be some kind of magic, cause:
>
> > The time is {% current_time "%Y-%m-%d %I:%M %p" %}.
>
> > is all what my arts.html contains now.
>
> > But i
> > 1) cleared firefox cache
> > 2) disabled caching from ff's web developer toolbar
> > 3) disabled firebug just in case
> > 4) restarted computer
>
> > and i still get the same markup plus the lorem ipsum text changes with
> > each reload. Just like it should, but i dont have lorem ipsum tag in
> > my template... HOW?
>
> > Alan
>
> Silly suggestion, but are you actually loading the 'arts.html' and not
> 'index.html' in your view?
> --
> 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-users@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: Create a web service for an existing stand alone python script

2009-05-02 Thread George Song

On 5/2/2009 10:01 AM, pallavi wrote:
> Dear Mr.George,
> 
> Thank a lot for your help.
> But, in the python program "science.py"  there are several  functions
> that do some calculations by reading the values in the two input
> files.
> 
> your code:
>> from science import my_function
>>
>> def science_service(request):
> 
> but how can i define and import all the modules in "my_function" as
> you said.
> Or can I directly paste the complete python code under my_function. I
> am confused as I am completely new this field.
> 
> May I request you to let me know if it is possible to make my big
> python program as an executable (science.exe or some thing) and
> directly call it in the views.py for example.
> Your help will be highly appreciated. Eagerly looking forward for your
> help.
> Thank you. Best regards -Pallavi

Hi Pallavi,

I don't have the time or the inclination to teach you Python. You should 
learn that on your own. There are excellent resources on the web to help 
you with that.

Also you should keep a group discussion thread going by replying to the 
group, not to me directly.

-- 
George

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



Re: Altering database object

2009-05-02 Thread Daniel Roseman

On May 2, 3:39 pm, Vedlen  wrote:
> Hi everybody,
>
> I started working with Django very recently and I'm basically a PHP
> developer so I'm pretty much confused with lots of different things
> right now as I'm getting used to Django ;)
>
> Here's my problem :
>
> First off, I fetch values from my database :
> s = Score.objects.filter(blablabla).order_by(blablabla)
>
> but among the fields returned above there's this one field called
> "moment" for which I need all occurences to be passed through a
> function called "DateFr()". However I can't call a function in the
> template, and I'm somehow not able to perform a "for ... in s" as
> Django returns " 'Score' object is unsubscriptable "
>
> Could anyone help me out with this?
>
> Thank you very much :]
>
> Vedlen

I think you might need to post some more code, as the line you have
posted has 'filter' and that always returns a queryset, but you
somehow seem to have got a single Score instead.

However, if you're sure you only need the 'moment' field and none of
the others, you might try this:
moments = Score.objects.filter(blablah).order_by(blahblah).values_list
('moment', flat=True)
which just returns a list of all the moment fields.
--
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-users@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: Debug middleware

2009-05-02 Thread George Song

On 5/2/2009 9:53 AM, Malcolm Tredinnick wrote:
> On Sat, 2009-05-02 at 04:11 -0700, Kless wrote:
>> How to debug a middleware? I would print any variables for a
>> middleware that I'm building
>>
>> Is there any way to make it?
> 
> In any sensible web server setup, printing to sys.stderr will send the
> output the server's error log. With Django's development server (the
> "runserver") command, it will send the output to the console that you
> started the dev server from. So use
> 
> print >> sys.stderr, ""
> 
> to your heart's content.

Or you can always use `pdb` if you're running the development server.

-- 
George

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



Re: Help beginner again: templatetags.

2009-05-02 Thread zayatzz

No matter. i figured out the cause, but now i have different how...
not one suitable for this thread though.

Alan.

On May 2, 8:52 pm, zayatzz  wrote:
> this must be some kind of magic, cause:
>
> The time is {% current_time "%Y-%m-%d %I:%M %p" %}.
>
> is all what my arts.html contains now.
>
> But i
> 1) cleared firefox cache
> 2) disabled caching from ff's web developer toolbar
> 3) disabled firebug just in case
> 4) restarted computer
>
> and i still get the same markup plus the lorem ipsum text changes with
> each reload. Just like it should, but i dont have lorem ipsum tag in
> my template... HOW?
>
> Alan
>
> On May 2, 8:34 pm, Malcolm Tredinnick 
> wrote:
>
> > On Sat, 2009-05-02 at 10:30 -0700, zayatzz wrote:
>
> > > > Start without the extends for a little while.
>
> > > I did - the outcome is still the same - stuff from index.html gets
> > > loaded.
>
> > > >I still think that is the
> > > > problem. If it isn't that, than there is a CSS or some other styling 
> > > > that is
> > > > hiding your markup. You can look and see if that is case by viewing the 
> > > > page
> > > > source and seeing if your markup is there.
>
> > > > I hope that helps,
>
> > > > Michael
>
> > > I have really simple page.
>
> > Well, it's not as simple as it could be. Given the problem you're
> > seeing, you should be doing everything possible to make things as simple
> > as possible. In this case, get rid of the Javascript lines. Remove all
> > the markup you possibly can. So that the body only contains, say, a
> > single "p" element containing a single string. Literally, get it down to
> > a hundred bytes of content so that there is no chance of anything
> > unexpected appearing.
>
> > 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help beginner again: templatetags.

2009-05-02 Thread zayatzz

No matter. i figured out the cause, but now i have different how...
not one suitable for this thread though.

Alan.

On May 2, 8:52 pm, zayatzz  wrote:
> this must be some kind of magic, cause:
>
> The time is {% current_time "%Y-%m-%d %I:%M %p" %}.
>
> is all what my arts.html contains now.
>
> But i
> 1) cleared firefox cache
> 2) disabled caching from ff's web developer toolbar
> 3) disabled firebug just in case
> 4) restarted computer
>
> and i still get the same markup plus the lorem ipsum text changes with
> each reload. Just like it should, but i dont have lorem ipsum tag in
> my template... HOW?
>
> Alan
>
> On May 2, 8:34 pm, Malcolm Tredinnick 
> wrote:
>
> > On Sat, 2009-05-02 at 10:30 -0700, zayatzz wrote:
>
> > > > Start without the extends for a little while.
>
> > > I did - the outcome is still the same - stuff from index.html gets
> > > loaded.
>
> > > >I still think that is the
> > > > problem. If it isn't that, than there is a CSS or some other styling 
> > > > that is
> > > > hiding your markup. You can look and see if that is case by viewing the 
> > > > page
> > > > source and seeing if your markup is there.
>
> > > > I hope that helps,
>
> > > > Michael
>
> > > I have really simple page.
>
> > Well, it's not as simple as it could be. Given the problem you're
> > seeing, you should be doing everything possible to make things as simple
> > as possible. In this case, get rid of the Javascript lines. Remove all
> > the markup you possibly can. So that the body only contains, say, a
> > single "p" element containing a single string. Literally, get it down to
> > a hundred bytes of content so that there is no chance of anything
> > unexpected appearing.
>
> > 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help beginner again: templatetags.

2009-05-02 Thread Daniel Roseman

On May 2, 6:52 pm, zayatzz  wrote:
> this must be some kind of magic, cause:
>
> The time is {% current_time "%Y-%m-%d %I:%M %p" %}.
>
> is all what my arts.html contains now.
>
> But i
> 1) cleared firefox cache
> 2) disabled caching from ff's web developer toolbar
> 3) disabled firebug just in case
> 4) restarted computer
>
> and i still get the same markup plus the lorem ipsum text changes with
> each reload. Just like it should, but i dont have lorem ipsum tag in
> my template... HOW?
>
> Alan
>

Silly suggestion, but are you actually loading the 'arts.html' and not
'index.html' in your view?
--
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-users@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: Help beginner again: templatetags.

2009-05-02 Thread zayatzz

this must be some kind of magic, cause:

The time is {% current_time "%Y-%m-%d %I:%M %p" %}.

is all what my arts.html contains now.

But i
1) cleared firefox cache
2) disabled caching from ff's web developer toolbar
3) disabled firebug just in case
4) restarted computer

and i still get the same markup plus the lorem ipsum text changes with
each reload. Just like it should, but i dont have lorem ipsum tag in
my template... HOW?

Alan

On May 2, 8:34 pm, Malcolm Tredinnick 
wrote:
> On Sat, 2009-05-02 at 10:30 -0700, zayatzz wrote:
>
> > > Start without the extends for a little while.
>
> > I did - the outcome is still the same - stuff from index.html gets
> > loaded.
>
> > >I still think that is the
> > > problem. If it isn't that, than there is a CSS or some other styling that 
> > > is
> > > hiding your markup. You can look and see if that is case by viewing the 
> > > page
> > > source and seeing if your markup is there.
>
> > > I hope that helps,
>
> > > Michael
>
> > I have really simple page.
>
> Well, it's not as simple as it could be. Given the problem you're
> seeing, you should be doing everything possible to make things as simple
> as possible. In this case, get rid of the Javascript lines. Remove all
> the markup you possibly can. So that the body only contains, say, a
> single "p" element containing a single string. Literally, get it down to
> a hundred bytes of content so that there is no chance of anything
> unexpected appearing.
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help beginner again: templatetags.

2009-05-02 Thread Malcolm Tredinnick

On Sat, 2009-05-02 at 10:30 -0700, zayatzz wrote:
> 
> > Start without the extends for a little while.
> 
> I did - the outcome is still the same - stuff from index.html gets
> loaded.
> 
> >I still think that is the
> > problem. If it isn't that, than there is a CSS or some other styling that is
> > hiding your markup. You can look and see if that is case by viewing the page
> > source and seeing if your markup is there.
> >
> > I hope that helps,
> >
> > Michael
> 
> I have really simple page.

Well, it's not as simple as it could be. Given the problem you're
seeing, you should be doing everything possible to make things as simple
as possible. In this case, get rid of the Javascript lines. Remove all
the markup you possibly can. So that the body only contains, say, a
single "p" element containing a single string. Literally, get it down to
a hundred bytes of content so that there is no chance of anything
unexpected appearing.

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



Re: Help beginner again: templatetags.

2009-05-02 Thread zayatzz


> Start without the extends for a little while.

I did - the outcome is still the same - stuff from index.html gets
loaded.

>I still think that is the
> problem. If it isn't that, than there is a CSS or some other styling that is
> hiding your markup. You can look and see if that is case by viewing the page
> source and seeing if your markup is there.
>
> I hope that helps,
>
> Michael

I have really simple page.



ENGRISGH
http://localhost/media/tinyMCE/
jscripts/tiny_mce/tiny_mce.js">



Change language:


ee




en



English


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.

Repudiandae facilis aliquam consequatur.

Aut minima ea neque unde cupiditate? Cum quisquam ut aliquid, sint
in hic tempora iste voluptates?





As you can see - head, body and few blocks of text. Lorem ipsum comes
from arts and rest comes from index html.

I cant understand how even commenting or outright deleting extends
line from template does absolutely nothing. Even when i run it on
development server with the extends line deleted i still get the old
page not the new one.

As you said the templates wont be cached unless its been turned on and
im too stupid to do it yet :).

So where does this problem come from? I just installed apache,
mod_python, mysql and phpmyadmin (Following the exampe :
http://www.howtoforge.com/perfect-server-ubuntu-9.04-ispconfig-2,
points 11, 14 and 17) for a first time so perhaps there are things
that should be tweaked?

Alan.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: offline population of django auth user table

2009-05-02 Thread Malcolm Tredinnick

On Sat, 2009-05-02 at 09:09 -0700, Jeff wrote:
> I'm using Django's authentication.  I would like to add several users
> through a command-line script (not through code executed via the
> website).  Something like manage.py createsuperuser but for normal
> users and not interactive.  I want to be able to put code like this in
> a script I can run offline like manage.py:
> 
> >>> from django.contrib.auth.models import User
> >>> User.objects.create_user('john', 'len...@thebeatles.com', 'johnpassword')
> 
> ...but I don't know what needs to go above that code to set up the
> environment to make it work.  I've started looking into how manage.py
> works, but I'm getting lost in Django internals.  I'd rather not
> fiddle with the database manually, since I'm not sure I know
> everything I'd need to touch to keep it consistent.
> 
> Any ideas?  How do I set up the environment of a Django app offline,
> in a simple command line script so that Users (or other parts of the
> db) can be modified without running through a web server?

There are a couple of different solutions to this problem. Ultimately,
it comes down to providing the necessary information so that Django can
use your settings to determine the database name and backend and things
like that. Here are a few possibilities:

(1) To my mind, the hackiest approach here is to call
django.core.management.setup_environ() and pass it the right things
(it's in django/core/management/__init__.py). Have a look at how Django
itself calls it in __init__.py -- it's only called in a couple of
places. I dislike what setup_environ() does to sys.path, adding in
something extra, but it's definitely the closest to what manage.py does,
since it's called as part of running manage.py.

(2) Fortunately, if you want to behave like manage.py, there's an
easier, more explicit approach. When you have "from django.conf import
settings" in your Python code, Django will use the
DJANGO_SETTINGS_MODULE environment variable to work out what module to
import. So you can set that directly in the environment before doing
anything that involves using Django itself:

import os
os.environ["DJANGO_SETTINGS_MODULE"] = "foo.bar.settings"

...
# Now do stuff involving Django, such as using the ORM


The string you assign to the environment variable here is something
importable (i.e. on the Python path). You could even use Python's
optparse module to process command line arguments and accept a
"--settings" option and use that as the thing to set.

(3) You could be Old Skool. Set the environment variable in the process
that calls your Django-using script. That means you won't need the
os.environ bit in the above fragment. I often use this when writing
little scripts. Calling them might look something like this:

DJANGO_SETTINGS_MODULE="test.settings" 
PYTHONPATH=/home/malcolm/CIA_factbook ./process_imports.py

(that's all on one line and is taken directly from my bash history). The
process_imports.py script here doesn't do anything special. It just uses
Django and whenever settings are needed, the environment variable is set
and so importing the right settings file Just Works(tm).

(4) Finally, the cleanest solution from a coding point of view is manual
configuration. This is specifically designed for using Django inside
other frameworks or larger applications. You call the configure() method
in the settings module and pass in only the settings you need:

from django.conf import settings
from django.contrib.auth import models
...

my_settings = {
   "DATABASE_ENGINE": "postgresql_psycopg2",
   "DATABASE_NAME": "secret_project",
   ...
}
settings.configure(**my_settings)

This is documented, to some extent:
http://docs.djangoproject.com/en/dev/topics/settings/#using-settings-without-setting-django-settings-module

What isn't document is which settings are needed if, for example, you're
only going to use the ORM portion, or only the template engine. That's a
been a "todo" item for about three years now. One day, it might even be
done. That being said, common-sense and a bit of experimentation goes a
long way. If you're using the ORM, you need a bunch of the
database-related settings and probably not much else. Then test and make
sure things work. Tweak appropriately.

Hopefully the above give you a few options. In my own code, both
personally and professionally, I use options (3) and (4) in different
situations. Option (3) is faster to get up and running and is pretty
clear if you have experience in Unix-like situations. Option (4) is
nicer if Django is a library being used with lots of other stuff, but
can be fiddlier to set up initially.

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 

Re: Proper way to rescue transaction after IntegrityError using postgres?

2009-05-02 Thread Malcolm Tredinnick

On Sat, 2009-05-02 at 06:57 -0700, Charlie DeTar wrote:
> Karen Tracey wrote:
> > Thing is, a side-effect of dealing with a test that raises an
> > IntegrityError, using PostgreSQL, is you need a working rollback in
> > order to recover.  So, even though you may not be interested in actually
> > testing rollback itself, you need it to work for this test to run
> > properly. You need the call to actually get processed by the database,
> > so that it will allow subsequent commands.  And to get a working
> > rollback, you need to use TransactionTestCase, not TestCase.
> 
> Thanks Karen, that makes sense, and clears things up a lot, even
> though I'm a bit surprised that the same code won't work for both
> SQLite and PostgresSQL when there is nothing fundamentally different
> happening to the data or logic in each case.
> 
> After doing some digging, I see a lot of prior discussion and tickets
> about postgres and connections after errors:
> http://code.djangoproject.com/ticket/852
> http://code.djangoproject.com/changeset/8314
> http://code.djangoproject.com/ticket/8739
> http://code.djangoproject.com/ticket/10813
> http://code.djangoproject.com/changeset/10657
> 
> I expect a lot of the difficulty might arise from the fact that
> postgres behaves differently from the other backends with regard to
> how active one must be in transaction management.  Perhaps postgres is
> doing it the right way and the other backends let you get away with
> being sloppy.

That last sentence is correct.

> 
> It seems that Django could do something like automatically issue a
> savepoint before each save operation and roll back to the savepoint if
> the save operation fails; though this may be overhead and
> automagicness that others would object to.

That problem is also the big issue. Adding overhead for error cases at
the expense of non-error cases (which are by far the majority situation)
isn't acceptable. Also, savepoints simply aren't supported in all the
versions of PostgreSQL we support (we still support 7.3).

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



Re: Debug middleware

2009-05-02 Thread Malcolm Tredinnick

On Sat, 2009-05-02 at 04:11 -0700, Kless wrote:
> How to debug a middleware? I would print any variables for a
> middleware that I'm building
> 
> Is there any way to make it?

In any sensible web server setup, printing to sys.stderr will send the
output the server's error log. With Django's development server (the
"runserver") command, it will send the output to the console that you
started the dev server from. So use

print >> sys.stderr, ""

to your heart's content.

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



Re: offline population of django auth user table

2009-05-02 Thread Carl Karsten

On Sat, May 2, 2009 at 11:09 AM, Jeff  wrote:
>
> I'm using Django's authentication.  I would like to add several users
> through a command-line script (not through code executed via the
> website).  Something like manage.py createsuperuser but for normal
> users and not interactive.  I want to be able to put code like this in
> a script I can run offline like manage.py:
>
 from django.contrib.auth.models import User
 User.objects.create_user('john', 'len...@thebeatles.com', 'johnpassword')
>
> ...but I don't know what needs to go above that code to set up the
> environment to make it work.  I've started looking into how manage.py
> works, but I'm getting lost in Django internals.  I'd rather not
> fiddle with the database manually, since I'm not sure I know
> everything I'd need to touch to keep it consistent.
>
> Any ideas?  How do I set up the environment of a Django app offline,
> in a simple command line script so that Users (or other parts of the
> db) can be modified without running through a web server?
>

Here is some code from my mygrate.py program - it should be all you
need, let me know (cc me, cuz I don't monitor this list) if you need
more.


# Create django Admin's
def mkAdmin( name, pw ):
print name, pw
user = User.objects.create_user( name.lower(), 't...@example.com', pw )
# User.objects.create_user('john', 'len...@thebeatles.com', 'johnpassword')
user.first_name=name
user.is_superuser=True
user.is_staff=True
user.date_joined=datetime.datetime.today()
user.last_login=datetime.datetime.today()
profile = UserProfile.objects.create(user=user,
datejoined=datetime.datetime(2008,1,1) )
user.save()
profile.save()

# bunch of accounts for the QA squad
# mkAdmin('user1','pass1')
# mkAdmin('user4','pass3')
mkAdmin('Carl','foo')
mkAdmin('Sheila','foo')
mkAdmin('Tim','foo')
# Create django Users
# select MemberNumber,
#   Surname, `Given name`, `Familiar Name`,
#   `Email Address`,  UserID, UserPassword, Telephone
cSql="""
  select *
from RidgeMoorJonas.Member
where UserID is not null
and MemberNumber not in (
'271', '139', '139A', '287', '0558', '0185', '0319',
'0599', '0754', '388'
 )
 and `Date Joined` is not null
limit 3000
"""
cur.execute(cSql)
# members = cur.fetchall()
# for member in  members:
for member in cur:

  print member
# for member in cur.fetchone():
  email = member['Email Address'] or "buc...@ridgemoorcc.com"
  user = User.objects.create_user( member['UserID'], email,
member['UserPassword<<>>'] )
  user.last_login=datetime.datetime(2005,1,1,0,0,0)
  user.date_joined=datetime.datetime(2005,1,1,0,0,0)
  # flip some field names around
  maps = {
'first_name':'Given name',
'given_name':'Given name',
'givenname':'Given name',
'last_name':'Surname',
'familiarname':'Familiar Name',
'postalcode':'Postal Code',
'datejoined':'Date Joined' }
  # for map in maps:
  #  member[map]=member[maps[map]]
  # now lower all the fids
  for f in member.keys():
# member[f.lower()]=member[f]
maps[f.lower()]=f

  user.first_name=member['Given name']
  user.last_name = member['Surname']
  # if user.username=='LS0696':
  ## Make Larry staff so I can assign things to him :)
  #user.is_staff=True
  #print "Larry is staff!"
  #print user.id

  print member['Date Joined']
  member['Date Joined'] = parse(member['Date Joined'])

  profile = UserProfile.objects.create(user=user,
datejoined=member['Date Joined'] )

  if member['Birthdate'] == datetime.datetime(1853, 5, 11, 0, 0):
member['Birthdate'] = datetime.datetime(1953, 5, 11, 0, 0)

  if ' ' in member['Given name']:
member['middlename']=member['Given name'].split(' ')[-1]

  for f in profile.__dict__:
if f not in ['id','misc_info','user_id',
'nicname', 'middlename', 'picture' ]:
  # print f,maps[f], member[maps[f]]
  val= member[maps[f]]
  print f,maps[f],val
  if "date" not in f and val is None: val=''
  profile.__setattr__(f,val)

  # profile.append(member)
  # profile.phone_number=member['Telephone']

  user.save()
  profile.save()


-- 
Carl K

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



offline population of django auth user table

2009-05-02 Thread Jeff

I'm using Django's authentication.  I would like to add several users
through a command-line script (not through code executed via the
website).  Something like manage.py createsuperuser but for normal
users and not interactive.  I want to be able to put code like this in
a script I can run offline like manage.py:

>>> from django.contrib.auth.models import User
>>> User.objects.create_user('john', 'len...@thebeatles.com', 'johnpassword')

...but I don't know what needs to go above that code to set up the
environment to make it work.  I've started looking into how manage.py
works, but I'm getting lost in Django internals.  I'd rather not
fiddle with the database manually, since I'm not sure I know
everything I'd need to touch to keep it consistent.

Any ideas?  How do I set up the environment of a Django app offline,
in a simple command line script so that Users (or other parts of the
db) can be modified without running through a web server?

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



Re: Recursive Model Setup in Admin - Error (null, blank = True)

2009-05-02 Thread Anthony


Well, I figured it out.   I needed to rerun they 'syncdb' command
after making my change.

Thanks for reading!


On May 2, 8:49 am, Anthony  wrote:
> On May 2, 1:32 am, Daniel Roseman 
> wrote:
>
> > On May 2, 8:48 am, Anthony  wrote:
> > > My model:
>
> > > class Bracket(models.Model):
> > >     m = models.ForeignKey(OtherModel)                                     
> > >         <- no problem with this
> > >     parent = models.ForeignKey('self', blank=True, null=True)             
> > > <- problem with this
> > >     name = models.CharField(max_length = 30)
>
> > No, you need to allow null=True on the foreign key, otherwise you
> > can't have a top-level parent bracket.
>
> I'm not sure I understand what you mean.  My recursive foreign key is
> set to 'Null=True'.  If you're referring to model 'm', that is a
> different foreign key that points to something else.  I could leave it
> off the model, but it doesn't change my problem.
>
> > --
> > 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-users@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: getting no such table error

2009-05-02 Thread George Song

On 5/2/2009 8:32 AM, tekion wrote:
> No, I ended up removing the db and recreating it via manage.py
> syncdb.  it works after this.
> 
> Next time I will log into SQL lite and check it out.
> 
> I am curious why running "manage.py syncdb" didn't work until I blow
> away the db and re-run it.

Is it possible you made model changes after the first time you ran syncdb?

-- 
George

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



Re: Recursive Model Setup in Admin - Error (null, blank = True)

2009-05-02 Thread Anthony



On May 2, 1:32 am, Daniel Roseman 
wrote:
> On May 2, 8:48 am, Anthony  wrote:
> > My model:
>
> > class Bracket(models.Model):
> >     m = models.ForeignKey(OtherModel)   
> >   <- no problem with this
> >     parent = models.ForeignKey('self', blank=True, null=True) 
> > <- problem with this
> >     name = models.CharField(max_length = 30)
>

>
> No, you need to allow null=True on the foreign key, otherwise you
> can't have a top-level parent bracket.

I'm not sure I understand what you mean.  My recursive foreign key is
set to 'Null=True'.  If you're referring to model 'm', that is a
different foreign key that points to something else.  I could leave it
off the model, but it doesn't change my problem.

> --
> 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-users@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: Help beginner again: templatetags.

2009-05-02 Thread Michael
On Sat, May 2, 2009 at 2:00 AM, zayatzz  wrote:

> This indeed is major clue that i did not think of before. But i think
> that the problem is not what you think - the arts block is in
> front.index.html.
>
> It seems i have some kind of cache problem - since when i comment out
> (or delete) lorem ipsum in arts.html -
>

I doubt it is a cache issue. Django templates don't cache without explicit
caching set up, when you make a change to a template, the page should change
(unless your browser caches it, which would require front end caching set up
in some way.


> {% extends "front/index.html" %}
>
> The lorem ipsum is still loaded into template and the lorem ipsum is
> not in from/index.html
>
> index.html cant be overwriting arts.html either because index.html
> only has
> 


Start without the extends for a little while. I still think that is the
problem. If it isn't that, than there is a CSS or some other styling that is
hiding your markup. You can look and see if that is case by viewing the page
source and seeing if your markup is there.

I hope that helps,

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-users@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: getting no such table error

2009-05-02 Thread tekion

No, I ended up removing the db and recreating it via manage.py
syncdb.  it works after this.

Next time I will log into SQL lite and check it out.

I am curious why running "manage.py syncdb" didn't work until I blow
away the db and re-run it.

On May 2, 10:56 am, George Song  wrote:
> On 5/2/2009 6:02 AM, tekion wrote:
>
> > Exception Type: OperationalError at /play_django/page/start/save/
> > Exception Value: no such table: mywiki_page_tags
>
> Did you log into SQLite and see if that table exists?
>
> --
> George
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Displaying rows as columns

2009-05-02 Thread George Song

On 5/2/2009 7:40 AM, George Song wrote:
> Pass `entries` and `schedule` as context vars to your template, and 
> you can iterate through your schedule using ordered list of entries.

There's also `django.utils.datastructures.SortedDict` so you can bypass 
the `entries` business and save yourself another query.

-- 
George

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



Altering database object

2009-05-02 Thread Vedlen

Hi everybody,

I started working with Django very recently and I'm basically a PHP
developer so I'm pretty much confused with lots of different things
right now as I'm getting used to Django ;)

Here's my problem :

First off, I fetch values from my database :
s = Score.objects.filter(blablabla).order_by(blablabla)

but among the fields returned above there's this one field called
"moment" for which I need all occurences to be passed through a
function called "DateFr()". However I can't call a function in the
template, and I'm somehow not able to perform a "for ... in s" as
Django returns " 'Score' object is unsubscriptable "

Could anyone help me out with this?

Thank you very much :]


Vedlen

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



Re: Accessing related object data in template

2009-05-02 Thread George Song

On 5/2/2009 6:07 AM, Paddy Joy wrote:
> I have a model "Car" with a related model "Car_Attribute" where I
> store instance specific details.
> 
> 
> class Car(models.Model):
> name = models.CharField(max_length=50)
> 
> class Car_Attribute(models.Model):
> car = models.ForeignKey(Car)
> key = models.CharField(max_length=50)
> data = models.TextField()
> 
> I have written a custom template filter to retrieve attributes
> 
> from django import template
> 
> register = template.Library()
> 
> @register.filter(name='car_tag_get')
> def car_tag_get(value, arg):
> try:
> return value.car_attribute_set.get(key=arg).data
> except:
> return "#CAR_ATTRIBUTE_NOT_FOUND key: %s" % arg
> car_tag_get.is_safe = False
> 
> and in my templates I use
> 
> {{ car|car_tag_get:"colour" }}
> 
> This works fine but is there an easier or more practical way?

 on 
your Car model is perhaps the way to go.

-- 
George

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



Re: getting no such table error

2009-05-02 Thread George Song

On 5/2/2009 6:02 AM, tekion wrote:
> Exception Type: OperationalError at /play_django/page/start/save/
> Exception Value: no such table: mywiki_page_tags

Did you log into SQLite and see if that table exists?

-- 
George

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



temporarily log in as another user

2009-05-02 Thread Dave Brueck

Hi all,

I would like an admin user on my site to be able to temporarily
"become" a normal user and see the site as if logged in as that normal
user. However, I also need to retain one admin-related permission
after I become the normal user.

On my site there are admin users that aren't staff or superusers from
Django's perspective - instead they are users that belong to an admin
group and, by extension, have an 'app.is_admin' permission.

To support this "login as" functionality, I created a custom
authentication backend and added it to my list in settings.py. This
backend subclasses ModelBackend so that for the most part permissions
and so forth work normally, except that authentication happens purely
based on user ID:

class LoginAsBackend(ModelBackend):
'''Special-case backend for when the admin needs to login as
another user'''
def authenticate(self, id=None, **kwargs):
try:
return User.objects.get(id=id)
except User.DoesNotExist:
return None

def has_perm(self, user, perm):
# If we authenticated this user, then they are an admin
if perm == 'app.is_admin' and user.backend ==
'app.backends.LoginAsBackend':
return True

# for other permissions, though, look them up from the usual
place
return super(LoginAsBackend, self).has_perm(user, perm)

The overridden has_perm method is supposed to allow this user to
continue to be a site admin, otherwise as soon as you become the
normal user, you're effectively logged out as an admin, which means if
you need to look at the account for multiple users you'd have to re-
login using your own credentials each time.

The problem I'm having is that the above successfully gets me logged
in as the desired user, but I lose the knowledge that I used to be an
admin - when has_perm is called, the user object does not have a
backend property.

The view to become another user looks something like this:

@permission_required('app.is_admin', login_url='/user/noperm/')
def UserLoginAs(r, id):
user = authenticate(id=id) # id is a user ID here
assert user
login(r, user)
return HttpResponseRedirect('/')

Immediately after the login() call, user.backend *does* exist and does
have the name of my custom backend, but on any subsequent requests the
user object does not have backend set (probably because in a later
request, it's a different instance of the user object or something).

All of the site admin functionality is wrapped in permission_required
calls that require the app.is_admin permission, so I just need some
way for this user to have that permission - but only for the current
session. I don't want to actually give the user that permission since
it's temporary.

Is there some better way to do all this? Or am I on the right track
but just missing a step?

I also noticed that the user's session retains knowledge of which
backend was used (req.session['_auth_user_backend']) but I couldn't
figure out a good way to make use of that via permission_required.
Maybe I need to change all uses of permission_required to a custom
decorator that does what I need? (ugh)

Thanks for any help you can give me!
-Dave

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



Re: Displaying rows as columns

2009-05-02 Thread George Song

On 5/1/2009 5:47 PM, mamco wrote:
> In attempting to get a better grasp of Django, I'm attempting a fairly
> simple timecard app.  Multiple users of a small chain of retail
> stores, where occasionally the employees jump between stores(company),
> and between projects and activities.
> 
> The interesting model is something like this:
> 
> class Timecard(models.Model):
>  employee = models.ForeignKey(Employee)
>  company = models.ForeignKey(Company)
>  project = models.ForeignKey(Project)
>  activity = models.ForeignKey(Activity)
>  start = models.DateTimeField('The start time of the shift')
>  duration = models.DecimalField('The duration of the shift in
> hours',max_digits=4, decimal_places=2)
>  notes = models.TextField('Special Notes on the shift')
> 
> I've populated it with some data from a previous system (trying to
> reproduce with Django), and I'm now trying to display a form which
> shows a week at a time given a particular start date (which for now is
> always a Sunday).
> 
> I'm trying to show
> employee, company, project  on a single line followed by the totals
> (summing the activity as its always 'default' for now) for Sun to Sat
> and a total.
> 
> So something like the following (pipes show columns for this post
> purpose only):
> J Smith | BranchA | Admin | 0.0 | 4.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0 |
> 36.5
> J Smith | BranchA | Training | 0.0 | 3.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0
> | 36.5

I always like to represent code as closely to how I think first and then 
optimize. There are probably more clever ways of achieving this, but 
this is generally how I would approach it (in pseudo code):

{{{
sd = datetime.date(start_date)
ed = datetime.date(end_date)
# Iterate to populat this, obviously
date_header = {
 datetime.date(first_day): 0,
 datetime.date(second_day): 1,
 datetime.date(third_day): 2,
 ...
 }

entries = TC.objects.range_filtered.values_list(
 'employee', 'company', 'project').order_by(...)

schedule = {}
timecards = Timecards.objects.range_filtered
for t in timecards:
 info = schedule.setdefault((t.employee, t.company, t.project), {})
 by_day = info.setdefault('by_day', [0]*len(date_header))
 i = date_header[datetime.date(t.start)]
 by_day[i] += t.duration
 info['total'] = info.get('total', 0) + t.duration
}}}

Pass `entries` and `schedule` as context vars to your template, and you 
can iterate through your schedule using ordered list of entries. You get 
the idea.

-- 
George

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



Re: Proper way to rescue transaction after IntegrityError using postgres?

2009-05-02 Thread Charlie DeTar

Karen Tracey wrote:
> Thing is, a side-effect of dealing with a test that raises an
> IntegrityError, using PostgreSQL, is you need a working rollback in
> order to recover.  So, even though you may not be interested in actually
> testing rollback itself, you need it to work for this test to run
> properly. You need the call to actually get processed by the database,
> so that it will allow subsequent commands.  And to get a working
> rollback, you need to use TransactionTestCase, not TestCase.

Thanks Karen, that makes sense, and clears things up a lot, even
though I'm a bit surprised that the same code won't work for both
SQLite and PostgresSQL when there is nothing fundamentally different
happening to the data or logic in each case.

After doing some digging, I see a lot of prior discussion and tickets
about postgres and connections after errors:
http://code.djangoproject.com/ticket/852
http://code.djangoproject.com/changeset/8314
http://code.djangoproject.com/ticket/8739
http://code.djangoproject.com/ticket/10813
http://code.djangoproject.com/changeset/10657

I expect a lot of the difficulty might arise from the fact that
postgres behaves differently from the other backends with regard to
how active one must be in transaction management.  Perhaps postgres is
doing it the right way and the other backends let you get away with
being sloppy.

It seems that Django could do something like automatically issue a
savepoint before each save operation and roll back to the savepoint if
the save operation fails; though this may be overhead and
automagicness that others would object to.  At any rate, I can now get
my tests to pass.

Thanks for the help,
Charlie
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Accessing related object data in template

2009-05-02 Thread Paddy Joy

I have a model "Car" with a related model "Car_Attribute" where I
store instance specific details.


class Car(models.Model):
name = models.CharField(max_length=50)

class Car_Attribute(models.Model):
car = models.ForeignKey(Car)
key = models.CharField(max_length=50)
data = models.TextField()

I have written a custom template filter to retrieve attributes

from django import template

register = template.Library()

@register.filter(name='car_tag_get')
def car_tag_get(value, arg):
try:
return value.car_attribute_set.get(key=arg).data
except:
return "#CAR_ATTRIBUTE_NOT_FOUND key: %s" % arg
car_tag_get.is_safe = False

and in my templates I use

{{ car|car_tag_get:"colour" }}

This works fine but is there an easier or more practical way?

Paddy


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



getting no such table error

2009-05-02 Thread tekion

Folks, I am following a tutorial.  I am getting the following error
even after I ran manage.py syncdb:

Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Documents and Settings\blank\My Documents\Scripts\play_django
\..\play_django\mywiki\views.py" in save_page
  57.   page.tags.add(tag)
File "C:\Python26\lib\site-packages\django\db\models\fields
\related.py" in add
  406. self._add_items(self.source_col_name,
self.target_col_name, *objs)
File "C:\Python26\lib\site-packages\django\db\models\fields
\related.py" in _add_items
  473. [self._pk_val] + list(new_ids))
File "C:\Python26\lib\site-packages\django\db\backends\util.py" in
execute
  19. return self.cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends
\sqlite3\base.py" in execute
  193. return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /play_django/page/start/save/
Exception Value: no such table: mywiki_page_tags

My model script:
from django.db import models

# Create your models here.
class Tag(models.Model):
name = models.CharField(max_length="20", primary_key=True)

class Page(models.Model):
name = models.CharField(max_length="20", primary_key=True)
content = models.TextField(blank=True)
tags = models.ManyToManyField(Tag)

Any thoughts.  Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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: using django 1.1 beta and having problem with cleaned_data attribute

2009-05-02 Thread tekion

Thanks again.  It works after the the second underscore.

On Apr 26, 8:18 pm, Alex Gaynor  wrote:
> On Sun, Apr 26, 2009 at 8:17 PM, tekion  wrote:
>
> > Doh!!!, I can't believe I missed that.  Thanks that work.
>
> > I ran into another issue with Page.objects.filter, namely:
> > Exception Value:
> > Cannot resolve keyword 'name_contains' into field. Choices are:
> > content, name
>
> > I used name and it works.  I am assuming the "name_contains" is
> > deprecated in Django 1.1?  Thanks.
>
> > On Apr 26, 7:39 pm, Alex Gaynor  wrote:
> > > On Sun, Apr 26, 2009 at 7:37 PM, tekion  wrote:
>
> > > > All,
> > > > I am trying to follow a tutorial,  below is the code snippet:
> > > > # Create your views here.
> > > > from play_django.mywiki.models import Page
> > > > from django.shortcuts import render_to_response
> > > > from django.http import HttpResponseRedirect
> > > > from django import forms
> > > > import markdown
>
> > > > class SearchForm(forms.Form):
> > > >        text =  forms.CharField(label="Enter Search Form")
>
> > > > def search_page(request):
> > > >        if request.method == "POST":
> > > >                f = SearchForm(request.POST)
> > > >                if  f.is_valid:
> > > >                        pages = Page.objects.filter(name_contains =
> > > > f.cleaned_data['text'])
> > > >                        return render_to_response("search.html",
> > {"form":f,
> > > > "pages":pages})
> > > >                else:
> > > >                        return render_to_response("search.html",
> > {"form":f})
> > > >        f = SearchForm()
> > > >        return render_to_response("search.html", {"form":f})
>
> > > > Below is the error:
> > > > AttributeError at /play_django/SearchPage/
>
> > > > 'SearchForm' object has no attribute 'cleaned_data'
>
> > > > Request Method:         POST
> > > > Request URL:    http://127.0.0.1:8000/play_django/SearchPage/
> > > > Exception Type:         AttributeError
> > > > Exception Value:
>
> > > > 'SearchForm' object has no attribute 'cleaned_data'
>
> > > > Exception Location:     C:\Documents and Settings\kchan\My Documents
> > > > \Scripts\play_django\..\play_django\mywiki\views.py in search_page,
> > > > line 15
> > > > Python Executable:      C:\Python26\python.exe
> > > > Python Version:         2.6.2
> > > > Python Path:    ['C:\\Documents and Settings\\kchan\\My Documents\
> > > > \Scripts\\play_django', 'C:\\WINDOWS\\system32\\python26.zip', 'C:\
> > > > \Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win',
> > > > 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\site-
> > > > packages']
> > > > Server time:    Sun, 26 Apr 2009 17:29:12 -0400
>
> > > > Any thoughts as to why it is not recognizing cleanted_data? Thanks in
> > > > advance.
>
> > > You need to call is_valid, it is a method, not a property, so that should
> > be
> > > if f.is_valid().
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> You dropped a second underscore, it should be name__contains, to use that
> lookup.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Debug middleware

2009-05-02 Thread Kless

How to debug a middleware? I would print any variables for a
middleware that I'm building

Is there any way to make 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-users@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: Displaying rows as columns

2009-05-02 Thread mamco

@George
great question.  In a very long ago php implementation of something
similar with Access as a backend, I simply queried the date range in
question, and built up an array, then walked through that while
building the html table.  It was ugly and even had some queries right
in along the tr/td tags to go look up what was budgeted for that
particular task and coloured the row accordingly for over/under
budget.  All accomplished in one big ole procedural ugly php file
without any separation of logic and content.  In another environment
with Cold Fusion and Informix as the db, a not too complex single sql
statement handled it all with case statements, and a bit of a custom
informix function/stored procedure handling the totals versus
budgeted.  In the informix implementation calls to the database were
'expensive' so attempts were made to do everything in a single sql
statement where possible.

So I'm open to what would be the sort of best practice taking
advantage of python's strengths along with a mysql db, keeping in mind
that that the db may switch to postgresql at some point (trying to
stay away from non-standard sql calls).

@Lars
I like the idea of the a function like get_week as that allows for
future needs like get_month, get_day 

if I have something like
start_date = datetime.date(2009, 5, 3)
end_date = datetime.date(2009, 5, 9)
Timecard.objects.filter(start__range=(start_date, end_date))

my question is more of the what is the best approach to take to then
display the data outlined in the original post.  I provided the model
and the specific implementation as it seems that lots of times that
information gets requested instead of the generic details.

The more I read through the documentation, the more I find very
specific functions which could make life very simple.  Having no real
experience with Python outside of following along with tutorials, I am
asking here for advice.  Is there an 'absolute beginner' section where
this would be better posted?  If I want to put the week at a time into
python structure, which structure would be recommended, should I let
the db sort the data or not bother and build the equivalent of an
multi-dimensional array, then sort it?  It wouldn't surprise me that
someone has a function already written (I've looked on djangosnippets)
which does just this which I could use as a starting point.

I do not want to change the model for this presentation requirement.
Everything else is much easier with the model in this way.  The
timecards will be subsequently be sent to a journal table, used for
billing/cost analysis.  Being able to bring up detail for a particular
day in the timecard table without the rest of the week as well has
served quite well.  The supervisor approval process will also be able
to reject a particular entry for a particular task while allowing
everything else for that pay period - the current model allows for
that (along with some other tables).  Having a whole week of time
delayed for billing would not work out for this implementation.  I
appreciate the suggestion though.  I'm also planning on pulling in a
few years worth of data which is currently stored in a very similar
format - would love to keep that process as easy as possible.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



[ANN] django-piston

2009-05-02 Thread jespern

Hi list,

For some time, I've been working on a Django-app for creating APIs.
This was specifically crafted for Bitbucket.org, but we decided early
on to make it reusable for others, since there's a lack of code in
this area.

It's been making its rounds on HN and proggit seeing it's only alpha,
but it's been well received and I feel confident enough to post it to
here.

Major features include:

* Ties into Django's internal mechanisms, so you don't have to.
* Supports OAuth out of the box (as well as Basic/Digest or custom
auth.)
* Doesn't require tying to models, allowing arbitrary resources.
* Speaks JSON, YAML, Python Pickle & XML (and HATEOAS.)
* Respects and encourages proper use of HTTP (status codes, ...)
* Has built in (optional) form validation (via Django), throttling,
etc.

Any feedback would be greatly appreciated, and hopefully the community
will find this helpful!

Get it here: http://bitbucket.org/jespern/django-piston/wiki/Home

It's also documented thoroughly with examples, tips & tricks, etc.:
http://bitbucket.org/jespern/django-piston/wiki/Documentation

To top it off, it comes bundled with an extremely simple Django app
(emulating a blog), with an API on top. It contains a README.txt
demonstrating how to speak to the API via curl (reading both
authorized and anonymous, and creating new posts.)

The API specific parts live in api/, and should give a good example of
how easy and powerful this is: 
http://bitbucket.org/jespern/django-piston/src/tip/examples/blogserver/


Jesper Noehr
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recursive Model Setup in Admin - Error (null, blank = True)

2009-05-02 Thread Daniel Roseman

On May 2, 8:48 am, Anthony  wrote:
> I'm trying to instantiate a recursive object model via the admin, but
> am getting an error.
>
> My model:
>
> class Bracket(models.Model):
>     m = models.ForeignKey(OtherModel)
>     parent = models.ForeignKey('self', blank=True, null=True)
>     name = models.CharField(max_length = 30)
>
> The error:
>
> IntegrityError at /admin/myapp/bracket/add/
>
> myapp_bracket.parent_id may not be NULL
>
> Request Method:         POST
> Request URL:    http://mysite/admin/myapp/bracket/add/
> Exception Type:         IntegrityError
> Exception Value:
>
> myapp_bracket.parent_id may not be NULL
>
> What do I need to let the admin interface allow me to enter a root
> level instance?  I was able to enter the brackets via the shell, so I
> think the model is set up properly.

No, you need to allow null=True on the foreign key, otherwise you
can't have a top-level parent bracket.
--
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-users@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: A way to specify different template code for every 6th item in a list?

2009-05-02 Thread Daniel Roseman

On May 2, 7:28 am, "Chris O'Donnell"  wrote:
> I'm using the Blueprint CSS framework and need to be able to have
> every 6th list item processed with different code than every  1st-5th.
> I guess you could do some sort of "is divisible by 6" thing, but I'm
> not sure exactly what's entailed to get the job done. New to Django,
> if you haven't noticed. Any help will be greatly appreciated.

Well, you probably want the "divisibleby" filter...

{% for item in list %}
{{ item }}
{% endfor %}
--
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-users@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
-~--~~~~--~~--~--~---



Recursive Model Setup in Admin - Error (null, blank = True)

2009-05-02 Thread Anthony

I'm trying to instantiate a recursive object model via the admin, but
am getting an error.


My model:

class Bracket(models.Model):
m = models.ForeignKey(OtherModel)
parent = models.ForeignKey('self', blank=True, null=True)
name = models.CharField(max_length = 30)


The error:

IntegrityError at /admin/myapp/bracket/add/

myapp_bracket.parent_id may not be NULL

Request Method: POST
Request URL:http://mysite/admin/myapp/bracket/add/
Exception Type: IntegrityError
Exception Value:

myapp_bracket.parent_id may not be NULL


What do I need to let the admin interface allow me to enter a root
level instance?  I was able to enter the brackets via the shell, so I
think the model is set up properly.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



A way to specify different template code for every 6th item in a list?

2009-05-02 Thread Chris O'Donnell

I'm using the Blueprint CSS framework and need to be able to have
every 6th list item processed with different code than every  1st-5th.
I guess you could do some sort of "is divisible by 6" thing, but I'm
not sure exactly what's entailed to get the job done. New to Django,
if you haven't noticed. Any help will be greatly appreciated.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Displaying rows as columns

2009-05-02 Thread Lars Stavholm

mamco wrote:
> Hi,
> In attempting to get a better grasp of Django, I'm attempting a fairly
> simple timecard app.  Multiple users of a small chain of retail
> stores, where occasionally the employees jump between stores(company),
> and between projects and activities.
> 
> The interesting model is something like this:
> 
> class Timecard(models.Model):
>  employee = models.ForeignKey(Employee)
>  company = models.ForeignKey(Company)
>  project = models.ForeignKey(Project)
>  activity = models.ForeignKey(Activity)
>  start = models.DateTimeField('The start time of the shift')
>  duration = models.DecimalField('The duration of the shift in
> hours',max_digits=4, decimal_places=2)
>  notes = models.TextField('Special Notes on the shift')
> 
> I've populated it with some data from a previous system (trying to
> reproduce with Django), and I'm now trying to display a form which, 
> shows a week at a time given a particular start date (which for now is
> always a Sunday).
> 
> I'm trying to show
> employee, company, project  on a single line followed by the totals
> (summing the activity as its always 'default' for now) for Sun to Sat
> and a total.
> 
> So something like the following (pipes show columns for this post
> purpose only):
> J Smith | BranchA | Admin | 0.0 | 4.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0 |
> 36.5
> J Smith | BranchA | Training | 0.0 | 3.5 | 8.0 | 8.0 | 8.0 | 8.0 | 0.0
> | 36.5
> 
> Being new to Python and Django, I can't seem to get a function written
> to kick this output out.  Any pointers?

I'm new to both python and django as well, but how about writing
a presentation method and mention that method in the list_display
of the admin interface, something like...

class Timecard(models.Model):
employee...
...
notes...

def get_week_result(self):
# make a result string like '0.0 4.5 8.0 8.0 ...etc.
# The 'start' field contains the weekday.
# or maybe one method for each day of the week.
return result

class TimecardAdmin(admin.ModelAdmin):
...
list_display = ('employee', ..., 'get_week_result')
...

However, the model you defined is slightly askew from your
presentation, if you want to look at a week at a time,
maybe you'd be better of defining the model/record as
being a week. Simply make things easier on yourself.

Just my 2c
/Lars Stavholm


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



Re: Help beginner again: templatetags.

2009-05-02 Thread zayatzz

> This is a major clue. Even if nothing was returned from your template tag
> the paragraph text would still show up. My bet is that you don't have a
> Block 'arts' in the "front/index.html." You will need that if you want it to
> display. 
> Seehttp://docs.djangoproject.com/en/dev/topics/templates/#template-inher...
>

This indeed is major clue that i did not think of before. But i think
that the problem is not what you think - the arts block is in
front.index.html.

It seems i have some kind of cache problem - since when i comment out
(or delete) lorem ipsum in arts.html -

{% extends "front/index.html" %}

{% block arts %}

{*% lorem 3 p %*}
{% load arts_tag %}
The time is {% current_time "%Y-%m-%d %I:%M %p" %}.
{% endblock %}

The lorem ipsum is still loaded into template and the lorem ipsum is
not in from/index.html

index.html cant be overwriting arts.html either because index.html
only has

{% block arts %}
crap!
{% endblock %}

Thank you, Malcolm for the info about debugging. I'll run searches for
django debugging and see what comes up. But since no changes that i do
in templates are hitting the browser i think the problem could be
something unrelated to the template tags.

Alan
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---