Ejemplo n.º 1
0
def edit(request, object_id, template_name='accounts/accounts_edit.html', next='accounts_detail'):

    # object = get_one_or_404(Account, id=object_id)
    object = get_one_or_404(Account, id=ObjectId(object_id), user=request.user, perm='can_edit')
    user = request.user
    if not (user.is_staff or object.local_id == str(user.id)):
        raise PermissionDenied()
    
    if request.method == 'POST':
        form = AccountForm(request.POST, instance=object)
        locationform = LocationUpdateForm(request.POST, instance=object)
        if form.is_valid(request.user) and locationform.is_valid():
            acct = get_account(request.user.id)

            object.locations = locationform.locations
            object.save()

            increment_resource_crud('account_edit', account=acct)
            object = form.save(False)
            object.save(reindex=True)
            return HttpResponseRedirect(reverse(next, args=[object.id]))
    else:
        form = AccountForm(instance=object)
        locationform = LocationUpdateForm(instance=object)
    
    template_context = {
        'form': form, 'object': object, 
        'locationform': locationform, 'new': False }

    return render_to_response(
        template_name,
        template_context,
        RequestContext(request)
    )
Ejemplo n.º 2
0
def resource_edit(request, object_id, template_name='depot/resource_edit.html'):
    """ edits an existing resource. Uses a wizard-like approach, so checks resource.collection_status
        and hands off to resource_* function handler
    """
    UPDATE_LOCS = 'Update locations'
    UPDATE_TAGS = 'Update tags'

    object = get_one_or_404(Resource, id=ObjectId(object_id), user=request.user, perm='can_edit')

    # doc = ''
    # places = None
    template_info = _template_info(request.REQUEST.get('popup', ''))

    if request.method == 'POST':
        result = request.POST.get('result', '') # or request.POST.get('result', '')
        if result == 'Cancel':
            return resource_edit_complete(request, object, template_info)
        resourceform = ShortResourceForm(request.POST, instance=object)
        eventform = EventForm(request.POST, instance=object.calendar_event)
        locationform = LocationUpdateForm(request.POST, instance=object)
        # shelflifeform = ShelflifeForm(request.POST, instance=object)

        if resourceform.is_valid(request.user) and locationform.is_valid() and eventform.is_valid():
            acct = get_account(request.user.id)
            object.locations = locationform.locations
            increment_resource_crud('resouce_edit', account=acct)

            # Event dates
            event_start = eventform.cleaned_data['start']
            if event_start:
                object.calendar_event = CalendarEvent(start=event_start, end=eventform.cleaned_data['end'])
            else:
                object.calendar_event = None
            object = resourceform.save(do_save=False)            
            try:
                object.save(author=acct, reindex=True)
                return resource_edit_complete(request, object, template_info)
            except OperationError:
                pass
    else:
        resourceform = ShortResourceForm(instance=object)
        locationform = LocationUpdateForm(instance=object)
        eventform = EventForm(instance=object.calendar_event)
        # shelflifeform = ShelflifeForm(instance=object)

    return render_to_response(template_name,
        RequestContext( request, { 'template_info': template_info, 'object': object,
            'resourceform': resourceform, 'locationform': locationform, 'eventform': eventform, #'places': places,
            # 'tagsform': tagsform, #'shelflifeform': shelflifeform,
            'UPDATE_LOCS': UPDATE_LOCS, 'UPDATE_TAGS': UPDATE_TAGS  }))
Ejemplo n.º 3
0
def resource_edit(request,
                  object_id,
                  template_name='depot/resource_edit.html'):
    """ edits an existing resource. Uses a wizard-like approach, so checks resource.collection_status
        and hands off to resource_* function handler
    """
    UPDATE_LOCS = 'Update locations'
    UPDATE_TAGS = 'Update tags'

    object = get_one_or_404(Resource,
                            id=ObjectId(object_id),
                            user=request.user,
                            perm='can_edit')

    # doc = ''
    # places = None
    template_info = _template_info(request.REQUEST.get('popup', ''))

    if request.method == 'POST':
        result = request.POST.get('result',
                                  '')  # or request.POST.get('result', '')
        if result == 'Cancel':
            return resource_edit_complete(request, object, template_info)
        resourceform = ShortResourceForm(request.POST, instance=object)
        eventform = EventForm(request.POST, instance=object.calendar_event)
        locationform = LocationUpdateForm(request.POST, instance=object)
        # shelflifeform = ShelflifeForm(request.POST, instance=object)

        if resourceform.is_valid(request.user) and locationform.is_valid(
        ) and eventform.is_valid():
            acct = get_account(request.user.id)
            object.locations = locationform.locations
            increment_resource_crud('resouce_edit', account=acct)

            # Event dates
            event_start = eventform.cleaned_data['start']
            if event_start:
                object.calendar_event = CalendarEvent(
                    start=event_start, end=eventform.cleaned_data['end'])
            else:
                object.calendar_event = None
            object = resourceform.save(do_save=False)
            try:
                object.save(author=acct, reindex=True)
                return resource_edit_complete(request, object, template_info)
            except OperationError:
                pass
    else:
        resourceform = ShortResourceForm(instance=object)
        locationform = LocationUpdateForm(instance=object)
        eventform = EventForm(instance=object.calendar_event)
        # shelflifeform = ShelflifeForm(instance=object)

    return render_to_response(
        template_name,
        RequestContext(
            request,
            {
                'template_info': template_info,
                'object': object,
                'resourceform': resourceform,
                'locationform': locationform,
                'eventform': eventform,  #'places': places,
                # 'tagsform': tagsform, #'shelflifeform': shelflifeform,
                'UPDATE_LOCS': UPDATE_LOCS,
                'UPDATE_TAGS': UPDATE_TAGS
            }))