Example #1
0
def handle_installation_component(request, installationid=None):
    logger = logging.getLogger('webapp')
    logger.info('run handle_installation_component run')

    i = Installation.objects.get(id=installationid)
    form = ComponentForm(request.POST)

    if form.is_valid():

        m = InstallationImageMarkup()
        m.x0 = form.cleaned_data['x0']
        m.y0 = form.cleaned_data['y0']
        m.x1 = form.cleaned_data['x1']
        m.y1 = form.cleaned_data['y1']

        i.installationimagemarkup_set.add(m)

        c = Component()
        c.componentModel = form.cleaned_data['componentModel']
        c.serialNumber = form.cleaned_data['serialNumber']
        c.lotNumber = form.cleaned_data['lotNumber']
        c.beginningOfLife = form.cleaned_data['beginningOfLife']
        c.endOfLife = form.cleaned_data['endOfLife']
        c.componentStatus = form.cleaned_data['componentStatus']
        c.installationImageMarkup = m

        i.component_set.add(c)

        changelog = ComponentChangeLog()
        changelog.componentStatus = c.componentStatus
        changelog.changeDate = datetime.datetime.now()
        changelog.changeDescription = 'CREATE [{}]'.format(getpass.getuser())
        changelog.user = get_user(request)
        c.componentchangelog_set.add(changelog)

        notification_message = "component identified"

    b = i.building
    l = b.location
    a = l.area
    return render(request, 'installation/master.html', {'installation': i, 'building': b, 'location': l, 'area': a, 'form': form})
Example #2
0
def replace_component(request, installationid=None, componentid=None):
    logger = logging.getLogger('webapp')
    logger.info('run replace_component run')
    c = Component.objects.get(id=int(componentid))
    if request.method == 'POST':
        form = ComponentForm(request.POST, instance=c)
        if form.is_valid():
            newc = Component()
            newc.componentModel = form.cleaned_data['componentModel']
            newc.serialNumber = form.cleaned_data['serialNumber']
            newc.lotNumber = form.cleaned_data['lotNumber']
            newc.beginningOfLife = form.cleaned_data['beginningOfLife']
            newc.endOfLife = form.cleaned_data['endOfLife']
            newc.componentStatus = form.cleaned_data['componentStatus']

            newc.save()

            if c.endOfLife == None or c.endOfLife > datetime.now():
                logger.info('endOfLife > now, set it to current time')
                c.endOfLife = datetime.now()
            if c.componentStatus.name == 'ACTIVE':
                logger.info('status is active, set it to used')
                c.componentStatus = ComponentStatus.objects.get(name='USED')

            c.save()

            changelog = ComponentChangeLog()
            changelog.componentStatus = c.componentStatus
            changelog.changeDate = datetime.now()
            changelog.changeDescription = 'REPLACE [{}]'.format(getpass.getuser())
            changelog.user = request.user
            c.componentchangelog_set.add(changelog)




        return edit_installation(request, installationid)