예제 #1
0
파일: views.py 프로젝트: cjaniake/ionicweb
def view_edit_installation_component(request, installationid=None, componentid=None):
    c = Component.objects.get(id=int(componentid))
    if request.method == 'GET':
        componentdata = {'type': c.componentModel.componentType.name,
                         'manufacturer': c.componentModel.manufacturer.name,
                         'model': c.componentModel.name, 'componentmodelid': c.componentModel.id,
                         'serialNumber': c.serialNumber, 'lotNumber': c.lotNumber,
                         'beginningOfLife': c.beginningOfLife.date().isoformat(), 'endOfLife': c.endOfLife.date().isoformat(),
                         'status': c.componentStatus.name
                         }
        return HttpResponse(json.dumps(componentdata), content_type="application/json")
    else:
        form = ComponentForm(request.POST, instance=c)
        if form.is_valid():
            before = str(c)

            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.save()

            changelog = ComponentChangeLog()
            changelog.componentStatus = c.componentStatus
            changelog.changeDate = datetime.now()
            changelog.changeDescription = 'CHANGE %s TO %s [{}]'.format(before, c, getpass.getuser())
            changelog.user = request.user
            c.componentchangelog_set.add(changelog)

        return edit_installation(request, installationid)
예제 #2
0
파일: views.py 프로젝트: cjaniake/ionicweb
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})
예제 #3
0
파일: views.py 프로젝트: cjaniake/ionicweb
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)