Re: is_member_of method for user objects

2006-02-11 Thread Max Battcher


Roberto Aguilar wrote:

In my situation, what I wanted to do was limit the display of a bunch
of menu items depending on the group of the user.  I accomplished this
with a for loop and a test for a group:

{% for group in user.get_list %}
{% ifequal group 'desired_group' %}
[...]

It's a two-step process rather than one, but it gets the job done.

That being said, should the menu evaluation go in a view rather than
the template?  To me it sounds logical to keep the menu in the
template, but what do the more experienced django developers have to
say?


It depends on the circumstance, as most things do.  For simple cases it 
might suffice in your template code.  However, if you are doing a lot of 
logic there and you start to see more {% ... %} than HTML tags, then 
that is probably the point when you want to build a {% site_menu %} 
custom tag.


That's the key, really.  It is it "too much" logic, and that is in some 
way an aesthetic judgment.


--
--Max Battcher--
http://www.worldmaker.net/


Re: Django+Postgre+Apache+Windows

2006-02-11 Thread Tom Tobin
Okay, smack me for reading the subject line one second after hitting Send.  :-p

On 2/12/06, Tom Tobin <[EMAIL PROTECTED]> wrote:
> On 2/11/06, David S. <[EMAIL PROTECTED]> wrote:
> >
> > Sorry for the lack of details, but any guidance is appreciated.
>
> That's where I'd start — more details.  ;-)  Can you tell us, e.g.,
> what platforms the two machines are running?
>


Django+Postgre+Apache+Windows

2006-02-11 Thread David S .

I have followed the docs to the letter regarding my mod_python setup but I am
having a frustrating experience with Apache falling over.  I can not seem to
find a foothold for solving this and I thought I would ask if anyone has advice
or has seen (and fixed!) anything like this. 

The behavior is that I refresh a couple of times in a row and it just hangs
until I stop and start the server again.  No error in the log or any other info
that I can find.  It happens on 2 different machines.  I have the default 2.0
httpd.conf with the Django stuff from the docs.  

Sorry for the lack of details, but any guidance is appreciated.

Peace



Re: subclasses reverse field order

2006-02-11 Thread Kenneth Gonsalves

On Sunday 12 Feb 2006 3:38 am, you wrote:
> I have the same problem as described below. How did you solve it?

i didnt solve it - i just stopped subclassing classes where one has 
to remove fields from the original class. I only subclass where i 
have to add fields - this doesnt mess up the order


-- 
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!


Re: custom admin view for edit_inline object

2006-02-11 Thread Robert Wittams


> Okay, I get it now. Sorry, I need to read more carefully. It would save
> me a lot of time.
> 
> Colleen 

No worries, just glad someone is finding this stuff useful ;-)

Robert



Re: Is context variable 'user' automatic in templates?

2006-02-11 Thread Luke Plant

On Saturday 11 February 2006 22:00, Roberto Aguilar wrote:

> I've noticed that in certain instances, in a flatpage, for example,
> the user context variable is available in my templates.  However,
> most of the time I have to explicity provide it like when using
> render_to_response.  Is this a bug, feature, or am I just not doing
> something right?

The 'user' context variable is provided by 'DjangoContext' (more 
specifically, by one of the 'processors' that DjangoContext uses:
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext
 )

DjangoContext is used by all the generic views (including flatpage). If 
you want it in your own views, just use DjangoContext instead of 
Context, passing the 'request' object into the DjangoContext 
constructor.

Regards,

Luke

-- 
Life is complex. It has both real and imaginary components. 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: custom admin view for edit_inline object

2006-02-11 Thread Colleen Owens

On 11 Feb, 2006, at 06.55, Robert Wittams wrote:
> I do not know how to make it any clearer than that. MyBoundRelatedObject
> is a class.
>
> You do *not* need to make up a new constant like TABULAR. It is purely a
> mechanism that allows people to specify the tabular view or whatever
> without making the core system depend on the admin code.

Okay, I get it now. Sorry, I need to read more carefully. It would save
me a lot of time.

Colleen



Re: is_member_of method for user objects

2006-02-11 Thread Roberto Aguilar

In my situation, what I wanted to do was limit the display of a bunch
of menu items depending on the group of the user.  I accomplished this
with a for loop and a test for a group:

{% for group in user.get_list %}
{% ifequal group 'desired_group' %}
[...]

It's a two-step process rather than one, but it gets the job done.

That being said, should the menu evaluation go in a view rather than
the template?  To me it sounds logical to keep the menu in the
template, but what do the more experienced django developers have to
say?

Thanks!
-berto.

On 2/11/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
> On 2/11/06, Luke Skibinski Holt <[EMAIL PROTECTED]> wrote:
> >
> > > Would it be possible for me to use this function within a template
> > > {% if user.is_member_of:"blah" %}
> >
> > I think calling functions with parameters from within a template was
> > deliberately not included for security and simplicity reasons.
>
> The biggest reason for this isn't security or simplicity - it is to
> prevent view logic from slipping into the template. Django templates
> are deliberately 'simple' to prevent template writers from embedding
> view logic in the template.
>
> If a complex logical operation required is required, it must be a
> representation of some larger abstract concept. Evaluate the condition
> in the view, and pass it in to the template as a context variable.
> That way, if the logical condition describing the abstract concept
> ever changes, you don't have to modify the template - just the view
> logic that evaluates the context variable.
>
> Russ Magee %-)
>


Web Services

2006-02-11 Thread ChaosKCW

Hi

I have read the web services link and done some research but nothing
stands out.

I am interested in designing and application around the web services
model. That is I want the core backend functions as standalone in that
they can be hooked up via any front end ie XML-RPC or SOAP etc..
even hosted on a seperate server is need be.

Does anyone have any ideas on a good approach do doing this. Are there
any frameworks out there, or has anyone done anything similiar.

The following is just food for thought. Any ideas or comments welcome:

One question I am pondering is wether to allow direct acccess. So if
you write your services in pythin

def AddAccount(
def DeleteAccount(

You could call these directly

from services.account import AddAccount

def HandlePost(
  ..
  AddAccount(

but they would be available throufh say SOAP as well.

One good option may be to have a default dispatcher or object factory
which could allow the service call to be configured dymanuically.

say

def handlepost(
   AddAccount = dispatchFactory.get("AddAccount")
   AddAccout(.)

this would allow the services configured in a cfg file. They could be
local and direct, or local and access via a protocol like soap or
remote, and could be accesses via RPC or SOAP.

Another question which springs up is the handling of errors. Once you
go remote you lose exceptions (unless I am mistaken). Whats a good way
to handle errors. 

Thanks, 

S



Version 1.0 Features

2006-02-11 Thread ChaosKCW

Hi

I have looked all over the roadmap etc.. and cant find any dates on the
features.

The most important feature for me is the transaction support in the ORM
layer.

Does anyone have any ideas on the progress or timeline for this ?

Thanks,



Re: Background process?

2006-02-11 Thread hugo

>I have a repetitive background task I'd like to run in my Django
>environment, for example, once a minute.  What's the best way to do
>this?  Currently, I run a cron job that executes a Python script,
>imports the Django modules it needs, and does its work.  But this means
>configuring this cron job on every development machine and server to
>have the complete environment.

One way is to do it with a crontab entry - at least if it is a
background job that is triggered by a given time. If it is triggered by
an event, it might be better to use something like my jobcontrol
application:

https://simon.bofh.ms/cgi-bin/trac-django-projects.cgi/wiki/JobControl

Essentially it's just a way to do a fork from your django project, so
whenever you know that some event in your app needs some background
execution, you can hook it up to the jobcontrol stuff. The jobs
themselves are tracked in the database, so you can see wether they are
still running or already done. I use it for example to trigger pings to
Ping-O-Matic when adding new content to my site.

bye, Georg



Re: Background process?

2006-02-11 Thread Adrian Holovaty

On 2/11/06, Ned Batchelder <[EMAIL PROTECTED]> wrote:
> I have a repetitive background task I'd like to run in my Django
> environment, for example, once a minute.  What's the best way to do
> this?  Currently, I run a cron job that executes a Python script,
> imports the Django modules it needs, and does its work.  But this means
> configuring this cron job on every development machine and server to
> have the complete environment.
>
> Is there a good way to do this sort of thing within Django itself?  How
> have other people solved this problem?

Hey Ned,

That's exactly how I'd recommend doing it. There's no sort of event or
scheduling framework within Django itself -- we've always relied on
cron to do repetitive tasks.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Background process?

2006-02-11 Thread Ned Batchelder

I have a repetitive background task I'd like to run in my Django
environment, for example, once a minute.  What's the best way to do
this?  Currently, I run a cron job that executes a Python script,
imports the Django modules it needs, and does its work.  But this means
configuring this cron job on every development machine and server to
have the complete environment.

Is there a good way to do this sort of thing within Django itself?  How
have other people solved this problem? 

--Ned
http://nedbatchelder.com



Re: relating ManyToMany to itself

2006-02-11 Thread Russell Keith-Magee

On 2/6/06, Brice Carpentier <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I've got an Article object (what a surprise !), and was willing to
> relate it to other articles
> My initial plan was to use a ManyToMany relationship, but it doesn't
> seem to be possible (I tried specifying "self").
> I also tried to specify my ManyToMany relationship using an
> intermediary table, but this doesn't seem to be edited inline (I get a
> "bool object is not callable" error). Am I missing something ?

No - this looks like it is a bug. The recursive relationship handling
doesn't appear to be implemented for ManyToMany fields in the trunk.

This has been fixed in magic-removal, so "self" or "Article" would
both be valid for defining a recursive ManyToMany field.

However, there is a related problem - the SQL that is currently
generated for this situation is currently incorrect. I've logged this
as bug #1346 (http://code.djangoproject.com/ticket/1346)

Yours,
Russ Magee %-)


Re: displaying a foreign key in admin list and template exception

2006-02-11 Thread Robert M.
Hello, first of all big "Thank You" to Django developers!

Sorry for connecting to this thread, but I seem to have a similar problem ?

My model is as follows:

// model start
from django.core import meta

class Customer(meta.Model):
  name = meta.CharField(maxlength=20, blank=False)
  last = meta.CharField(maxlength=30, blank=False)
  addres = meta.TextField(blank=False)
  email = meta.EmailField(blank=False)
  pn = meta.CharField(maxlength=20, blank=False)
  date_connected = meta.DateField()
  payment = meta.IntegerField(blank=False, maxlength=3)
  company_name = meta.CharField(maxlength=30, blank=False)
  np = meta.CharField(maxlength=20, unique=True, blank=False)
  note = meta.TextField()

  def __repr__(self):
return self.name

  class META:
admin = meta.Admin()


class Pause(meta.Model):
  cust = meta.ForeignKey(Customer)
  when_stared = meta.DateField()
  when_ended = meta.DateField()

  def __repr__(self):
  return self.cust

  class META:
admin = meta.Admin()
// model end

I'm getting errors when adding a new Pause record. (using sqlite3 as db backend)

Error on web page (and runserver output is ending with:
"TemplateSyntaxError: Caught an exception while rendering.")

Am I doing something wrong ?

Thanks,

Robert

On 2/11/06, Andu <[EMAIL PROTECTED]> wrote:
>
> Removing to_field makes it work ok. I will investigate it more and file
> a ticket if appropiate.
> I also solved the template exception by making TEMPLATE_DEBUG=False. It
> came up that the error was the fact that __repr__ returned an int, not
> a string.
>
> Andu
>
>


--
Robert


Re: is_member_of method for user objects

2006-02-11 Thread Russell Keith-Magee

On 2/11/06, Luke Skibinski Holt <[EMAIL PROTECTED]> wrote:
>
> > Would it be possible for me to use this function within a template
> > {% if user.is_member_of:"blah" %}
>
> I think calling functions with parameters from within a template was
> deliberately not included for security and simplicity reasons.

The biggest reason for this isn't security or simplicity - it is to
prevent view logic from slipping into the template. Django templates
are deliberately 'simple' to prevent template writers from embedding
view logic in the template.

If a complex logical operation required is required, it must be a
representation of some larger abstract concept. Evaluate the condition
in the view, and pass it in to the template as a context variable.
That way, if the logical condition describing the abstract concept
ever changes, you don't have to modify the template - just the view
logic that evaluates the context variable.

Russ Magee %-)


Re: How to find the label for a value

2006-02-11 Thread Luke Plant

On Saturday 11 February 2006 10:53, PythonistL wrote:

> 
> Choice 1
> Choice2
>   
>
> It is easy to find the value( here 1 and 2) but how, in Django , can
> I find the label( here Choice 1 and Choice2) ?
> E.g. when a user chooses the first option, I need to know that the
> choosen label was Choice 1

The only piece of data that is passed back is the 'value' - this is 
standard HTML and Django doesn't do any different.  You will have to 
map the values back to choices when checking the GET/POST data. 

The clever thing to do, to obey DRY, is something like this:

view module:

CHOICES = {
1: 'Choice 1',
2: 'Choice 2',
}

view code (for creating the form):
--
context['choices'] = CHOICES.items()
# render_to_response stuff etc.


template code:
--

{% for choice in choices %}
 {{ choice.1|escape }}
{% endfor %}


view code (for parsing input):
--
try:
choice = CHOICES[request.GET['userchoice']]
except AttributeError:
# handle invalid input


Luke

-- 
Life is complex. It has both real and imaginary components. 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: displaying a foreign key in admin list and template exception

2006-02-11 Thread Luke Plant

On Friday 10 February 2006 23:28, Andu wrote:

> Now, addinga a currency works fine. Trying to add a customdata, when
> saving, yelds a template exception. I've read on this group that this
> might be because something's wrong in the model. Any ideas?

The only thing that is unusual in your model is the use of 'to_field'.  
It is possible that there is a bug in the admin when 'to_field' is 
used.  You could try changing your example to simply remove it (so that 
the default primary key is used instead), and see if that works.  
Alternatively, change the Currency model so that 'name' is the primary 
key (in which case you can still remove the to_field in CustomData).

If it does work with those changes, then it is probably a bug with 
to_field - it would be really helpful in that case if you file a 
ticket.

Thanks,

Luke

-- 
Life is complex. It has both real and imaginary components. 

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: recursive template calls

2006-02-11 Thread Robert Wittams

Shannon -jj Behrens wrote:
>>  You don't *need* recursion on templates for threaded messages like
>>your example app, that's exactly the point :)
> 
> 
> Julio, with all due respect for your programming prowess, I *like*
> recursion.  It can often make hard problems easy, even when generating
> HTML.
> 
> Anyway, I figured out how to solve the problem *using recursion*, and
> I blogged about it: 
> .
>  It works, but it's nowhere near as elegant as simply being able to
> add a function to the template that I could call recursively. :-/
> 
> Best Regards,
> -jj
> 

This is ridiculous. Something like this seems a lot easier to me...

templatetags.py:

register = template.Library()

@register.inclusion_tag('comment')
def show_comment(comment):
{'comment': comment}


comment.html:

{% load comments %}
{% comment.subject %}
{% comment.body %}
{% for child in comments.children %}
   {%show_comment child %}
{% endfor %}

page.html:

{% show_comment comment %}


The moral of the story : custom template tags aren't really an optional
bit of the framework. If you don't learn how to use at least simple_tag
and inclusion_tag, you will get annoyed quite often.

Robert



Re: custom admin view for edit_inline object

2006-02-11 Thread Robert Wittams

Colleen Owens wrote:
> On 09 Feb, 2006, at 13.21, Robert Wittams wrote:
> 


> 
> 
> I'd be happy to write this up once I get it working. The problem I'm
> having right now is that there seems to be no elegant way of updating
> the dictionary bound_related_object_overrides in admin_modify.py to let
> it know about additional view types. I can, of course, edit it directly
> in admin_modify, but this isn't very nice.
> 
> Any suggestions? All ideas I can come up with involve changing the
> admin code.
> 
> Colleen
> 
> 

As I explained before:

The overrides stuff is just to allow TABULAR and STACKED to continue to
work, without meaning that the core django has a dependency on the admin
code.
  As you are defining your own class, that shouldn't matter for you, you
can just use the class directly, eg

from path.to.custom.admin.code import MyBoundRelatedObject

class Whatever(Model):
parent = ForeignKey(edit_inline=MyBoundRelatedObject)
--
I do not know how to make it any clearer than that. MyBoundRelatedObject
is a class.

You do *not* need to make up a new constant like TABULAR. It is purely a
mechanism that allows people to specify the tabular view or whatever
without making the core system depend on the admin code.



Re: is_member_of method for user objects

2006-02-11 Thread Luke Skibinski Holt

> Would it be possible for me to use this function within a template
> {% if user.is_member_of:"blah" %}

I think calling functions with parameters from within a template was
deliberately not included for security and simplicity reasons. This
doesn't stop you from evaluating it in the view or writing a custom
tag.

{% member_of "group" %} for just requests or
{% member_of "user, group" %} for users and groups ...

it's not a very elegant solution, which makes me suspect there may be a
nicer way of doing this. what would be nice is a

{% if "groupname" in user.get_group_list %}

But my template skillz are mediocre at best ;)


Luke Skibinski Holt



Re: locale settings

2006-02-11 Thread hugo

>And those date hierarchy filters were displayed like they should be
>displayed. I mean translated. This was because date formatter uses
>strftime, which uses locale settings.

Yeah, but that only works with a single locale - many apps need
per-request locales, that's the reason why date formatting should
better use the Django datetime formatters.

>So it seems to me that Django's own datetime formatters could be
>replaced with Python's own locale module
>(http://www.python.org/doc/lib/module-locale.html), which would be good
>thing for internationalizating Django.

Actually the other way around would be much better: replace the
strftime usage by Django formatting :-)

The locale module is quite a pain in servers, because it's just one
global setting - but if you need a language switch per request, locale
won't work, because you would switch the locale for all running code at
that time - and if your server is multithreaded, you will switch the
locale of the other threads and therefore other requests.

If you find strftime usage in the code, please open a ticket (target
"internationalization") with the filename where this happens, so that
those places can be changed to the correct way. There are several ways
to do (mostly) correct date and time formatting and translating in
Django.

bye, Georg