Exemplo n.º 1
0
    def open_gate(self, gate, user_id, command='open'):
        """Handle gate opening via web interface.
        """
        if command == 'open':
            requests.get(gate.uri_open, timeout=1)

        elif command == 'close':
            requests.get(gate.uri_close, timeout=1)

        else:
            return None

        requests.get(gate.uri_nvr, timeout=1)

        snapshot = self.save_snapshot(gate.id)

        a = Activity()
        a.gate = gate.id
        a.snapshot = snapshot
        a.command = command
        a.success = True
        a.user = user_id
        a.meta = {'tags': ['web'] if command == 'open' else ['close', 'web']}

        db.session.add(a)
        db.session.commit()

        return a.success
Exemplo n.º 2
0
    def insert_one(self, activity):

        new_activity = Activity()

        if "activity" in activity:
            new_activity.activity = activity["activity"]

        if "user_id" in activity:
            new_activity.user = User.objects.get(pk=activity["user_id"])

        new_activity.save()
        return False if new_activity.pk is None else new_activity