예제 #1
0
 def setUpClass(cls):
     super(ReceiptTest, cls).setUpClass()
     EMG_AND_REC_SMS_HANDLERS.set('ils-test-domain', True, namespace=NAMESPACE_DOMAIN)
     cls.order = EmergencyOrder(
         domain=TEST_DOMAIN,
         requesting_user_id=cls.user1.get_id,
         requesting_phone_number='5551234',
         location=cls.user1.sql_location,
         location_code=cls.user1.sql_location.site_code,
         timestamp=datetime.utcnow()
     )
     update_product_quantity_json_field(
         cls.order.products_requested, [ProductQuantity('dp', 100), ProductQuantity('fs', 50)]
     )
     cls.order.save()
예제 #2
0
 def setUpClass(cls):
     super(ReceiptTest, cls).setUpClass()
     EMG_AND_REC_SMS_HANDLERS.set('ils-test-domain', True, namespace=NAMESPACE_DOMAIN)
     cls.order = EmergencyOrder(
         domain=TEST_DOMAIN,
         requesting_user_id=cls.user1.get_id,
         requesting_phone_number='5551234',
         location=cls.user1.sql_location,
         location_code=cls.user1.sql_location.site_code,
         timestamp=datetime.utcnow()
     )
     update_product_quantity_json_field(
         cls.order.products_requested, [ProductQuantity('dp', 100), ProductQuantity('fs', 50)]
     )
     cls.order.save()
예제 #3
0
 def show_in_navigation(cls, domain=None, project=None, user=None):
     return domain and EMG_AND_REC_SMS_HANDLERS.enabled(domain)
예제 #4
0
 def show_in_navigation(cls, domain=None, project=None, user=None):
     return domain and EMG_AND_REC_SMS_HANDLERS.enabled(domain)
예제 #5
0
def handle(verified_contact, text, msg):
    if verified_contact:
        user = verified_contact.owner
        domain = verified_contact.domain
    elif msg.domain:
        user = None
        domain = msg.domain
    else:
        return False

    if not ILSGatewayConfig.for_domain(domain):
        return False

    text = text.replace('\r', ' ').replace('\n', ' ').strip()
    args = text.split()
    if not args:
        return False
    keyword = args[0]

    if keyword.startswith('#'):
        return False

    args = args[1:]
    params = {
        'user': user,
        'domain': domain,
        'args': args,
        'msg': msg,
        'verified_contact': verified_contact
    }

    def not_function(word):
        if args and re.match("del", word):
            return NotDeliveredHandler
        elif args and re.match("sub", word):
            return NotSubmittedHandler
        return None

    handlers_for_unregistered_or_registered_users = {
        ('register', 'reg', 'join', 'sajili'): RegisterHandler,
    }

    handlers_for_registered_users = {
        ('help', 'msaada'): HelpHandler,
        ('language', 'lang', 'lugha'): LanguageHandler,
        ('stop', 'acha', 'hapo'): StopHandler,
        ('test', ): MessageInitiatior,
    }

    handlers_for_registered_users_with_location = {
        ('soh', 'hmk'): SOHHandler,
        ('delivered', 'dlvd', 'nimepokea'): DeliveredHandler,
        ('sijapokea', ): NotDeliveredHandler,
        ('sijatuma', ): NotSubmittedHandler,
        ('la', 'um'): LossAndAdjustment,
        ('stockout', 'hakuna'): StockoutHandler,
        ('not', ): not_function(args[0]) if args else None,
        ('trans', ): TransferHandler
    }

    if EMG_AND_REC_SMS_HANDLERS.enabled(domain):
        handlers_for_registered_users_with_location[(
            'emg', )] = EmergencyHandler
        handlers_for_registered_users_with_location[('rec', )] = ReceiptHandler

    handler_class = (choose_handler(
        keyword, handlers_for_unregistered_or_registered_users)
                     or choose_handler(keyword, handlers_for_registered_users)
                     or choose_handler(
                         keyword, handlers_for_registered_users_with_location))

    if (not user and handler_class not in list(
            handlers_for_unregistered_or_registered_users.values())):
        return True

    if (handler_class in list(
            handlers_for_registered_users_with_location.values())
            and (not user or not user.location_id)):
        return True

    handler = handler_class(**params) if handler_class else None
    if handler:
        if args:
            return handler.handle()
        else:
            return handler.help()
    elif keyword != 'l':
        with localize(verified_contact.owner.get_language_code()):
            send_sms_to_verified_number(verified_contact,
                                        six.text_type(CONTACT_SUPERVISOR))
        return True
예제 #6
0
 def setUpClass(cls):
     super(EmergencyTest, cls).setUpClass()
     EMG_AND_REC_SMS_HANDLERS.set('domain:ils-test-domain', True)
예제 #7
0
 def setUpClass(cls):
     super(EmergencyTest, cls).setUpClass()
     EMG_AND_REC_SMS_HANDLERS.set('ils-test-domain', True, namespace=NAMESPACE_DOMAIN)
예제 #8
0
def handle(verified_contact, text, msg=None):
    user = verified_contact.owner if verified_contact else None
    domain = user.domain

    if domain and not ILSGatewayConfig.for_domain(domain):
        return False

    text = text.replace('\r', ' ').replace('\n', ' ').strip()
    args = text.split()
    if not args:
        return False
    keyword = args[0]

    if keyword.startswith('#'):
        return False

    args = args[1:]
    params = {
        'user': user,
        'domain': domain,
        'args': args,
        'msg': msg,
        'verified_contact': verified_contact
    }

    def not_function(word):
        if args and re.match("del", word):
            return NotDeliveredHandler
        elif args and re.match("sub", word):
            return NotSubmittedHandler
        return None

    handlers = {
        ('arrived', 'aliwasili'): ArrivedHandler,
        ('help', 'msaada'): HelpHandler,
        ('language', 'lang', 'lugha'): LanguageHandler,
        ('stop', 'acha', 'hapo'): StopHandler,
        ('yes', 'ndio', 'ndyo'): YesHandler,
        ('register', 'reg', 'join', 'sajili'): RegisterHandler,
        ('test',): MessageInitiatior,
    }

    location_needed_handlers = {
        ('soh', 'hmk'): SOHHandler,
        ('submitted', 'nimetuma'): RandrHandler,
        ('delivered', 'dlvd', 'nimepokea'): DeliveredHandler,
        ('sijapokea',): NotDeliveredHandler,
        ('sijatuma',): NotSubmittedHandler,
        ('supervision', 'usimamizi'): SupervisionHandler,
        ('la', 'um'): LossAndAdjustment,
        ('stockout', 'hakuna'): StockoutHandler,
        ('not',): not_function(args[0]) if args else None,
        ('trans',): TransferHandler
    }

    if EMG_AND_REC_SMS_HANDLERS.enabled(domain):
        location_needed_handlers[('emg', )] = EmergencyHandler
        location_needed_handlers[('rec',)] = ReceiptHandler

    handler_class = choose_handler(keyword, location_needed_handlers)
    if handler_class and not user.location_id:
        return True

    if not handler_class:
        handler_class = choose_handler(keyword, handlers)

    handler = handler_class(**params) if handler_class else None
    if handler:
        if args:
            return handler.handle()
        else:
            return handler.help()
    elif keyword != 'l':
        with localize(verified_contact.owner.get_language_code()):
            send_sms_to_verified_number(verified_contact, unicode(CONTACT_SUPERVISOR))
        return True
예제 #9
0
def handle(verified_contact, text, msg):
    if verified_contact:
        user = verified_contact.owner
        domain = verified_contact.domain
    elif msg.domain:
        user = None
        domain = msg.domain
    else:
        return False

    if not ILSGatewayConfig.for_domain(domain):
        return False

    text = text.replace('\r', ' ').replace('\n', ' ').strip()
    args = text.split()
    if not args:
        return False
    keyword = args[0]

    if keyword.startswith('#'):
        return False

    args = args[1:]
    params = {
        'user': user,
        'domain': domain,
        'args': args,
        'msg': msg,
        'verified_contact': verified_contact
    }

    def not_function(word):
        if args and re.match("del", word):
            return NotDeliveredHandler
        elif args and re.match("sub", word):
            return NotSubmittedHandler
        return None

    handlers_for_unregistered_or_registered_users = {
        ('register', 'reg', 'join', 'sajili'): RegisterHandler,
    }

    handlers_for_registered_users = {
        ('arrived', 'aliwasili'): ArrivedHandler,
        ('help', 'msaada'): HelpHandler,
        ('language', 'lang', 'lugha'): LanguageHandler,
        ('stop', 'acha', 'hapo'): StopHandler,
        ('yes', 'ndio', 'ndyo'): YesHandler,
        ('test',): MessageInitiatior,
    }

    handlers_for_registered_users_with_location = {
        ('soh', 'hmk'): SOHHandler,
        ('submitted', 'nimetuma'): RandrHandler,
        ('delivered', 'dlvd', 'nimepokea'): DeliveredHandler,
        ('sijapokea',): NotDeliveredHandler,
        ('sijatuma',): NotSubmittedHandler,
        ('supervision', 'usimamizi'): SupervisionHandler,
        ('la', 'um'): LossAndAdjustment,
        ('stockout', 'hakuna'): StockoutHandler,
        ('not',): not_function(args[0]) if args else None,
        ('trans',): TransferHandler
    }

    if EMG_AND_REC_SMS_HANDLERS.enabled(domain):
        handlers_for_registered_users_with_location[('emg',)] = EmergencyHandler
        handlers_for_registered_users_with_location[('rec',)] = ReceiptHandler

    handler_class = (
        choose_handler(keyword, handlers_for_unregistered_or_registered_users) or
        choose_handler(keyword, handlers_for_registered_users) or
        choose_handler(keyword, handlers_for_registered_users_with_location)
    )

    if (
        not user and
        handler_class not in list(handlers_for_unregistered_or_registered_users.values())
    ):
        return True

    if (
        handler_class in list(handlers_for_registered_users_with_location.values()) and
        (not user or not user.location_id)
    ):
        return True

    handler = handler_class(**params) if handler_class else None
    if handler:
        if args:
            return handler.handle()
        else:
            return handler.help()
    elif keyword != 'l':
        with localize(verified_contact.owner.get_language_code()):
            send_sms_to_verified_number(verified_contact, six.text_type(CONTACT_SUPERVISOR))
        return True
예제 #10
0
def handle(verified_contact, text, msg):
    if verified_contact:
        user = verified_contact.owner
        domain = verified_contact.domain
    elif msg.domain:
        user = None
        domain = msg.domain
    else:
        return False

    if not ILSGatewayConfig.for_domain(domain):
        return False

    text = text.replace("\r", " ").replace("\n", " ").strip()
    args = text.split()
    if not args:
        return False
    keyword = args[0]

    if keyword.startswith("#"):
        return False

    args = args[1:]
    params = {"user": user, "domain": domain, "args": args, "msg": msg, "verified_contact": verified_contact}

    def not_function(word):
        if args and re.match("del", word):
            return NotDeliveredHandler
        elif args and re.match("sub", word):
            return NotSubmittedHandler
        return None

    handlers_for_unregistered_or_registered_users = {("register", "reg", "join", "sajili"): RegisterHandler}

    handlers_for_registered_users = {
        ("arrived", "aliwasili"): ArrivedHandler,
        ("help", "msaada"): HelpHandler,
        ("language", "lang", "lugha"): LanguageHandler,
        ("stop", "acha", "hapo"): StopHandler,
        ("yes", "ndio", "ndyo"): YesHandler,
        ("test",): MessageInitiatior,
    }

    handlers_for_registered_users_with_location = {
        ("soh", "hmk"): SOHHandler,
        ("submitted", "nimetuma"): RandrHandler,
        ("delivered", "dlvd", "nimepokea"): DeliveredHandler,
        ("sijapokea",): NotDeliveredHandler,
        ("sijatuma",): NotSubmittedHandler,
        ("supervision", "usimamizi"): SupervisionHandler,
        ("la", "um"): LossAndAdjustment,
        ("stockout", "hakuna"): StockoutHandler,
        ("not",): not_function(args[0]) if args else None,
        ("trans",): TransferHandler,
    }

    if EMG_AND_REC_SMS_HANDLERS.enabled(domain):
        handlers_for_registered_users_with_location[("emg",)] = EmergencyHandler
        handlers_for_registered_users_with_location[("rec",)] = ReceiptHandler

    handler_class = (
        choose_handler(keyword, handlers_for_unregistered_or_registered_users)
        or choose_handler(keyword, handlers_for_registered_users)
        or choose_handler(keyword, handlers_for_registered_users_with_location)
    )

    if not user and handler_class not in handlers_for_unregistered_or_registered_users.values():
        return True

    if handler_class in handlers_for_registered_users_with_location.values() and (not user or not user.location_id):
        return True

    handler = handler_class(**params) if handler_class else None
    if handler:
        if args:
            return handler.handle()
        else:
            return handler.help()
    elif keyword != "l":
        with localize(verified_contact.owner.get_language_code()):
            send_sms_to_verified_number(verified_contact, unicode(CONTACT_SUPERVISOR))
        return True