Example #1
0
def editor(obj=None, parent=None):
	form = PermissionForm(request.form, prefix="perm")
	form.for_objtyp.choices = tuple((str(x.id),x.name) for x in ObjType.q.all())
	form.new_objtyp.choices = (('-','–'),) + form.for_objtyp.choices
	form.new_mimetyp.choices = (('-','–'),) + tuple((str(x.id),x.name) for x in MIMEtype.q.all())
	if request.method == 'POST' and form.validate():
		user = Object.by_oid(form.user.data)
		dest = Object.by_oid(form.target.data)
		for_objtyp = int(form.for_objtyp.data)
		new_objtyp = ObjType.get(int(form.new_objtyp.data)) if form.new_objtyp.data != "-" else None
		new_mimetyp = MIMEtype.id.get_by(form.new_mimetyp.data) if form.new_mimetyp.data != "-" else None
		right = int(form.right.data)

		if form.inherit.data == "Yes": inherit = True
		elif form.inherit.data == "No": inherit = False
		elif form.inherit.data == "*": inherit = None
		else: assert False

		if parent:
			obj = Permission.new(user, dest, for_objtyp,new_objtyp=new_objtyp,new_mimetyp=new_mimetyp, right=right, inherit=inherit)
		else:
			obj.owner = user
			obj.parent = dest
			obj.for_objtyp = for_objtyp
			obj.right = right
			obj.inherit = inherit
			obj.new_objtyp = new_objtyp
			obj.new_mimetyp = new_mimetyp

		flash(u"Gespeichert.",True)

		return redirect(url_for("pybble.views.view_oid", oid=dest.oid))

	
	elif request.method == 'GET':
		if obj:
			form.target.data = parent.oid if parent else obj.parent.oid
			form.user.data = obj.owner.oid
			form.for_objtyp.data = str(obj.for_objtyp.id)
			form.new_objtyp.data = str(obj.new_objtyp.id) if obj.new_objtyp else "-"
			form.new_mimetyp.data = str(obj.new_mimetyp.id) if obj.new_mimetyp else "-"
			form.inherit.data = "*" if obj.inherit is None else "Yes" if obj.inherit else "No"
			form.right.data = str(obj.right)
		else:
			form.target.data = parent.oid
			form.user.data = request.user.oid
			form.right.data = str(PERM_NONE)
			form.for_objtyp.data = str(parent.type_id)
			form.new_objtyp.data = "-"
			form.new_mimetyp.data = "-"
			form.inherit.data = "*"

	return render_template('edit/permission.html', parent=parent, obj=obj, form=form, title_trace=["New permission" if parent else "Edit permission"])
Example #2
0
def new_oid(oid, objtyp=None, name=None):
	obj=Object.by_oid(oid)
	if objtyp is None:
		objtyp = obj.type
	else:
		try: objtyp = int(objtyp)
		except ValueError: pass
		objtyp = ObjType.get(objtyp)
	request.user.will_add(obj,new_objtyp=objtyp)

	ed = ObjEditor(objtyp,obj)
	args = {}
	if name is not None: args["name"]=name
	args["parent"]=obj
	return ed.editor(**args)
Example #3
0
def view_snippet2(oid, objtyp,k):
	obj = Object.by_oid(oid)
	objtyp = ObjType.get(objtyp)
	
	sub=list(obj.get_refs(objtyp,k))
	return render_template("snippet2.html", cls=objtyp, obj=obj, sub=sub, k=k, count=len(sub), _root=current_site)
Example #4
0
def editor(obj=None, parent=None):
    form = PermissionForm(request.form, prefix="perm")
    form.for_objtyp.choices = tuple(
        (str(x.id), x.name) for x in ObjType.q.all())
    form.new_objtyp.choices = (('-', '–'), ) + form.for_objtyp.choices
    form.new_mimetyp.choices = (('-', '–'), ) + tuple(
        (str(x.id), x.name) for x in MIMEtype.q.all())
    if request.method == 'POST' and form.validate():
        user = Object.by_oid(form.user.data)
        dest = Object.by_oid(form.target.data)
        for_objtyp = int(form.for_objtyp.data)
        new_objtyp = ObjType.get(int(
            form.new_objtyp.data)) if form.new_objtyp.data != "-" else None
        new_mimetyp = MIMEtype.id.get_by(
            form.new_mimetyp.data) if form.new_mimetyp.data != "-" else None
        right = int(form.right.data)

        if form.inherit.data == "Yes": inherit = True
        elif form.inherit.data == "No": inherit = False
        elif form.inherit.data == "*": inherit = None
        else: assert False

        if parent:
            obj = Permission.new(user,
                                 dest,
                                 for_objtyp,
                                 new_objtyp=new_objtyp,
                                 new_mimetyp=new_mimetyp,
                                 right=right,
                                 inherit=inherit)
        else:
            obj.owner = user
            obj.parent = dest
            obj.for_objtyp = for_objtyp
            obj.right = right
            obj.inherit = inherit
            obj.new_objtyp = new_objtyp
            obj.new_mimetyp = new_mimetyp

        flash(u"Gespeichert.", True)

        return redirect(url_for("pybble.views.view_oid", oid=dest.oid))

    elif request.method == 'GET':
        if obj:
            form.target.data = parent.oid if parent else obj.parent.oid
            form.user.data = obj.owner.oid
            form.for_objtyp.data = str(obj.for_objtyp.id)
            form.new_objtyp.data = str(
                obj.new_objtyp.id) if obj.new_objtyp else "-"
            form.new_mimetyp.data = str(
                obj.new_mimetyp.id) if obj.new_mimetyp else "-"
            form.inherit.data = "*" if obj.inherit is None else "Yes" if obj.inherit else "No"
            form.right.data = str(obj.right)
        else:
            form.target.data = parent.oid
            form.user.data = request.user.oid
            form.right.data = str(PERM_NONE)
            form.for_objtyp.data = str(parent.type_id)
            form.new_objtyp.data = "-"
            form.new_mimetyp.data = "-"
            form.inherit.data = "*"

    return render_template(
        'edit/permission.html',
        parent=parent,
        obj=obj,
        form=form,
        title_trace=["New permission" if parent else "Edit permission"])