예제 #1
0
파일: handlers.py 프로젝트: vingodu/treeio
    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 = ContactForm(contact_type=item.contact_type,
                           instance=item,
                           **attrs)
        if form.is_valid():
            item = form.save(request)
            return item
        else:
            self.status = 400
            return form.errors
예제 #2
0
def contact_add_typed(request, type_id, response_format='html'):
    "Contact add with preselected type"

    contact_type = get_object_or_404(ContactType, pk=type_id)
    if not request.user.get_profile().has_permission(contact_type, mode='x'):
        return user_denied(request,
                           message="You don't have access to create " +
                           unicode(contact_type))

    if request.POST:
        if not 'cancel' in request.POST:
            form = ContactForm(request.user.get_profile(),
                               contact_type,
                               request.POST,
                               files=request.FILES)
            if form.is_valid():
                contact = form.save(request, contact_type)
                contact.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('identities_contact_view', args=[contact.id]))
        else:
            return HttpResponseRedirect(reverse('identities_index'))
    else:
        form = ContactForm(request.user.get_profile(), contact_type)

    types = Object.filter_by_request(request,
                                     ContactType.objects.order_by('name'))

    return render_to_response('identities/contact_add_typed', {
        'type': contact_type,
        'types': types,
        'form': form
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)
예제 #3
0
파일: handlers.py 프로젝트: AlexLX2/treeio
    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 = ContactForm(
            contact_type=item.contact_type, instance=item, **attrs)
        if form.is_valid():
            item = form.save(request)
            return item
        else:
            self.status = 400
            return form.errors
예제 #4
0
def contact_edit(request, contact_id, response_format='html'):
    "Contact edit"
    
    contact = get_object_or_404(Contact, pk=contact_id)
    if not request.user.get_profile().has_permission(contact, mode='w'):
        return user_denied(request, message="You don't have write access to this Contact")

    if request.POST:
        if not 'cancel' in request.POST:
            form = ContactForm(request.user.get_profile(), contact.contact_type, request.POST, 
                               files=request.FILES, instance=contact)
            if form.is_valid():
                contact = form.save(request)
                return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id]))
        else:
            return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id]))
    else:
        form = ContactForm(request.user.get_profile(), contact.contact_type, instance=contact)
    
    
    types = Object.filter_by_request(request, ContactType.objects.order_by('name'))
    
    return render_to_response('identities/contact_edit',
                              {'contact': contact,
                               'types': types,
                               'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
예제 #5
0
def contact_add_typed(request, type_id, response_format='html'):
    "Contact add with preselected type"
    
    contact_type = get_object_or_404(ContactType, pk=type_id)
    if not request.user.get_profile().has_permission(contact_type, mode='x'):
        return user_denied(request, message="You don't have access to create " + unicode(contact_type))

    if request.POST:
        if not 'cancel' in request.POST:
            form = ContactForm(request.user.get_profile(), contact_type, request.POST, files=request.FILES)
            if form.is_valid():
                contact = form.save(request, contact_type)
                contact.set_user_from_request(request)
                return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id]))
        else:
            return HttpResponseRedirect(reverse('identities_index'))
    else:
        form = ContactForm(request.user.get_profile(), contact_type)
    
    types = Object.filter_by_request(request, ContactType.objects.order_by('name'))
    
    
    return render_to_response('identities/contact_add_typed',
                              {'type': contact_type, 'types': types, 'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
예제 #6
0
파일: handlers.py 프로젝트: AlexLX2/treeio
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

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

        attrs = self.flatten_dict(request)

        form = ContactForm(contact_type=contact_type, **attrs)
        if form.is_valid():
            contact = form.save(request, contact_type)
            contact.set_user_from_request(request)
            return contact
        else:
            self.status = 400
            return form.errors
예제 #7
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

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

        attrs = self.flatten_dict(request)

        form = ContactForm(contact_type = contact_type, **attrs)
        if form.is_valid():
            contact = form.save(request, contact_type)
            contact.set_user_from_request(request)
            return contact
        else:
            self.status = 400
            return form.errors
예제 #8
0
def contact_edit(request, contact_id, response_format='html'):
    "Contact edit"

    contact = get_object_or_404(Contact, pk=contact_id)
    if not request.user.get_profile().has_permission(contact, mode='w'):
        return user_denied(
            request, message="You don't have write access to this Contact")

    if request.POST:
        if not 'cancel' in request.POST:
            form = ContactForm(request.user.get_profile(),
                               contact.contact_type,
                               request.POST,
                               files=request.FILES,
                               instance=contact)
            if form.is_valid():
                contact = form.save(request)
                return HttpResponseRedirect(
                    reverse('identities_contact_view', args=[contact.id]))
        else:
            return HttpResponseRedirect(
                reverse('identities_contact_view', args=[contact.id]))
    else:
        form = ContactForm(request.user.get_profile(),
                           contact.contact_type,
                           instance=contact)

    types = Object.filter_by_request(request,
                                     ContactType.objects.order_by('name'))

    return render_to_response('identities/contact_edit', {
        'contact': contact,
        'types': types,
        'form': form
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)