コード例 #1
0
ファイル: campaign.py プロジェクト: hderaps/bccf
def create(request):
    form = CampaignForm(initial={'user':request.user, 'by_user':True, 'status':1, 'approve':False})
    if request.method == 'POST':
        form = CampaignForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            
            # Send moderation email
            send_moderate("A Campaign needs moderation", context={'campaign':form.instance.pk})            
            
            messages.success(request, 'Campaign successfully created. The campaign is subject to review and can be taken down without notice.')
            return HttpResponseRedirect(form.instance.edit_url())
        else:
            messages.error(request, 'Please fix the errors below')
    title = 'Create Campaign'
    context = RequestContext(request, locals())
    return render_to_response('bccf/campaign_create.html', {}, context)   
コード例 #2
0
ファイル: campaign.py プロジェクト: hderaps/bccf
def edit(request, slug):
    user = request.user
    profile = user.profile
    
    if not Campaign.objects.filter(slug=slug, user=user).exists():
        return HttpResponseRedirect('/')
        
    campaign = Campaign.objects.get(slug=slug)
    form = CampaignForm(instance=campaign)
    title = 'Edit %s' % campaign.title    
    
    if request.method == 'POST':
        form = CampaignForm(request.POST, request.FILES, instance=campaign)
        if form.is_valid():
            form.save()
            messages.success(request, 'Campaign successfully updated')    
            title = 'Edit %s' % form.instance.title
        else:
            messages.error(request, 'Please fix the errors below')
       
    context = RequestContext(request, locals())
    return render_to_response('bccf/campaign_create.html', {}, context)