def test_get_package_handler(self):
     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/packages/1')
     response = request.get_response(main.app)
     self.assertEqual(response.status_int, 200)
     right_json = u'''{
         "id": "1",
         "name": "package1",
         "release_time": 1,
         "words": [
             "tea",
             "coffee"
         ]
     }
     '''
     right = json.loads(right_json)
     response_struct = json.loads(response.body)
     self.assertEqual(right, response_struct)
Ejemplo n.º 2
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_change_words_handler(self):
     PackageDictionary(id='package_id_1',
                       name='package1',
                       release_time=1,
                       words=['apple', 'banana']).put()
     request = webapp2.Request.blank(
         '/admin/streams/packages/package_id_1/words')
     response = request.get_response(main.app)
     self.assertEqual(response.status_int, 200)
Ejemplo n.º 4
0
    def get(self, **kwargs):
        packages = PackageDictionary.query(PackageDictionary.id == kwargs.get('package_id')).fetch(1)

        if len(packages) == 0:
            self.error(404)
        else:
            package = packages[0]
            json_obj = {"id": package.id, "name": package.name, "release_time": package.release_time,
                        "words": package.words}

            self.response.write(json.dumps(json_obj))
Ejemplo n.º 5
0
    def post(self, **kwargs):
        words = self.request.get("text")
        list_word = []
        for word in words.strip().split("\n"):
            list_word.append(word.strip())

        package = PackageDictionary.query(PackageDictionary.id == kwargs.get("package_id")).get()
        package.words = list_word
        package.put()
        template = JINJA_ENVIRONMENT.get_template("templates/packagewordsscreen.html")
        self.response.write(template.render({"package_id": kwargs.get("package_id"), "words": words}))
Ejemplo n.º 6
0
 def get(self, **kwargs):
     template = JINJA_ENVIRONMENT.get_template("templates/packagewordsscreen.html")
     packages = PackageDictionary.query(PackageDictionary.id == kwargs.get("package_id")).fetch(1)
     if len(packages) == 0:
         self.error(404)
     else:
         list_words = packages[0].words
         words = ""
         for word in list_words:
             words += "\n" + word
         self.response.write(template.render({"package_id": kwargs.get("package_id"), "words": words}))
Ejemplo n.º 7
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
Ejemplo n.º 8
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")
Ejemplo n.º 9
0
 def get(self, **kwargs):
     template = JINJA_ENVIRONMENT.get_template(
         'templates/packagewordsscreen.html')
     packages = PackageDictionary.query(
         PackageDictionary.id == kwargs.get('package_id')).fetch(1)
     if len(packages) == 0:
         self.error(404)
     else:
         list_words = packages[0].words
         words = ''
         for word in list_words:
             words += '\n' + word
         self.response.write(
             template.render({
                 'package_id': kwargs.get('package_id'),
                 'words': words
             }))
Ejemplo n.º 10
0
    def post(self, **kwargs):
        words = self.request.get('text')
        list_word = []
        for word in words.strip().split('\n'):
            list_word.append(word.strip())

        package = PackageDictionary.query(
            PackageDictionary.id == kwargs.get('package_id')).get()
        package.words = list_word
        package.put()
        template = JINJA_ENVIRONMENT.get_template(
            'templates/packagewordsscreen.html')
        self.response.write(
            template.render({
                'package_id': kwargs.get('package_id'),
                'words': words
            }))
Ejemplo n.º 11
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))
Ejemplo n.º 12
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