Re: Sending mass, yet personalised email newsletters using Django

2008-11-12 Thread Patrick J. Anderson

On Tue, 11 Nov 2008 00:27:06 -0800, [EMAIL PROTECTED] wrote:

> Hello Patrick,
> 
> On Nov 11, 1:53 am, "Patrick J. Anderson" <[EMAIL PROTECTED]>
> wrote:
>>
>> Some of the main requirements are:
>>
>> * Personalised HTML/text messages
>> * Manual delivery twice a week
>> * Message logging/archiving
>> * Amount of newsleter issues: ~50
>> * Amount of subscribers: 500-5000
> 
> We (as company) has created 6 different versions of Newsletter for our
> customers. They are
> all commercial, but we plan to release some non-commercial version too,
> as part of our e-commerce
> solution, djWarehouse.
> 
> What about the Newsletter, I can explain the architecture for you, so
> you would not fall into problems which had us to rewrite our Newsletter
> 6 times until we get satisfied with results.
> 
> 
> We have the following models:
>  Newsletter (name, added, sent, status (NEW, READY, SCHEDULING,
> SENDING, SENT)
>  MessageSet (name, newsletter, category, status (same as in
> newsletter))
>  Message (messageset foreign key, marker_tag, subject, from name, from
> email, format, message)
>  MessageCopy(user, messageset, message) MessageResponse(message, url,
>  count)
> 
> This newsletter is used on some of our sites, with thousands of
> subscribers. (10-20).  The logick is the following: customers
> are subscribed to some specific  categories on site. We have choice to
> send general newsletter to all customers, or customize messages by
> categories. MesageSet - a number of messages sent to specific
> category[ies]. Every newsletter can contain a few message sets. Why so
> complicated? Because we need to know what information is more
> interesting to end users. Counting the results in MessageResponse we
> find out how many customers clicked the links in one or another
> newsletter, and know what customers are more interested in - this data
> is used for next monthly newsletter from the site.
> 
> Now, the process of sending newsletter. That is one of the most
> difficult parts of the process, since the SMTP protocol and message
> daemons are not allowing to do many things, so we have to organize
> things ourself. For example, since our sites have such a large users
> base, Yahoo, Gmail, and specifically Hotmail were blocking our legal
> newsletter every time, because from a few hundreds thousands
> subscribers, a large part belongs to those online services (a few
> thousands) and those services will automatically put you in "block list"
> as soon as you try to send messages too quick.
> 
> That is why, we don't just send mails out via SMTP. The process of
> sending is the following:
>  1. When admin press "send" newsletter button, this only triggers the
> process to save data to MesageCopy.
>  2. An external program, run in 'daemon' mode, watches the table, and
> maintains the list
> of exeternal web services (Yahoo, MSN, etc). This daemon controls
> that SMTP send out rate should
> not exceed some specific amount for specific service.
> 
> So far, this architecture works out the best. We are using this 6th
> version of improved newsletter for last 1.5 years, without any problems.
> 
> I can not post the whole code here because the program is commercial,
> but... some smaller  version will be released soon. Anyway, most of
> customers need to only send mails to a few thousands customers, not a
> few hundreds thousands, so some advanced functions are just not needed
> for an average customer.
> 
> Hope that information is useful.
> 
> Best Regards.
> Alex

Thanks for your comments and tips.

I was actually thinking already about doing it with javascript by sending 
AJAX requests. I was considering some sort of cron jobs, but this would 
not be my preference. 

With sending emails via AJAX requests one consideration was to time it so 
sending messages doesn't overwhelm Apache. My solution to this would be 
to segment the list by region, since I will have that information. This 
should split the load somewhat. But I'd have to test it first to see what 
kind of burden it'll put on the server.

The other main issue is rendering and creating about 1000 or more 
messages in the database with a click of a button. This could be a 
bottleneck, but perhaps I could segment that as well.



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



Sending mass, yet personalised email newsletters using Django

2008-11-10 Thread Patrick J. Anderson

I'm in the process of writing a simple newsletter managers with a web 
interface and since I've been a Django user for the past 2 years, I 
thought of using Django for this task.

Some of the main requirements are:

* Personalised HTML/text messages
* Manual delivery twice a week
* Message logging/archiving
* Amount of newsleter issues: ~50
* Amount of subscribers: 500-5000

I was wondering about sending personalised mass mail and scaling issues, 
since I assume that each email message would need to be rendered 
separately to insert subscribers' first and last name, and other related 
information and sent using its own SMTPConnection.

Can Django handle this task reliably? If so, I'd be interested in best, 
most efficient ways of doing so from other Django users who have done it 
before.

I'd appreciate your comments, suggestions, tips and any other advice you 
might offer.


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



mod_wsgi and 500 error

2008-10-01 Thread Patrick J. Anderson

I'm running mod_wsgi, and I'm wondering if anybody else who uses mod_wsgi  
has experienced problems with Django directing requests to 500.html  
template when the server returns 500 status code.

Is there any configuration that needs to be set? When running mod_python,  
this was wroking fine.


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


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



limiting choices in admin.ModelAdmin based on request.user

2008-08-24 Thread Patrick J. Anderson

How should I limit choices for ForeignKey fields in admin.ModelAdmin 
instances based on request.user attributes, since I can't pass a request 
object to the forms.ModelForm constructor?


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



Re: Authenticated user from models.py

2008-05-23 Thread Patrick J. Anderson

On Thu, 22 May 2008 09:32:40 -0700, jonknee wrote:

> On May 21, 9:33 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
> 
>> Well, newforms-admin is being written to make the HttpRequest object
>> available as an argument to the various ModelAdmin methods, which means
>> that when you set up your own custom admin you can do pretty much
>> anything you want.
>>
>> Which will make a lot of people happy, and let them go right on
>> building workflows that don't make a lot of sense (if somebody's a
>> trusted administrator, how come you don't trust them to fill in a field
>> properly?).
>>
>>
> I agree with you in theory, but it has some merit in practice. If you
> have a lot of admins (let's say 20+), selecting through a large list of
> users is time consuming and error prone. I'm OK with writing custom
> views for edge cases though.
> 
Agree in theory as well, but practice is almost always different. No 
bigger client will agree with "they're trusted" argument, none of my 
clients do, and I end up creating separate, custom-built admin interfaces 
for this group and that group of users.

Admin is just a contrib app, made for a specific use-case, so I'm not 
complaining, and I understand the MVC separation of concerns, but I 
secretly wish that there was a straightforward, optimized and documented 
way of dealing with this very common need for a model instance to know 
who's messing with it. This probably doesn't belong in the model, but for 
now, I'll stick with threadlocals.get_current_user() until I take a 
closer look at using newforms-admin.


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



Re: Authenticated user from models.py

2008-05-21 Thread Patrick J. Anderson

On Wed, 21 May 2008 20:33:35 -0500, James Bennett wrote:

> On Wed, May 21, 2008 at 8:23 PM, Patrick J. Anderson
> <[EMAIL PROTECTED]> wrote:
>> Passing a Request object should work in application views, but what if
>> one wants to capture that information on every save() call, including
>> in the admin?
>>
>> What would be an elegant and beautiful approach to solving this
>> problem?
> 
> Well, newforms-admin is being written to make the HttpRequest object
> available as an argument to the various ModelAdmin methods, which means
> that when you set up your own custom admin you can do pretty much
> anything you want.
> 
> Which will make a lot of people happy, and let them go right on building
> workflows that don't make a lot of sense (if somebody's a trusted
> administrator, how come you don't trust them to fill in a field
> properly?).

This is probably not an example of how to do this, but it saves me time 
since I only have to do it once and in a single place on Model instance 
save(). 

I use admin, but my clients want many pseudo-admin interfaces for various 
reasons and various levels of trust.

So for example, in my models I have been doing something similar to this:

class Item(models.Model):
...
creator = models.ForeignKey(User, 
related_name = 'items_created',
editable = False)
time_created = models.DateTimeField(editable = False)
editor = models.ForeignKey(User,
related_name = 'items_modified',
editable = False)
time_modified = models.DateTimeField(editable = False)

def save(self):
user,now = threadlocals.get_current_user(),datetime.now()
if not self.id:
self.creator, self.time_created = user, now
self.editor, self.time_modified = user, now
super(Item, self).save()

I know that probably I should have a Log model somewhere for all this 
stuff, but this is simple enough for me and works.

I'm glad that there'll be a way to do stuff like this. In the meantime, 
I'm always ready to learn something new and better.


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



Re: Authenticated user from models.py

2008-05-21 Thread Patrick J. Anderson

On Wed, 21 May 2008 19:46:20 -0500, James Bennett wrote:

> On Wed, May 21, 2008 at 7:35 PM, Juanjo Conti <[EMAIL PROTECTED]> wrote:
>> Ugly. Is this the only way?
> 
> Sigh.
> 
> No, "ugly" is magical global variables and things that appear out of
> thin air.
> 
> Code that's clean and understandable, where you can clearly see where
> everything comes from and what it's doing, is beautiful.

Passing a Request object should work in application views, but what if 
one wants to capture that information on every save() call, including in 
the admin?

What would be an elegant and beautiful approach to solving this problem?


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



Re: TypeError on forms.ChoiceField

2008-01-30 Thread Patrick J. Anderson

On Wed, 30 Jan 2008 10:30:04 +0200, Eren T�rkay wrote:

> On 30 Jan 2008 Wed 05:49:28 Patrick J. Anderson wrote:
>> How can I inject a subset of related photoalbums into this form?
> 
> I don't know much about iteration of models, but in traditional ways,
> you can create "choices" tuple from "PhotoAlbum" instance.
> 
> 
I was trying to do that using choices = PhotoAlbum.objects.all()


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



TypeError on forms.ChoiceField

2008-01-29 Thread Patrick J. Anderson

I'm using newforms and ModelForm and I'm getting a TypeError on the 
following code:

class PhotographForm(forms.ModelForm):
album = forms.ChoiceField(choices = PhotoAlbum.objects.all())
class Meta:
model = Photograph


The error message states: "'PhotoAlbum' object is not iterable" 

I had previously thought and Django documentation states that a Queryset 
was an iterable.

The debugging information shows this:

attrs   {'id': u'id_album'}
choices ()
final_attrs {'id': u'id_album', 'name': 'album'}
name 'album'
output [u'']
self 
str_value u'1'
value 1

How can I inject a subset of related photoalbums into this form?



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



newforms SelectDateWidget preventing errors

2007-09-11 Thread Patrick J. Anderson

Hi, I know that this might not belong in the framework, but since this
widget is part of the newforms, I thought I could ask this.

I was wondering if this widget could be modified so that when rendering
an unbound form, the initial values for month, day and year could be
set, as to force the users to choose the appropriate date and prevent
common errors where (because date was not manually set) it is set to a
valid 'January 1, '.

Perhaps there could an optional parameter added that would instruct the
widget to render itself in such as way that the user is forced to select
the month, data and year.

Just a small improvement to that I think could help avoid some common
omissions when processing the form.


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



How could/should I save subsequent objects when I save an object?

2007-02-23 Thread Patrick J. Anderson

I'm trying to come up with the best working solution to allow my
application to save subsequent objects when I save an object. Here's my
model:


class Milestone(models.Model):
"""Catalogue of project milestones"""
...
deadline = models.DateField()
...

def save(self):
user = threadlocals.get_current_user()
posted = threadlocals.get_post_data()

if self.id:
   if posted.has_key('shift_in_future') and posted['shift_in_future'] 
== 'on':
   oDeadline = 
datetime.date(*time.strptime(posted['original_deadline'], '%Y-%m-%d')[:3])
   nDeadline = datetime.date(*time.strptime(posted['deadline'], 
'%Y-%m-%d')[:3])
   interval = timedelta(nDeadline - oDeadline)

future_milestones = Milestone.objects.filter(deadline__gte = 
oDeadline)
for f in future_milestones:
f.deadline = f.deadline + interval
super(Milestone, f).save()

self.editor = user
super(Milestone, self).save()


# threadlocals.py middleware
try:
from threading import local
except ImportError:
from django.utils._threading_local import local

_thread_locals = local()

def get_current_user():
return getattr(_thread_locals, 'user', None)

def get_post_data():
return getattr(_thread_locals, 'POST', None)

class ThreadLocals(object):
"""Middleware that gets various objects from the
request object and saves them in thread local storage."""
def process_request(self, request):
_thread_locals.user = getattr(request, 'user', None)
_thread_locals.POST = getattr(request, 'POST', None)



Well, it doesn't work, and I'm not sure if this is the best way to do
this. Any ideas from those who would know more and how to achieve this?


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



Re: plotting queryset objects into a calendar

2007-02-12 Thread Patrick J. Anderson

On Mon, 12 Feb 2007 17:54:55 +, Patrick J. Anderson wrote:

> On Mon, 12 Feb 2007 13:06:19 +0000, Patrick J. Anderson wrote:
> 
>> I want to plot my milestones into a 28-week calendar using Django. What
>> would be the best approach to doing that?
>> 
>> I have the following code:
>> 
>> 
>> [dashboardcalendar.py (custom template tag)]
>> 
>> from datetime import datetime, timedelta
>> from django.template import Library,Node
>> 
>> register = Library()
>> 
>> 
>> def plot_calendar(context):
>> """
>> Plot milestones into an XHTML calendar
>> 
>> Calendar starts today and ends at the end of day range defined by days 
>> (default = 28)
>> """
>> 
>> week = [datetime.today() + timedelta(days = n) for n in range(7)]
>> week_days = [d.strftime("%A") for d in week]
>> 
>> # calendar_milestones is a list of Milestone model objects
>> # with date_close (date) attribute
>> 
>> if context.has_key('calendar_milestones'):
>> milestones = context['calendar_milestones']
>> else:
>> milestones = None
>> 
>> if not context.has_key('weeks'):
>> days = int(context['weeks']) * 7
>> else:
>> days = 28
>> 
>> dates = []
>> 
>> for n in range(days):
>> date = datetime.today() + timedelta(days=n)
>> dates.append(date)
>>
>> return {
>> 'week_days': week_days,
>> 'calendar_days': dates,
>> 'calendar_milestones': milestones,
>> }
>> 
>> register.inclusion_tag('dashboard/widgets/calendar.html', 
>>takes_context = True)(plot_calendar)
>> 
>> 
>> 
>> and my template:
>> 
>> [dashboard/widget/calendar.html (customfilters: isSunday, isFirstofMonth,
>> isOverdue)]
>> 
>> {% load customfilters %}
>> 
>> {% if week_days %}
>> 
>> > class="calendar">
>> Milestones due in the next 4 weeks
>> 
>> 
>> {% for w in week_days %}
>> {{ w }}
>> {% endfor %}   
>> 
>> 
>> 
>> 
>> {% if calendar_days %}
>>  {% for d in calendar_days %}
>>  {% if forloop.counter0|divisibleby:7 %}
>>  {% if not forloop.first %}{% endif %}
>>  {% if not forloop.last %}{% endif %}
>>  {% endif %}
>>  {% if forloop.first %}
>>  
>>  TODAY
>>  
>>  
>>  {% else %}
>>  {% if d|isSunday %}{% else %}{% endif %}
>>  {% if d|isFirstOfMonth %}> class="black">{{ d|date:"j N" }}{% else %}{{ d|date:"j" }}{% endif 
>> %}
>>  
>>  
>>  {% endif %}
>>  
>>  
>>  {% endfor %}
>> {% else %}
>>  
>>  
>>  Can't create calendar cells because 
>> I don't know the day range
>>  
>>  
>> {% endif %}
>> 
>> 
>> 
>> {% endif %}
>> 
>> 
>> {% if calendar_milestones %}
>>  
>>  {% for m in calendar_milestones %}
>>  {% if m.date_close|isOverdue %}{% else %}{% 
>> endif %}
>>  {{ m.date_close|date:"j F" }} | {{ m.name }} ({{ m.project.name 
>> }})
>>  {% endfor %}
>>  
>> {% endif %}
>> 
>> 
>> 
> Can someone look at this code and tell me if I'm on the right track here?
> 
> This is a part of my modified version of my dashboardcalendar.py inclusion
> tag I posted before, where I want to create a 2-dimensional list where
> each item contains a datetime object and possibly a list of milestones due
> on that date, which come from a Milestone queryset?
> 
> 
> # create list of datetime objects in range(days)
> 
> dates = []
> [dates.append(datetime.today() + timedelta(days=n)) for n in
> range(days)]
> 
> # create a 2-dimensional list of objects # containing a datetime
> object and any related milestones 
> 
> calendar_date_data = [] for k, v in enumerate(dates):
> d = []
> d.append(v)
> [d

Re: plotting queryset objects into a calendar

2007-02-12 Thread Patrick J. Anderson

On Mon, 12 Feb 2007 13:06:19 +, Patrick J. Anderson wrote:

> I want to plot my milestones into a 28-week calendar using Django. What
> would be the best approach to doing that?
> 
> I have the following code:
> 
> 
> [dashboardcalendar.py (custom template tag)]
> 
> from datetime import datetime, timedelta
> from django.template import Library,Node
> 
> register = Library()
> 
> 
> def plot_calendar(context):
> """
> Plot milestones into an XHTML calendar
> 
> Calendar starts today and ends at the end of day range defined by days 
> (default = 28)
> """
> 
> week = [datetime.today() + timedelta(days = n) for n in range(7)]
> week_days = [d.strftime("%A") for d in week]
> 
> # calendar_milestones is a list of Milestone model objects
> # with date_close (date) attribute
> 
> if context.has_key('calendar_milestones'):
> milestones = context['calendar_milestones']
> else:
> milestones = None
> 
> if not context.has_key('weeks'):
> days = int(context['weeks']) * 7
> else:
> days = 28
> 
> dates = []
> 
> for n in range(days):
> date = datetime.today() + timedelta(days=n)
> dates.append(date)
>
> return {
> 'week_days': week_days,
> 'calendar_days': dates,
> 'calendar_milestones': milestones,
> }
> 
> register.inclusion_tag('dashboard/widgets/calendar.html', 
>takes_context = True)(plot_calendar)
> 
> 
> 
> and my template:
> 
> [dashboard/widget/calendar.html (customfilters: isSunday, isFirstofMonth,
> isOverdue)]
> 
> {% load customfilters %}
> 
> {% if week_days %}
> 
>  class="calendar">
> Milestones due in the next 4 weeks
> 
> 
> {% for w in week_days %}
> {{ w }}
> {% endfor %}   
> 
> 
> 
> 
> {% if calendar_days %}
>   {% for d in calendar_days %}
>   {% if forloop.counter0|divisibleby:7 %}
>   {% if not forloop.first %}{% endif %}
>   {% if not forloop.last %}{% endif %}
>   {% endif %}
>   {% if forloop.first %}
>   
>   TODAY
>   
>   
>   {% else %}
>   {% if d|isSunday %}{% else %}{% endif %}
>   {% if d|isFirstOfMonth %} class="black">{{ d|date:"j N" }}{% else %}{{ d|date:"j" }}{% endif %}
>   
>   
>   {% endif %}
>   
>   
>   {% endfor %}
> {% else %}
>   
>   
>   Can't create calendar cells because 
> I don't know the day range
>   
>   
> {% endif %}
> 
> 
> 
> {% endif %}
> 
> 
> {% if calendar_milestones %}
>   
>   {% for m in calendar_milestones %}
>   {% if m.date_close|isOverdue %}{% else %}{% 
> endif %}
>   {{ m.date_close|date:"j F" }} | {{ m.name }} ({{ m.project.name 
> }})
>   {% endfor %}
>   
> {% endif %}
> 
> 
> 
Can someone look at this code and tell me if I'm on the right track here?

This is a part of my modified version of my dashboardcalendar.py inclusion
tag I posted before, where I want to create a 2-dimensional list where
each item contains a datetime object and possibly a list of milestones due
on that date, which come from a Milestone queryset?


# create list of datetime objects in range(days)

dates = []
[dates.append(datetime.today() + timedelta(days=n)) for n in
range(days)]

# create a 2-dimensional list of objects # containing a datetime
object and any related milestones 

calendar_date_data = [] for k, v in enumerate(dates):
d = []
d.append(v)
[d.append(m) for m in milestones if m.date_close == v.isoformat()]
calendar_date_data.append(d)

return {
...
'calendar_days': calendar_date_data,
...
}


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



plotting queryset objects into a calendar

2007-02-12 Thread Patrick J. Anderson

I want to plot my milestones into a 28-week calendar using Django. What
would be the best approach to doing that?

I have the following code:


[dashboardcalendar.py (custom template tag)]

from datetime import datetime, timedelta
from django.template import Library,Node

register = Library()


def plot_calendar(context):
"""
Plot milestones into an XHTML calendar

Calendar starts today and ends at the end of day range defined by days 
(default = 28)
"""

week = [datetime.today() + timedelta(days = n) for n in range(7)]
week_days = [d.strftime("%A") for d in week]

# calendar_milestones is a list of Milestone model objects
# with date_close (date) attribute

if context.has_key('calendar_milestones'):
milestones = context['calendar_milestones']
else:
milestones = None

if not context.has_key('weeks'):
days = int(context['weeks']) * 7
else:
days = 28

dates = []

for n in range(days):
date = datetime.today() + timedelta(days=n)
dates.append(date)
   
return {
'week_days': week_days,
'calendar_days': dates,
'calendar_milestones': milestones,
}

register.inclusion_tag('dashboard/widgets/calendar.html', 
   takes_context = True)(plot_calendar)



and my template:

[dashboard/widget/calendar.html (customfilters: isSunday, isFirstofMonth,
isOverdue)]

{% load customfilters %}

{% if week_days %}


Milestones due in the next 4 weeks


{% for w in week_days %}
{{ w }}
{% endfor %}   




{% if calendar_days %}
{% for d in calendar_days %}
{% if forloop.counter0|divisibleby:7 %}
{% if not forloop.first %}{% endif %}
{% if not forloop.last %}{% endif %}
{% endif %}
{% if forloop.first %}

TODAY


{% else %}
{% if d|isSunday %}{% else %}{% endif %}
{% if d|isFirstOfMonth %}{{ d|date:"j N" }}{% else %}{{ d|date:"j" }}{% endif %}


{% endif %}


{% endfor %}
{% else %}


Can't create calendar cells because 
I don't know the day range


{% endif %}



{% endif %}


{% if calendar_milestones %}

{% for m in calendar_milestones %}
{% if m.date_close|isOverdue %}{% else %}{% 
endif %}
{{ m.date_close|date:"j F" }} | {{ m.name }} ({{ m.project.name 
}})
{% endfor %}

{% endif %}


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



Re: date template filter + ifequal weirdness?

2007-02-12 Thread Patrick J. Anderson

On Mon, 12 Feb 2007 05:50:32 +, Patrick J. Anderson wrote:

> On Mon, 12 Feb 2007 15:32:07 +1100, Malcolm Tredinnick wrote:
> 
>> On Mon, 2007-02-12 at 03:49 +0000, Patrick J. Anderson wrote:
>>> I think I might be missing something, but I have a problem with
>>> date filter. Why doesn't this template code work?
>>> 
>>> {% ifequal d|date:"l" "Sunday" %}
>>> 
>>> {% else %}
>>> 
>>> {% endifequal %}
>>> 
>>> {{ d|date:"l" }}
>>> 
>>> But inside the HTML list item {{ d|date:"l" }} produces full weekday
>>> names. 
>> 
>> The Django resolver for template tags is a bit simple-minded about what
>> you can pass as arguments: basically either string literals or
>> references to variables in the template's context are permitted. What it
>> cannot do is taken something that is a context variable modified by a
>> filter and work out that value. So Django is failing quietly on the
>> first argument there and effectively comparing the empty string to the
>> string "Sunday", I suspect.
>> 
>>> Can and should this evaluation be done in such a way, or perhaps
>>> there's a better way or no way this can be done using Django templates?
>> 
>> Assuming this is related to your post from a few hours ago about
>> determining if it is the first day of the week, I cannot really think of
>> any way to do it with the default filters and template tags. A couple of
>> possibilities that spring to mind:
>> 
>> (1) If your object had a "is first day of the week" method, you could
>> call that. I realise in this case you are probably passing in standard
>> Python datetime objects, in which case you are stuck, but maybe "d" is
>> something custom that you have control over and create a method that
>> returns a boolean.
>> 
>> (2) Write a custom template tag that tests if the date is the first day
>> of the week (or equal to another date). It isn't too hard to write
>> custom tags and it really is the recommended way for any kind of
>> advanced functionality you want to make accessible through the template.
>> You could pass the "d" variable and the day of the week to the tag and
>> have it act like an if tag if the args were equal (copying the default
>> "if" tag from django/templates/defaulttags.py as a starting point is one
>> way to start here).
>> 
>> Regards,
>> Malcolm
>> 
>> 
>> 
>> 
> Thanks, Malcolm. I see. I didn't know that a Django tag couldn't take a
> variable modified by a filter. Thanks for explaining that part. I'll try
> to come up with a custom template tag by looking at the docs and Django
> built-in tags in the file you mentioned.
> 
> Yes the posts were related, as I'm trying to plot an HTML 28-day calendar
> with objects coming from a queryset. It's a little bit challenging with
> Python and Django templating, but I'm determined to find a good solution
> without resorting to PHP-style mixing of programming logic with
> presentation.
> 
> Right now, I can easily create that calendar with dates using a custom tag
> I write, but the trick is to properly associate events coming from my
> model with the dates coming from context in my template tag.
> 
> Below is the code I wrote so far (inclusion tag and corresponding calendar
> template):
> 
> [file:dashboardcalendar.py]
> 
> from datetime import datetime, timedelta
> from django.template import Library,Node
> 
> register = Library()
> 
> 
> def plot_calendar(context):
> """
> Plot milestones into an XHTML calendar
> 
> Calendar starts today and ends at the end of day range defined by days 
> (default = 28)
> """
> 
> week = [datetime.today() + timedelta(days = n) for n in range(7)]
> week_days = [d.strftime("%A") for d in week]
> 
> if context.has_key('calendar_milestones'):
> milestones = context['calendar_milestones']
> else:
> milestones = None
> 
> if not context.has_key('weeks'):
> days = int(context['weeks']) * 7
> else:
> days = 28
> 
> dates = []
> 
> for n in range(days):
> date = datetime.today() + timedelta(days=n)
> dates.append(date)
>
> return {
> 'week_days': week_days,
> 'calendar_days': dates,
> 'calendar_milestones': milestones,
> }
> 
> register.inclusion_tag('dashboard/widgets/calendar

Re: date template filter + ifequal weirdness?

2007-02-11 Thread Patrick J. Anderson

On Mon, 12 Feb 2007 15:32:07 +1100, Malcolm Tredinnick wrote:

> On Mon, 2007-02-12 at 03:49 +0000, Patrick J. Anderson wrote:
>> I think I might be missing something, but I have a problem with
>> date filter. Why doesn't this template code work?
>> 
>> {% ifequal d|date:"l" "Sunday" %}
>>  
>> {% else %}
>>  
>> {% endifequal %}
>> 
>> {{ d|date:"l" }}
>> 
>> But inside the HTML list item {{ d|date:"l" }} produces full weekday
>> names. 
> 
> The Django resolver for template tags is a bit simple-minded about what
> you can pass as arguments: basically either string literals or
> references to variables in the template's context are permitted. What it
> cannot do is taken something that is a context variable modified by a
> filter and work out that value. So Django is failing quietly on the
> first argument there and effectively comparing the empty string to the
> string "Sunday", I suspect.
> 
>> Can and should this evaluation be done in such a way, or perhaps
>> there's a better way or no way this can be done using Django templates?
> 
> Assuming this is related to your post from a few hours ago about
> determining if it is the first day of the week, I cannot really think of
> any way to do it with the default filters and template tags. A couple of
> possibilities that spring to mind:
> 
> (1) If your object had a "is first day of the week" method, you could
> call that. I realise in this case you are probably passing in standard
> Python datetime objects, in which case you are stuck, but maybe "d" is
> something custom that you have control over and create a method that
> returns a boolean.
> 
> (2) Write a custom template tag that tests if the date is the first day
> of the week (or equal to another date). It isn't too hard to write
> custom tags and it really is the recommended way for any kind of
> advanced functionality you want to make accessible through the template.
> You could pass the "d" variable and the day of the week to the tag and
> have it act like an if tag if the args were equal (copying the default
> "if" tag from django/templates/defaulttags.py as a starting point is one
> way to start here).
> 
> Regards,
> Malcolm
> 
> 
> 
> 
Thanks, Malcolm. I see. I didn't know that a Django tag couldn't take a
variable modified by a filter. Thanks for explaining that part. I'll try
to come up with a custom template tag by looking at the docs and Django
built-in tags in the file you mentioned.

Yes the posts were related, as I'm trying to plot an HTML 28-day calendar
with objects coming from a queryset. It's a little bit challenging with
Python and Django templating, but I'm determined to find a good solution
without resorting to PHP-style mixing of programming logic with
presentation.

Right now, I can easily create that calendar with dates using a custom tag
I write, but the trick is to properly associate events coming from my
model with the dates coming from context in my template tag.

Below is the code I wrote so far (inclusion tag and corresponding calendar
template):

[file:dashboardcalendar.py]

from datetime import datetime, timedelta
from django.template import Library,Node

register = Library()


def plot_calendar(context):
"""
Plot milestones into an XHTML calendar

Calendar starts today and ends at the end of day range defined by days 
(default = 28)
"""

week = [datetime.today() + timedelta(days = n) for n in range(7)]
week_days = [d.strftime("%A") for d in week]

if context.has_key('calendar_milestones'):
milestones = context['calendar_milestones']
else:
milestones = None

if not context.has_key('weeks'):
days = int(context['weeks']) * 7
else:
days = 28

dates = []

for n in range(days):
date = datetime.today() + timedelta(days=n)
dates.append(date)
   
return {
'week_days': week_days,
'calendar_days': dates,
'calendar_milestones': milestones,
}

register.inclusion_tag('dashboard/widgets/calendar.html', 
   takes_context = True)(plot_calendar)



[file: calendar.html]
{% if week_days %}


Milestones due in the next 4 weeks


{% for w in week_days %}
{{ w }}
{% endfor %}   




{% if calendar_days %}
{% for d in calendar_days %}
{% if forloop.counter0|divisibleby:7 %}
{% if not forloop.first %}{% endif %}
{% if not forloop.last %}{% endif %}
{% endif %}
 

date template filter + ifequal weirdness?

2007-02-11 Thread Patrick J. Anderson

I think I might be missing something, but I have a problem with
date filter. Why doesn't this template code work?

{% ifequal d|date:"l" "Sunday" %}

{% else %}

{% endifequal %}

{{ d|date:"l" }}

But inside the HTML list item {{ d|date:"l" }} produces full weekday
names. Can and should this evaluation be done in such a way, or perhaps
there's a better way or no way this can be done using Django templates?

Thanks for any help in solving this. 
Patrick Anderson


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



compare date string in template

2007-02-11 Thread Patrick J. Anderson

Hi, I'm building a calendar for my site and in my template I
need to evaluate whether the day is the first of the month. But I cannot
do this, or it doesn't work as I expected:

{% if equal "1" day|date:"j" %}do something{% endifequal %}

or {% if equal "01" day|date:"d" %}do something{% endifequal %}

How can I find whether a day is the first of the month within my template?
Thanks for any clues.


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



Context-sensitive 'upload_to' parameter for FileField

2007-01-19 Thread Patrick J. Anderson


Hi, I was wondering if it is possible, and if so then how, to have a
context-sensitive 'upload_to' parameter set for FileField.

Let's say, I have the following model concept:

class MyModel(models.Model):
folder = models.CharField(maxlength = 8)
file_html = models.FileField(upload_to = '%s/html' % x)
file_pdf = models.FielField(upload_to = '%s/pdf' % x)


How could I set the 'x' variable to be the same as 'folder' before the
object is saved?


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



Re: Internationalization problem in template system

2007-01-18 Thread Patrick J. Anderson


On Thu, 11 Jan 2007 16:58:34 -0600, Jacob Kaplan-Moss wrote:


On 1/11/07 2:35 PM, Nuno Mariz wrote:
Any idea to resolve this , this don't scale. If I what to add another 
language, I have to patch all of my templates.


If I were you, I'd write a simple accessor on your model to get the current 
translation.  Off the top of my head, you could do something like::


from django.utils import translation

class MyModel(Model):
text_pt = TextField()
text_en = TextField()

def get_text(self):
text_field = "text_%s" % translation.get_language()
return getattr(self, text_field)

Then in a template you can just do::

{{ myobject.get_text }}

Jacob



This solution seems simple, but there's a problem when you put something
like this in your model:

class MyModel(models.Model):
text_en = TextField()
text_pt-br = TextField()

Django complains with a SyntaxError: can't assign to operator on
"text_pt-br = TextField()" line

This just what I did in my models, but perhaps there's a clean way to go
about doing it right.


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



Re: Portuguese (pt) request.LANGUAGE_CODE problem

2007-01-17 Thread Patrick J. Anderson


On Wed, 17 Jan 2007 17:27:05 +, Nuno Mariz wrote:


Hi,
I'm portuguese and I'm going to translate django to pt-pt in this
month. Stay tune.

Nuno Mariz




That'd be great! Looking forward to it being included in the framework!


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



Re: Portuguese (pt) request.LANGUAGE_CODE problem

2007-01-16 Thread Patrick J. Anderson


James Bennett wrote:


On 1/16/07, Patrick J. Anderson <[EMAIL PROTECTED]> wrote:

I'd appreciate some help with figuring out how to go about adding that
locale to my site in simplest and sensible way.


The simplest way is to produce a translation for the 'pt' locale ;)

See this for information:

http://www.djangoproject.com/documentation/i18n/#how-to-create-language-files 



You might also want to check on the django-i18n mailing list to see if
anyone else is working on a 'pt' translation, and coordinate efforts.
Once the translation is ready, you can begin using it, and if you like
you can open a ticket in the Django Trac for it to have it added to
the framework.



Thanks, James! I would do it if I spoke Portuguese :) Unfortunately, I'm 
just a developer with a requirement for Portuguese translations.


Maybe I should copy 'pt_br' locale to 'pt' and when I add this language 
to my project, I'll ask translators to go through the Brazilian 
Portuguese   .po file and make it 'Portuguese'.



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



Portuguese (pt) request.LANGUAGE_CODE problem

2007-01-16 Thread Patrick J. Anderson


Hi, everybody!

I wanted to post about a little problem I have while developing 
multilingual site I'm working on.


I plan to include content in various languages, focusing on 3 at the 
moment: English, Spanish and Portuguese.


I have followed the docs on i18n and this are working great, except for 
one little detail. I'm not able to switch current language to 
Portuguese(pt) language, while I can change to Brazilian 
Portuguese(pt_br). I see that Portuguese(pt) locale does not exist in 
the framework, but does that prevent me from using it on my site?


Below are the appropriate settings I use in settings.py:

---

LANGUAGE_CODE   = 'en'

LANGUAGES = (
#('de', 'Deutsch'),
('en', 'English'),
('es', 'Espa�ol'),
#('fr', 'Fran�ais'),
#('hu', 'Magyar'),
#('it', 'Italiano'),
#('ja', '   '),
#('pl', 'Polski'),
('pt', 'Portugu�s'),
#('ro', 'Rom�n '),
#('ru', '  '),
#('zh', '  '),
)

USE_I18N = True

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)

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




Has anyone working on Portuguese sites encountered the same problem? 
Should I use Brazilian Portuguese instead?


I'd appreciate some help with figuring out how to go about adding that 
locale to my site in simplest and sensible way.



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



Re: a candidate for a custom decorator?

2007-01-11 Thread Patrick J. Anderson

Brian Beck wrote:
> I think your problem is the return values. args is a tuple and request
> should be there instead. In both of your decorators, return fn(request,
> *args, **kwargs) instead of fn(args, kwargs).
> 
> 
> > 
> 

Yes, Brian, that was the problem. 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



a candidate for a custom decorator?

2007-01-11 Thread Patrick J. Anderson

Hello,

I wanted to ask for some advice on a little issue I have with 
implementing decorators in my views.

I have this piece of code, which I include in each view, to redirect 
anonymous and staff users to a notice page (I don't want them to access 
site members stuff):


def my_view(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(MYSTUFF_FORBIDDEN_URL)
if request.user.is_staff:
return HttpResponseRedirect(MYSTUFF_STAFF_URL)

# view logic and HttpResponse


I wanted how to implement a custom site decorator, based on this blog post:
http://siddhi.blogspot.com/2006/12/using-python-decorators-to-implement.html


Here's what I wrote:


from django.http import HttpResponseRedirect

def redirect_anonymous(fn):
 def _check(request, *args, **kwargs):
 try:
 user = request.user.is_authenticated()
 except KeyError:
 return HttpResponseRedirect('/my-stuff/forbidden/')
 return fn(args, kwargs)
 return _check


def redirect_staff(fn):
 def _check(request, *args, **kwargs):
 if request.user.is_staff:
 return HttpResponseRedirect('/my-stuff/staff/')
 return fn(args, kwargs) # here's where I receive error
 return _check



However when I modify my view function to add these checks as decorators:

@redirect_staff
@redirect_anonymous
def my_view(request):
#view logic and HttpResponse


and I log in to my site as a normal user, I receive an AttributeError 
stating that:

'tuple' object has no attribute 'user'


How should I go about creating my decorators? Is there something I'm 
doing wrong?

Patrick


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



Re: filters on form objects

2006-10-26 Thread Patrick J. Anderson

RajeshD wrote:
> 
>> Or do I have to pass this list of
>> albums to the template:
>>
>> my_albums = Album.objects.filter(owner = request.user)
> 
> This will work.
> 
>> and then construct a select box based on that list. If so, I'd probably
>> "break out" of {{ form.albums }} and loose {{ form.errors }}. Is that so?
> 
> No. You will not lose form.errors. If you plan to render in HTML just
> that particular album selection drop-down, all you need to make sure is
> that you use the same form field names that Django's would've used.
> Then when such a form is submitted the manipulator will see the posted
> data exactly like it would had you used Django's own select renderer.
> So, you will get the necessary form.error field for your select
> element.
> 
>> If not, how should it be done using Django {{ form }}?
> 
> Another option is to use a custom manipulator. You can then fully
> control what shows in the select list right when the custom manipulator
> gets initialized. The custom manipulator can even extend the default
> manipulator if you wish -- this is especially useful if you only want
> to change the behaviour of a small number of fields and are happy with
> how the default manipulators handle the rest of your fields.
> 
> This code excerpt by Ivan might help:
> http://groups-beta.google.com/group/django-users/msg/f1635e9a27c6ae68
> 
> 
> > 
> 


Thanks! I was thinking of custom forms and manipulators, but passing a 
list of user albums to the template and writing a custom select box 
based on that list worked fine, so at least for now, I'll stick with that.

Regards, Patrick


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



Re: date navigation inclusion tag (problems with context)

2006-10-25 Thread Patrick J. Anderson

Patrick J. Anderson wrote:
> Here's one of the inclusion tags I wrote this morning for my blog date 
> navigation:
> 
> ---
> 
> from django.template import Library,Node
> from project.apps.news.models import Article
> 
> register = Library()
> 
> def articles_months(context):
>  if context['year']:
>  year = context['year']
>  elif context['month']:
>  year = context['month'].strftime("%Y")
>  elif context['day']:
>  year = context['day'].strftime("%Y")
> 
>  months = Article.objects.filter(time_added__year = year, status = 
> 1, is_approved = True).dates(
>  'time_added', 'month', order = 'DESC')
>  if months:
>  return { 'articles_months': months, }
> 
> register.inclusion_tag('news/widgets/articles_months_menu.html',
> takes_context = True)(articles_months)
> 
> -
> 
> It works fine if I view the year archive, but once I try to view a 
> monthly archive, I receive an error:
> 
> x
> 
> Request Method:   GET
> Request URL:  http://am.ws.local/news/2005/10/
> Exception Type:   KeyError
> Exception Value:  'year'
> Exception Location: 
> /usr/lib/python2.4/site-packages/django/template/context.py in 
> __getitem__, line 40
> 
> x
> 
> 
> What am I doing wrong?
> 
> 
> > 
> 

Found a better solution using context['object_list']



from django.template import Library

register = Library()

def articles_months(context):
 output = []

 for m in context['object_list']:
 output.append(m.time_added)

 if output:
 return { 'articles_months': output, }

register.inclusion_tag('news/widgets/articles_months_menu.html',
takes_context = True)(articles_months)


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



date navigation inclusion tag (problems with context)

2006-10-25 Thread Patrick J. Anderson

Here's one of the inclusion tags I wrote this morning for my blog date 
navigation:

---

from django.template import Library,Node
from project.apps.news.models import Article

register = Library()

def articles_months(context):
 if context['year']:
 year = context['year']
 elif context['month']:
 year = context['month'].strftime("%Y")
 elif context['day']:
 year = context['day'].strftime("%Y")

 months = Article.objects.filter(time_added__year = year, status = 
1, is_approved = True).dates(
 'time_added', 'month', order = 'DESC')
 if months:
 return { 'articles_months': months, }

register.inclusion_tag('news/widgets/articles_months_menu.html',
takes_context = True)(articles_months)

-

It works fine if I view the year archive, but once I try to view a 
monthly archive, I receive an error:

x

Request Method: GET
Request URL:http://am.ws.local/news/2005/10/
Exception Type: KeyError
Exception Value:'year'
Exception Location: 
/usr/lib/python2.4/site-packages/django/template/context.py in 
__getitem__, line 40

x


What am I doing wrong?


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



Accessing session variables in templates

2006-10-12 Thread Patrick J. Anderson

Hi!

I have a member_id session variable, which I set at login (it is 
different than "user").

I need to check that variable in my templates to display member-specific 
navigation.

How can I check do this? Or do I need to do the checking in each view 
function and pass the value in a template variable?

Regards, Patrick


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



Re: NullBoolean/Boolean Field weirdness

2006-10-11 Thread Patrick J. Anderson

Malcolm Tredinnick wrote:
> On Wed, 2006-10-11 at 22:45 -0500, Patrick J. Anderson wrote:
> [...] 
>> Thanks for your comments, Malcolm. I realize that a determined person 
>> could submit an altered form and edit other profiles.
>>
>> I guess this is not a Django-specific question, but what would be the 
>> best way of preventing that from happening?
> 
> You already know what you want the original value to be (False). So set
> it explicitly to False in the view prior to saving it upon creation.
> There is no need for the user's input to be involved for that attribute
> at all, so don't include it in the form.
> 
> Regards,
> Malcolm
> 
> 
> 
> > 
> 
Here's my wrapper for update_object view:

def edit_profile(request):
 if not request.user.is_authenticated():
 return HttpResponseRedirect('/community/login/')

 from django.views.generic.create_update import update_object
 from my_project.apps.community.models import Member
 return update_object(request,
 model = Member,
 object_id = request.session['member_id'],
 login_required = True,
 template_name="community/profile_form.html",
 )


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



Re: NullBoolean/Boolean Field weirdness

2006-10-11 Thread Patrick J. Anderson

Malcolm Tredinnick wrote:
> On Wed, 2006-10-11 at 22:45 -0500, Patrick J. Anderson wrote:
> [...] 
>> Thanks for your comments, Malcolm. I realize that a determined person 
>> could submit an altered form and edit other profiles.
>>
>> I guess this is not a Django-specific question, but what would be the 
>> best way of preventing that from happening?
> 
> You already know what you want the original value to be (False). So set
> it explicitly to False in the view prior to saving it upon creation.
> There is no need for the user's input to be involved for that attribute
> at all, so don't include it in the form.
> 
> Regards,
> Malcolm
> 
> 
> 
> > 
> 
But if I don't set it to True in the form (well "2" to be exact; "True" 
returns KeyError if my value is in hidden input), it reverts to False 
for approved members.

I have a fairly large Member model and I was hoping to avoid writing 
custom form manipulators

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



Re: NullBoolean/Boolean Field weirdness

2006-10-11 Thread Patrick J. Anderson

Malcolm Tredinnick wrote:
> On Wed, 2006-10-11 at 21:33 -0500, Patrick J. Anderson wrote:
> [...]
>> I guess the concept of approving members needs to be refined. My project 
>> has some "special" requirements and this is one of them.
> 
> There's no problem with special requirements. My point was that it's not
> at all secure to include that value as a hidden input form variable. If
> it should be set to False upon creation, do that in the save() method or
> in the view function that processes the form submission. Putting the
> value in the form and trusting what is submitted means that people will
> be able to approve themselves if they have a few clues about how web
> form submission works and the inclination to do so.
> 
>> On the value of {{ object.is_approved }}: I see None for "Unknown", 1 
>> for "Yes" and 0 for "No". I'm not sure why either.
> 
> I guess one question to ask here is whether "object" in your example is
> a form manipulator or the model instance itself. If it's a form
> manipulator, then you are reference a form field instance, not the model
> field. If it's the model field, I would expect the value in a template
> to be the same as the value if I print object.is_approved at a shell
> prompt (which will be a boolean or None). Looking at what you are
> reporting, it sounds like you are referencing a manipulator there, which
> changes things.
> 
> Regards,
> Malcolm
> 
> 
> 
> > 
> 
Thanks for your comments, Malcolm. I realize that a determined person 
could submit an altered form and edit other profiles.

I guess this is not a Django-specific question, but what would be the 
best way of preventing that from happening?


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



Re: NullBoolean/Boolean Field weirdness

2006-10-11 Thread Patrick J. Anderson

Malcolm Tredinnick wrote:
> On Wed, 2006-10-11 at 21:33 -0500, Patrick J. Anderson wrote:
> [...]
>> I guess the concept of approving members needs to be refined. My project 
>> has some "special" requirements and this is one of them.
> 
> There's no problem with special requirements. My point was that it's not
> at all secure to include that value as a hidden input form variable. If
> it should be set to False upon creation, do that in the save() method or
> in the view function that processes the form submission. Putting the
> value in the form and trusting what is submitted means that people will
> be able to approve themselves if they have a few clues about how web
> form submission works and the inclination to do so.
> 
>> On the value of {{ object.is_approved }}: I see None for "Unknown", 1 
>> for "Yes" and 0 for "No". I'm not sure why either.
> 
> I guess one question to ask here is whether "object" in your example is
> a form manipulator or the model instance itself. If it's a form
> manipulator, then you are reference a form field instance, not the model
> field. If it's the model field, I would expect the value in a template
> to be the same as the value if I print object.is_approved at a shell
> prompt (which will be a boolean or None). Looking at what you are
> reporting, it sounds like you are referencing a manipulator there, which
> changes things.
> 
> Regards,
> Malcolm
> 
> 
> 
> > 
> 

I use "object" to reference original model instance and "form" for the 
form instance.

{{ form.is_approved }} displays the dropdown with current value being 
selected, but obviously I don't want members to change that.

I changed my model to:

is_approved = models.NullBooleanField(blank = True, null = True)

as I don't want to include that field in the form presented to members.

I'm having second thoughts about member approval idea, though. But at 
the moment, I don't know yet what would be the best solution here. 
Perhaps I only approved members should be aable to edit their profile 
details, but then again defaulting to True on this field doesn't make 
sense either.




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



Re: NullBoolean/Boolean Field weirdness

2006-10-11 Thread Patrick J. Anderson

Malcolm Tredinnick wrote:
> On Wed, 2006-10-11 at 15:07 -0500, Patrick J. Anderson wrote:
>> I have extended Django User model (site members as opposed to users) and 
>> I want to approve them before they can use all site features. Below is 
>> my model:
>>
>> class Member(models.Model):
>>  user = models.ForeignKey(User)
>>  ...
>>  is_approved - models.NullBooleanField(default = False)
>>  ...
>>
>> Now, I want members to use site forms (not admin) to edit their profile 
>> details. Obviously, I don't want them to approve themselves, so I use 
>> hidden input value in my form:
>>
>> 
> 
> If you don't want people approving themselves, then this won't stop
> them. It is very easy to change the value of even a hidden field in a
> form prior to submission Type="hidden" just means it won't display in
> the UI. It doesn't mean the user can't change it.
> 
> 
>> However, whenever a member (even approved member) saves their profile, 
>> the value of "is_approved" is set to NULL.
>>
>> By the way, I'm using generic views. I looked at the admin interface 
>> source for this model type of input code and found this:
>>
>> Approved?:
>>> name="is_approved" size="1">
>>  Unknown
>>  Yes
>>  No
>>
>>
>> I assume that the framework translates this into appropriate values 
>> before saving the record and it works fine using admin interface.
>>
>> When I looked at the value of {{ object.is_approved }} in my template, 
>> the value for approved member is "1", and when that profile is saved, 
>> the value of is_approved changes to NULL.
> 
> It sounds like this part is working correctly, except for putting in the
> correct initial value: you have a value of "1" in the form and this is
> converted into the NULL case after submission.
> 
> I'm not sure why you are seeing a "1" in the hidden input field. I would
> have expected the string "False" to appear, since the value of the field
> in your model is going to be None, True or False (and the latter by
> default).
> 
> Regards,
> Malcolm
> 
> 
> 
> > 
> 

I guess the concept of approving members needs to be refined. My project 
has some "special" requirements and this is one of them.

On the value of {{ object.is_approved }}: I see None for "Unknown", 1 
for "Yes" and 0 for "No". I'm not sure why either.


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



NullBoolean/Boolean Field weirdness

2006-10-11 Thread Patrick J. Anderson

I have extended Django User model (site members as opposed to users) and 
I want to approve them before they can use all site features. Below is 
my model:

class Member(models.Model):
user = models.ForeignKey(User)
...
is_approved - models.NullBooleanField(default = False)
...

Now, I want members to use site forms (not admin) to edit their profile 
details. Obviously, I don't want them to approve themselves, so I use 
hidden input value in my form:



However, whenever a member (even approved member) saves their profile, 
the value of "is_approved" is set to NULL.

By the way, I'm using generic views. I looked at the admin interface 
source for this model type of input code and found this:

Approved?:
   
 Unknown
 Yes
 No
   

I assume that the framework translates this into appropriate values 
before saving the record and it works fine using admin interface.

When I looked at the value of {{ object.is_approved }} in my template, 
the value for approved member is "1", and when that profile is saved, 
the value of is_approved changes to NULL.

What is the proper way of handling this type of situation?


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



Re: global template tags

2006-10-04 Thread Patrick J. Anderson

RajeshD wrote:
> Firstly, the statement "user = User.objects.get(id=request.user.id)" is
> redundant -- you could directly use request.user instead of that query
> with the same effect.
> 
> As far as the actual problem is concerned, your Queryset is returning
> multiple rows because request.user.id probably resolves to None (in
> that case the query will match all User records). This in turn implies
> that request.user is not good.
> 
> Have a look at:
> http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requests
> 
> That will tell you what you need to setup in your project in order for
> Django to populate request.user for you.
> 
> Beware also that request.user may not always point to a logged in user.
> Always check this with the is_anonymous() call or other permission
> method calls before you use the user instance for anything serious.
> 
> Good luck!
> -Rajesh
> 
> 
> > 
> 
Thanks again, Rajesh. That worked. Below is my rudimentary userinfo tag:


from django.template import Library, Node
from django.contrib.auth.models import User

register = Library()

def user_info(context):
 """
 Get user information
 """
 request = context['request']
 if request.user.is_authenticated():
 # Do something for authenticated users.
 user = request.user
 else:
 # Do something for anonymous users.
 user = None

 return {'current_user': user,}

register.inclusion_tag('user_info.html', takes_context=True)(user_info)



I guess one thing to remember is to always use RequestContext


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



Re: global template tags

2006-10-04 Thread Patrick J. Anderson

RajeshD wrote:
> You could use:
> 
> 1. a regular tag or
> 2. an inclusion tag  with takes_context=True
> (See:
> http://www.djangoproject.com/documentation/templates_python/#inclusion-tags)
> 
> In both cases, your render or tag function will get called with a
> context object from which you can obtain the request instance like so:
> request = context['request'] (assuming that you have done the necessary
> setup in your project to use a RequestContext instead of the default
> Context)
> 
> 
> > 
> 
Thanks for your lead, Rajesh. I followed your advice with this code:

from django.template import Library, Node
from django.contrib.auth.models import User

register = Library()

def user_info(context):
 """
 Get user and associated (if exists) profile information
 """
 request = context['request']
 user = User.objects.get(id = request.user.id)
 return {
 'current_user': user,
 }

register.inclusion_tag('user_info.html', takes_context=True)(user_info)


But I receive multiple user objects. I guess my request context doesn't work


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



Re: global template tags

2006-10-04 Thread Patrick J. Anderson

Waylan Limberg wrote:
> On 10/4/06, Patrick J. Anderson <[EMAIL PROTECTED]> wrote:
>> Hi, everyone!
>>
>> I have a question I've been trying to find answers to in the docs, but
>> perhaps I'm not looking in the right places, because I can't find it.
>>
>> I'm wondering about the use of templatetags in project instead of
>> application scope. I put my applications in 'apps' subdirectory and
>> under each I created 'templatetags' directory to hold my template tags.
>>
>> I have a need for a tag that would display user and user-related
>> information (no. of posts and comments, etc.) in header of each page and
>> I thought that I could create a template tag for this purpose, which I
>> would load in the base template.
>>
>> I guess the question is simple : where should this template tag be
>> stored and can I import current RequestContext object to it?
>>
>>
> This was just answered the other day:
> 
> http://groups.google.com/group/django-users/browse_thread/thread/49e9669c64e353b2/
> 
> 

Well, yeah, I could put that tag probably in any installed app.

What about request object being available inside that tag, so to speak?


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



global template tags

2006-10-04 Thread Patrick J. Anderson

Hi, everyone!

I have a question I've been trying to find answers to in the docs, but 
perhaps I'm not looking in the right places, because I can't find it.

I'm wondering about the use of templatetags in project instead of 
application scope. I put my applications in 'apps' subdirectory and 
under each I created 'templatetags' directory to hold my template tags.

I have a need for a tag that would display user and user-related 
information (no. of posts and comments, etc.) in header of each page and 
I thought that I could create a template tag for this purpose, which I 
would load in the base template.

I guess the question is simple : where should this template tag be 
stored and can I import current RequestContext object to 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: User object available in base template

2006-10-04 Thread Patrick J. Anderson

Don Arbow wrote:
> On Oct 3, 2006, at 9:30 PM, Patrick J. Anderson wrote:
>> def main(request):
>>  posts = Post.objects.filter(is_approved =
>> True).order_by('-time_added')[:5]
>>  t = loader.get_template('homepage.html')
>>  c = RequestContext({
>>  'latest_posts': posts,
>>  })
>>  return HttpResponse(t.render(c))
>>
>> What am I doing wrong?
> 
> 
> 
> You have to pass the request object into the RequestContext  
> constructor. Then the user object will show up in your templates.
> 
> c= RequestContext(request, { ... })
> 
> Don
> 
> 
> 
> > 
> 

Thanks, guys!

I guess to create a user info box and make it available in all the 
templates, I'd create a template tag and load it in the base template, 
right?


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



Re: User object available in base template

2006-10-03 Thread Patrick J. Anderson

Forgot to add my specific error:

Exception Type: AttributeError
Exception Value:'dict' object has no attribute 'user'
Exception Location: 
/usr/lib/python2.4/site-packages/django/core/context_processors.py in 
auth, line 17

Patrick J. Anderson



Patrick J. Anderson wrote:
> In my project, I have a root template called base.html, which all other 
> templates extend.
> 
> I'd like to create a simple navigation with user information, which I 
> want to write once and put in the base template to be shown on every page.
> 
> I'm not sure what the best way of retrieving information from User 
> object at the template root level is. I've read about RequestContext 
> object and template processors, but the docs are not very clear to me 
> and leave a lot to be guessed. I've followed the guides, but still I 
> can't get User object in my template. But then again, perhaps the 
> solution is simple, and I'm just too dense to see it.
> 
> Below is the very simple view code I'm testing:
> 
> from django.template import RequestContext, loader
> from django.http import HttpResponse
> from myproject.apps.journal.models import Post
> 
> 
> def main(request):
>  posts = Post.objects.filter(is_approved = 
> True).order_by('-time_added')[:5]
>  t = loader.get_template('homepage.html')
>  c = RequestContext({
>  'latest_posts': posts,
>  })
>  return HttpResponse(t.render(c))
> 
> 
> And here's a piece of template from "homepage.html":
> 
> {% block user_nav %}
> 
> {% if user %}
>   {{ user.first_name 
> }}
> {% else %}
>   Anonymous
> {% endif %}
> 
> {% endblock %}
> 
> 
> What am I doing wrong?
> 
> 
> > 
> 


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



User object available in base template

2006-10-03 Thread Patrick J. Anderson

In my project, I have a root template called base.html, which all other 
templates extend.

I'd like to create a simple navigation with user information, which I 
want to write once and put in the base template to be shown on every page.

I'm not sure what the best way of retrieving information from User 
object at the template root level is. I've read about RequestContext 
object and template processors, but the docs are not very clear to me 
and leave a lot to be guessed. I've followed the guides, but still I 
can't get User object in my template. But then again, perhaps the 
solution is simple, and I'm just too dense to see it.

Below is the very simple view code I'm testing:

from django.template import RequestContext, loader
from django.http import HttpResponse
from myproject.apps.journal.models import Post


def main(request):
 posts = Post.objects.filter(is_approved = 
True).order_by('-time_added')[:5]
 t = loader.get_template('homepage.html')
 c = RequestContext({
 'latest_posts': posts,
 })
 return HttpResponse(t.render(c))


And here's a piece of template from "homepage.html":

{% block user_nav %}

{% if user %}
{{ user.first_name 
}}
{% else %}
Anonymous
{% endif %}

{% endblock %}


What am I doing wrong?


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



slug field and generic create view

2006-10-03 Thread Patrick J. Anderson

Is there a simple way to add the slug field to a custom form template?

I'm using django.views.generic.create_update.create_object and my model 
has a slug field. Whenever I try to add a new item to database, I 
receive error saying that my "title" is similar to the on existing in 
the database, so I suspect it has to do with the slug field not being 
populated.

I looked at the source code of admin pages and I see urlify.js script in 
the head of the document, but how should I include it in my own template?

Patrick J.Anderson


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



__str__ question

2006-09-14 Thread Patrick J. Anderson

I'm not totally clear, perhaps it's a Python and not Django-specific 
question, but in my e-commerce app model, I have Currency and 
ExchangeRate classes:


class Currency(models.Model):
 name = models.CharField(maxlength = 50)
 code = models.CharField(maxlength = 3)

 class Meta:
 db_table = 'world_currencies'
 verbose_name = 'currency'
 verbose_name_plural = 'currencies'

 class Admin:
 pass

 def __str__(self):
 return self.name


class ExchangeRate(models.Model):
 company = ForeignKey(Company)
 source = ForeignKey(Currency, related_name = 'source')
 destination = ForeignKey(Currency, related_name = 'destination')
 rate = FloatField(max_digits = 10, decimal_places = 2)

 class Meta:
 db_table = 'company_exchange_rates'
 verbose_name = 'exchange rate'
 verbose_name_plural = 'exchange rates'

 class Admin:
 pass


What should I use to describe an ExhangeRate object in __str__ ?


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



Re: LANGUAGES in template

2006-09-07 Thread Patrick J. Anderson

gjiro wrote:
> Hi Patrick,
> 
> Check if your settings.py conforms to:
> http://www.djangoproject.com/documentation/settings/#languages
> 
> The context processor that exposes LANGUAGES to the template's
> "context":
> http://code.djangoproject.com/browser/django/trunk/django/core/context_processors.py
> 
> James Bennett's excellent writeup:
> http://www.b-list.org/weblog/2006/06/14/django-tips-template-context-processors
> 
> "...Then we open up our settings file and add this (keep in mind that
> Django enables the auth, debug and i18n context processors by default,
> and editing the TEMPLATE_CONTEXT_PROCESSORS setting will override that,
> so if you want to keep those you'll need to add them back
> manually)..."
> 
> Regards,
> gjiro
> 
> 
> > 
> 

Thanks gjiro,
I've been reading up on 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



LANGUAGES in template

2006-09-07 Thread Patrick J. Anderson

I'm following the docs on i18n. In there, there's a sample of template 
code for a language selection form:


 
 
 {% for lang in LANGUAGES %}
 {{ lang.1 }}
 {% endfor %}
 
 


But LANGUAGES is empty for me in the template. How can I use LANGUAGES 
variable in the template?


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



how to return unique days in month_archive generic view

2006-08-03 Thread Patrick J. Anderson

Hi!

I'm building a day-based navigation for my blog posts. I'm using generic 
view (month_archive) object_list to get all post for a specific month.

How can I get unique days in my template loop on object_list if I have 
multiple posts per day? Is there a way to do it "generically", or do I 
need to write something new myself?

Patrick


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



Re: logged-in user id as default value on ForeignKey relation

2006-07-17 Thread Patrick J. Anderson

Malcolm Tredinnick wrote:
> On Mon, 2006-07-17 at 09:41 -0700, Patrick J. Anderson wrote:
>> Sorry, but would you be able to explain this in detail? I was thinking
>> about acomplishing this in model classes, not in views, so I'm not sure
>> if I understand what you mean.
> 
> You have to pass the information through from a view, though, because
> the models have no concept of "logged in user" or "current user" or
> anything like that: those are view-level concepts. There is no way for a
> model, on its own, to be able to work out which "user" (whatever that
> may mean) is performing the action. There are many ways to access models
> and views are only one way.
> 
> Still, just to prove that nothing is impossible if you're prepared to be
> sufficiently devious: if you were really, really determined to do this,
> you could hook into the pre-save signal on a model, walk back up the
> Python calling stack to the view function (use the tracback module. You
> would need a list somewhere detailing what are the view functions so
> that you knew when had arrived) and then extract the request object from
> the function's locals and look for the user that way. However, if you
> use that method, you are not allowed to ever mention my name as having
> suggested it. I am evil, but I don't want people to know that.
> 
> Regards,
> Malcolm
> 
> 
> > 
> 
Thanks, Malcolm!

Whether I use your method or not, I'll keep your name safe and secret :)


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



Re: logged-in user id as default value on ForeignKey relation

2006-07-17 Thread Patrick J. Anderson

Sorry, but would you be able to explain this in detail? I was thinking
about acomplishing this in model classes, not in views, so I'm not sure
if I understand what you mean.


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



logged-in user id as default value on ForeignKey relation

2006-07-17 Thread Patrick J. Anderson

In my model I'd like to keep track of who added/updated a particular record.

class Entry(models.Model):
 ...
 time_added = models.DateTimeField(auto_now_add = True, editable = 
False)
 user_added = models.ForeignKey(User, default = ?, editable = False)
 time_updated = models.DateTimeField(auto_now = True, editable = False)
 user_updated = models.ForeignKey(user, default = ?, editable = False)

How could I add a currently logged in (to admin interface) user id 
automatically as a value for that field? Is it possible to do that 
without writing extra class methods? Any helpful suggestions or tips are 
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: ManyToMany and filter_interface

2006-07-12 Thread Patrick J. Anderson

[EMAIL PROTECTED] wrote:
> I can't seem to get filter_interface on M2M relationships to work.
> There are no errors but the admin interface looks identical with and
> without the extra directive in there. Here's the relevant field:
> 
> attributes  = models.ManyToManyField(Attribute,
> filter_interface=models.HORIZONTAL, related_name="attributes")
> 
> Any ideas? I've imported models as is the case with a standard
> (default) model file.
> 
> 
> > 
> 

Hi!

Yeah, I noticed it too after updating the trunk. Not sure if this will 
be helpful, but make sure that USE_I18N is not set to True in your 
settings.py.

I think it's an error, which hopefully will get fixed, as this setting 
should only apply to internationalization, but somehow it affects other 
parts.


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



Populating multiple text fields from a set of values. Possible?

2006-06-29 Thread Patrick J. Anderson

I am wondering if it is possible to populate a list of text input
fields in admin forms from a default store (database or text). Perhaps a
problem I'm trying to solve will illustrate it better.

Code:

class Project(models.Model):
""" Production Projects """
name= models.CharField(maxlength = 
100, help_text = 'Max. 100 characters')
...


class Milestone(models.Model):
""" Production Project Milestone """
project = models.ForeignKey(Project, 
edit_inline=models.TABULAR,num_in_admin=15)
name= models.CharField(maxlength = 
100, core = True)



I'm working on a model that will allow a team to create projects with
milestones. Their projects are fairly consistent and a set of
milestones or project phases doesn't change very often, though it could
sometime.

How could I help a user by providing a template with editable milestone
name in the 'Add project' form? Also, is there a way to add additional
milestones in the same form?

I hope I make it clear.


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



Re: SuspiciousOperation: User tampered with session cookie

2006-06-28 Thread Patrick J. Anderson

On Tue, 27 Jun 2006 23:30:56 -0500, Patrick .J. Anderson wrote:

> Malcolm Tredinnick wrote:
>> [quoted text muted]
> 
> Hi, Malcolm
> 
> Yes, I noticed that too. Perhaps it would be good if I tested this
> behaviour on another distro, but I don't want to resetup my development
> machine again. Maybe someone with a distro other than Ubuntu Dapper
> could compare the session_keys in django_sessions table with mod_python
> as well as builtin server, and see if this is also happening.
> 
> Patrick
> 
> 
> 
Well, I reinstalled Fedora Core 5 and setup django-trunk. There is no
problem with FC5, so I suspect that there's something wrong with Ubuntu
Dapper here.

Here's my session_key after logging into admin using mod_python:

21d78b3bd4da4a79bd7f02c038c0707d


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



Re: SuspiciousOperation: User tampered with session cookie

2006-06-27 Thread Patrick .J. Anderson

Malcolm Tredinnick wrote:
> On Tue, 2006-06-27 at 23:09 -0500, Patrick .J. Anderson wrote:
>> Jacob Kaplan-Moss wrote:
>>> Hi Patrick --
>>>
>>> What happens when you clear out your sessions table?
>>>
>>> FYI, there's nothing about Ubuntu versus mod_python that would/could  
>>> cause this (I use both).
>>>
>>> Jacob
>>>
>> I cleared the session table and tried to login using my
>> apache/mod_python virtual host setup. This is the session_key I get:
>>
>> 0abcebfdaff71c28a368d8bd
>>
>>
>> When I log in using the development server, I can login successfully and
>> the session_key I see is:
>>
>> 6b668c51d7d4fddd89c14e14e0569417
>>
>>
>> These are obviously very different, particularly the 0s in the beginning
>> of the session_key from mod_python.
> 
> One common thing that I noticed between your current problem (which
> looks a lot like Nikolaus Shlemm's md5 sum problem) and the original
> problem Nikolaus demonstrated on the mod_python list is that you are
> both using a reasonably recent Ubuntu installation. No idea why that
> will contribute (or even if it is a differentiating factor), but it's
> something to note.
> 
> Malcolm
> 
> 
> > 
> 

Hi, Malcolm

Yes, I noticed that too. Perhaps it would be good if I tested this
behaviour on another distro, but I don't want to resetup my development
machine again. Maybe someone with a distro other than Ubuntu Dapper
could compare the session_keys in django_sessions table with mod_python
as well as builtin server, and see if this is also happening.

Patrick


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



Re: SuspiciousOperation: User tampered with session cookie

2006-06-27 Thread Patrick .J. Anderson

Jacob Kaplan-Moss wrote:
> Hi Patrick --
> 
> What happens when you clear out your sessions table?
> 
> FYI, there's nothing about Ubuntu versus mod_python that would/could  
> cause this (I use both).
> 
> Jacob
> 
> > 
> 
I cleared the session table and tried to login using my
apache/mod_python virtual host setup. This is the session_key I get:

0abcebfdaff71c28a368d8bd


When I log in using the development server, I can login successfully and
the session_key I see is:

6b668c51d7d4fddd89c14e14e0569417


These are obviously very different, particularly the 0s in the beginning
of the session_key from mod_python.



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



Re: SuspiciousOperation: User tampered with session cookie

2006-06-27 Thread Patrick .J. Anderson

Nikolaus Schlemm wrote:
>> I've heard that the problem might be related to md5 hashing (someone
>> just recently posted it here in the groups with the same error
>> message). I looked at the django code and that where that error message
>> is thrown and it seemed to confirm that, but I don't know why this
>> happens.
> simply try generating the reference hashes provided at the end of the md5 
> rfc[1] within a django-view - if they are not calculated correctly, you might 
> want to switch from md5 to sha for a quick workaround and possibly follow the 
> thread on the modpy mailinglist[2].
> 
> another solution might be something along the lines of the patch I posted 
> earlier[3] - but of course, I don't know whether or when this will make it in 
> into django ;)
> 
> [1] http://www.ietf.org/rfc/rfc1321.txt
> [2] http://modpython.org/pipermail/mod_python/2006-June/021482.html
> [3] 
> http://groups.google.com/group/django-users/browse_thread/thread/eeb44c894342d6f7/4b951b6d3a8644dd

Hmm, I don't want to modify the framework code and start creating this
sort of workarounds since I use django-trunk...

I guess I'll have to wait until this problem is resolved, though I
thought Django was for developers with deadlines :)

Well, this makes me a little cautious in using the framework for my web
development. Sad, 'cause I liked it. But I'll dig for more info and try
to find a solution


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



Re: SuspiciousOperation: User tampered with session cookie

2006-06-27 Thread Patrick .J. Anderson

Patrick .J. Anderson wrote:
> [EMAIL PROTECTED] wrote:
>> Clear the cookies in your browser and the problem will go away.
>>
>>
> clearing the cookies doesn't help (I guess you answered that one).
> 
> hmm, i don't know exactly what to do here, as I haven't tampered with
> anything. I'll try to recreate the project (extra work, but maybe it'll
> work)
> 
> 
> > 
> 
I recreated the project using django-admin.py (of course, I restored my
models and database), but still experience this behaviour and error
messsages when I try to log in to admin section. Weird, as everything I
have in my settings.py file is new and I obviously haven't tampered with
the session.

If this is a problem with mod_python in Ubuntu, I'll have to switch back
to FC5 where things 'worked'.


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



Re: SuspiciousOperation: User tampered with session cookie

2006-06-27 Thread Patrick .J. Anderson

[EMAIL PROTECTED] wrote:
> Clear the cookies in your browser and the problem will go away.
> 
> 
> > 
> 
clearing the cookies doesn't help (I guess you answered that one).

hmm, i don't know exactly what to do here, as I haven't tampered with
anything. I'll try to recreate the project (extra work, but maybe it'll
work)


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



Re: SuspiciousOperation: User tampered with session cookie

2006-06-27 Thread Patrick J. Anderson

Hmm, I haven't changed domains. I simply took my previous setup on
Fedora Core 5 with apache+mod_python and put it on Ubuntu Dapper with
apache+mod_python.

I've heard that the problem might be related to md5 hashing (someone
just recently posted it here in the groups with the same error
message). I looked at the django code and that where that error message
is thrown and it seemed to confirm that, but I don't know why this
happens.

Could there be a bug with mod_python? I simply don't know, but would
appreciate someone more experienced looking into 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: list_display (ManyToManyField)

2006-06-23 Thread Patrick J. Anderson

Thanks, that works well.


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



list_display (ManyToManyField)

2006-06-23 Thread Patrick J. Anderson

I'd like to display a list of tags (ManyToMany relationship to
Articles) in admin list_display.

I'm getting a reference to an object. Is there a way to do this in
Admin class inside my model?

Below is a code chunk from my model:

class Article(models.Model):
#...
tags= models.ManyToManyField(Tag, filter_interface
= models.HORIZONTAL)

class Admin:
  list_display = ('heading', 'date_received',
'time_added', 'time_updated', 'tags')


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



Re: Comments: Failed lookup for key [id] in ''

2006-06-22 Thread Patrick J. Anderson

That's right! Thanks for spotting this silly mistake.


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



Re: Best way to resuse admin pagination?

2006-06-22 Thread Patrick J. Anderson

Yes, that's true, but what would be the easiest way to reuse the
pagination "widget" (if you can call it that) instead of writing my
own? Sorry, if I haven't explained it in more detail


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



Comments: Failed lookup for key [id] in ''

2006-06-22 Thread Patrick J. Anderson

Following documentation found on
http://code.djangoproject.com/wiki/UsingFreeComment, I run into this
problem. Below is my template:

{% load comments.comments %}


{% for p in latest %}
{% get_free_comment_count for blog.post object.id as comment_count
%}
{{ p.title
}}

{{ p.intro|truncatewords:"100" }}
Posted on {{ p.time_added|date:"M j, Y" }} at
{{ p.time_added|date:"P" }}|
{{ comment_count }}
Comments


{% endfor %}


What could be the reason for failed lookup on key[id]?


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



Best way to resuse admin pagination?

2006-06-22 Thread Patrick J. Anderson

What is the best way to reuse admin pagination in a generic object_list
view template?


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



Re: Problem with date_based generic views

2006-06-21 Thread Patrick J. Anderson

Well, that fixed it. I guess development using mod_python can be a
little cumbersome.


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



Re: Problem with date_based generic views

2006-06-21 Thread Patrick J. Anderson

I'm trying to display my records based on date. I've removed
object.list... same result, page returns the same error message.

It's weird, because it was working fine just a few minutes ago.


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



Problem with date_based generic views

2006-06-21 Thread Patrick J. Anderson

Hi, I've been working with date_based generic views in my application,
and while everything was going great, all of a sudden I'm getting this
error on, while trying to access records for a specific month:


ViewDoesNotExist at /projects/2006/jun/
Could not import django.views.generic.date_based.archive_month. Error
was: No module named archive_month


Here's my urlpattern for projects:


# Projects

(r'^projects/(?P\d{4})/(?P[a-z]{3})/(?P\d{2})/(?P[-\w]+)/$',

 'django.views.generic.date_based.object_detail',
 dict(projects_dict, slug_field='slug',
template_name='project_detail.html')
 ),

(r'^projects/(?P\d{4})/(?P[a-z]{3})/$',
 'django.views.generic.date_based.archive_month.object_list',
 dict(projects_dict, template_name='projects_month.html')
 ),

(r'^projects/(?P\d{4})/$',
 'django.views.generic.date_based.archive_year.object_list',
 dict(projects_dict, make_object_list = True,
template_name='projects_year.html')
 ),

(r'^projects/$',
 'django.views.generic.date_based.archive_index',
 dict(projects_dict, template_name='projects_latest.html')
 ),


What could be wrong and why can't I import archive_month module?


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



Re: How would Django handle a large number of records

2006-06-21 Thread Patrick J. Anderson

Thanks, guys! That's what I thought, but it helps to have a
conformation, Wilson:). Great job on Django!

There are a few small admin interface issues I'd still need to work
out, mainly I might have a similar number of records related to
articles (the number of article assignments might be slighltly smaller
to the number of articles, lets say 20,000), so I'd like to limit
foreign key form elements to something user-friendly. Not sure yet how
to do it, but I'm sure I'll find a way.

Wilson Miner wrote:
> > The World Online admin
> > interface (where Django was born) has a number of content types with
> > tens of thousands -- if not hundreds of thousands -- of records.
>
> 393,181 stories and counting...
>
> On 6/21/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
> >
> > On 6/21/06, Patrick Anderson <[EMAIL PROTECTED]> wrote:
> > > We have about 80,000 records which we will need to migrate. I'm wondering
> > > how Django admin interface would deal with such amount of data (they
> > > are of the same type, so they might be managed by a single app). I know
> > > Django comes from the news publishing world, where databases are huge,
> > > but this is a key question for us, and would like to hear comments that
> > > will put my concerns to rest, so we can start coding (well, we already
> > > have the models and the admin interface:)). Any tips would be appreciated,
> > > too.
> >
> > Hey Patrick,
> >
> > The admin interface really doesn't care about how many records you
> > have; the user interface is built to scale. I wouldn't expect to have
> > any problems with the admin interface. The World Online admin
> > interface (where Django was born) has a number of content types with
> > tens of thousands -- if not hundreds of thousands -- of records.
> > Pagination, filters and searches on the changelist are quite useful in
> > those cases! :)
> >
> > Generally when dealing with lots of records, the pressure point is the
> > database. Make sure your database is optimized for the data you have.
> >
> > Adrian
> >
> > --
> > Adrian Holovaty
> > holovaty.com | djangoproject.com
> >
> > >
> >


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