<commit_before>from __future__ import absolute_import
from datetime import datetime
from couchdbkit.ext.django.schema import Document, StringProperty, DateTimeProperty
from dimagi.utils.parsing import json_format_datetime
from .utils import generate_aes_key

class MobileAuthKeyRecord(Document):
    """

    Data model for generating the XML for mobile auth
    (from https://bitbucket.org/commcare/commcare/wiki/CentralAuthAPI)

    """

    domain = StringProperty()
    user_id = StringProperty()

    valid = DateTimeProperty()
    expires = DateTimeProperty()
    type = StringProperty(choices=['AES256'], default='AES256')
    key = StringProperty()

    def __init__(self, *args, **kwargs):
        super(MobileAuthKeyRecord, self).__init__(*args, **kwargs)
        if not self.key:
            self.key = generate_aes_key()
        if not self._id:
            self._id = self.get_db().server.next_uuid()

    @property
    def uuid(self):
        return self.get_id

    @classmethod
    def current_for_user(cls, domain, user_id, now=None):
        now = now or datetime.utcnow()
        now_json = json_format_datetime(now)
        key_record = cls.view('mobile_auth/key_records',
            startkey=[domain, user_id, now_json],
            endkey=[domain, user_id, ""],
            descending=True,
            limit=1,
            include_docs=True,
            stale=settings.COUCH_STALE_QUERY,
        ).first()
        if key_record and now < key_record.expires:
            return key_record
        else:
            return None
<commit_msg>remove stale=update_after from somewhere inappropriate<commit_after>from __future__ import absolute_import
from datetime import datetime
from couchdbkit.ext.django.schema import Document, StringProperty, DateTimeProperty
from dimagi.utils.parsing import json_format_datetime
from .utils import generate_aes_key

class MobileAuthKeyRecord(Document):
    """

    Data model for generating the XML for mobile auth
    (from https://bitbucket.org/commcare/commcare/wiki/CentralAuthAPI)

    """

    domain = StringProperty()
    user_id = StringProperty()

    valid = DateTimeProperty()
    expires = DateTimeProperty()
    type = StringProperty(choices=['AES256'], default='AES256')
    key = StringProperty()

    def __init__(self, *args, **kwargs):
        super(MobileAuthKeyRecord, self).__init__(*args, **kwargs)
        if not self.key:
            self.key = generate_aes_key()
        if not self._id:
            self._id = self.get_db().server.next_uuid()

    @property
    def uuid(self):
        return self.get_id

    @classmethod
    def current_for_user(cls, domain, user_id, now=None):
        now = now or datetime.utcnow()
        now_json = json_format_datetime(now)
        key_record = cls.view('mobile_auth/key_records',
            startkey=[domain, user_id, now_json],
            endkey=[domain, user_id, ""],
            descending=True,
            limit=1,
            include_docs=True,
        ).first()
        if key_record and now < key_record.expires:
            return key_record
        else:
            return None

{'fraction_non_alphanumeric': 0.0955434434113498, 'fraction_numerical': 0.004488618146841937, 'mean_word_length': 2.800243605359318, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6625154', 'n_tokens_mistral': 913, 'n_tokens_neox': 881, 'n_words': 211}