django-odb / odb / views.py

from odb.traverse import get_object, put_object
from django.http import HttpResponse
from odb.models import ContentObject, ObjectGroup, Model, Person
from django.views.generic.edit import FormView
from django.shortcuts import redirect, render

def manage(req, path):
    o = get_object(path)
    if hasattr(o, 'iteritems') and callable(o.iteritems):
        object_list = []
        for k, v in o.iteritems():
            obj = {'name':k, 'class':v.__class__.__name__}
            if isinstance(v, dict): obj.update({'is_directory':True})
            object_list.append(obj)
        return render(req, "odb/manage.html", {'object_list':object_list,'path':path})
    if not isinstance(o, Model):
        return HttpResponse('Object type not supported.')
    if req.method == 'POST':
        form = o.get_form_class()(req.POST)
        if o.process_form(form):
            if put_object(path, o):
                return redirect(path)
            return HttpResponse('Error saving object.')
    else:
        form = o.get_form()
    return render(req, "odb/form.html", {'form':form})

def create(req, path):
    if req.method == 'GET':
        return HttpResponse('Error!')
    obj_name = req.POST.get('obj_name', None)
    if obj_name == None:
        return redirect(path)
    o = get_object(path)
    if obj_name in o:
        return redirect("%s%s" % (path, obj_name))
    p = Person()
    if put_object("%s%s" % (path,obj_name), p):
        return redirect("/manage%s%s" % (path, obj_name))
    return HttpResponse("Error creating object.")

def remove(req, path):
    o = get_object("/"+"/".join(path[1:].split('/')[:-1]))
    del o[str(path[1:].split('/')[-1])]
    return redirect(path)

def mkdir(req, path):
    put_object(path, {})
    return redirect(path)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.