def modify_pub(request, pub_slug): '''Page to do various modifications to an ad and delete it ''' try: pub = Publisher.objects.get(slug=pub_slug) except Publisher.DoesNotExist: request.user.message_set.create(message=_(u"Saitul apelat nu exista!")) return redirect("/user/profile/") else: if request.method == 'POST': if request.user == pub.owner: form = PublisherForm(request.POST, instance=pub) if form.is_valid(): pub = form.save() request.user.message_set.create( message=_(u'The site has been successfully modified!')) else: return render_to_response( "modify_pub.html", { 'form': form, 'form_action': '/user/pub/modify/' + pub.slug, 'pub_slug': pub.slug, 'pub': pub, }, context_instance=RequestContext(request)) else: request.user.message_set.create( message=_(u'Nu ai dreptul de a modifica acest sait!')) return redirect("/user/pub/modify/%s" % pub.slug) else: # GET form = PublisherForm(instance=pub) graph_url = graph_monthly_imp(pub) return render_to_response( "modify_pub.html", { 'domain': settings.SITE_URL, 'form': form, 'form_action': '/user/pub/modify/' + pub.slug, 'pub_slug': pub.slug, 'pub': pub, 'graph_url': graph_url, }, context_instance=RequestContext(request))
def modify_pub(request, pub_slug): '''Page to do various modifications to an ad and delete it ''' try: pub = Publisher.objects.get(slug=pub_slug) except Publisher.DoesNotExist: request.user.message_set.create(message=_(u"Saitul apelat nu exista!")) return redirect("/user/profile/") else: if request.method == 'POST': if request.user == pub.owner: form = PublisherForm(request.POST, instance=pub) if form.is_valid(): pub = form.save() request.user.message_set.create(message=_( u'The site has been successfully modified!')) else: return render_to_response("modify_pub.html", { 'form':form, 'form_action': '/user/pub/modify/'+pub.slug, 'pub_slug':pub.slug, 'pub':pub, }, context_instance=RequestContext(request)) else: request.user.message_set.create(message=_( u'Nu ai dreptul de a modifica acest sait!')) return redirect("/user/pub/modify/%s" % pub.slug) else: # GET form = PublisherForm(instance=pub) graph_url = graph_monthly_imp(pub) return render_to_response("modify_pub.html", { 'domain':settings.SITE_URL, 'form':form, 'form_action': '/user/pub/modify/'+pub.slug, 'pub_slug':pub.slug, 'pub':pub, 'graph_url':graph_url, }, context_instance=RequestContext(request))
def profile(request): '''User profile. Returns a list of the total impressions on all the user`s Publishers. :pub_imp: a list of publisher details formed like this: [publisher name, publisher slug, total impressions, real impressions] :domain: use this to build nice snippets (should go away at some point) :products: a list of Product objects belonging to the user ''' form = PublisherForm() if request.method == 'POST': form = PublisherForm(request.POST) if form.is_valid(): new_pub = form.save(commit=False) new_pub.owner = request.user new_pub.save() request.user.message_set.create( message=_(u"The new site was successfully added.")) publishers = Publisher.objects.filter(owner=request.user) products = Product.objects.filter(owner=request.user) pub_imp = [] for pub in publishers: imp = Impression.objects.filter(publisher=pub.url).count() real_imp = Impression.objects.filter(referer_netloc=pub.url).count() pub_imp.append([pub.name, pub.slug, imp, real_imp]) return render_to_response("profile.html", { 'pub_imp': pub_imp, 'domain': settings.SITE_URL, 'products': products, 'form': form, }, context_instance=RequestContext(request))
def profile(request): '''User profile. Returns a list of the total impressions on all the user`s Publishers. :pub_imp: a list of publisher details formed like this: [publisher name, publisher slug, total impressions, real impressions] :domain: use this to build nice snippets (should go away at some point) :products: a list of Product objects belonging to the user ''' form = PublisherForm() if request.method == 'POST': form = PublisherForm(request.POST) if form.is_valid(): new_pub = form.save(commit=False) new_pub.owner = request.user new_pub.save() request.user.message_set.create(message=_( u"The new site was successfully added.")) publishers = Publisher.objects.filter(owner=request.user) products = Product.objects.filter(owner=request.user) pub_imp = [] for pub in publishers: imp = Impression.objects.filter(publisher=pub.url).count() real_imp = Impression.objects.filter(referer_netloc=pub.url).count() pub_imp.append([pub.name, pub.slug, imp, real_imp]) return render_to_response("profile.html", { 'pub_imp':pub_imp, 'domain': settings.SITE_URL, 'products': products, 'form':form, }, context_instance=RequestContext(request))