def iter_all_domains_and_deleted_domains_with_name(domain): """There should only ever be one!""" yield from Domain.view('domain/deleted_domains', key=domain, reduce=False, include_docs=True).all() yield from Domain.view('domain/domains', key=domain, reduce=False, include_docs=True).all()
def get_domain_ids_by_names(names): return [result['id'] for result in Domain.view( "domain/domains", keys=names, reduce=False, include_docs=False )]
def handle(self, *args, **options): domains = Domain.get_all() seen = set([]) dups = set([]) for domain in domains: if domain.name in seen: dups.add(domain.name) else: seen.add(domain.name) if not dups: self.stdout.write('Found no duplicate domains\n') for domain in list(dups): real_dom = Domain.get_by_name(domain) total_doms = Domain.view("domain/domains", key=domain, reduce=False, include_docs=True, ).all() fake_doms = [d for d in total_doms if d.get_id != real_dom.get_id] self.stdout.write('Found Dup: %s\n' % domain) self.stdout.write(" -- _id of correct domain: %s\n" % real_dom.get_id) self.stdout.write(" -- ids of duplicate domains: %s\n" % [d.get_id for d in fake_doms]) for dom in fake_doms: dom.doc_type = 'Domain-DUPLICATE' dom.save()
def _get_domains_without_last_modified_date(self): docs = iter_docs(Domain.get_db(), [ domain['id'] for domain in Domain.view( "domain/domains", reduce=False, include_docs=False) ]) return filter( lambda x: 'last_modified' not in x or not x['last_modified'], docs)
def _get_domains_without_last_modified_date(self): docs = iter_docs(Domain.get_db(), [ domain['id'] for domain in Domain.view( "domain/domains", reduce=False, include_docs=False ) ]) return [x for x in docs if 'last_modified' not in x or not x['last_modified']]
def handle(self, *args, **options): print "Migrating snapshot documents to have a marked head" for domain in Domain.get_all(include_docs=False): head = Domain.view('domain/snapshots', startkey=[domain['id'], {}], endkey=[domain['id'], None], reduce=False, include_docs=True, descending=True, limit=1).first() if head: head.snapshot_head = True head.save()
def process_view(self, request, view_func, view_args, view_kwargs): if 'domain' in view_kwargs: request.domain = view_kwargs['domain'] if 'org' in view_kwargs: request.org = view_kwargs['org'] if request.user and hasattr(request.user, 'get_profile'): sessionid = request.COOKIES.get('sessionid', None) if sessionid: # roundabout way to keep doc_id based caching consistent. # get user doc_id from session_id MISSING = object() INTERRUPTED = object() try: cached_user_doc_id = rcache.get( SESSION_USER_KEY_PREFIX % sessionid, MISSING) except ConnectionInterrumped: cached_user_doc_id = INTERRUPTED # disable session based couch user caching - to be enabled later. if cached_user_doc_id not in (MISSING, INTERRUPTED): # cache hit couch_user = CouchUser.wrap_correctly( cache_core.cached_open_doc(CouchUser.get_db(), cached_user_doc_id)) else: # cache miss, write to cache couch_user = CouchUser.from_django_user(request.user) if couch_user: cache_core.do_cache_doc(couch_user.to_json()) if cached_user_doc_id is not INTERRUPTED: rcache.set(SESSION_USER_KEY_PREFIX % sessionid, couch_user.get_id) request.couch_user = couch_user if 'domain' in view_kwargs: domain = request.domain if not request.couch_user: couch_domain = Domain.view( "domain/domains", key=domain, reduce=False, include_docs=True, ).one() if couch_domain and couch_domain.is_public: request.couch_user = PublicUser(domain) else: request.couch_user = InvalidUser() if request.couch_user: request.couch_user.current_domain = domain return None
def process_view(self, request, view_func, view_args, view_kwargs): if 'domain' in view_kwargs: request.domain = view_kwargs['domain'] if 'org' in view_kwargs: request.org = view_kwargs['org'] if request.user and hasattr(request.user, 'get_profile'): sessionid = request.COOKIES.get('sessionid', None) if sessionid: # roundabout way to keep doc_id based caching consistent. # get user doc_id from session_id MISSING = object() INTERRUPTED = object() try: cached_user_doc_id = rcache.get(SESSION_USER_KEY_PREFIX % sessionid, MISSING) except ConnectionInterrumped: cached_user_doc_id = INTERRUPTED # disable session based couch user caching - to be enabled later. if cached_user_doc_id not in (MISSING, INTERRUPTED): # cache hit couch_user = CouchUser.wrap_correctly( cache_core.cached_open_doc( CouchUser.get_db(), cached_user_doc_id ) ) else: # cache miss, write to cache couch_user = CouchUser.from_django_user(request.user) if couch_user: cache_core.do_cache_doc(couch_user.to_json()) if cached_user_doc_id is not INTERRUPTED: rcache.set(SESSION_USER_KEY_PREFIX % sessionid, couch_user.get_id) request.couch_user = couch_user if 'domain' in view_kwargs: domain = request.domain if not request.couch_user: couch_domain = Domain.view("domain/domains", key=domain, reduce=False, include_docs=True, ).one() if couch_domain and couch_domain.is_public: request.couch_user = PublicUser(domain) else: request.couch_user = InvalidUser() if request.couch_user: request.couch_user.current_domain = domain return None
def handle(self, **options): print("Migrating snapshot documents to have a marked head") for domain in Domain.get_all(include_docs=False): head = Domain.view( 'domain/snapshots', startkey=[domain['id'], {}], endkey=[domain['id'], None], reduce=False, include_docs=True, descending=True, limit=1 ).first() if head: head.snapshot_head = True head.save()
def process_view(self, request, view_func, view_args, view_kwargs): if 'domain' in view_kwargs: request.domain = view_kwargs['domain'] if request.user and hasattr(request.user, 'get_profile'): request.couch_user = CouchUser.from_django_user(request.user) if 'domain' in view_kwargs: domain = request.domain if not request.couch_user: couch_domain = Domain.view("domain/domains", key=domain, reduce=False, include_docs=True).one() if couch_domain and couch_domain.is_public: request.couch_user = PublicUser(domain) else: request.couch_user = InvalidUser() if request.couch_user: request.couch_user.current_domain = domain return None
def process_view(self, request, view_func, view_args, view_kwargs): if 'domain' in view_kwargs: request.domain = view_kwargs['domain'] if 'org' in view_kwargs: request.org = view_kwargs['org'] if request.user and hasattr(request.user, 'get_profile'): request.couch_user = CouchUser.from_django_user(request.user) if 'domain' in view_kwargs: domain = request.domain if not request.couch_user: couch_domain = Domain.view("domain/domains", key=domain, reduce=False, include_docs=True, stale=settings.COUCH_STALE_QUERY, ).one() if couch_domain and couch_domain.is_public: request.couch_user = PublicUser(domain) else: request.couch_user = InvalidUser() if request.couch_user: request.couch_user.current_domain = domain return None
def get_active_domains(self): domain_names = self.domain_names return Domain.view("domain/domains", keys=domain_names, reduce=False, include_docs=True).all()