Exemplo n.º 1
0
    def post(self, *args, **kwargs):
        if PackagesStream.query(PackagesStream.id == self.request.get(
                'stream_id')).get() is None:
            PackagesStream(id=self.request.get('stream_id'),
                           name=self.request.get('stream_name'),
                           packages_id_list=[]).put()

        self.redirect('/admin/streams')
 def test_add_package_handler(self):
     PackagesStream(id='stream_id_1', name='stream1',
                    packages_id_list=[]).put()
     request = webapp2.Request.blank(
         '/admin/streams/stream_id_1/packages/add')
     response = request.get_response(main.app)
     self.assertEqual(response.status_int, 200)
Exemplo n.º 3
0
def get_streams():
    streams_list = PackagesStream.query()
    streams = 'id name<br/>'
    for stream in streams_list:
        streams += "<a href='/admin/streams/" + stream.id + "/packages/add'>" + stream.id + ' ' + stream.name + '</a><br/>'

    return streams
 def test_get_packages_list_handler(self):
     PackagesStream(id='1', name='stream1', packages_id_list=['1',
                                                              '2']).put()
     PackageDictionary(id='1',
                       name='package1',
                       release_time=1,
                       words=['tea', 'coffee']).put()
     PackageDictionary(id='2',
                       name='package2',
                       release_time=2,
                       words=['apple', 'banana']).put()
     request = webapp2.Request.blank(r'/device_id_1/streams/1')
     response = request.get_response(main.app)
     self.assertEqual(response.status_int, 200)
     right_json = u'''{
         "packages": [
             {
                 "id": "1",
                 "name": "package1",
                 "release_time": 1
             },
             {
                 "id": "2",
                 "name": "package2",
                 "release_time": 2
             }
         ]
     }
     '''
     right = json.loads(right_json)
     response_struct = json.loads(response.body)
     self.assertEqual(response_struct, right)
Exemplo n.º 5
0
    def get(self, *args, **kwargs):
        streams_list = PackagesStream.query()
        json_obj = {'streams': []}
        for stream in streams_list:
            json_obj['streams'].append({'id': stream.id, 'name': stream.name})

        self.response.write(json.dumps(json_obj))
Exemplo n.º 6
0
    def post(self, *args, **kwargs):
        if PackagesStream.query(PackagesStream.id == self.request.get("stream_id")).get() is None:
            PackagesStream(
                id=self.request.get("stream_id"), name=self.request.get("stream_name"), packages_id_list=[]
            ).put()

        self.redirect("/admin/streams")
Exemplo n.º 7
0
def get_streams():
    streams_list = PackagesStream.query()
    streams = "id name<br/>"
    for stream in streams_list:
        streams += (
            "<a href='/admin/streams/" + stream.id + "/packages/add'>" + stream.id + " " + stream.name + "</a><br/>"
        )

    return streams
Exemplo n.º 8
0
def get_packages(stream_id):
    packages_stream = PackagesStream.query(
        PackagesStream.id == stream_id).get()
    packages_list = []
    for package_id in packages_stream.packages_id_list:
        packages_list.append(
            PackageDictionary.query(PackageDictionary.id == package_id).get())

    packages = 'id name<br/>'
    for package in packages_list:
        packages += "<a href='/admin/streams/packages/" + package.id + "/words'>" + \
                    package.id + ' ' + package.name + "</a><br/>"

    return packages
Exemplo n.º 9
0
    def post(self, **kwargs):
        if PackageDictionary.query(PackageDictionary.id == self.request.get("package_id")).get() is None:
            PackageDictionary(
                id=self.request.get("package_id"),
                name=self.request.get("package_name"),
                release_time=int(self.request.get("release_time")),
                words=[],
            ).put()

        stream = PackagesStream.query(PackagesStream.id == kwargs.get("stream_id")).get()
        if self.request.get("package_id") not in stream.packages_id_list:
            stream.packages_id_list.append(self.request.get("package_id"))
        stream.put()
        self.redirect("/admin/streams/" + kwargs.get("stream_id") + "/packages/add")
    def test_get_streams_list_handler(self):
        PackagesStream(id='1', name='stream1', packages_id_list=['1',
                                                                 '2']).put()
        PackagesStream(id='2', name='stream2', packages_id_list=['3']).put()

        request = webapp2.Request.blank('/device_id_1/streams')
        response = request.get_response(main.app)
        self.assertEqual(response.status_int, 200)
        right_json = u'''{
            "streams": [
                {
                    "id": "1",
                    "name": "stream1"
                },
                {
                    "id": "2",
                    "name": "stream2"
                }
            ]
        }
        '''
        right = json.loads(right_json)
        response_struct = json.loads(response.body)
        self.assertEqual(response_struct, right)
Exemplo n.º 11
0
    def post(self, **kwargs):
        if PackageDictionary.query(PackageDictionary.id == self.request.get(
                'package_id')).get() is None:
            PackageDictionary(id=self.request.get('package_id'),
                              name=self.request.get('package_name'),
                              release_time=int(
                                  self.request.get('release_time')),
                              words=[]).put()

        stream = PackagesStream.query(
            PackagesStream.id == kwargs.get('stream_id')).get()
        if self.request.get('package_id') not in stream.packages_id_list:
            stream.packages_id_list.append(self.request.get('package_id'))
        stream.put()
        self.redirect('/admin/streams/' + kwargs.get('stream_id') +
                      '/packages/add')
Exemplo n.º 12
0
    def get(self, **kwargs):
        packages_stream = PackagesStream.query(PackagesStream.id == kwargs.get('stream_id')).fetch(1)

        if len(packages_stream) == 0:
            self.error(404)
        else:
            packages_list = []
            for package_id in packages_stream[0].packages_id_list:
                packages = PackageDictionary.query(PackageDictionary.id == package_id).fetch(1)
                if len(packages) == 0:
                    self.error(404)
                packages_list.append(packages[0])
            json_obj = {'packages': []}
            for package in packages_list:
                json_obj['packages'].append(
                    {'id': package.id, 'name': package.name, 'release_time': package.release_time})

            self.response.write(json.dumps(json_obj))
Exemplo n.º 13
0
def get_packages(stream_id):
    packages_stream = PackagesStream.query(PackagesStream.id == stream_id).get()
    packages_list = []
    for package_id in packages_stream.packages_id_list:
        packages_list.append(PackageDictionary.query(PackageDictionary.id == package_id).get())

    packages = "id name<br/>"
    for package in packages_list:
        packages += (
            "<a href='/admin/streams/packages/"
            + package.id
            + "/words'>"
            + package.id
            + " "
            + package.name
            + "</a><br/>"
        )

    return packages