def site_view(request): if request.method == 'POST': form = SiteForm(request.POST, request.FILES) if form.is_valid(): form.save() else: request.session['errors'] = form.errors return redirect('site') errors = request.session.get('errors') request.session['errors'] = None ctx = {'sites': Website.objects.all(), 'errors': errors} return render_to_response('dashboard/site.html', context=ctx, context_instance=RequestContext(request))
def sites_edit(request, site_id): site = get_object_or_404(ApiAccount, pk=site_id, disabled=False) if not site.user == request.user: raise Http404() error = None if request.method == 'POST': form = SiteForm(request.user, request.POST, error_class=SpanErrorList, instance=site) if form.is_valid(): form.save() messages.success(request, "Your site '%s' was saved." % site.site_prefix) return HttpResponseRedirect(reverse('sites_list')) else: form = SiteForm(request.user, initial={'site_prefix': site.site_prefix}, instance=site) return render_to_response('sites_edit.html', { 'form': form, 'site': site, }, context_instance=RequestContext(request))
def sites_add(request): if request.method == 'POST': form = SiteForm(request.user, request.POST, request.FILES, error_class=SpanErrorList) if form.is_valid(): acc = form.save(commit=False) api_key = ApiAccount.create_api_key() secret_key = ApiAccount.create_api_key() acc.api_key = api_key acc.secret_key = secret_key acc.user = request.user acc.save() user_perm = ClientUserPermissions.objects.create(client_user=request.user, api_account=acc, is_admin=True) messages.success(request, "Your site '%s' was added." % form.cleaned_data['site_prefix']) return HttpResponseRedirect(reverse('sites_list')) else: form = SiteForm(request.user) return render_to_response('sites_add.html', {'form':form}, context_instance=RequestContext(request))
def sites_edit(request, site_id): site = get_object_or_404(ApiAccount, pk=site_id, disabled=False) if not site.user == request.user: raise Http404() error = None if request.method == 'POST': form = SiteForm(request.user, request.POST, error_class=SpanErrorList, instance=site) if form.is_valid(): form.save() messages.success(request, "Your site '%s' was saved." % site.site_prefix) return HttpResponseRedirect(reverse('sites_list')) else: form = SiteForm(request.user, initial={'site_prefix':site.site_prefix}, instance=site) return render_to_response('sites_edit.html', {'form':form, 'site':site, }, context_instance=RequestContext(request))
def sites_add(request): if request.method == 'POST': form = SiteForm(request.user, request.POST, request.FILES, error_class=SpanErrorList) if form.is_valid(): acc = form.save(commit=False) api_key = ApiAccount.create_api_key() secret_key = ApiAccount.create_api_key() acc.api_key = api_key acc.secret_key = secret_key acc.user = request.user acc.save() user_perm = ClientUserPermissions.objects.create( client_user=request.user, api_account=acc, is_admin=True) messages.success( request, "Your site '%s' was added." % form.cleaned_data['site_prefix']) return HttpResponseRedirect(reverse('sites_list')) else: form = SiteForm(request.user) return render_to_response('sites_add.html', {'form': form}, context_instance=RequestContext(request))
def site_update_view(request): if request.method == 'POST': site_id = request.POST.get('id') site = get_object_or_404(Website, pk=site_id) form = SiteForm(request.POST, request.FILES, instance=site) if form.is_valid(): form.save() else: request.session['errors'] = form.errors return redirect('site') else: form = SiteForm() request.session.update({'errors': form.errors}) return redirect('site')