def post(self, request): form = HomeForm(request.POST) if form.is_valid(): text = form.cleaned_data['post'] args = {'form': form, 'text': text} return render(request, self.template_name, args)
def page_edit_home(request): shop = request.shop static_pages = Page.objects.filter(shop=shop) dynamic_pages = DynamicPageContent.objects.filter(shop=shop) try: home = Home.objects.filter(shop=shop).get() except: home = Home(shop=shop) home.save() if request.POST: form = HomeForm(request.POST, request.FILES, instance=home) if form.is_valid(): form.save() request.flash['message'] = unicode(_("Page successfully saved.")) request.flash['severity'] = "success" return HttpResponseRedirect(reverse('page_edit_home')) else: form = HomeForm(instance=home) return render_to_response( 'store_admin/web_store/pages_edit_home.html', { 'form': form, 'home': home, 'static_pages': static_pages, 'dynamic_pages': dynamic_pages }, RequestContext(request))
def post(self, request): form = HomeForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.user = request.user post.save() text = form.cleaned_data['post'] form = HomeForm() args = {'form': form, 'text': text} return render(request, self.template_name, args)
def create(request): if request.method == 'POST': form = HomeForm(request.POST) if form.is_valid(): home = form.save(commit=False) home.home_data = timezone.now() home.save() return redirect('apps.hello.views.home', pk=home.pk) else: form = HomeForm() args = {} args['form'] = form return render(request, 'post_edit.html', args)
def post_edit(request, pk): home = get_object_or_404(Home, pk=pk) args = {} args['home'] = home if request.method == 'POST': form = HomeForm(request.POST, instance=home) if form.is_valid(): home = form.save(commit=False) home.home_data = timezone.now() home.save() return redirect('apps.hello.views.home', pk=home.pk) else: form = HomeForm(instance=home) args['form'] = form return render(request, 'post_edit.html', args)
def page_edit_home(request): shop = request.shop static_pages = Page.objects.filter(shop=shop) dynamic_pages = DynamicPageContent.objects.filter(shop=shop) try: home = Home.objects.filter(shop=shop).get() except: home = Home(shop=shop) home.save() if request.POST: form = HomeForm(request.POST, request.FILES, instance=home) if form.is_valid(): form.save() request.flash['message'] = unicode(_("Page successfully saved.")) request.flash['severity'] = "success" return HttpResponseRedirect(reverse('page_edit_home')) else: form = HomeForm(instance=home) return render_to_response('store_admin/web_store/pages_edit_home.html', {'form': form, 'home': home, 'static_pages': static_pages, 'dynamic_pages': dynamic_pages}, RequestContext(request))
def home(request): if request.method == 'POST': # If the form has been submitted... form = HomeForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... product = form.cleaned_data['product'] branch_id = form.cleaned_data['branch'].branch_id testgroups = form.cleaned_data['testgroups'] tg_ids = [str(x.testgroup_id) for x in testgroups] cursor = connection.cursor() cursor.execute(getsql(product.product_id, branch_id, tg_ids)) # Create the HttpResponse object with the appropriate CSV header. response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=%s_litmusoutput.csv' % product.name csv_writer = UnicodeWriter(response) csv_writer.writerow([i[0] for i in cursor.description]) # write headers csv_writer.writerows(cursor) del csv_writer # this will close the CSV file return response else: form = HomeForm() # An unbound form branches = Branches.objects.all().order_by('name') testgroups = Testgroups.objects.all().order_by('name') return render_to_response('home.html', {'form': form, 'branches': branches, 'testgroups': testgroups }, context_instance=RequestContext(request))
def page_edit_home(request): shop = request.shop static_pages = Page.objects.filter(shop=shop) dynamic_pages = DynamicPageContent.objects.filter(shop=shop) try: home = Home.objects.filter(shop=shop).get() except: home = Home(shop=shop) home.save() if request.POST: form = HomeForm(request.POST, request.FILES, instance=home) if form.is_valid(): form.save() request.flash["message"] = unicode(_("Page successfully saved.")) request.flash["severity"] = "success" return HttpResponseRedirect(reverse("page_edit_home")) else: form = HomeForm(instance=home) return render_to_response( "store_admin/web_store/pages_edit_home.html", {"form": form, "home": home, "static_pages": static_pages, "dynamic_pages": dynamic_pages}, RequestContext(request), )
def home(request): if request.method == 'POST': # If the form has been submitted... form = HomeForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... product = form.cleaned_data['product'] branch = form.cleaned_data['branch'] testgroups = form.cleaned_data['testgroups'] response_data = get_response_json(product, branch, testgroups) # Create the HttpResponse object with the appropriate CSV header. response = HttpResponse(dumps(response_data), mimetype='application/json') response['Content-Disposition'] = 'attachment; filename=%s_litmusoutput.json' % product.name logger.error(response) return response else: logger.error('logging the request') logger.error(request) form = HomeForm() # An unbound form branches = Branch.objects.all().order_by('name') testgroups = Testgroup.objects.all().order_by('name') return render_to_response('home.html', {'form': form, 'branches': branches, 'testgroups': testgroups }, context_instance=RequestContext(request))