def already_randomized(case): any_message = FRIRandomizedMessage.view( "fri/randomized_message", startkey=[case.domain, case.case_id], endkey=[case.domain, case.case_id, {}], include_docs=True).first() return any_message is not None
def already_randomized(case): any_message = FRIRandomizedMessage.view( "fri/randomized_message", startkey=[case.domain, case._id], endkey=[case.domain, case._id, {}], include_docs=True ).first() return any_message is not None
def handle(self, **options): self.delete_docs( 'FRIMessageBankMessage', FRIMessageBankMessage.view('fri/message_bank', include_docs=True).all()) self.delete_docs( 'FRIRandomizedMessage', FRIRandomizedMessage.view('fri/randomized_message', include_docs=True).all()) self.delete_docs( 'FRIExtraMessage', FRIExtraMessage.view('fri/extra_message', include_docs=True).all())
def get_randomized_message(case, order): if order >= 0 and order <= 279: client = get_redis_client() lock = client.lock("fri-randomization-%s" % case._id, timeout=300) lock.acquire(blocking=True) if not already_randomized(case): randomize_messages(case) release_lock(lock, True) message = FRIRandomizedMessage.view( "fri/randomized_message", key=[case.domain, case._id, order], include_docs=True ).one() return message else: return None
include_docs=True).first() return any_message is not None def get_randomized_message(case, order): if order >= 0 and order <= 279: client = get_redis_client() lock = client.lock("fri-randomization-%s" % case.case_id, timeout=300) lock.acquire(blocking=True) if not already_randomized(case): randomize_messages(case) release_lock(lock, True) message = FRIRandomizedMessage.view( "fri/randomized_message", key=[case.domain, case.case_id, order], include_docs=True).one() return message else: return None def get_date(case, prop): value = case.get_case_property(prop) # A datetime is a date, but a date is not a datetime if isinstance(value, datetime): return datetime.date() elif isinstance(value, date): return value elif isinstance(value, basestring):
def get_randomized_message(case, order): return FRIRandomizedMessage.view("fri/randomized_message", key=[case.domain, case._id, order], include_docs=True).one()