def save(request): if settings.DEBUG and not request.POST: request.POST = request.GET if settings.REQUIRE_LOGIN and not request.user.is_authenticated(): raise Http404 form = SaveForm(request.POST) overwrite = request.POST.get('overwrite', False) result = '' if form.is_valid(): content = request.POST.get('content', '') name = form.cleaned_data['name'] user = request.user if not user.is_authenticated(): user = None try: worksheet = Worksheet.objects.get(user=user, name=name) if overwrite: worksheet.content = content else: result = 'overwrite' except Worksheet.DoesNotExist: worksheet = Worksheet(user=user, name=name, content=content) worksheet.save() return JsonResponse({ 'form': form.as_json(), 'result': result, })
def save(request): if settings.DEBUG and not request.POST: request.POST = request.GET if settings.REQUIRE_LOGIN and not request.user.is_authenticated(): raise Http404 form = SaveForm(request.POST) overwrite = request.POST.get('overwrite', False) result = '' general_errors = [] if form.is_valid(): content = request.POST.get('content', '') name = form.cleaned_data['name'] if re.match(r'^[0-9A-Za-z]+[0-9A-Za-z._()\-\[\] ]*$', name) is None: general_errors = ["Worksheet name is invalid."] else: user = request.user if not user.is_authenticated(): user = None try: worksheet = Worksheet.objects.get(user=user, name=name) if overwrite: worksheet.content = content else: result = 'overwrite' except Worksheet.DoesNotExist: worksheet = Worksheet(user=user, name=name, content=content) worksheet.save() return JsonResponse({ 'form': form.as_json(general_errors=general_errors), 'result': result, })
def main_view(request): content_type = get_content_type(request) return render_to_response('main.html', { 'login_form': LoginForm(), 'save_form': SaveForm(), 'require_login': settings.REQUIRE_LOGIN, }, context_instance=RequestContext(request), content_type=content_type)
def main_view(request): context = { 'login_form': LoginForm(), 'save_form': SaveForm(), 'require_login': settings.REQUIRE_LOGIN, } return render(request, 'main.html', context)
def main_view(request): context = { "login_form": LoginForm(), "save_form": SaveForm(), "require_login": settings.REQUIRE_LOGIN, } return render(request, "main.html", context)
def worksheets(request): content_type = get_content_type(request) return render_to_response('worksheets.html', { 'login_form': LoginForm(), 'save_form': SaveForm(), 'delete_form': DeleteForm(), 'require_login': settings.REQUIRE_LOGIN, }, context_instance=RequestContext(request), content_type=content_type)