Esempio n. 1
0
def new_part(request):
    FORM_TITLE_NEW = _('New Book Part')
    FORM_TITLE_EDIT = _('Editing %s')

    monograph_id = request.matchdict['sbid']

    localizer = get_localizer(request)
    part_form = PartForm.get_form(localizer)

    main = get_renderer(BASE_TEMPLATE).implementation()

    if request.method == 'POST':

        controls = request.POST.items()
        try:
            appstruct = part_form.validate(controls)
        except deform.ValidationFailure, e:
            return {'content':e.render(),
                    'main':main,
                    'user':get_logged_user(request),
                    'general_stuff':{'form_title':FORM_TITLE_NEW},
                    }

        part = Part.from_python(appstruct)
        part.monograph = monograph_id

        is_new = True if getattr(part, '_rev', None) is None else False

        part.save(request.db)
        if is_new:
            request.session.flash(_('Successfully added.'))
        else:
            request.session.flash(_('Successfully updated.'))

        return HTTPFound(location=request.route_url('staff.edit_part', sbid=part.monograph, part_id=part._id))
Esempio n. 2
0
def new_part(request):
    FORM_TITLE_NEW = _('New Book Part')
    FORM_TITLE_EDIT = '%s'

    monograph_id = request.matchdict['sbid']
    try:
       monograph = Monograph.get(request.db, monograph_id)
    except couchdbkit.ResourceNotFound:
        raise exceptions.NotFound()

    localizer = get_localizer(request)
    part_form = PartForm.get_form(localizer)

    main = get_renderer(BASE_TEMPLATE).implementation()

    if request.method == 'POST':
        if 'btn_cancel' in request.POST:
            return HTTPFound(location=request.route_path('staff.book_details', sbid=request.matchdict['sbid']))

        controls = request.POST.items()
        try:
            appstruct = part_form.validate(controls)
        except deform.ValidationFailure, e:
            return {'content':e.render(),
                    'main':main,
                    'user':get_logged_user(request),
                    'general_stuff':{'form_title':FORM_TITLE_NEW,
                              'breadcrumb': [
                                (_('Dashboard'), request.route_path('staff.panel')),
                                (monograph.title, request.route_path('staff.book_details', sbid=monograph_id)),
                                (_('New Book Part'), None),
                              ]
                             },
                    }
        try:
           monograph = Monograph.get(request.db, monograph_id)
        except couchdbkit.ResourceNotFound:
            raise exceptions.NotFound()

        monograph_as_python = monograph.to_python()
        appstruct.update({
                'monograph':monograph_as_python['_id'],
                'visible': monograph_as_python['visible'],
                'monograph_title': monograph_as_python['title'],
                'monograph_isbn': monograph_as_python['isbn'],
                'monograph_creators': monograph_as_python['creators'],
                'monograph_publisher': monograph_as_python['publisher'],})
        part = Part.from_python(appstruct)

        if hasattr(monograph, 'language') and monograph.language:
            part.monograph_language = monograph.language
        if hasattr(monograph, 'year') and monograph.year:
            part.monograph_year = monograph.year

        is_new = True if getattr(part, '_rev', None) is None else False

        part.save(request.db)
        if is_new:
            request.session.flash(_('Successfully added.'))
        else:
            request.session.flash(_('Successfully updated.'))

        return HTTPFound(location=request.route_path('staff.book_details', sbid=request.matchdict['sbid']))
Esempio n. 3
0
def new_part(request):
    FORM_TITLE_NEW = _('New Book Part')
    FORM_TITLE_EDIT = '%s'

    monograph_id = request.matchdict['sbid']
    try:
        monograph = Monograph.get(request.db, monograph_id)
    except couchdbkit.ResourceNotFound:
        raise exceptions.NotFound()

    localizer = get_localizer(request)
    part_form = PartForm.get_form(localizer)

    main = get_renderer(BASE_TEMPLATE).implementation()

    if request.method == 'POST':
        if 'btn_cancel' in request.POST:
            return HTTPFound(location=request.route_path(
                'staff.book_details', sbid=request.matchdict['sbid']))

        controls = request.POST.items()
        try:
            appstruct = part_form.validate(controls)
        except deform.ValidationFailure, e:
            return {
                'content': e.render(),
                'main': main,
                'user': get_logged_user(request),
                'general_stuff': {
                    'form_title':
                    FORM_TITLE_NEW,
                    'breadcrumb': [
                        (_('Dashboard'), request.route_path('staff.panel')),
                        (monograph.title,
                         request.route_path('staff.book_details',
                                            sbid=monograph_id)),
                        (_('New Book Part'), None),
                    ]
                },
            }
        try:
            monograph = Monograph.get(request.db, monograph_id)
        except couchdbkit.ResourceNotFound:
            raise exceptions.NotFound()

        monograph_as_python = monograph.to_python()
        appstruct.update({
            'monograph':
            monograph_as_python['_id'],
            'visible':
            monograph_as_python['visible'],
            'monograph_title':
            monograph_as_python['title'],
            'monograph_isbn':
            monograph_as_python.get('isbn'),
            'monograph_creators':
            monograph_as_python['creators'],
            'monograph_publisher':
            monograph_as_python['publisher'],
        })
        part = Part.from_python(appstruct)

        if hasattr(monograph, 'language') and monograph.language:
            part.monograph_language = monograph.language
        if hasattr(monograph, 'year') and monograph.year:
            part.monograph_year = monograph.year

        is_new = True if getattr(part, '_rev', None) is None else False

        part.save(request.db)
        if is_new:
            request.session.flash(_('Successfully added.'))
        else:
            request.session.flash(_('Successfully updated.'))

        return HTTPFound(location=request.route_path(
            'staff.book_details', sbid=request.matchdict['sbid']))