def section_contraptions_add(request): if request.method == 'POST': log = logging.getLogger(__name__) log.info("we're trying to save a new contraption.") form_order = request.POST.get('order', 0) form_title = request.POST.get('title', None) form_description = request.POST.get('description', None) form_visible = False if request.POST.get('visible', None) == 'on': form_visible = True else: form_visible = False #contraption_no = len(Contraption.objects) + 1 c = Contraption(order=form_order, title=form_title, description=form_description, visible=form_visible, created_at=datetime.datetime.now, last_modified=datetime.datetime.now) #contraption_no = contraption_no) c.save() return HttpResponseRedirect(reverse('section_contraptions'))
def section_contraptions_delete_contraption(request): log = logging.getLogger(__name__) log.info("we're trying to delete a contraption.") if request.method == 'GET': if request.session['authenticated'] == True: id_param = request.GET.get('id', None) if id_param <> None: Contraption.objects(id=id_param)[0].delete() return HttpResponse(json.dumps({"status": "ok"}), mimetype="application/json") return HttpResponseRedirect(reverse('section_contraptions'))
def contraption_page_edit(request): log = logging.getLogger(__name__) log.info("we're editing a contraption page.") if request.method == 'GET': param_contraptionid = request.GET.get('contraptionid', None) param_pageid = request.GET.get('pageid', None) c = Contraption.objects(id=param_contraptionid)[0] p = Page.objects(id=param_pageid)[0] ctx = RequestContext(request) ctx['section'] = 'page_edit' ctx['contraption'] = ContraptionHtml(c) ctx['page'] = PageHtml(p) ctx['page_title'] = p.title t = get_template("index.html") html = t.render(ctx) return render(request, "index.html", ctx) elif request.method == 'POST': param_pageid = request.POST.get('pageid', None) # todo: update the contraption's last_modified field when modifying a page. param_order = request.POST.get('order', None) param_title = request.POST.get('title', None) param_content = request.POST.get('content', None) p = Page.objects(id=param_pageid)[0] p.title = param_title p.order = param_order p.content = param_content p.save() return HttpResponseRedirect(request.META['HTTP_REFERER'])
def section_contraptions_get_contraption_raw(request): log = logging.getLogger(__name__) log.info("we're getting a raw contraption!") if request.method == 'GET': id_param = request.GET.get('id', None) if id_param <> None: o = Contraption.objects(id=id_param)[0] return HttpResponse(json.dumps(ContraptionsEncoder().encode(o)), mimetype="application/json")
def contraption_page_delete(request): log = logging.getLogger(__name__) log.info("we're trying to delete a page.") if request.method == "GET": if request.session["authenticated"] == True: pid_param = request.GET.get("pid", None) cid_param = request.GET.get("cid", None) if cid_param <> None and pid_param <> None: c = Contraption.objects(id=cid_param)[0] p = Page.objects(id=pid_param)[0] c.pages.remove(p) c.save() p.delete() return HttpResponse(json.dumps({"status": "ok"}), mimetype="application/json")
def section_contraptions_view(request): log = logging.getLogger(__name__) log.info("we're trying to view a contraption") ctx = RequestContext(request) ctx["section"] = 'contraption_view' if request.method == 'GET': id_param = request.GET.get('id', None) if id_param <> None: ctx['contraption'] = ContraptionHtml( Contraption.objects(id=id_param)[0]) ctx["page_title"] = ctx["contraption"].title t = get_template("index.html") html = t.render(ctx) return render(request, "index.html", ctx)
def contraption_page_add(request): log = logging.getLogger(__name__) log.info("we're adding a contraption page.") if request.method == 'GET': param_contraptionid = request.GET.get('contraptionid', None) if param_contraptionid <> None: c = Contraption.objects(id=param_contraptionid)[0] if c.order is None: c.order = 0 p = Page(order=0, title="New Page", lastModified=datetime.datetime.now) p.save() c.pages.append(p) c.last_modified = datetime.datetime.now c.save() return HttpResponseRedirect(request.META['HTTP_REFERER'])
def section_contraptions_edit(request): if request.method == 'POST': log = logging.getLogger(__name__) log.info("we're trying to change a contraption") form_id = request.POST.get('id', None) form_order = request.POST.get('order', 0) form_title = request.POST.get('title', None) form_description = request.POST.get('description', None) form_visible = False if request.POST.get('visible', None) == 'on': form_visible = True else: form_visible = False c = Contraption.objects(id=form_id)[0] c.order = form_order c.title = form_title c.description = form_description c.visible = form_visible c.last_modified = datetime.datetime.now c.save() return HttpResponseRedirect(reverse('section_contraptions'))