File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed
Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 3838 "Programming Language :: Python :: 3.7" ,
3939 "Programming Language :: Python :: 3.8" ,
4040 "Programming Language :: Python :: 3.9" ,
41+ "Programming Language :: Python :: 3.10"
42+ "Programming Language :: Python :: 3.11"
4143 ],
4244)
Original file line number Diff line number Diff line change 11{% load vote %}
2- {% for comment in comments %}
3- {{comment.content}} {% vote_exists comment user %}
4- {% endfor %}
2+ < ol >
3+ {% for comment in comments %}
4+ < li >
5+ {{comment.content}} - up:{% vote_count comment "up" %} - down: {% vote_count comment "down" %} - exists_up:
6+ {%vote_exists comment user %} - exists_down: {% vote_exists comment user "down"%}
7+ </ li >
8+ {% endfor %}
9+ </ ol >
Original file line number Diff line number Diff line change 33from django import template
44from django .contrib .auth .models import AnonymousUser
55
6- from vote .models import UP
6+ from vote .models import UP , DOWN
77
88register = template .Library ()
99
1010
1111@register .simple_tag
12- def vote_exists (model , user = AnonymousUser (), action = UP ):
12+ def vote_exists (model , user = AnonymousUser (), action = "UP" ):
1313 if user .is_anonymous :
1414 return False
15+ if action .lower () == "up" :
16+ action = UP
17+ else :
18+ action = DOWN
1519 return model .votes .exists (user .pk , action = action )
20+
21+
22+ @register .simple_tag
23+ def vote_count (model , action = "UP" ):
24+ if action .lower () == "up" :
25+ action = UP
26+ else :
27+ action = DOWN
28+ return model .votes .count (action = action )
You can’t perform that action at this time.
0 commit comments