コード例 #1
0
ファイル: app.py プロジェクト: cash2one/Logistics
    def get(self):
        try:
            data = self.get_query_args()
            data = Schema({
                'app_name': schema_utf8,
                'platform': schema_utf8,
                Optional('version', default=0): Use(int),
            }).validate(data)
            app_name = data['app_name']
            platform = data['platform']
            version = data['version']
        except (SchemaError, Exception):
            logging.exception("参数解析出错")
            self.write_parse_args_failed_response()
            return

        utc_now = TimeZone.utc_now()
        if version == 0:
            app = Application.objects(
                app_name=app_name,
                platform=platform,
                release_time__lte=utc_now).order_by("-release_time").first()
        else:
            app = Application.objects(app_name=app_name,
                                      platform=platform,
                                      version=version).first()
        if not app:
            self.write_not_found_entity_response()
            return

        app.update(inc__download_times=1)
        self.write_response(content=app.link)
コード例 #2
0
ファイル: app.py プロジェクト: cash2one/Logistics
 def post(self):
     try:
         data = json.loads(self.request.body)
         data = Schema({
             'app_name':
             schema_utf8,
             'platform':
             schema_utf8,
             'version':
             Use(int),
             'link':
             schema_utf8,
             'changelog':
             schema_utf8,
             Optional('release_time'):
             And(schema_utf8, Use(TimeZone.str_to_datetime)),
         }).validate(data)
     except (SchemaError, Exception):
         logging.exception("参数解析出错")
         self.write_parse_args_failed_response()
         return
     try:
         app = Application(**data).save()
         self.write_response(content=app.format_response(),
                             status_code=HTTP_201_CREATED)
         return
     except NotUniqueError:
         self.write_duplicate_entry_response()
         return
コード例 #3
0
ファイル: app.py プロジェクト: cash2one/Logistics
 def get(self):
     try:
         data = self.get_query_args()
         data = Schema({
             'app_name':
             schema_utf8,
             Optional('platform', default='android'):
             schema_utf8,
             Optional('page', default=1):
             Use(int),
             Optional('count', default=20):
             Use(int),
             Optional('limit', default=True):
             And(Use(int), Use(bool)),
         }).validate(data)
         page = data.pop('page')
         count = data.pop('count')
         limit = data.pop('limit')
     except (SchemaError, Exception):
         logging.exception("参数解析出错")
         self.write_parse_args_failed_response()
         return
     # apps = Application.objects(**data)
     count, apps = paginator(Application.objects(**data), page, count,
                             limit)
     content = [app.format_response() for app in apps]
     self.set_header('X-Resource-Count', count)
     self.write_response(content=content)
コード例 #4
0
ファイル: app.py プロジェクト: cash2one/Logistics
    def put(self):
        try:
            data = json.loads(self.request.body)
            data = Schema({
                'app_name':
                schema_utf8,
                'platform':
                schema_utf8,
                'version':
                Use(int),
                'link':
                schema_utf8,
                'changelog':
                schema_utf8,
                Optional('release_time'):
                And(schema_utf8, Use(TimeZone.str_to_datetime)),
            }).validate(data)
            app_name = data.pop('app_name')
            platform = data.pop('platform')
            version = data.pop('version')
        except (SchemaError, Exception):
            logging.exception("参数解析出错")
            self.write_parse_args_failed_response()
            return
        app = Application.objects(app_name=app_name,
                                  platform=platform,
                                  version=version).first()
        if not app:
            self.write_not_found_entity_response()
            return

        app.modify(**data)
        self.write_response(content=app.format_response(),
                            status_code=HTTP_201_CREATED)
コード例 #5
0
ファイル: app.py プロジェクト: cash2one/Logistics
    def delete(self):
        try:
            data = self.get_query_args()
            data = Schema({
                'app_name': schema_utf8,
                'platform': schema_utf8,
                'version': Use(int),
            }).validate(data)
        except (SchemaError, Exception):
            logging.exception("参数解析出错")
            self.write_parse_args_failed_response()
            return

        app = Application.objects(**data).delete()
        self.write_no_content_response()
コード例 #6
0
    def gen_app(self, seed=8888, activity_num=None, event_num=None):
        activity_num = activity_num or random.randint(4, 20)
        app = Application(identify='RandomApp_%s' % seed)
        for i in range(activity_num):
            app.add(self.gen_activity())

        app.push_activity(app.sub_list[0])

        event_num = int(event_num
                        or sum([len(a)
                                for a in app.sub_list if a]) * 0.5)  # 总控件数的一半
        for i in range(event_num):
            self.gen_event(app)
        return app
コード例 #7
0
ファイル: app.py プロジェクト: cash2one/Logistics
 def get(self):
     try:
         data = self.get_query_args()
         data = Schema({
             'app_name': schema_utf8,
             'platform': schema_utf8
         }).validate(data)
         app_name = data['app_name']
         platform = data['platform']
     except (SchemaError, Exception):
         logging.exception("参数解析出错")
         self.write_parse_args_failed_response()
         return
     utc_now = TimeZone.utc_now()
     app = Application.objects(
         app_name=app_name, platform=platform,
         release_time__lte=utc_now).order_by("-release_time").first()
     if not app:
         self.write_not_found_entity_response()
         return
     self.write_response(content=app.format_response())
コード例 #8
0
def gen_app_example():
    app = Application(identify='QQ')
    activity_aio = Activity(identify='aio')
    button_jump = Widget(identify='button_jump',
                         t=Widget.BUTTON,
                         position=Position(Position.RECT, 0, 0, 100, 50))
    activity_aio.add(button_jump)
    activity_chat = Activity(identify='chat')
    app.add_list([activity_aio, activity_chat])
    app.push_activity(activity_aio)

    print app

    # bind events
    button_jump.bind('click',
                     BasicEventHandler.gen_push_activity(app, activity_chat))
    button_jump.trigger('click')

    print app
    print button_jump