# Path: languk/corpus/models.py
# class Corpus:
#     @staticmethod
#     def get_sources():
#         grouped = defaultdict(list)
# 
#         for source in db.corpus__sources.find():
#             try:
#                 grouped[source["collection"]].append(source)
#             except KeyError:
#                 pass
# 
#         return grouped
# 
#     @staticmethod
#     def get_source(collection, _id):
# 
#         return db.corpus__sources.find_one({"collection": collection, "_id": _id})
# 
#     @staticmethod
#     def get_sample(source, slug):
#         if slug not in source["sampling_results"]:
#             return None
# 
#         sample = source["sampling_results"][slug]
#         samples = [i["_id"] for i in sample["ids"]]
# 
#         documents = list(db[source["collection"]].find({"_id": {"$in": samples}}))
#         documents.sort(key=lambda doc: samples.index(doc["_id"]))
# 
#         sample["documents"] = documents
# 
#         return sample
# 
#     @staticmethod
#     def get_article(source, article_id):
#         article = db[source["collection"]].find_one({"_id": article_id})
# 
#         return article


from django.utils.translation import gettext as _
from django.http import Http404
from django.views.generic.base import TemplateView
from .models import Corpus



class CorpusHomeView(TemplateView):
    template_name = "corpus/corpus_home.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["corpus_sources"] = Corpus.get_sources()
        return context


class CorpusSourceView(TemplateView):
    template_name = "corpus/corpus_source.html"

    def get_context_data(self, collection, source_id, **kwargs):
        context = super().get_context_data(**kwargs)


# Path: languk/corpus/models.py
# class Corpus:
#     @staticmethod
#     def get_sources():
#         grouped = defaultdict(list)
# 
#         for source in db.corpus__sources.find():
#             try:
#                 grouped[source["collection"]].append(source)
#             except KeyError:
#                 pass
# 
#         return grouped
# 
#     @staticmethod
#     def get_source(collection, _id):
# 
#         return db.corpus__sources.find_one({"collection": collection, "_id": _id})
# 
#     @staticmethod
#     def get_sample(source, slug):
#         if slug not in source["sampling_results"]:
#             return None
# 
#         sample = source["sampling_results"][slug]
#         samples = [i["_id"] for i in sample["ids"]]
# 
#         documents = list(db[source["collection"]].find({"_id": {"$in": samples}}))
#         documents.sort(key=lambda doc: samples.index(doc["_id"]))
# 
#         sample["documents"] = documents
# 
#         return sample
# 
#     @staticmethod
#     def get_article(source, article_id):
#         article = db[source["collection"]].find_one({"_id": article_id})
# 
#         return article


# Path: languk/corpus/views.py
from django.utils.translation import gettext as _
from django.http import Http404
from django.views.generic.base import TemplateView
from .models import Corpus




class CorpusHomeView(TemplateView):
    template_name = "corpus/corpus_home.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["corpus_sources"] = Corpus.get_sources()
        return context


class CorpusSourceView(TemplateView):
    template_name = "corpus/corpus_source.html"

    def get_context_data(self, collection, source_id, **kwargs):
        context = super().get_context_data(**kwargs)


        source = Corpus.get_source(collection, source_id)