how to add new message prompt in base template?

2009-12-05 Thread lzhshen
Hi,

I adopt django-messages as one of my site's application. Does
anyone know how to add a new message prompt in base template? I mean
how I can get one application's data in base template. Does this make
sense?

Thanks in advance!

--

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




Timer and Caching

2009-12-05 Thread OnCEL
My users have a lot of information provided as json by django when
they log on my application. Instead of computing this json each time
someone logs in, i would like to cache it. I think about having it as
a string that I would simply copy to the response object.

However, some actions must make update this string as they modify
information it contains. But I don't want to update it if a lot of
user actions are done in a too little time. Typically, i'd like to
have a kind of timer. If another action is done within N seconds, it
will cancel the timer and restart it. When the timer timeout, the
update of the cached data must be done.

Is there a native system providing this kind of feature? Should I code
my own timer/thread managing code to do this?

--

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




Re: Parsing XML in the template? (New to Django and Python)

2009-12-05 Thread Sam Lai
Inline.

2009/12/6 sleepjunk :
> Thank you for the response. I don't believe I explained well enough
> exactly what I'm trying to do.
>
> I have table Video with a field vimeo_code. Each vimeo_code has its
> own XML file. The XML file I used in my views.py is just a random
> video I saw on vimeo. I need to replace the vimeo_code so the XML file
> I'm parsing looks like http://vimeo.com/api/v2/video/vimeo_code.xml

Ok, so just replace this line:

 feed = urllib.urlopen("http://vimeo.com/api/v2/video/7875440.xml;)

with,

 feed =
urllib.urlopen("http://vimeo.com/api/v2/video/%s.xml; % v.vimeo_code)

This replaces the code in the URL with the current vimeo_code in the loop.

I think we're on the same page; give it a shot and see how it goes.

> Would it be a better idea to do this as a tag filter? Any additional
> information for me if I do it that way?

I'm sure someone will have a more concrete reason for doing it one way
or the other. Personally though, it's a matter of style. I prefer
having it in the view function because then I can see immediately that
extra http calls will be made when looking through my code. If I used
a tag filter, I would have to look at the view function to find the
template, then the template to see if custom tag filters were used,
then the .py files for the tag filters to see what it's doing.

Tag filters are pretty simple things; the Django docs link I gave
should be easy enough. Feel free to post questions if you get stuck
though.

> Thanks again, I appreciate your help.
> Matt
>
> On Dec 5, 10:07 pm, Sam Lai  wrote:
>> See inline.
>>
>> 2009/12/6 sleepjunk :
>>
>> > Hello :) I am working on a small video site that allows a user to add
>> > a video to the site by submitting a Vimeo.com or Youtube.com URL. I'm
>> > trying to display thumbnails without hosting them. For Vimeo videos I
>> > need to parse an XML file to find the thumbnail location.
>>
>> > On my homepage I would like to display the 5 newest videos. As of now
>> > I'm displaying every video in the database on the homepage. Each video
>> > will have a different thumbnail and XML file to parse. As of right now
>> > my "main_page" in my views.py file looks like this:
>>
>> > def home_page(request):
>> >        template = get_template('home_page.html')
>> >        videos = Video.objects.all()
>>
>>           videos_context = [ ]
>>           for v in videos:>             feed = 
>> urllib.urlopen("http://vimeo.com/api/v2/video/7875440.xml;)
>> >             tree = ET.parse(feed)
>> >             root = tree.getroot()
>> >             vimeo_thumbnail = root.findtext("video/thumbnail_medium")
>>
>>                videos_context.append( { 'video' : v, 'thumbnail_url' :
>> vimeo_thumbnail } )
>>
>> >        variables = Context({
>> >                'videos' : videos_context,
>> >        })
>> >        output = template.render(variables)
>> >        return HttpResponse(output)
>>
>> > How can I parse a different XML file for every video? Thank you much.
>> > Again, I am new and could be going about this completely wrong and
>> > gladly accept any feedback you have.
>>
>> You could try something like the modified view above. It loops through
>> every video, gets the thumbnail URL, creates an object containing the
>> video model instance and the thumbnail URL, and adds it to the list
>> videos_context.
>>
>> You could then access them in your template like this (assuming
>> there's a name field in your Video model):
>>
>> {% for v in videos %}
>> {{ v.video.name }}
>> {% endfor %}
>>
>> The alternate way of doing this is to make a tag filter, 
>> seehttp://docs.djangoproject.com/en/dev/howto/custom-template-tags/
>>
>> HTH,
>>
>> Sam
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: Parsing XML in the template? (New to Django and Python)

2009-12-05 Thread sleepjunk
Thank you for the response. I don't believe I explained well enough
exactly what I'm trying to do.

I have table Video with a field vimeo_code. Each vimeo_code has its
own XML file. The XML file I used in my views.py is just a random
video I saw on vimeo. I need to replace the vimeo_code so the XML file
I'm parsing looks like http://vimeo.com/api/v2/video/vimeo_code.xml

Would it be a better idea to do this as a tag filter? Any additional
information for me if I do it that way?

Thanks again, I appreciate your help.
Matt

On Dec 5, 10:07 pm, Sam Lai  wrote:
> See inline.
>
> 2009/12/6 sleepjunk :
>
> > Hello :) I am working on a small video site that allows a user to add
> > a video to the site by submitting a Vimeo.com or Youtube.com URL. I'm
> > trying to display thumbnails without hosting them. For Vimeo videos I
> > need to parse an XML file to find the thumbnail location.
>
> > On my homepage I would like to display the 5 newest videos. As of now
> > I'm displaying every video in the database on the homepage. Each video
> > will have a different thumbnail and XML file to parse. As of right now
> > my "main_page" in my views.py file looks like this:
>
> > def home_page(request):
> >        template = get_template('home_page.html')
> >        videos = Video.objects.all()
>
>           videos_context = [ ]
>           for v in videos:>             feed = 
> urllib.urlopen("http://vimeo.com/api/v2/video/7875440.xml;)
> >             tree = ET.parse(feed)
> >             root = tree.getroot()
> >             vimeo_thumbnail = root.findtext("video/thumbnail_medium")
>
>                videos_context.append( { 'video' : v, 'thumbnail_url' :
> vimeo_thumbnail } )
>
> >        variables = Context({
> >                'videos' : videos_context,
> >        })
> >        output = template.render(variables)
> >        return HttpResponse(output)
>
> > How can I parse a different XML file for every video? Thank you much.
> > Again, I am new and could be going about this completely wrong and
> > gladly accept any feedback you have.
>
> You could try something like the modified view above. It loops through
> every video, gets the thumbnail URL, creates an object containing the
> video model instance and the thumbnail URL, and adds it to the list
> videos_context.
>
> You could then access them in your template like this (assuming
> there's a name field in your Video model):
>
> {% for v in videos %}
> {{ v.video.name }}
> {% endfor %}
>
> The alternate way of doing this is to make a tag filter, 
> seehttp://docs.djangoproject.com/en/dev/howto/custom-template-tags/
>
> HTH,
>
> Sam

--

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




Re: How to create multiple 'submit' buttons using 'forms' package

2009-12-05 Thread Ken
Sorry for repeating what you said Shawn, but for some reason your
reply wasn't showing up in my browser until after I had answered the
question for myself.

Thanks,
Ken

--

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




Re: How to show site down for maintenance page

2009-12-05 Thread Brian Neal
On Dec 5, 6:54 pm, zweb  wrote:
> What is the best way to show site down for maintenance page ?

If you are using mod_wsgi:

http://www.caktusgroup.com/blog/2009/05/25/seamlessly-switch-off-and-on-a-django-or-other-wsgi-site-for-upgrades/

--

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




Re: How to create multiple 'submit' buttons using 'forms' package

2009-12-05 Thread Ken
Never mind, got it. the forms package merely provides the interior of
the ; the  markup, plus any submit buttons, are the
responsibility of the template (or other code).

Thanks,
Ken

On Dec 5, 8:55 pm, Ken  wrote:
> I have the following form, which displays nicely:
>
> class BuySellForm(forms.Form):
>     symbol = forms.CharField()
>     shares = forms.CharField()
>     price = forms.CharField()
>
> However, I can't figure out how to get multiple 'submit' buttons to
> display (one 'buy' and the other 'sell'). Actually, I can't even
> figure out how to get a single standard submit button to show up--
> there doesn't seem to be a 'submit widget' listed in the Django book.
> Or perhaps I'm just not seeing it?
>
> As you can tell, I'm an absolute newbie. First day. Thanks for the
> patience.
>
> Ken

--

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




Re: Parsing XML in the template? (New to Django and Python)

2009-12-05 Thread Sam Lai
See inline.

2009/12/6 sleepjunk :
> Hello :) I am working on a small video site that allows a user to add
> a video to the site by submitting a Vimeo.com or Youtube.com URL. I'm
> trying to display thumbnails without hosting them. For Vimeo videos I
> need to parse an XML file to find the thumbnail location.
>
> On my homepage I would like to display the 5 newest videos. As of now
> I'm displaying every video in the database on the homepage. Each video
> will have a different thumbnail and XML file to parse. As of right now
> my "main_page" in my views.py file looks like this:
>
> def home_page(request):
>        template = get_template('home_page.html')
>        videos = Video.objects.all()

  videos_context = [ ]
  for v in videos:
>         feed = urllib.urlopen("http://vimeo.com/api/v2/video/7875440.xml;)
>         tree = ET.parse(feed)
>         root = tree.getroot()
>         vimeo_thumbnail = root.findtext("video/thumbnail_medium")
   videos_context.append( { 'video' : v, 'thumbnail_url' :
vimeo_thumbnail } )

>        variables = Context({
>                'videos' : videos_context,
>        })
>        output = template.render(variables)
>        return HttpResponse(output)
>
> How can I parse a different XML file for every video? Thank you much.
> Again, I am new and could be going about this completely wrong and
> gladly accept any feedback you have.

You could try something like the modified view above. It loops through
every video, gets the thumbnail URL, creates an object containing the
video model instance and the thumbnail URL, and adds it to the list
videos_context.

You could then access them in your template like this (assuming
there's a name field in your Video model):

{% for v in videos %}
{{ v.video.name }}
{% endfor %}

The alternate way of doing this is to make a tag filter, see
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/

HTH,

Sam

--

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




Re: How to create multiple 'submit' buttons using 'forms' package

2009-12-05 Thread Shawn Milochik
Ken,

You just put the submit buttons in the HTML form as you would normally.

The submit button isn't part of a Django Model or Form. It really  
doesn't make sense there; there's no data there.

Shawn



On Dec 5, 2009, at 9:55 PM, Ken   
wrote:

> I have the following form, which displays nicely:
>
> class BuySellForm(forms.Form):
>symbol = forms.CharField()
>shares = forms.CharField()
>price = forms.CharField()
>
> However, I can't figure out how to get multiple 'submit' buttons to
> display (one 'buy' and the other 'sell'). Actually, I can't even
> figure out how to get a single standard submit button to show up--
> there doesn't seem to be a 'submit widget' listed in the Django book.
> Or perhaps I'm just not seeing it?
>
> As you can tell, I'm an absolute newbie. First day. Thanks for the
> patience.
>
> Ken
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en 
> .
>
>

--

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




Re: New to django, python, etc. - ForeignKey question

2009-12-05 Thread Sam Lai
The error is occurring here as you have mentioned -

rolestartdate = models.DateField(default = \
   Project.objects.get
(pk=project.id).startdate)

You're right that Django creates an attribute named id for every model
without a primary key explicitly specified, but I suspect the issue
here is that Django is trying to resolve 'project.id' before the
Project model has been fully initialized. Also, Django is trying to
resolve project.id for the model class, and not a model instance which
won't work as model classes do not contain data.

I believe 'default' can only be used to specify static values, not
values that depend on other models (there is no defined behaviour for
that, so if it works, it's by chance and might not work later).

To do what you want, I suggest you override the save method in the
model, and add the startdate from the related Project model to the
Role model.

I'm a bit rusty on this, but something like this should work:

def save(self):
if self.project != None:
self.rolestartdate = project.startdate

#don't worry about handling if self.project == None; foreign keys
are required by default and the superclass' save method will raise an
exception
super(Role, self).save()

2009/12/6 Guy :
>
> I am using the code shown below.  The part causing the problem is the
> Role class which describes the role a person might have on a project.
> As part of that role, I would have an attribute that records the start
> and end date of the person's involvement.  The problem seems to be
> coming when I make an ill-fated attempt to define a default start date
> as the startdate of the project to which the role is linked.
>
> -code--
> from django.db import models
>
> class Project(models.Model):
>    """class to describe the attributes that characterize a project"""
>
>    #reference number for project
>    referencenum = models.CharField("reference number for project",
>                                                      max_length=20)
>    #begin date of project
>    startdate =  models.DateField()
>
> class Role(models.Model):
>    """class to describe a Person object's affiliation to a Project
> object"""
>
>    #project in which person is involved
>    project =   models.ForeignKey(Project)
>
>    #begin date of person's involvement on project; this is the
> problem line
>    rolestartdate = models.DateField(default = \
>                                Project.objects.get
> (pk=project.id).startdate)
>
> -
> when I run:
>      manage.py syncdb
> I get the following error:
>
>   rolestartdate = models.DateField(default = Project.objects.get
> (pk=project.id).st
>   artdate)
>   AttributeError: 'ForeignKey' object has no attribute 'id'
>
> I was under the impression that django creates an attribute on every
> model, foo.id, that serves as a primary key.
>
> Many thanks in advance to anyone who can explain what what I not
> grasping here.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




How to create multiple 'submit' buttons using 'forms' package

2009-12-05 Thread Ken
I have the following form, which displays nicely:

class BuySellForm(forms.Form):
symbol = forms.CharField()
shares = forms.CharField()
price = forms.CharField()

However, I can't figure out how to get multiple 'submit' buttons to
display (one 'buy' and the other 'sell'). Actually, I can't even
figure out how to get a single standard submit button to show up--
there doesn't seem to be a 'submit widget' listed in the Django book.
Or perhaps I'm just not seeing it?

As you can tell, I'm an absolute newbie. First day. Thanks for the
patience.

Ken

--

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




New to django, python, etc. - ForeignKey question

2009-12-05 Thread Guy

I am using the code shown below.  The part causing the problem is the
Role class which describes the role a person might have on a project.
As part of that role, I would have an attribute that records the start
and end date of the person's involvement.  The problem seems to be
coming when I make an ill-fated attempt to define a default start date
as the startdate of the project to which the role is linked.

-code--
from django.db import models

class Project(models.Model):
"""class to describe the attributes that characterize a project"""

#reference number for project
referencenum = models.CharField("reference number for project",
  max_length=20)
#begin date of project
startdate =  models.DateField()

class Role(models.Model):
"""class to describe a Person object's affiliation to a Project
object"""

#project in which person is involved
project =   models.ForeignKey(Project)

#begin date of person's involvement on project; this is the
problem line
rolestartdate = models.DateField(default = \
Project.objects.get
(pk=project.id).startdate)

-
when I run:
  manage.py syncdb
I get the following error:

   rolestartdate = models.DateField(default = Project.objects.get
(pk=project.id).st
   artdate)
   AttributeError: 'ForeignKey' object has no attribute 'id'

I was under the impression that django creates an attribute on every
model, foo.id, that serves as a primary key.

Many thanks in advance to anyone who can explain what what I not
grasping here.

--

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




Parsing XML in the template? (New to Django and Python)

2009-12-05 Thread sleepjunk
Hello :) I am working on a small video site that allows a user to add
a video to the site by submitting a Vimeo.com or Youtube.com URL. I'm
trying to display thumbnails without hosting them. For Vimeo videos I
need to parse an XML file to find the thumbnail location.

On my homepage I would like to display the 5 newest videos. As of now
I'm displaying every video in the database on the homepage. Each video
will have a different thumbnail and XML file to parse. As of right now
my "main_page" in my views.py file looks like this:

def home_page(request):
template = get_template('home_page.html')
video = Video.objects.all()
feed = urllib.urlopen("http://vimeo.com/api/v2/video/7875440.xml;)
tree = ET.parse(feed)
root = tree.getroot()
vimeo_thumbnail = root.findtext("video/thumbnail_medium")
variables = Context({
'video': video,
'vimeo_thumbnail': vimeo_thumbnail
})
output = template.render(variables)
return HttpResponse(output)

How can I parse a different XML file for every video? Thank you much.
Again, I am new and could be going about this completely wrong and
gladly accept any feedback you have.

Thank you,
Matt

--

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




ModelFormSet foreign keys display

2009-12-05 Thread Kev Dwyer
Hello List,

I am having problems getting the forms within a modelformset to display 
as I wish.  I'm using 
Django 1.1 with python 2.6.

The model class is:

class Availability(DefaultColumns):

"""Record analyst availability."""

date = django.db.models.ForeignKey(WorkShift)
analyst = django.db.models.ForeignKey(Analyst)
status = django.db.models.ForeignKey(AvailabilityStatus)

(DefaultColumns inherits from django.db.models.Model)

This is the WorkShift model referenced in "date":

class WorkShift(DefaultColumns):

"""A shift as originally generated."""


rota = django.db.models.ForeignKey(WorkRota)
date = django.db.models.DateField()
shift_type = django.db.models.ForeignKey(ShiftType)

def __unicode__(self):
return u'' % (self.date, self.shift_type)

class Meta:

"""Internal class."""

ordering = ['date']

The form used by the formset looks like this:

class AvailabilityForm(django.forms.ModelForm):

"""ModelForm for Availability model."""

status = django.forms.ModelChoiceField(
queryset=rota.models.AvailabilityStatus.objects.all(),
empty_label=None,
widget=django.forms.RadioSelect)

def __init__(self, *args, **kwargs):
django.forms.ModelForm.__init__(self, *args, **kwargs)
self.logger = logging.getLogger('rota.forms.AvailabilityForm')
self.logger.debug('Initialisation complete.')

class Meta:
"""Meta class."""

model = rota.models.Availability


I want the form to display the date as a read-only field, however so far 
I 
can't make this work.  The code here outputs the date as a selectable 
ModelChoiceField.  If I declare date in the ModelForm class I always end 
up 
with the id from the WorkShift object rather than the date itself.

Can you advise how I can declare date (or do something else) to make this
work as I'd like?

Many thanks,

Kev


--

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




Re: How to show site down for maintenance page

2009-12-05 Thread Chris Moffitt
Try this - http://code.google.com/p/django-maintenancemode/

-Chris

On Sat, Dec 5, 2009 at 6:54 PM, zweb  wrote:

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

--

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




How to change this function to use generic view

2009-12-05 Thread 邓超
Hi all,
  I want to change below function to use the generic view function
update_object:

@login_required
def edit_bug_page(request, bug_id = None):
if bug_id == None:
bugInstance = Bug()
else:
bugInstance = get_object_or_404(Bug, pk = bug_id)
members = bugInstance.project.member.order_by('member')

if request.user not in members:
return HttpResponseRedirect('/bug/fail/')

if request.method == 'POST':
form = BugForm(request.POST, instance = bugInstance)

if form.is_valid():
bug = form.save()

return HttpResponseRedirect('/bug/success/')
else:
form = BugForm(instance = bugInstance)

variables = RequestContext(request, {'form': form})

return render_to_response('add_bug.html', variables)

But how to use the update_object function in my views.py? Someone can help
me? Thanks a lot!
-- 
Deng Chao

--

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




How to show site down for maintenance page

2009-12-05 Thread zweb
What is the best way to show site down for maintenance page ?

--

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




Re: Trying to Migrate Databases: Getting "auth_group_permissions' doesn't exist"

2009-12-05 Thread Daniel Howard
On Mon, Nov 30, 2009 at 1:41 PM, Daniel Howard  wrote:
> Hello,
>
> I started development on an older version of Django, and the system
> Django was subsequently upgraded.  The system is presently at 1.1.
>
> I am trying to migrate from sqlite to MySQL.  I have tried a few
> different approaches but none seem to work.  Either of these
> approaches yields the same flavor of failure:
[ . . . ]

After a lot of false starts and dead ends, I eventually got the
migration from sqlite to MySQL worked out.  My notes on this process
are at:

http://dannyman.toldme.com/2009/12/04/django-migrate-database-sqlite-mysql/

Sincerely,
-daniel

-- 
http://dannyman.toldme.com

--

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




Re: Pydev + Django + Ubuntu 9.10

2009-12-05 Thread Info Cascade
Turkan,

Perhaps this will help. I just have done this
(PostGIS/Eclipse/Pydev/Django on Ubuntu 9.10) and it's working great! 
After having problems because I had installed Postgres 8.4, I found the
script below, on the net somewhere.
Modify, as appropriate, if you don't need GIS.

You may also want this, for full support in pgadmin3:
apt-get install postgresql-contrib-8.3
cd /usr/share/postgresql/8.3/contrib
psql -U  postgres < adminpack.sql

Getting Eclipse working took some time, and I learned a lot from this:
http://www.socialtext.net/hearplanet/index.cgi?action=display;is_incipient=1;page_name=http%3A%2F%2Fblog.vlku.com%2Findex.php%2F2009%2F06%2F10%2Fdjangoeclipse-with-code-complete-screencast%2F

Best,
Liam
> # Script for installing Django, PostgreSQL, and PostGIS
> # Run with sudo
>
> # Install Django:
> apt-get install python-django python-django-doc
>
> # Install PostgreSQL 8.3
> apt-get install postgresql-8.3 python-psycopg2 pgadmin3
>
> # Packages needed by GeoDjango (gdal is optional, but useful)
> apt-get install postgresql-8.3-postgis binutils libgdal1-1.5.0
> gdal-bin libgeos-3.1.0 proj libpq-dev
>
> # Set yourself up as a PostgreSQL superuser
> su - postgres
> createuser --createdb --superuser `whoami`
>
> # Create the template spatial database
> createdb -E UTF8 template_postgis
> createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
>
> # Allows non-superusers the ability to create from this template
> psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE
> datname='template_postgis';"
>
> # Load the PostGIS SQL routines
> psql -d template_postgis -f
> /usr/share/postgresql-8.3-postgis/lwpostgis.sql
> psql -d template_postgis -f
> /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql
>
> # Enable users to alter spatial tables
> psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
> psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
> exit





turkan wrote:
> Hello.
>
> I know ... this topic was discussed quite often. But all the hints I
> found don't really help to setup Eclipse/Pydev under Ubuntu 9.10 for
> Django 1.1 (from the official Ubuntu repositories).
> I tried to follow this tutorial (http://solyaris.wordpress.com/
> 2007/05/16/how-to-djangopydev-on-feisty/), but /usr/share/python-
> support/python-django/ is not present anymore under Ubuntu 9.10.
> So I tried to add /usr/shared/pyshared/django, usr/share/python-
> support/, /usr/lib/python/django to the PYTHONPATH, but without any
> success. My projects still come up with many "undefined variable"
> errors. For example an error is presented for User.add_to_class.
> add_to_class (add_to_class is unkown), even if User seems to be known.
> I read that it is difficult for the IDE to recognize all variables,
> cause of the way some of those are generated on the fly (I am also new
> to Python). But is it possible to get error free projects with Django
> + Pydev?
> Why does Aptana for example does provide such a good Ruby support?
> Does Python/Django provide more dynamic stuff than Ruby?
>
> Regards,
> Kai
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>   

--

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




Re: Initial values and unbound forms (apparently a bug?)

2009-12-05 Thread Gaffar Durmaz
i use in my form
form = MatchForm(instance=match, initial={'startDate':'%s-%s-%s'%
(y,mo,d),'startTime':'%s:%s:%s'%(h,mi,s)})

but ur initial value is a list, initial=[bla bla]
instead of this use  dict {}

On Dec 5, 11:35 pm, Liam  wrote:
> Haven't been able to get this to work, and no one has responded with
> advice or a workaround.
> Can anyone confirm that this is a bug, or tell me what I'm doing
> wrong?
>
> On Dec 3, 5:28 pm, Info Cascade  wrote:
>
> > Hi --
>
> > I am trying to set some reasonable defaults asinitialfieldvaluesin a
> > formset.  Here is what I'm doing
>
> > section_form_initial = {
> >             'audio_publisher':default_publisher,
> >             'audio_license':default_license,
> >             'text_format':default_text_format
> >             }
>
> > If I do this:
> >         section_forms = SectionFormSet(initial=[section_form_initial])
> > Only the first form has theinitialvalues.
>
> > If I do this:
> >         section_forms =
> > SectionFormSet(initial=[section_form_initial]*extra_form_count)
> > The first  forms haveinitialvalues, but the formset creates an
> > additional  forms.
>
> > How can I setinitialvaluesfor the correct number of forms?
>
> > Liam

--

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




Re: How to get the last item of array in a built-in template tag?

2009-12-05 Thread Gaffar Durmaz
if u register EXPR tag in ur templatetag
for example ur templatetag file is mytags.py
in ur template load this as like {% load mytags %}
so
{% expr matchList.count() as i %}
i is {{i}}
{{matchList.i}}

i does not tried this but i think it will..


On Dec 5, 10:19 pm, workingbird  wrote:
> in built-in template tags, i just know to get item of array by
> index,just like:
> {{ my_array.2 }}
>
> but if i want to get the last, how should i do?  i've tried
> {{ my_array.-1 }}, but it seems something wrong.
>
> any help will be greatly appreciated.

--

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




Pydev + Django + Ubuntu 9.10

2009-12-05 Thread turkan
Hello.

I know ... this topic was discussed quite often. But all the hints I
found don't really help to setup Eclipse/Pydev under Ubuntu 9.10 for
Django 1.1 (from the official Ubuntu repositories).
I tried to follow this tutorial (http://solyaris.wordpress.com/
2007/05/16/how-to-djangopydev-on-feisty/), but /usr/share/python-
support/python-django/ is not present anymore under Ubuntu 9.10.
So I tried to add /usr/shared/pyshared/django, usr/share/python-
support/, /usr/lib/python/django to the PYTHONPATH, but without any
success. My projects still come up with many "undefined variable"
errors. For example an error is presented for User.add_to_class.
add_to_class (add_to_class is unkown), even if User seems to be known.
I read that it is difficult for the IDE to recognize all variables,
cause of the way some of those are generated on the fly (I am also new
to Python). But is it possible to get error free projects with Django
+ Pydev?
Why does Aptana for example does provide such a good Ruby support?
Does Python/Django provide more dynamic stuff than Ruby?

Regards,
Kai

--

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




Re: Initial values and unbound forms (apparently a bug?)

2009-12-05 Thread Liam
Haven't been able to get this to work, and no one has responded with
advice or a workaround.
Can anyone confirm that this is a bug, or tell me what I'm doing
wrong?

On Dec 3, 5:28 pm, Info Cascade  wrote:
> Hi --
>
> I am trying to set some reasonable defaults asinitialfieldvaluesin a
> formset.  Here is what I'm doing
>
> section_form_initial = {
>             'audio_publisher':default_publisher,
>             'audio_license':default_license,
>             'text_format':default_text_format
>             }
>
> If I do this:
>         section_forms = SectionFormSet(initial=[section_form_initial])
> Only the first form has theinitialvalues.
>
> If I do this:
>         section_forms =
> SectionFormSet(initial=[section_form_initial]*extra_form_count)
> The first  forms haveinitialvalues, but the formset creates an
> additional  forms.
>
> How can I setinitialvaluesfor the correct number of forms?
>
> Liam

--

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




How to get the last item of array in a built-in template tag?

2009-12-05 Thread workingbird
in built-in template tags, i just know to get item of array by
index,just like:
{{ my_array.2 }}

but if i want to get the last, how should i do?  i've tried
{{ my_array.-1 }}, but it seems something wrong.

any help will be greatly appreciated.

--

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




Re: Porting issu 0.96 > 1.0

2009-12-05 Thread Daniel Roseman
On Dec 5, 4:14 pm, Robert  wrote:
> Hi,
>
> I try to run an app that ran successfully on 0.96 but doesn't run on
> version 1.1.1.
>
> I have validated my models.py with the command python manage.py
> validate.
>
> It output a syntax error in this line:
>
> if not force_update and self.next_update and self.next_update >
> datetime.datetime.now():
>             return
>
> I have looked through an article about porting on djangoproject.com
> but I didn't see anything there that could give me a clue.
>
> Are you able to spot the error?
>
> Thanks
>
> Robert

Do you think it might be useful to actually post the traceback, plus
some context for the line the error is on?
--
DR.

--

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




Re: DRY up your Django templates with Showell Markup

2009-12-05 Thread David Martorana
I wrote this rather quickly.  It allows you to put a template.showell
file in each app folder, and will render the templates on demand if
you call "render_showell_to_response(...)".  It'll check the last
modification time of the .showell files, and re-renders them if
they've changed, allowing you to come close to ignoring any running of
the Showell pre-processor on your own.

===

import os, sys
import showell

from django.conf import settings
from django.utils.importlib import import_module
from django.shortcuts import render_to_response

from datetime import datetime

_SHOWELL_FILES_ = []

def render_showell_to_response(template, *args, **kwargs):
'''
Monitor any templates.showell file in an app folder
for changes, and republish them if necessary before
serving up the request
'''
# Get a list of app showell files
# Runs only once
if len(_SHOWELL_FILES_) == 0:
for app in settings.INSTALLED_APPS:
m = import_module(app)
for path in m.__path__:
sfile = os.path.join(path, 'templates.showell')
if os.path.exists(sfile):
_SHOWELL_FILES_.append(sfile)

# Check the date of each showell file
for sfile in _SHOWELL_FILES_:
if not hasattr(settings, '_SHOWELL_LAST_RENDERED_') or \
datetime.fromtimestamp(os.path.getmtime(sfile)) >
settings._SHOWELL_LAST_RENDERED_:
#print 'Republishing %s' % sfile
showell.publish(sfile)

# Set the last time we looked
settings._SHOWELL_LAST_RENDERED_ = datetime.now()

# Render normal template
return render_to_response(template, *args, **kwargs)

On Nov 27, 1:08 pm, Steve Howell  wrote:
> I would like to announce an early version ofShowellMarkup.  It
> allows you or your designer to create web pages without the visual
> clutter of , , {% endfor %}, {% endwith %}, and friends.
>
> Unlike templating solutions that compete with Django, theShowell
> Markup plays nice with Django and still delegates all the heavy
> lifting to Django, so you still get variable interpolation, extends,
> custom filter tags, include, etc. from Django.
>
> ShowellMarkup just does two jobs and does them well:
>
>   1. Allow for indentation-based blocking (both for HTML and Django
> tags)
>   2. Allow for clean HTML one-liners that truly separate markup from
> content.
>
> The implementation ofShowellMarkup is just a preprocessor to publish
> Django templates.  You edit theShowellMarkup from a master file and
> then publish the templates to their locations within the Django
> directory structure and you're done.   You can keep both markups under
> source control.  The preprocessor writes clean markup, so you can
> debug at the Django level as needed.  Also, you are not forced to 
> useShowellidioms everywhere; normal Django and HTML still passes through
> the preprocessor without modification.
>
> You can find the implementation here:
>
> http://www.djangosnippets.org/snippets/1819/
>
> The indentation feature is, of course, inspired by Python/YAML/HAML/
> etc.
>
> The one-liner syntax is inspired by Django's use of pipes to implement
> filters.
>
> Here are some examples (some of which look better in a monospace
> font)...
>
>     You can use indentation syntax for HTML tags like table.
>
>     Instead of this...
>
>     
>         
>             
>                 Right
>             
>             
>                 Center
>             
>             
>                 Left
>             
>         
>     
>
>     You can write DRY code this...
>
>     >> table
>         >> tr
>             >> td
>                 Right
>             >> td
>                 Center
>             >> td
>                 Left
>
>     Lists work the same way, and note that attributes are not a
> problem.
>
>     Instead of this...
>
>     
>         
>             
>                 One
>             
>             
>                Two
>             
>         
>     
>
>     You can write DRY code this...
>
>     >> div class="spinnable"
>         >> ul
>             >> li id="item1"
>                 One
>             >> li id="item2"
>                Two
>
>     This tool should play nice with most templating engines, but it
> has
>     specific support for Django.
>
>     Instead of this...
>
>     {% extends 'base.html' %}
>     {% load smartif %}
>
>     {% block body %}
>         {% for book in books %}
>             {{ book }}
>         {% endfor %}
>
>         {% if condition %}
>             Display this
>         {% elif condition %}
>             Display that
>         {% else %}
>             {% include 'other.html' %}
>         {% endif %}
>     {% endblock %}
>
>     You can write DRY code this...
>
>     %% extends 'base.html'
>     %% load smartif
>
>     %% block body
>         %% for book in books
>             {{ book }}
>
>         %% if condition
>             Display this
>         %% elif condition
>         

[ANN] obviews: object oriented views

2009-12-05 Thread Manu
Hi all,

My first post to share an habit of mine that you might find useful: it
deals with views and wraps them into objects.

I have replaced the functions with objects for a while now, found it
very handy and add pieces of code here and there in my little home-
land, but never shared it. Which might be common, but still not really
grateful. So I am refactoring all bit by bit and making some releases
when I feel its readable. The starting point if you are interested
could be on www.obviews.com, a demo web-site that will replace any
long speech.

Do not hesitate posting some feedback,
Manu

--

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




Porting issu 0.96 > 1.0

2009-12-05 Thread Robert
Hi,

I try to run an app that ran successfully on 0.96 but doesn't run on
version 1.1.1.

I have validated my models.py with the command python manage.py
validate.

It output a syntax error in this line:

if not force_update and self.next_update and self.next_update >
datetime.datetime.now():
return

I have looked through an article about porting on djangoproject.com
but I didn't see anything there that could give me a clue.

Are you able to spot the error?

Thanks

Robert

--

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




Re: How to get timeuntil tag to display minutes?

2009-12-05 Thread Preston Holmes
Not simply. The design of the tag to drop smaller time frames the
further out you are.

The source is all there for you to copy and modify into your own
custom filter, but that may be more than you want to bother with...

-Preston


On Dec 4, 3:22 pm, Continuation  wrote:
> I use the timeuntil tag in my template:
>
> (( object.end_time|timeuntil }}
>
> where end_time is a DateTimeField.
>
> What I got is output like "2 days, 23 hours"
>
> Is there any way to get timeuntil to display minutes as well?
>
> Thanks

--

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




Re: What apps do besides provide views?

2009-12-05 Thread Preston Holmes


On Dec 3, 12:02 pm, Wayne Koorts  wrote:
> >> > remember that an app can do a lot more than provide views.
>
> >> Explain this one to me.  AFAICS, its just http request/response all the 
> >> way down and this is basically done by getting a
>
> > An app can expose views, indeed. It can also expose models - one of
> > the most important parts of an application -, templatetags, filters,
> > forms, fields, widgets etc. FWIW, the views are perhaps one of the
> > less important thing an app has to offer - and obviously the most easy
> > to factor out, cf genericviews. Models, OTHO, are really the core. If
> > you end up writing most of your code in views, then you more than
> > probably failed to identify what belongs to the model and what belongs
> > to the views. The fact that "views" are a mandatory part of the
> > request-response cycle doesn't mean they are the most important part
> > of the app.
>
> Can anyone point out a section in the docs (or anywhere else actually)
> the Django "app" concept?  I've had a look through the docs but
> haven't been able to find anything specifically about that.

This is not very well documented in official docs, and is really a bit
amorphous.

I like to think of an app is to Django as a Class is to Python.

That it is an encapsulation of code including attributes (models) and
methods (views) that provide some sort of defined value when combined
with other Classes (apps) to make a project.

-Preston

>
> Regards,
> Wayne

--

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




Re: Where to store repetitive form logic?

2009-12-05 Thread Preston Holmes


On Dec 4, 6:43 pm, jwpeddle  wrote:
> Not having any luck with this. Surely there's a simple example out
> there somewhere of view agnostic DRY form logic.

The old thread you point to still makes sense.

A redirect can only happen in response to a request

a request is handled by a view

It sounds like you need a view in your comment app that just handles
comment posts in an agnostic way and redirects back to the page object
that holds the comments.

-Preston

>
> On Dec 4, 10:43 am, jwpeddle  wrote:
>
>
>
> > That is definitely one approach I hadn't considered, and just might
> > work in my situation.
>
> > On Dec 4, 10:13 am, Heigler  wrote:
>
> > > I think the way is build your own generic view if you have customized
> > > things like that comment tag.

--

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




Paginated objects in django sitemap

2009-12-05 Thread Alessandro Ronchi
I have some objects that needs to be paginated . I want to get all my pages
on my sitemap.
Is there any smart way to make items(self) returns all the pages for that
objects and not only the get_absoute_url without page= get variable?

-- 
Alessandro Ronchi

http://www.soasi.com
SOASI - Sviluppo Software e Sistemi Open Source

http://hobbygiochi.com
Hobby & Giochi, l'e-commerce del divertimento

--

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




Re: my http://site/admin link

2009-12-05 Thread Ishwor Gurung
Hello,

2009/12/5 rhce.san :
> i set up django perfectly and added few apps and ran the syncdb , but
> still i am facing issue when i go the http://site/admin link.
>
> It logs in but doesn't provide the apps info there it provides just
> the blank page.
>
> Can any one please help, please also cc to rhce@gmail.com when
> ever you answer the query.

Register you app with the admin site.
http://docs.djangoproject.com/en/dev/intro/tutorial02/#make-the-poll-app-modifiable-in-the-admin
-- 
Regards,
Ishwor Gurung

--

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




my http://site/admin link

2009-12-05 Thread rhce.san
i set up django perfectly and added few apps and ran the syncdb , but
still i am facing issue when i go the http://site/admin link.

It logs in but doesn't provide the apps info there it provides just
the blank page.

Can any one please help, please also cc to rhce@gmail.com when
ever you answer the query.

Thanks,
San

--

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