예제 #1
0
파일: views.py 프로젝트: bmount/courseslate
def update_edit_xhr(request, nid):
    if request.is_ajax():
        if request.method == "GET":
            note = Update.objects.get(id=nid)
            form = UpdatesForm(instance=note)
            c = {"form":form}
            c.update(csrf(request))
            formt = 'includes/gen_form_inc.html'
            html = render_to_string(formt, c)
            res = {"html":html}
            response = simplejson.dumps(res)
            return HttpResponse(response, mimetype='application/json')
        if request.method == "POST":
            note = Update.objects.get(id=nid)
            form = UpdatesForm(request.POST, instance=note)
            if form.is_valid():
                form = form.save()
                template = 'includes/update_inc.html'
                html = render_to_string(template, {"u":form})
                res = {"html":html}
                response = simplejson.dumps(res)
                return HttpResponse(response, mimetype='application/json')
            else:
                return Http404
    return Http404
예제 #2
0
 def get_context_data(self, **kwargs):
     context = super(TopicDetailView, self).get_context_data(**kwargs)
     context['update_form'] = UpdatesForm()
     context['tr_form'] = TopicResourceForm()
     context['update_list'] = Update.objects.filter(
         topic=self.object).order_by('-added')
     context['tr_list'] = TopicResource.objects.select_related().filter(
         topic=self.object).order_by('-added')
     return context
예제 #3
0
def update_edit_xhr(request, nid):
    if request.is_ajax():
        if request.method == "GET":
            note = Update.objects.get(id=nid)
            form = UpdatesForm(instance=note)
            c = {"form": form}
            c.update(csrf(request))
            formt = 'includes/gen_form_inc.html'
            html = render_to_string(formt, c)
            res = {"html": html}
            response = simplejson.dumps(res)
            return HttpResponse(response, mimetype='application/json')
        if request.method == "POST":
            note = Update.objects.get(id=nid)
            form = UpdatesForm(request.POST, instance=note)
            if form.is_valid():
                form = form.save()
                template = 'includes/update_inc.html'
                html = render_to_string(template, {"u": form})
                res = {"html": html}
                response = simplejson.dumps(res)
                return HttpResponse(response, mimetype='application/json')
            else:
                return Http404
    return Http404
예제 #4
0
def update_create_xhr(request, person, slug):
    if request.method == "POST":
        form = UpdatesForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
        else:
            return Http404
        try:
            t = Topic.objects.get(person__user=request.user, slug__iexact=slug)
        except Topic.DoesNotExist:
            return Http404
        form.topic = t
        form.save()
        if request.is_ajax():
            html = render_to_string('includes/update_inc.html', {
                "u": form,
                "topic": t
            })
            res = {"html": html}
            response = simplejson.dumps(res)
            return HttpResponse(response, mimetype='application/json')
        else:
            return HttpResponseRedirect('../..')
    return Http404
예제 #5
0
파일: views.py 프로젝트: bmount/courseslate
def update_create_xhr(request, person, slug):
    if request.method == "POST":
        form = UpdatesForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
        else:
            return Http404
        try:
            t = Topic.objects.get(person__user=request.user, slug__iexact=slug)
        except Topic.DoesNotExist:
            return Http404
        form.topic = t
        form.save()
        if request.is_ajax():
            html = render_to_string('includes/update_inc.html',{"u":form,"topic":t})
            res = {"html":html}
            response = simplejson.dumps(res)
            return HttpResponse(response, mimetype='application/json')
        else:
            return HttpResponseRedirect('../..')
    return Http404