Ejemplo n.º 1
0
def pledge(request, action_id):
    """User pledges to perform an action"""

    if request.method != 'POST':
        return HttpResponseNotAllowed(['POST'])

    current_user = request.user.get_profile()
    action = get_object_or_404(Action, pk=action_id)

    action.pledge(current_user)
    ActionView.clear_popular_cache(action.campaign)    # TODO: Should be done by ge_worker

    action_view = ActionView(action, current_user)
    action_html = render_to_string(
            'action/action_full_include.html',
            {'action': action_view, 'geuser': current_user, 'expand': True},
            context_instance=RequestContext(request))
    return HttpResponse(action_html, mimetype='text/html') 
Ejemplo n.º 2
0
def create(request, campaign_slug):
    """Create a new Action and Pledge on it"""

    if request.method != 'POST':
        return HttpResponseNotAllowed(['POST'])

    geuser = request.user.get_profile()
    if not 'title' in request.POST or not 'description' in request.POST:
        return HttpResponse('ERROR: title and description are required',
                mimetype='text/plain')
    
    title = request.POST['title']
    description = request.POST['description']

    action = Action.objects.create(
            campaign = get_current_campaign(),
            title = title,
            description = description,
            created_by = geuser)

    action.pledge(geuser)
    ActionView.clear_popular_cache(action.campaign)

    return redirect_to_indicator(request, campaign_slug=campaign_slug) 
Ejemplo n.º 3
0
 def save_model(self, request, action, form, change):
     """Clear the cache"""
     super(ActionAdmin, self).save_model(request, action, form, change)
     Action.objects.clear_dashboard_cache(action.campaign)
     ActionView.clear_popular_cache(action.campaign)