Changeset 102
- Timestamp:
- 02/05/09 21:07:35 (1 year ago)
- Files:
-
- trunk/news/views.py (modified) (1 diff)
- trunk/polls/views.py (modified) (2 diffs)
- trunk/quicks/views.py (modified) (1 diff)
- trunk/settings.py (modified) (1 diff)
- trunk/templates/portal.html (modified) (1 diff)
- trunk/templates/quicks/display.html (deleted)
- trunk/templates/quicks/list.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/news/views.py
r101 r102 35 35 36 36 return direct_to_template(request, 'news/display.html', {'news_list':news_list, 'qnews':True}) 37 37 38 38 def view(request, slug): 39 39 #raise Exception(repr(offset)) trunk/polls/views.py
r100 r102 58 58 selected_choice.save() 59 59 request.session['has_voted'] = True 60 60 61 61 poll = Poll.objects.get(pk=request.POST['poll_id']) 62 62 mydict = {'poll':poll} … … 64 64 except Poll.DoesNotExist: 65 65 raise Http404 66 return render_to_response('polls/votes.html', mydict , context_instance=RequestContext(request))66 return render_to_response('polls/votes.html', mydict) trunk/quicks/views.py
r101 r102 78 78 return HttpResponseRedirect('/') 79 79 80 def vote(request): 81 if request.method == 'POST': 82 form = ContactForm(request.POST) 80 def addvote(request): 81 #raise Exception(repr(request.POST)) 82 if request.user.is_authenticated(): 83 try: 84 if request.method == 'POST': 85 q = Quicks.objects.get(pk=request.POST['quick_id']) 86 voto = q.votes 87 new_vote = voto + 1 if request.POST['sense'] == 1 else voto - 1 88 q.votes = new_vote 89 q.save() 90 # has voted 91 request.session['hvoted'][q.id] = True 92 request.session['sense'][q.id] = 1 if request.POST['sense'] == 1 else 0 93 mydict = {'votes':new_vote, 'sense': request.POST['sense']} 94 95 except Quicks.DoesNotExist: 96 raise Http404 97 return render_to_response('polls/votes.html', mydict, context_instance=RequestContext(request)) 98 83 99 84 100 class Feed(models.Model): trunk/settings.py
r95 r102 68 68 SECRET_KEY = 'z7lwsg43t#1+d3redr56_h6m*(n=snx0kxvejw$e0+_ido' 69 69 70 # A tuple of callables that are used to populate the context in RequestContext 71 # http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEMPLATE_CONTEXT_PROCESSORS 72 TEMPLATE_CONTEXT_PROCESSORS = ( 73 'django.core.context_processors.auth', 74 'django.core.context_processors.debug', 75 'django.core.context_processors.i18n', 76 'django.core.context_processors.media', 77 'django.core.context_processors.request', 78 ) 79 70 80 # List of callables that know how to import templates from various sources. 71 81 TEMPLATE_LOADERS = ( trunk/templates/portal.html
r100 r102 62 62 {% last_posts %} 63 63 64 65 64 {# Show the poll #} 66 65 {% if not request.session.has_voted %} trunk/templates/quicks/list.html
r101 r102 1 1 <script type="text/JavaScript"> 2 $(document).ready(function() 3 { 4 // generate markup 5 var ratingMarkup = ["Please rate: "]; 6 for(var i=1; i <= 5; i++) 7 { 8 ratingMarkup[ratingMarkup.length] = "<a href='#'>" + i + "</a> "; 9 } 10 // add markup to container and applier click handlers to anchors 11 $("#rating").append( ratingMarkup.join('') ).find("a").click(function(e) { 12 e.preventDefault(); 13 // send requests 14 $.post("/quick/rate", {rating: $(this).html()}, function(xml) { 15 // format result 16 var result = [ 17 "Thanks for rating, current average: ", 18 $("average", xml).text(), 19 ", number of votes: ", 20 $("count", xml).text() 21 ]; 22 // output result 23 $("#rating").html(result.join('')); 24 } ); 25 }); 26 }); 2 //<![CDATA[ 3 //global vars 4 var inputPollid = $("#poll_id"); 5 var loading = $("#loading2"); 6 var div2update = $("#div2update"); 7 $("#votebutton").attr({ disabled:false, value:"Vote" }); 8 9 function updateDiv() 10 { 11 //just for the fade effect 12 div2update.hide(); 13 loading.fadeIn(); 14 //send the post to view 15 $.ajax({ 16 type: "POST", url: "/polls/results/", data: "action=update", 17 complete: function(data) 18 { 19 loading.fadeOut(); 20 div2update.html(data.responseText); 21 div2update.fadeIn(2000); 22 } 23 }); 24 } 25 26 //check if all fields are filled 27 function checkForm(poll_id, choice) 28 { 29 if ( poll_id && choice) 30 return true; 31 else 32 return false; 33 } 34 35 //on submit event 36 function mod(quick_id, sense) 37 { 38 //alert('quick_id: ' + quick_id + ' sense: ' + sense); 39 var divArrow = 'arrows_' + quick_id; 40 $(divArrow).attr({ value:"" }); 41 // we deactivate submit button while sending 42 //send the post to django views.py 43 $.ajax({ 44 type: "POST", url: "/quicks/addvote/", data: "action=insert&quick_id=" + quick_id + "&sense=" + sense, 45 complete: function(data) 46 { 47 $(divArrow).html(data.responseText); 48 // updateDiv(); 49 } 50 }); 51 //we prevent the refresh of the page after submitting the form 52 return false; 53 } 54 55 //]]> 27 56 </script> 57 {% spaceless %} 28 58 29 59 <h3>Quick News</h3> … … 33 63 <div id="thingrow_t3_7i65c" class="odd link" > 34 64 <p id="pre_t3_7i65c"></p><span class="rank" style="width: 1.10ex;" id="num_t3_7i65c">{{forloop.counter}}</span> 35 36 <div id="arrows_ t3_{{quick.id}}" class="midcol" style="width:15px;" >37 < div id="up_t3_{{quick.id}}" class="arrow up" onclick="mod('t3_{{quick.id}}', 1)" ></div>65 {% if not request.session.hvoted.id %} 66 <div id="arrows_{{quick.id}}" class="midcol" style="width:15px;" > 67 <a href="javascript:mod({{quick.id}}, 1)"><img src="/media/img/static/aupgray.gif" alt="Vote" /></a> 38 68 <div id="score_{{quick.id}}" class="score">{{quick.votes}}</div> 39 < div id="down_t3_{{quick.id}}" class="arrow down" onclick="mod('t3_{{quick.id}}', 0)" ></div>69 <a href="javascript:mod({{quick.id}}, 0)"><img src="/media/img/static/adowngray.gif" alt="Vote" /></a> 40 70 </div> 41 71 {% else %} 72 <a href="javascript:mod({{quick.id}}, 1)"><img src="/media/img/static/aupmod.gif" alt="Vote" /></a> 73 <div id="score_{{quick.id}}" class="score">{{quick.votes}}</div> 74 <a href="javascript:mod({{quick.id}}, 0)"><img src="/media/img/static/adownmod.gif" alt="Vote" /></a> 75 {% endif %} 42 76 <div id="entry_t3_7i65c" class="entry"> 43 77 <p class="title" id="titlerow_t3_7i65c"> … … 82 116 <a href="/quicks/display" id="a_report_t3_7i65c">All quick news</a> 83 117 </div> 118 {% endspaceless %}