Example #1
0
    def get_screen(self, id):
        """
        Get single screen by ID
        :param id: screen ID (primary INT key not optional attribute screen_name)
        :return: single DAO object Display
        """
        con = self._get_connection()
        try:
            cur = con.cursor()
            cur.row_factory = sql.Row
            cur.execute("SELECT * FROM Displays WHERE Id=:id", {
                'id': id,
            })
            row = cur.fetchone()

            return DAO.Display(id=row['Id'],
                               device_id=row['Device_id'],
                               display_name=row['Display_name'],
                               screen_name=row['Screen_name'],
                               params=row['Params'])
        except sql.Error as e:
            print(e.args[0])
            return None
        except IndexError:
            print("No item found")
            return None
        finally:
            con.close()
Example #2
0
def save_screen(request, device_id):
    """
    Receive screen parameters from display setting. Insert or update existing screen from DB. Action for 'add screen' and 'save' btn. 
    :param request: 
    :param device_id: parent device ID
    :return: 
    """
    if request.is_ajax() and request.POST.get(
            'destination-device') == device_id and request.POST.get(
                'destination-display-name'):

        screen_id = request.POST.get('destination-screen-id')
        screen_params = {
            'source_device': request.POST.get('data-source-device'),
            'source_ability': request.POST.get('data-source-ability')
        }

        db = DBA.Dba(conf.get('db', 'path'))
        if screen_id:
            # update display setting (already have screen_id)
            old_display = db.get_screen(screen_id)
            old_display.params = json.dumps(screen_params)
            db.update_display(old_display)

        else:
            # insert new display settings (dont have screen_id)
            new_display = DAO.Display(
                device_id=request.POST.get('destination-device'),
                display_name=request.POST.get('destination-display-name'),
                params=json.dumps(screen_params))
            db.insert_display(new_display)

    return HttpResponse('ok')
Example #3
0
    def get_display(self, device_id, display_name):
        """
        Get all screen for single display
        :param device_id: ID of device
        :param display_name: ability name
        :return: list of DAO objects Display
        """
        con = self._get_connection()
        try:
            cur = con.cursor()
            cur.row_factory = sql.Row
            cur.execute(
                "SELECT * FROM Displays WHERE Device_id=:Device_id AND Display_name=:Display_name",
                {
                    "Device_id": device_id,
                    "Display_name": display_name
                })
            rows = cur.fetchall()
            return [
                DAO.Display(id=row['Id'],
                            device_id=row['Device_id'],
                            display_name=row['Display_name'],
                            screen_name=row['Screen_name'],
                            params=row['Params']) for row in rows
            ]

        except sql.Error as e:
            print(e.args[0])
            return None
        except IndexError:
            print("No item found")
            return None
        finally:
            con.close()