rendering to template help

2010-05-24 Thread Pirate Pete
I have been trying to get some kind of kind response from django for a
few days now and it has been very unkind to me :P

basically i need to create a page that has a video title (link) and an
average rating with the amount of people that rated it in brackets.

so it will look like ... Awesom video 5(3)  : where awesom video is
the name 5 is the average rating and 3 people have rated the video.

i can display the videos easily by using a for loop in the template
however i am having much difficulty displaying the average ratings and
count

rating model:


class RatingManager(models.Manager):
def average_rating(self,video):
avg = 
Rating.objects.filter(id=video.id).aggregate(Avg('rating'))
return avg

def vote_count(self,video):
num = 
Rating.objects.filter(id=video.id).aggregate(Count('rating'))
return num

class Rating(models.Model):
user = models.ForeignKey(User, unique=False)
vid = models.ForeignKey(Video, unique=False)
rating = models.PositiveIntegerField(help_text="User rating of the
video.")
objects = RatingManager()

def __str__(self):
return str(self.user) + "'s rating: " + str(self.vid)



View:

def index(request):
videos = Video.objects.all()
dict= []
for vid in videos:
ratec =
(Rating.objects.vote_count(vid),Rating.objects.average_rating(vid))
dict.append(ratec)

return render_to_response("index.html",
{'videos':videos,'ratecount':dict})



index.html: (please note ratecount is just trial and error this could
potentially be by all means completely incorrect)

TitleAverage Rating (Vote Count)
{% for video in videos %}
{{video.title}}{{ratecount.0.1}}({{ratecount.0.0}})
{% endfor %}



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.



db autoclobbering with automated tests

2010-05-24 Thread dmitry b
Hi,

I'm in the process of setting up automated selenium tests for a django
app using Hudson.  As part of the build script, I'm starting up a test
server:

$> python manage.py testserver --addrport 0.0.0.0:8080 ../../test/gui/
seed_data.json

However, when this line runs, I get the following message:

('42000', "[42000] [Microsoft][ODBC SQL
 Server Driver][SQL Server]Database 'test_Tools' already exists.
Choose a different database name. (1801) (SQLExecDirectW)")
Type 'yes' if you would like to try deleting the test database
'test_Tools',
 or 'no' to cancel: Traceback (most recent call last):

I see that the test apis have an option to autoclobber the database.
However, I cannot find a way to tell django to just quietly recreate
the database from the command line.  What am I missing?


Thanks
D.

-- 
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: inclusion tag variable resolving

2010-05-24 Thread Dennis Kaarsemaker
On ma, 2010-05-24 at 13:49 -0700, christian verkerk wrote:
> i made an inclusion tag for making an image button of varying widths,
> which i call through:
> 
> {% make_button 'click me' item.get_absolute_url %}
> 
> i then resolve the second param in context for the button link,
> however i would like to be able to do something along the lines of:
> 
> {% make_button 'click me' '/specific/url/with/{{foo}}' %}
> 
> in specific cases. resolving that whole second string into context to
> get something like '/specific/url/with/bar/'

{% make_button 'click me' '/specific/url/with/%s' foo %}

-- 
Dennis K.

They've gone to plaid!

-- 
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: inclusion tag variable resolving

2010-05-24 Thread Scott Gould
Can you not simply pass foo:

{% make_button 'click me' foo %}

... resolve it, and then use either its .get_absolute_url() or
something other url, depending on what foo is? The inclusion tag's
python code is far more equipped to deal with logic decisions, special
cases, etc. than the template is.

On May 24, 4:49 pm, christian verkerk 
wrote:
> i made an inclusion tag for making an image button of varying widths,
> which i call through:
>
> {% make_button 'click me' item.get_absolute_url %}
>
> i then resolve the second param in context for the button link,
> however i would like to be able to do something along the lines of:
>
> {% make_button 'click me' '/specific/url/with/{{foo}}' %}
>
> in specific cases. resolving that whole second string into context to
> get something like '/specific/url/with/bar/'
>
> --
> 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 
> athttp://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: ANN: Django 1.2.1 released

2010-05-24 Thread Dhruv Adhia
Awesome! Congrats guys!

Dhruv Vinodrai Adhia
http://www.thirdimension.com



On Mon, May 24, 2010 at 12:33 PM, James Bennett wrote:

> Following up on last week's Django 1.2 release, today we'd like to
> announce Django 1.2.1, the first bugfix release in the 1.2 series:
>
> * Announcement blog post:
> http://www.djangoproject.com/weblog/2010/may/24/121/
> * Download: http://www.djangoproject.com/download/
> * Checksums: http://media.djangoproject.com/pgp/Django-1.2.1.checksum.txt
>
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of
> correct."
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To post to this group, send email to django-develop...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-developers+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-developers?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.



view permission on django admin

2010-05-24 Thread rahul jain
Hi Django,

I know this has been discussed lot of times but not implemented on
admin because django developers think that django admin will not be
just used for viewing.

Anyways, I need it for my model.

I went through the path but was not able to solve this problem.

http://code.djangoproject.com/ticket/7150

I think this patch is for some old code

Here what its missing

a/django/contrib/admin/sites.py
old new 
281 281 'add': 
model_admin.has_add_permission(request),
282 282 'change':
model_admin.has_change_permission(request),
283 283 'delete':
model_admin.has_delete_permission(request),
284 'view': 
model_admin.has_view_permission(request),
284 285 }
285 286 
286 287 # Check whether user has any perm for this 
module.

I checked sites.py but none of the above exists now.

Anyone know the recent patch for this.

Thanks.

--RJ

-- 
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.



inclusion tag variable resolving

2010-05-24 Thread christian verkerk
i made an inclusion tag for making an image button of varying widths,
which i call through:

{% make_button 'click me' item.get_absolute_url %}

i then resolve the second param in context for the button link,
however i would like to be able to do something along the lines of:

{% make_button 'click me' '/specific/url/with/{{foo}}' %}

in specific cases. resolving that whole second string into context to
get something like '/specific/url/with/bar/'

-- 
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: Custom filterspec

2010-05-24 Thread Daniel Roseman
On May 24, 5:36 pm, Thales  wrote:
> Good afternoon,
>
> I am trying to make this snippet work:http://djangosnippets.org/snippets/1051/


>
> But I am always getting the error "__init__() got an unexpected
> keyword argument 'field_path'",

We'll need to see the actual traceback. `field_path` doesn't occur
either in that snippet or in the code you have pasted, or in Django's
own code, so it must be coming from somewhere else in your code.
--
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: passing variable values in javascript being served statically

2010-05-24 Thread Daniel Roseman
On May 24, 8:24 pm, gvkalra  wrote:
> Hi.
> I am trying to do something like this:
>
> views.py
>
> return render_to_response('abc.html',{'variable':value})
>
> abc.html
>
> 
> dummy = {{variable}};
> 
> 
>
> My problem:
> I am not able to use dummy inside xyz.js ... OR is there some
> other way by which I can use {{variable}} inside xyz.js ??

This is generally the right approach. What is the value of 'variable'
though? If it's a string, you'll need to wrap it in quotes for the
javascript to be valid. Also, the rule with Javascript is that
variables defined outside of a function need to be defined with "var"
to be global.

  var dummy = "{{variable}}";
--
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: passing variable values in javascript being served statically

2010-05-24 Thread gvkalra
yes it is a js problem .. But I was looking for a way in which I
can use Django Variables passed by a view function inside a statically
served js ... since it's static, the template engine won't parse
it .

On May 25, 12:38 am, Rodrigue Villetard 
wrote:
> Hello,
>
> I think you can use xyz.js as a template :
>  return render_to_response('xyz.js'
>
>
>
> > {'variable':value})
>
> Your problem is more a javscript problem of variable visibility as  src="xyz.js"> doesn't properly make an include.
>
> regards.
>
> 2010/5/24 gvkalra 
>
>
>
> > Hi.
> > I am trying to do something like this:
>
> > views.py
>
> > return render_to_response('abc.html',{'variable':value})
>
> > abc.html
>
> >