Пример #1
0
    def pledge(self, geuser):
        """geuser pledges to perform this action.
        Records the Pledge, posts a message to community feed, and clears relevant caches"""

        _, is_created = Pledge.objects.get_or_create(action = self, user = geuser)

        if is_created:
            entry = Entry(who = geuser,
                          msg = 'pledged to <strong>%s</strong>' % self.title,
                          campaign = self.campaign)
            entry.save()
            EntryView.refresh_recent_activity(self.campaign)
            Entry.objects.clear_dashboard_cache(self.campaign)

        Action.objects.clear_dashboard_cache(self.campaign)
Пример #2
0
def profile_settings(request, campaign_slug):
    """Settings page. Ajax only"""

    current_user = request.user.get_profile()
    campaign = Campaign.objects.default(campaign_slug, get_current_organization())

    if request.method == 'POST':
        form = SettingsForm(current_user, get_current_organization(), request.POST) 
        if form.is_valid():
            form.save()

            if 'survey' in request.GET:
                # Survey doesn't change any visible fields, so no need to reload page,
                # and 'Upload profile pic' bubble only shows on first load, 
                # so redirect would clear it.
                return HttpResponse(
                        JSONEncoder().encode({'close': True}), 
                        mimetype='application/json')
            else:
                # Refresh the cache
                cache.delete( Entry.objects.dashboard_cache_key(campaign, current_user) )
                EntryView.refresh_recent_activity(campaign)
                campaign.users_json(force=True)

                campaign_url = reverse('campaign_home', kwargs={'campaign_slug': campaign_slug})
                return HttpResponse(
                        JSONEncoder().encode({'location': campaign_url}), 
                        mimetype='application/json')
    else:
        form = SettingsForm(current_user, get_current_organization())

    html = render_to_string(
            'profile/settings_include.html',
            {'form': form, 'campaign': campaign},
            context_instance=RequestContext(request))

    result = {'html': html, 'close': False}
    encoder = JSONEncoder(default = json_encoder_default)
    return HttpResponse(encoder.encode(result), mimetype='application/json')