from ocds.storage.helpers import CouchView


class AllDocs(CouchView):

    design = 'docs'

    @staticmethod
    def map(doc):
        yield (doc['tenderID'], doc)


class DateView(CouchView):

    design = 'dates'

    @staticmethod
    def map(doc):
        yield (doc['dateModified'], doc)


views = [
    AllDocs(),
    DateView()
]

from ocds.storage.helpers import CouchView


class AllDocs(CouchView):

    design = 'docs'

    @staticmethod
    def map(doc):
        if 'doc_type' in doc and doc['doc_type'] != 'Tender':
            return

        yield doc['_id'], doc


class DateView(CouchView):

    design = 'dates'

    @staticmethod
    def map(doc):
        if 'doc_type' in doc and doc['doc_type'] != 'Tender':
            return

        yield doc['_id'], doc['dateModified']


views = [
    AllDocs(),
    DateView()
]

Add filter in design docs
Add filter in design docs

  from ocds.storage.helpers import CouchView
  
  
  class AllDocs(CouchView):
  
      design = 'docs'
  
      @staticmethod
      def map(doc):
+         if 'doc_type' in doc and doc['doc_type'] != 'Tender':
+             return
+ 
-         yield (doc['tenderID'], doc)
+         yield doc['_id'], doc
  
  
  class DateView(CouchView):
  
      design = 'dates'
  
      @staticmethod
      def map(doc):
+         if 'doc_type' in doc and doc['doc_type'] != 'Tender':
+             return
+ 
-         yield (doc['dateModified'], doc)
+         yield doc['_id'], doc['dateModified']
  
  
  views = [
      AllDocs(),
      DateView()
  ]
  
Add filter in design docs
## Code Before:
from ocds.storage.helpers import CouchView


class AllDocs(CouchView):

    design = 'docs'

    @staticmethod
    def map(doc):
        yield (doc['tenderID'], doc)


class DateView(CouchView):

    design = 'dates'

    @staticmethod
    def map(doc):
        yield (doc['dateModified'], doc)


views = [
    AllDocs(),
    DateView()
]

## Instruction:
Add filter in design docs
## Code After:
from ocds.storage.helpers import CouchView


class AllDocs(CouchView):

    design = 'docs'

    @staticmethod
    def map(doc):
        if 'doc_type' in doc and doc['doc_type'] != 'Tender':
            return

        yield doc['_id'], doc


class DateView(CouchView):

    design = 'dates'

    @staticmethod
    def map(doc):
        if 'doc_type' in doc and doc['doc_type'] != 'Tender':
            return

        yield doc['_id'], doc['dateModified']


views = [
    AllDocs(),
    DateView()
]
