Assembla home | Assembla project page
 

Changeset 102

Show
Ignore:
Timestamp:
02/05/09 21:07:35 (1 year ago)
Author:
aarkerio
Message:

Template contexts added

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/news/views.py

    r101 r102  
    3535 
    3636    return direct_to_template(request, 'news/display.html', {'news_list':news_list, 'qnews':True}) 
    37  
     37     
    3838def view(request, slug): 
    3939    #raise Exception(repr(offset)) 
  • trunk/polls/views.py

    r100 r102  
    5858                selected_choice.save() 
    5959                request.session['has_voted'] = True 
    60                  
     60 
    6161                poll = Poll.objects.get(pk=request.POST['poll_id']) 
    6262                mydict = {'poll':poll} 
     
    6464       except Poll.DoesNotExist: 
    6565           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  
    7878    return HttpResponseRedirect('/') 
    7979 
    80 def vote(request): 
    81     if request.method == 'POST': 
    82         form = ContactForm(request.POST) 
     80def 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 
    8399     
    84100class Feed(models.Model): 
  • trunk/settings.py

    r95 r102  
    6868SECRET_KEY = 'z7lwsg43t#1+d3redr56_h6m*(n=snx0kxvejw$e0+_ido' 
    6969 
     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  
     72TEMPLATE_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 
    7080# List of callables that know how to import templates from various sources. 
    7181TEMPLATE_LOADERS = ( 
  • trunk/templates/portal.html

    r100 r102  
    6262{% last_posts %} 
    6363 
    64  
    6564{# Show the poll #} 
    6665{%  if not request.session.has_voted  %} 
  • trunk/templates/quicks/list.html

    r101 r102  
    11<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&amp;quick_id=" + quick_id + "&amp;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//]]> 
    2756</script>  
     57{% spaceless %} 
    2858 
    2959<h3>Quick News</h3> 
     
    3363<div id="thingrow_t3_7i65c" class="odd link" > 
    3464<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
    3868    <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
    4070</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 %} 
    4276<div id="entry_t3_7i65c" class="entry"> 
    4377<p class="title" id="titlerow_t3_7i65c"> 
     
    82116    <a href="/quicks/display" id="a_report_t3_7i65c">All quick news</a> 
    83117</div> 
     118{% endspaceless %}