Example #1
0
def part_edit(request, play_id, play, production_id, part_id):
    production = check_parameters(play_id, play, production_id)

    part = get_object_or_404(Part, id=part_id)
    if part.production != production:
        raise Http404()

    part_form = PartForm(
        data = request.POST or None,
        editing = True,
        instance = part,
        initial = { 'person': part.person } # To make form have name rather than ID
    )

    if request.method == 'POST':
        if request.POST.get('disregard'):
            messages.success(request, u"All right, we\u2019ve ignored any changes you made.")
            return HttpResponseRedirect(production.get_edit_cast_url())
        if part_form.is_valid():
            part_form.save()
            messages.success(request, "Your changes have been stored; thank you.")
            return HttpResponseRedirect(production.get_edit_cast_url())

    return render(request, 'productions/edit-part.html', {
        'id': part_id,
        'form': part_form,
        'production': production,
        'places': production.place_set.order_by('start_date', 'press_date'),
    })
Example #2
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))
Example #3
0
File: views.py Project: ZAM-/trackr
def check_in_or_update_part(request):
    errlst=[]
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        # Testing if Part() object exists
        try:    
            # Setting the part to pass as instance to form
            part = Part.objects.get(bar_code=request.POST.get('bar_code'))
        except Part.DoesNotExist:
            # Creating form with POST data & new row in part table
            myPart = Part(type=PartType(1), bar_code='') #Blank Part entry
            form = PartForm(request.POST, instance=myPart)
        else:
            # Create form with part instance
            # Updating part row with POST data-->most likely new status
            form = PartForm(request.POST, instance=part)
        if form.is_valid() and form.instance.check_in() == False:
            
            form.save(commit=True)
            sn = form.cleaned_data['bar_code']
            status = form.cleaned_data['status']
            messages.success(request,"bar code %s has been successfully %s!" % (sn,status))
        else:
            messages.ERROR(request,"Part is already checked in!")
            return http.HttpResponseRedirect('')   
    else:        
        form = PartForm(initial={'status': Status(3),'type':PartType(1)})
        
        
    return render(request,'add_part.html',{
                                           'title':'Add Item',
                                           'form': form,
                                           'errlist': errlst
                                           })
Example #4
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']))
Example #5
0
        'companies_formset': companies_formset,
        'production': production,
        'places': production.place_set.order_by('start_date', 'press_date'),
    })

@login_required
def production_edit_cast(request, play_id, play, production_id):
    """For picking someone to edit, or adding a new Part"""
    try:
        production = check_parameters(play_id, play, production_id)
    except UnmatchingSlugException, e:
        return HttpResponsePermanentRedirect(e.args[0].get_edit_cast_url())
    initial = { 'production': production }
    if request.GET.get('person'):
        initial['person'] = Person.objects.get(id=base32_to_int(request.GET.get('person')))
    part_form = PartForm(data=request.POST or None, editing=False, initial=initial)

    if request.method == 'POST':
        if part_form.is_valid():
            part_form.instance.production = production
            part_form.save()
            messages.success(request, "Your new part has been added; thank you.")
            return HttpResponseRedirect(production.get_edit_cast_url())

    return render(request, 'productions/edit-parts.html', {
        'production': production,
        'places': production.place_set.order_by('start_date', 'press_date'),
        'form': part_form,
        'parts': production.part_set.order_by('-cast', 'order', 'role', 'person__last_name', 'person__first_name'),
    })
Example #6
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']))