Пример #1
0
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()
Пример #2
0
def upload(
    request,
    username,
    name=None,
    id=None,
    parent=settings.STORAGE_BUCKET_ID,
    _ts=None,
    csrfmiddlewaretoken=None,
    **kwargs
):
    kwargs["page"] = "storage/file"
    data = {"view": True}

    if (id and not utils.is_numeric(id)) or (not name and not request.FILES):
        return utils.fail(kwargs, data=data, errors="Invalid Request")

    if float(parent) == settings.STORAGE_BUCKET_ID:
        return utils.fail(kwargs, data=data, errors="Objects are not allowed here.")

    user = request.user.get_profile().id if request.user.is_authenticated() else -1

    try:
        s = Directory.objects.get(id=parent)
        p = request.user.get_profile() if request.user.is_authenticated() else None
        name = name if name else request.FILES["file"].name

        if not id:
            name = get_available_name(name, s, user, request)
            try:
                f = File(name=name, type="file", parent=s, owner=p, author=request.user.username)
                print f.id
                f.add(user=user, ecolor="all." + request.user.username)
                data["file"] = f
            except utils.GuardException:
                return utils.fail(kwargs, data=data, errors="Not Authorized")
        else:
            f = File.objects.get(id=id)
            data["file"] = f

        if request.FILES:
            try:
                f.file = request.FILES["file"]
                f.mime = request.FILES["file"].content_type
                f.edit(user=user)
            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)
Пример #3
0
def create_person(sender, instance, created, **kwargs):
    if created:
		parent = Node.objects.get(id = settings.PEOPLE_ID)
		file = File(name = instance.username + '.png', author = instance.username, parent = parent, mime = 'image/png')
		file.add(user = settings.PEOPLE_ID)
		person = Person(user = instance, name = instance.username, type = 'user', author = instance.username, parent = parent, photo = file)
		person.add(user = settings.PEOPLE_ID)
		person.add(user = settings.PEOPLE_ID, parent = person, ecolor = 'owner.link')
		
		file.owner = person
		file.save()
		person.owner = person
		person.save()
Пример #4
0
def upload( request, username, name = None, id = None, parent = settings.STORAGE_BUCKET_ID, _ts = None, csrfmiddlewaretoken = None, **kwargs ):
	kwargs[ 'page' ] = 'storage/file'
	data = { 'view' : True }
	
	if( id and not utils.is_numeric( id ) ) or ( not name and not request.FILES ): 
		return utils.fail( kwargs, data = data, errors = 'Invalid Request' )
	
	if( float( parent ) == settings.STORAGE_BUCKET_ID ):
		return utils.fail( kwargs, data = data, errors = 'Objects are not allowed here.' )
	
	user = request.user.get_profile().id if request.user.is_authenticated() else -1
	
	try :
		s = Directory.objects.get( id = parent )
		p = request.user.get_profile() if request.user.is_authenticated() else None
		name = name if name else request.FILES[ 'file' ].name
		
		if not id:
			if s.authorize( request, action = 'add' ):
				f = File( name = name, type = settings.STORAGE_FILE_TYPE, owner = p, parent = s )
				f.add( base = settings.INTERLINK_COLOR_ALL )
				f.link( parent = s, base = p )
				data[ 'file' ] = f
			else: 
				return utils.fail( kwargs, data = data, errors = 'Not Authorized' )
		else:
			f = File.objects.get( id = id )
			data[ 'file' ] = f
		
		if request.FILES:
			if f.authorize( request, action = 'edit' ):
				f.write( request )
			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 )