def add(request, username, name, root=0, id=settings.STORAGE_BUCKET_ID, _ts=None, csrfmiddlewaretoken=None, **kwargs): kwargs["page"] = "storage/directory" data = {"view": True} if not utils.is_numeric(id, root): return utils.fail(kwargs, data=data, errors="Invalid Request") data["regions"] = settings.STORAGE_NAMES if float(id) == settings.STORAGE_BUCKET_ID else False user = request.user.get_profile().id if request.user.is_authenticated() else -1 try: s = Directory.objects.get(id=id) p = request.user.get_profile() if request.user.is_authenticated() else None name = get_available_name(name, s, user, request) try: d = Directory(name=name, type="directory", parent=s, owner=p, author=request.user.username) if data["regions"]: d.root = int(root) d.add(user=user, ecolor="all." + request.user.username) data["directory"] = d except utils.GuardException: return utils.fail(kwargs, data=data, errors="Not Authorized") data["storage"] = s data["admin"] = p.guard(user=user, action="add") except Directory.DoesNotExist: return utils.fail(kwargs, data=data, errors="Invalid Storage") return utils.success(kwargs, data=data)
def add(request, username, name, type = settings.STORAGE_DIRECTORY_TYPE, id = settings.STORAGE_BUCKET_ID, _ts = None, csrfmiddlewaretoken = None, **kwargs): kwargs[ 'page' ] = 'storage/directory' data = { 'view' : True } if not utils.is_numeric( id, type ): return utils.fail( kwargs, data = data, errors = 'Invalid Request' ) data[ 'regions' ] = settings.STORAGE_NAMES if float( id ) == settings.STORAGE_BUCKET_ID else False user = request.user.get_profile().id if request.user.is_authenticated() else -1 try : s = Directory.objects.get( id = id ) p = request.user.get_profile() if request.user.is_authenticated() else None if d.authorize( request, action = 'add' ): d = Directory( name = name, owner = p, parent = s ) if data[ 'regions' ]: d.type = int( type ) d.add( base = settings.INTERLINK_COLOR_ALL ) d.link( parent = s, base = p ) data[ 'directory' ] = d else: return utils.fail( kwargs, data = data, errors = 'Not Authorized' ) data[ 'storage' ] = s data[ 'admin' ] = p.authorize( request, action = 'add' ) except Directory.DoesNotExist: return utils.fail( kwargs, data = data, errors = 'Invalid Storage' ) return utils.success( kwargs, data = data )
def create_person_main( sender, instance, created, **kwargs ): if created: stghome = Directory( name = instance.username, parent = Node.objects.get( id = settings.PEOPLE_PERSON_STORAGE_HOME ) ) stghome.add() uihome = Directory( name = instance.username, parent = Node.objects.get( id = settings.PEOPLE_PERSON_UI_HOME ) ) uihome.add() file = File( name = 'photo.png', mime = 'image/png', parent = uihome ) file.add() person = Person( user = instance, name = instance.username, title = instance.username, photo = file, uihome = uihome, stghome = stghome, parent = Node.objects.get( id = settings.PEOPLE_ID ), g_node = Node.objects.get( id = settings.PEOPLE_GUARD ) ) person.add() # person.add( parent = person ) uihome.owner = person uihome.save() stghome.owner = person stghome.save() file.owner = person file.save() person.owner = person person.save()