예제 #1
0
파일: views.py 프로젝트: alejo8591/maker
def item_edit(request, item_id, response_format='html'):
    "Item edit page"
    item = get_object_or_404(Item, pk=item_id)
    if not request.user.get_profile().has_permission(item, mode="w"):
        return user_denied(request, message="You don't have write access to this Item", 
                           response_format=response_format)

    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemForm(request.user.get_profile(), item.item_type, request.POST, 
                            files=request.FILES, instance=item)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
    else:
        form = ItemForm(request.user.get_profile(), item.item_type, instance=item)
    
    context = _get_default_context(request)
    context.update({'item': item,
                    'form': form })

    return render_to_response('infrastructure/item_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
예제 #2
0
파일: handlers.py 프로젝트: alejo8591/maker
    def update(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        pkfield = kwargs.get(self.model._meta.pk.name) or request.data.get(self.model._meta.pk.name)

        if not pkfield:
            return rc.BAD_REQUEST

        item = getOrNone(self.model, pkfield)
        if not item:
            return rc.NOT_FOUND

        if not request.user.get_profile().has_permission(item, mode="w"):
            return rc.FORBIDDEN

        attrs = self.flatten_dict(request)

        form = ItemForm( item_type=item.item_type, instance=item, **attrs)
        if form.is_valid():
            item = form.save(request)
            return item
        else:
            self.status = 400
            return form.errors
예제 #3
0
파일: views.py 프로젝트: alejo8591/maker
def item_add_typed(request, type_id, response_format='html'):
    "Item add with preselected type"
    
    item_type = get_object_or_404(ItemType, pk=type_id)
    if not request.user.get_profile().has_permission(item_type, mode='x'):
        return user_denied(request, message="You don't have access to create " + unicode(item_type), 
                           response_format=response_format)

    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemForm(request.user.get_profile(), item_type, request.POST, files=request.FILES)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_index'))
    else:
        form = ItemForm(request.user.get_profile(), item_type)
    
    context = _get_default_context(request)
    context.update({'item_type': item_type,
                    'form': form})
    
    return render_to_response('infrastructure/item_add_typed', context,
                              context_instance=RequestContext(request), response_format=response_format)
예제 #4
0
파일: handlers.py 프로젝트: alejo8591/maker
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        item_type = getOrNone(ItemType, request.data.get('type'))
        if not item_type or not request.user.get_profile().has_permission(item_type, mode='x'):
            return rc.FORBIDDEN

        attrs = self.flatten_dict(request)

        form = ItemForm( item_type=item_type, **attrs)
        if form.is_valid():
            item = form.save(request)
            return item
        else:
            self.status = 400
            return form.errors