def get_app_list(request): BaseResponse = BR() print(request.path) print(request.get_host()) if request.method == 'GET': user_id = request.GET.get("userId") if user_id is None or user_id == '': BaseResponse.error_msg = 'userId can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") user_model = mUser.objects.get(user_id=user_id) app_model = application.objects.values( 'user_id', 'app_id', 'app_name', 'app_url', 'app_logo', 'package_name', 'version_name', 'version_code', 'min_sdk_version', 'target_sdk_version', ).filter(user_id=user_model) BaseResponse.result = {"list": list(app_model)} BaseResponse.error_code = '1' BaseResponse.error_msg = '' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def delete_app(request): BaseResponse = BR() if request.method == 'DELETE': user_id = request.DELETE.get("userId") app_id = request.DELETE.get("appId") if user_id is None or user_id == '': BaseResponse.error_msg = 'userId can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if app_id is None or app_id == '': BaseResponse.error_msg = 'userId can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") application.objects.get(app_id=app_id).delete() BaseResponse.error_code = 1 BaseResponse.error_msg = 'delete app success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def update_apk(request): BaseResponse = BR() if request.method == 'PUT': user_id = request.PUT.get("userId") plugin_id = request.PUT.get("pluginId") apk_id = request.PUT.get("apkId") apk_url = request.PUT.get("apkUrl") min_sdk_version = request.PUT.get("minSdkVersion") target_sdk_version = request.PUT.get("targetSdkVersion") apk_description = request.PUT.get("apkDescription") if plugin_id is None or plugin_id == '': BaseResponse.error_msg = 'plugin id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if apk_id is None or apk_id == '': BaseResponse.error_msg = 'apk id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") apk_file_model = ApkFileModel.objects.get( plugin_id=PluginModel.objects.get(plugin_id=plugin_id), apk_id=apk_id) if target_sdk_version is not None and target_sdk_version != '': apk_file_model.objects.update( target_sdk_version=target_sdk_version) if apk_url is not None and apk_url != '': apk_file_model.objects.update(apk_url=apk_url) if apk_description is not None and apk_description != '': apk_file_model.objects.update(apk_description=apk_description) if min_sdk_version is not None and min_sdk_version != '': apk_file_model.objects.update(min_sdk_version=min_sdk_version) apk_file = request.FILES['file'] if apk_file is None: BaseResponse.error_msg = 'apk file can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") file_path = save_apk_file( apk_file, apk_file_model.apk_name + '_' + apk_file_model.version_code + '.apk', ApplicationModel.objects.get(app_id=PluginModel.objects.get( plugin_id=plugin_id).app_id).user_id) apk_file_model.objects.update(apk_path=file_path) apk_file_model.save() BaseResponse.error_code = 1 BaseResponse.error_msg = 'update plugin success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def get_plugin_list(request): BaseResponse = BR() if request.method == 'GET': app_id = request.GET.get("appId") if app_id is None or app_id == '': BaseResponse.error_msg = 'app id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") application_model = ApplicationModel.objects.get(app_id=app_id) plugin_models = PluginModel.objects.values( "plugin_id", "app_id", "plugin_name", "plugin_description", "package_name", "last_version_name", "last_version_code").filter(app_id=application_model) BaseResponse.result = {"list": list(plugin_models)} BaseResponse.error_code = 1 BaseResponse.error_msg = 'request success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def get_apk(request): BaseResponse = BR() if request.method == 'GET': user_id = request.GET.get("userId") plugin_id = request.GET.get("pluginId") apk_id = request.GET.get("apkId") if plugin_id is None or plugin_id == '': BaseResponse.error_msg = 'plugin id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if apk_id is None or apk_id == '': BaseResponse.error_msg = 'apk id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") BaseResponse.error_code = 1 BaseResponse.result = ApkFileModel.objects.get( plugin_id=PluginModel.objects.get(plugin_id=plugin_id), apk_id=apk_id) return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def delete_apk(request): BaseResponse = BR() if request.method == 'DELETE': plugin_id = request.DELETE.get("pluginId") apk_id = request.DELETE.get("apkId") if plugin_id is None or plugin_id == '': BaseResponse.error_msg = 'plugin id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if apk_id is None or apk_id == '': BaseResponse.error_msg = 'apk id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") ApkFileModel.objects.get( plugin_id=PluginModel.objects.get(plugin_id=plugin_id), apk_id=apk_id).delete() BaseResponse.error_code = 1 BaseResponse.error_msg = 'delete plugin success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def get_plugin(request): BaseResponse = BR() if request.method == 'GET': app_id = request.GET.get("appId") plugin_id = request.GET.get("pluginId") if app_id is None or app_id == '': BaseResponse.error_msg = 'app id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if plugin_id is None or plugin_id == '': BaseResponse.error_msg = 'plugin id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") application_model = ApplicationModel.objects.get(app_id=app_id) BaseResponse.result = PluginModel.objects.get(plugin_id=plugin_id, app_id=application_model) BaseResponse.error_code = 1 BaseResponse.error_msg = 'delete plugin success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def user_registered(request): base_response = BR() # userRegistered if request.method == 'POST': username = request.POST.get('userName', '') password = request.POST.get('passWord', '') if username.strip() == '': base_response.error_msg = Error.Registration_failed_UserName_empty return HttpResponse(jsonTool.object_to_json(base_response), "application/json") account_number = '' try: account_number = mUser.objects.get(accountNumber=username) except: pass if account_number is not None and account_number != '' and account_number.accountNumber != '' \ and account_number.accountNumber == username: base_response.error_msg = Error.Registration_failed_Cannot_register_repeatedly return HttpResponse(jsonTool.object_to_json(base_response), "application/json") if password.strip() == '': base_response.error_msg = Error.Registration_failed_password_empty return HttpResponse(jsonTool.object_to_json(base_response), "application/json") replace = uuid.uuid1().__str__().replace('-', '') try: mUser.objects.create(user_id=replace, account_number=username, pass_word=password).save() except IntegrityError: base_response.error_msg = 'User already exists' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") base_response.error_code = 1 base_response.error_msg = Error.Registered_Success return HttpResponse(jsonTool.object_to_json(base_response), "application/json") else: base_response.error_msg = Error.Request_method_error return HttpResponse(jsonTool.object_to_json(base_response), "application/json")
def user_login(request): base_response = BR() # userLogin if request.method == 'POST': username = request.POST.get('userName', '') password = request.POST.get('passWord', '') if username is None or username == '': base_response.error_msg = 'username can not be empty' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") if password is None or password == '': base_response.error_msg = 'password can not be empty' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") try: user = mUser.objects.values( 'user_id', 'account_number', 'user_name', 'user_logo', 'user_phone', 'pass_word').get(account_number=username) except FieldError: print(FieldError) base_response.error_msg = Error.Username_does_not_exist return HttpResponse(jsonTool.object_to_json(base_response), "application/json") except mUser.DoesNotExist: base_response.error_msg = Error.Username_does_not_exist return HttpResponse(jsonTool.object_to_json(base_response), "application/json") if user is not None and user['pass_word'] != password: base_response.error_msg = Error.Username_or_password_is_incorrect return HttpResponse(jsonTool.object_to_json(base_response), "application/json") base_response.error_code = 1 base_response.error_msg = Error.Login_Success del user['pass_word'] base_response.result = user return HttpResponse(jsonTool.object_to_json(base_response), "application/json") else: base_response.error_msg = Error.Request_method_error return HttpResponse(jsonTool.object_to_json(base_response), "application/json")
def update_app(request): BaseResponse = BR() if request.method == 'PUT': user_id = request.PUT.get("userId") app_id = request.PUT.get("appId") app_name = request.PUT.get("appName") app_url = request.PUT.get("appUrl") app_logo = request.PUT.get("appLogo") package_name = request.PUT.get("packageName") version_name = request.POST.get("versionName") version_code = request.POST.get("versionCode") min_sdk_version = request.POST.get("minSdkVersion") target_sdk_version = request.POST.get("targetSdkVersion") if user_id is None or user_id == '': BaseResponse.error_msg = 'userId can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if app_id is None or app_id == '': BaseResponse.error_msg = 'appId can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") user_model = mUser.objects.get(userId=user_id) app_model = application.objects.get(user_id=user_model, app_id=app_id) if app_name is not None and app_name != '': app_model.objects.update(app_name=app_name) if app_url is not None and app_url != '': app_model.objects.update(app_url=app_url) if app_logo is not None and app_logo != '': app_model.objects.update(app_logo=app_logo) if package_name is not None and package_name != '': app_model.objects.update(package_name=package_name) if version_name is not None and version_name != '': app_model.objects.update(version_name=version_name) if version_code is not None and version_code != '': app_model.objects.update(version_code=version_code) if min_sdk_version is not None and min_sdk_version != '': app_model.objects.update(min_sdk_version=min_sdk_version) if target_sdk_version is not None and target_sdk_version != '': app_model.objects.update(target_sdk_version=target_sdk_version) app_model.save() BaseResponse.error_code = 1 BaseResponse.error_msg = 'update app success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def up_load_file(request): base_response = BaseResponse() print(request.__dict__) if request.method == 'POST': user_id = request.POST.get("userId") print(user_id) if user_id is None or user_id == '': base_response.error_msg = 'user id can not be empty' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") try: user = UserModel.objects.get(user_id=user_id) except FieldError: base_response.error_msg = Error.Username_does_not_exist return HttpResponse(jsonTool.object_to_json(base_response), "application/json") except UserModel.DoesNotExist: base_response.error_msg = Error.Username_does_not_exist return HttpResponse(jsonTool.object_to_json(base_response), "application/json") if user is None: base_response.error_msg = 'user id can not be empty' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") apk_file = request.FILES['file'] if apk_file is None: base_response.error_msg = 'file can not be empty' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") replace = uuid.uuid1().__str__().replace('-', '') file_path = save_apk_file(apk_file, replace + '.png', user_id) file_model = FileModel.objects.create( user_id=UserModel.objects.get(user_id=user_id), serial_number=replace, file_path=file_path) file_model.save() base_response.result = {"file_id": file_model.serial_number} base_response.error_code = 1 base_response.error_msg = 'upload image success' return HttpResponse(jsonTool.object_to_json(base_response), "application/json")
def user_delete(request): base_response = BR() if request.method is 'POST': user_id = request.POST.get('userId', '') username = request.POST.get('userName', '') password = request.POST.get('passWord', '') if username is None or username == '': base_response.error_msg = 'username can not be empty' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") if password is None or password == '': base_response.error_msg = 'password can not be empty' return HttpResponse(jsonTool.object_to_json(base_response), "application/json") mUser.objects.get(user_id=user_id, account_number=username, pass_word=password).delete() base_response.error_code = 1 base_response.error_msg = 'delete user success' return HttpResponse(jsonTool.object_to_json(base_response), "application/json")
def register_app(request): BaseResponse = BR() if request.method == 'POST': user_id = request.POST.get("userId") app_name = request.POST.get("appName") app_url = request.POST.get("appUrl") app_logo = request.POST.get("appLogo") package_name = request.POST.get("packageName") version_name = request.POST.get("versionName") version_code = request.POST.get("versionCode") min_sdk_version = request.POST.get("minSdkVersion") target_sdk_version = request.POST.get("targetSdkVersion") if user_id is None or user_id == '': BaseResponse.error_msg = 'userId can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if app_name is None or app_name == '': BaseResponse.error_msg = 'appName can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if app_url is None or app_url == '': BaseResponse.error_msg = 'appUrl can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if app_logo is None or app_logo == '': BaseResponse.error_msg = 'appLogo can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if package_name is None or package_name == '': BaseResponse.error_msg = 'packageName can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") try: user_model = mUser.objects.get(user_id=user_id) except mUser.DoesNotExist: BaseResponse.error_msg = 'packageName can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") app_id = uuid.uuid1().__str__().replace('-', '') application.objects.create(user_id=user_model, app_id=app_id, app_name=app_name, app_url=app_url, app_logo=app_logo, package_name=package_name, version_name=version_name, version_code=version_code, min_sdk_version=min_sdk_version, target_sdk_version=target_sdk_version).save() BaseResponse.error_code = 1 BaseResponse.error_msg = 'register app success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def get_apk_list(request): BaseResponse = BR() if request.method == 'GET': user_id = request.GET.get("userId") plugin_id = request.GET.get("pluginId") if user_id is None or user_id == '': BaseResponse.error_msg = 'user id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if plugin_id is None or plugin_id == '': BaseResponse.error_msg = 'plugin id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") apk_file_model = ApkFileModel.objects.values( "plugin_id", "apk_id", "apk_name", "apk_description", "apk_url", "apk_path", "package_name", "version_code", "version_name", "min_sdk_version", "target_sdk_version", "file_path").filter( plugin_id=PluginModel.objects.get(plugin_id=plugin_id)) BaseResponse.error_code = 1 BaseResponse.result = {"list": list(apk_file_model)} BaseResponse.error_msg = 'request success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def register_plugin(request): BaseResponse = BR() # appId # pluginName # packageName if request.method == 'POST': app_id = request.POST.get("appId") plugin_name = request.POST.get("pluginName") package_name = request.POST.get("packageName") plugin_description = request.POST.get("pluginDescription") last_version_name = request.POST.get("versionName") last_version_code = request.POST.get("versionCode") if app_id is None or app_id == '': BaseResponse.error_msg = 'app id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if plugin_name is None or plugin_name == '': BaseResponse.error_msg = 'plugin name can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if package_name is None or package_name == '': BaseResponse.error_msg = 'package name can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") plugin_id = uuid.uuid1().__str__().replace('-', '') application_model = ApplicationModel.objects.get(app_id=app_id) PluginModel.objects.create(plugin_id=plugin_id, app_id=application_model, plugin_name=plugin_name, package_name=package_name, plugin_description=plugin_description, last_version_name=last_version_name, last_version_code=last_version_code).save() BaseResponse.error_code = 1 BaseResponse.error_msg = 'register plugin success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")
def upload_apk(request): BaseResponse = BR() if request.method == 'POST': user_id = request.POST.get("userId") plugin_id = request.POST.get("pluginId") apk_name = request.POST.get("appName") apk_url = request.POST.get("appUrl") package_name = request.POST.get("packageName") version_code = request.POST.get("versionCode") version_name = request.POST.get("versionName") min_sdk_version = request.POST.get("minSdkVersion") target_sdk_version = request.POST.get("targetSdkVersion") apk_description = request.POST.get("apkDescription") if user_id is None or user_id == '': BaseResponse.error_msg = 'user id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if plugin_id is None or plugin_id == '': BaseResponse.error_msg = 'plugin id can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if apk_name is None or apk_name == '': BaseResponse.error_msg = 'apk name can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if package_name is None or package_name == '': BaseResponse.error_msg = 'package name can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if version_code is None or version_code == '': BaseResponse.error_msg = 'version code can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if version_name is None or version_name == '': BaseResponse.error_msg = 'version name can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if target_sdk_version is None or target_sdk_version == '': BaseResponse.error_msg = 'target sdk version can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if apk_description is None or apk_description == '': BaseResponse.error_msg = 'apk description can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") if min_sdk_version is None or min_sdk_version == '': min_sdk_version = '-1' plugin_model = PluginModel.objects.get(plugin_id=plugin_id) apk_file = request.FILES['apkPath'] if apk_file is None: BaseResponse.error_msg = 'apk file can not be empty' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json") file_path = save_apk_file(apk_file, apk_name + '_' + version_code + '.apk', user_id) apk_id = uuid.uuid1().__str__().replace('-', '') ApkFileModel.objects.create(plugin_id=plugin_model, apk_name=apk_name, apk_url=apk_url, apk_id=apk_id, package_name=package_name, version_code=version_code, version_name=version_name, min_sdk_version=min_sdk_version, target_sdk_version=target_sdk_version, apk_description=apk_description, apk_path=file_path).save() BaseResponse.error_code = 1 BaseResponse.error_msg = 'upload plugin success' return HttpResponse(jsonTool.object_to_json(BaseResponse), "application/json")