def post(self):
        devName = self.request.get("deviceName")
        device_query = Device.all().filter("name = ", devName)
        devItem = device_query.fetch(1)[0]

        fwgName = self.request.get("fwgName")
        fw_query = FirmwareGroup.all().filter("name = ", fwgName)
        fwgItem = fw_query.fetch(1)[0]

        releaseNumber = self.request.get("releaseName")
        relQuery = Firmware.all().filter("group = ", fwgItem).filter("version = ", releaseNumber)
        relItem = relQuery.fetch(1)[0]

        installationTime = self.request.get("releaseDate")
        if installationTime.strip().lower() == "now":
            installationTime = None
        else:
            installationTime = datetime.strptime(installationTime, "%Y-%m-%d")

        gUser = users.get_current_user()
        query = User.all().filter("googleUser = ", gUser)
        res = query.fetch(1)
        myUser = res[0]

        udu = UserDeviceUpdates()
        udu.user = myUser
        udu.device = devItem
        udu.release = relItem
        if installationTime:
            udu.updateDatetime = installationTime
        udu.put()
    def get(self):
        gUser = users.get_current_user()
        query = User.all().filter("googleUser = "******"user = "******"sEcho")
        numberRecords = int(self.request.get("iDisplayLength"))
        startRecords = int(self.request.get("iDisplayStart"))
        try:
            indexSort = int(self.request.get("iSortCol_0"))
        except:
            indexSort = 0
        directionSort = self.request.get("sSortDir_0")
        if directionSort.strip().lower() == "desc":
            directionSort = "-"
        else:
            directionSort = ""
        #        sortList = ['device.name','device.manufactorer']
        #        device_query = device_query.order(directionSort + sortList[indexSort])
        i = 0
        devices = device_query.fetch(numberRecords, offset=startRecords)
        txt = (
            '{"sEcho": '
            + sEcho
            + ', "iTotalRecords": '
            + str(nrDevices)
            + ', "iTotalDisplayRecords": '
            + str(nrDevices)
            + ', "aaData":  ['
        )
        for device in devices:
            fws = 0
            if i:
                txt += ","
            if device.firmwareGroup:
                fwgName = device.firmwareGroup.name
                fwQuery = Firmware.all().filter("group =", device.firmwareGroup).order("-releaseDate")
                fws = fwQuery.fetch(1)
                if fws:
                    fws = fws[0]
                    fwgLatest = str(fws.version) + " (" + str(fws.releaseDate) + ")"
                else:
                    fwgLatest = "n.a."
            else:
                fwgName = "n.a."
                fwgLatest = "n.a."
            releaseQuery = (
                UserDeviceUpdates.all()
                .filter("user = "******"device = ", device.device)
                .order("-updateDatetime")
            )
            releases = releaseQuery.fetch(1)
            if releases:
                relName = releases[0].release.version
                relDate = str(releases[0].updateDatetime)
            else:
                relName = "n.a."
                relDate = "n.a."
            txt += (
                '["'
                + device.device.name
                + '","'
                + device.device.manufactorer.name
                + '","'
                + fwgName
                + '","'
                + relName
                + '","'
                + relDate
                + '","'
                + fwgLatest
                + '"'
            )

            # newer firmware available?
            if fws:
                if not releases:
                    txt += ', "1"]'
                elif releases[0].release.version != fws.version:
                    txt += ', "1"]'
                else:
                    txt += ', "0"]'
            else:
                txt += ', "0"]'

            i += 1
        txt += "]}"
        self.response.out.write(txt)