def pop_order(cls, user_address): db = Environment.get_db() order_collection = db.get_collection(Order) order_dic = order_collection.find_one({"user_address": user_address}) order = cls.deserialize(order_dic) order_collection.delete_many({"user_address": order.user_address}) return order
def update_application(action): from kanaria.core.environment import Environment kintone = kintoneInterface() order_type = action.order.order_type() field_name = action.order.target app = kintone.service.app(action.order.app_id) app_index = kintone.get_application_index(app.app_id) result = None with app.administration().form() as admin: if order_type == OrderType.ADD_ITEM: import pykintone.application_settings.form_field as ff analyzer = TextAnalyzer() field_type = analyzer.estimate_field_type(field_name) field_code = Environment.get_translator(kintone._env).translate(field_name, "en").replace(" ", "_") f = ff.BaseFormField.create(field_type, field_code, field_name) result = admin.add(f) else: fields = admin.get().fields target = [f for f in fields if f.label == field_name] if len(target) > 0: result = admin.delete(target[0]) return result, app_index
def pop_order(cls, user_address): db = Environment.get_db() order_collection = db.get_collection(Order) order_dic = order_collection.find_one({"user_address": user_address}) order = cls.deserialize(order_dic) order_collection.delete_many({"user_address": order.user_address}) return order
def update_application(action): from kanaria.core.environment import Environment kintone = kintoneInterface() order_type = action.order.order_type() field_name = action.order.target app = kintone.service.app(action.order.app_id) app_index = kintone.get_application_index(app.app_id) result = None with app.administration().form() as admin: if order_type == OrderType.ADD_ITEM: import pykintone.application_settings.form_field as ff analyzer = TextAnalyzer() field_type = analyzer.estimate_field_type(field_name) field_code = Environment.get_translator(kintone._env).translate( field_name, "en").replace(" ", "_") f = ff.BaseFormField.create(field_type, field_code, field_name) result = admin.add(f) else: fields = admin.get().fields target = [f for f in fields if f.label == field_name] if len(target) > 0: result = admin.delete(target[0]) return result, app_index
def setUpClass(cls): """ letter = Letter("クレームの管理をしたい", "") order = Order(OrderType.CREATE_APPLICATION, "test_service_brain_executor", letter.subject, target="クレーム管理", letter=letter) action = Action(DecisionType.EXECUTE, order) copied = executor.create_application(action) """ from kanaria.core.environment import Environment cls.TEST_APP = Environment.get_kintone_service().app(app_id=268) print("Caution: You have to delete application on kintone!")
def create_application(action, enable_copy=True): from kanaria.core.environment import Environment kintone = kintoneInterface() name = action.order.target code = Environment.get_translator(kintone._env).translate(name, "en").replace(" ", "_").lower() app_info = kintone.find_similar_applications(name, find_template=True) app = None app_index = None if len(app_info) > 0 and enable_copy: app = kintone.copy_application(app_info[0].app_id, name, code) else: app = kintone.create_default_application(name, code) if app: app_index = kintone.get_application_index(app.app_id) return app, app_index
def create_application(action, enable_copy=True): from kanaria.core.environment import Environment kintone = kintoneInterface() name = action.order.target code = Environment.get_translator(kintone._env).translate( name, "en").replace(" ", "_").lower() app_info = kintone.find_similar_applications(name, find_template=True) app = None app_index = None if len(app_info) > 0 and enable_copy: app = kintone.copy_application(app_info[0].app_id, name, code) else: app = kintone.create_default_application(name, code) if app: app_index = kintone.get_application_index(app.app_id) return app, app_index
def test_make_reply(self): from kanaria.core.environment import Environment from kanaria.core.service.brain import Brain env = Environment() domain = env.mail_domain kanaria_admin = Brain.MY_USER_NAME + "@" + domain from_address = "test_user@" + domain letter = Letter("報告日を追加してほしい", "", from_address=from_address, to_addresses=kanaria_admin) order = Order(OrderType.ADD_ITEM, "test_user", app_id=self.TEST_APP.app_id, letter=letter) action = Action(DecisionType.EXECUTE, order) reply = action.make_reply(message="返信を書きました") self.assertTrue(reply.subject) self.assertTrue(from_address in reply.to_addresses) # system mail letter.from_address = kanaria_admin letter.to_addresses = [kanaria_admin, from_address] reply = action.make_reply(message="管理者から返信を書きました") self.assertTrue(kanaria_admin not in reply.to_addresses)
def make_reply(self, subject="", message="", from_user=""): msg = message if message else self.message if not msg: return None sub = subject if subject else "Re: " + self.order.letter().subject env = Environment() letter = self.order.letter() admin_address = Brain.MY_USER_NAME + "@" + env.mail_domain from_address = from_user + "@" + env.mail_domain if from_user else admin_address to_addresses = [ a for a in letter.to_addresses + [letter.from_address] if a != from_address ] to_addresses = [ a for a in to_addresses if not a.startswith(Brain.MY_USER_NAME) and not a.endswith(env.mail_domain) ] letter = Letter(subject=sub, body=msg, from_address=from_address, to_addresses=to_addresses) return letter
def __init__(self): from kanaria.core.environment import Environment self._env = Environment() self.service = Environment.get_kintone_service(self._env) self.db = Environment.get_db(self._env)
def hold_order(cls, order): db = Environment.get_db() # delete previous held orders db.get_collection(Order).delete_many({"user_address": order.user_address}) db.save(order)
def __get_key_id(self): e = Environment() return e.mail_api_key
def test_load_environment(self): env = Environment() self.assertTrue(env) print(env)
def __init__(self): from kanaria.core.environment import Environment self._env = Environment() self.service = Environment.get_kintone_service(self._env) self.db = Environment.get_db(self._env)
def hold_order(cls, order): db = Environment.get_db() # delete previous held orders db.get_collection(Order).delete_many( {"user_address": order.user_address}) db.save(order)