def get_post_form( parent=None, parent_id=None, resource=None, instance=None, user=None, user_role=None, config=None, depth=0, form=None, ): """ Returns a dictionary with: a form for posting one of this resource, and a target url/method for the form. We're already checked, and the user is allowed to post one of these. """ if form is None: # The user is going to be the owner of this resource. this_config = permit.reduce_permissions_dictionary_to("owner", config) formfields = help.sorted_fields_of(this_config[resource]["fields"])["fields"] # We only want a form for the fields the owner can read and write. userfields = tuple(set(formfields["read"]) & set(formfields["write"])) # Now we create the form. this_model = help.model_for(resource) form = modelform_factory(this_model, fields=userfields)() result = { "target": { "url": reverse( "newviews:parsed-url", kwargs={"parent": parent, "parent_id": parent_id, "resource": resource} ), "method": "POST", "form": form, } } return result
def _spread_into_roles(d): """Take a fat dictionary and returns three, each one narrowed to a specific role. """ return {role: methods.reduce_permissions_dictionary_to(role, d) for role in ('owner', 'group', 'world')}
def setUp(self): self.narrowedConfig = { 'fields':{ 'foo':4, 'bar':5 }, 'methods':{ 'GET':5, 'PUT':0 } } self.fullConfig = { 'fields':{ 'foo':'0640', 'bar':'0755' }, 'methods':{ 'GET':'0555', 'PUT':'0700' } } self.modifier = { 'fields': { 'omit':['foo'], 'extend':['bar'] }, 'methods': { 'omit': ['PUT'] } } self.challenge_config = { 'challenges': { 'fields': { 'title': '0640', 'short_description': '0640', 'long_description': '0640', 'slug': '0400', 'created_at': '0000', 'skillset': '0755', 'user': '******', 'group': '0755', 'entries': '0755', 'resources': '0755', 'tags': '0755', 'tools': '0755' }, 'methods': { 'PUT': '0700', 'GET': '0555', 'DELETE': '0500' } } } self.tapered_config = permit.reduce_permissions_dictionary_to('group',self.challenge_config) self.client = Client() self.requestFactory = RequestFactory() self.group = GroupFactory.create() self.user = UserFactory.create() self.instance = ChallengeFactory.create()