예제 #1
0
def get_contributors(entity_id, author_id, type):
    contributors_ids = list(prototypes.ContributionPrototype._db_filter(type=type,
                                                                        entity_id=entity_id).order_by('created_at').values_list('account_id', flat=True))

    if author_id is not None and author_id not in contributors_ids:
        contributors_ids.append(author_id)

    contributors = AccountPrototype.from_query(AccountPrototype._db_filter(id__in=contributors_ids))
    clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype._db_filter(id__in=[account.clan_id for account in contributors if account.clan_id is not None]))}

    contributors.sort(key=lambda c: contributors_ids.index(c.id))

    return contributors, clans
예제 #2
0
파일: views.py 프로젝트: angru/the-tale
def get_contributors(entity_id, author_id, type):
    contributors_ids = list(prototypes.ContributionPrototype._db_filter(type=type,
                                                                        entity_id=entity_id).order_by('created_at').values_list('account_id', flat=True))

    if author_id is not None and author_id not in contributors_ids:
        contributors_ids.append(author_id)

    contributors = AccountPrototype.from_query(AccountPrototype._db_filter(id__in=contributors_ids))
    clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype._db_filter(id__in=[account.clan_id for account in contributors if account.clan_id is not None]))}

    contributors.sort(key=lambda c: contributors_ids.index(c.id))

    return contributors, clans
예제 #3
0
    def index(self, key=None, state=None, filter=None, restriction=None, errors_status=None, page=1, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT):
        templates_query = prototypes.TemplatePrototype._db_all().order_by('raw_template')

        if contributor is not None:
            entities_ids = prototypes.ContributionPrototype._db_filter(type=relations.CONTRIBUTION_TYPE.TEMPLATE,
                                                                       account_id=contributor.id).values_list('entity_id', flat=True)
            templates_query = templates_query.filter(models.Q(id__in=entities_ids)|models.Q(author_id=contributor.id))

        if key:
            templates_query = templates_query.filter(key=key)

        if state:
            templates_query = templates_query.filter(state=state)

        if errors_status:
            templates_query = templates_query.filter(errors_status=errors_status)

        if restriction:
            templates_query = templates_query.filter(templaterestriction__restriction_id=restriction.id)

        if filter:
            templates_query = templates_query.filter(raw_template__icontains=filter)


        if order_by.is_UPDATED_AT:
            templates_query = templates_query.order_by('-updated_at')
        elif order_by.is_TEXT:
            templates_query = templates_query.order_by('raw_template')

        page = int(page) - 1

        templates_count = templates_query.count()

        url_builder = UrlBuilder(reverse('linguistics:templates:'), arguments={ 'state': state.value if state else None,
                                                                                'errors_status': errors_status.value if errors_status else None,
                                                                                'contributor': contributor.id if contributor else None,
                                                                                'order_by': order_by.value,
                                                                                'filter': filter,
                                                                                'restriction': restriction.id if restriction is not None else None,
                                                                                'key': key.value if key is not None else None})

        index_filter = TemplatesIndexFilter(url_builder=url_builder, values={'state': state.value if state else None,
                                                                             'errors_status': errors_status.value if errors_status else None,
                                                                             'contributor': contributor.nick if contributor else None,
                                                                             'order_by': order_by.value,
                                                                             'filter': filter,
                                                                             'restriction': restriction.id if restriction is not None else None,
                                                                             'key': key.value if key is not None else None,
                                                                             'count': templates_query.count()})


        paginator = Paginator(page, templates_count, linguistics_settings.TEMPLATES_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        template_from, template_to = paginator.page_borders(page)

        templates = prototypes.TemplatePrototype.from_query(templates_query[template_from:template_to])

        authors = {account.id: account for account in AccountPrototype.from_query(AccountPrototype.get_list_by_id([template.author_id for template in templates]))}
        clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()]))}

        return self.template('linguistics/templates/index.html',
                             {'key': key,
                              'templates': templates,
                              'index_filter': index_filter,
                              'page_type': 'all-templates',
                              'paginator': paginator,
                              'authors': authors,
                              'clans': clans,
                              'LEXICON_KEY': keys.LEXICON_KEY} )
예제 #4
0
    def index(self, page=1, state=None, type=None, filter=None, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT):

        words_query = prototypes.WordPrototype._db_all().order_by('normal_form')

        if contributor is not None:
            entities_ids = prototypes.ContributionPrototype._db_filter(type=relations.CONTRIBUTION_TYPE.WORD,
                                                                       account_id=contributor.id).values_list('entity_id', flat=True)
            words_query = words_query.filter(models.Q(id__in=entities_ids)|models.Q(author_id=contributor.id))

        if state:
            words_query = words_query.filter(state=state)

        if type:
            words_query = words_query.filter(type=type.utg_type)

        if filter:
            words_query = words_query.filter(normal_form__istartswith=filter.lower())

        if order_by.is_UPDATED_AT:
            words_query = words_query.order_by('-updated_at')
        elif order_by.is_TEXT:
            words_query = words_query.order_by('normal_form')

        words_count = words_query.count()

        url_builder = UrlBuilder(reverse('linguistics:words:'), arguments={ 'state': state.value if state else None,
                                                                            'type': type.value if type else None,
                                                                            'contributor': contributor.id if contributor else None,
                                                                            'order_by': order_by.value,
                                                                            'filter': filter})

        index_filter = WordsIndexFilter(url_builder=url_builder, values={'state': state.value if state else None,
                                                                         'type': type.value if type else None,
                                                                         'filter': filter,
                                                                         'contributor': contributor.nick if contributor else None,
                                                                         'order_by': order_by.value,
                                                                         'count': words_count})

        page = int(page) - 1

        paginator = Paginator(page, words_count, linguistics_settings.WORDS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        words_from, words_to = paginator.page_borders(page)

        words = prototypes.WordPrototype.from_query(words_query[words_from:words_to])

        authors = {account.id: account for account in AccountPrototype.from_query(AccountPrototype.get_list_by_id([word.author_id for word in words]))}
        clans = {clan.id: clan for clan in ClanPrototype.from_query(ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()]))}


        return self.template('linguistics/words/index.html',
                             {'words': words,
                              'page_type': 'dictionary',
                              'paginator': paginator,
                              'authors': authors,
                              'clans': clans,
                              'ALLOWED_WORD_TYPE': relations.ALLOWED_WORD_TYPE,
                              'index_filter': index_filter} )
예제 #5
0
    def index(self,
              key=None,
              state=None,
              filter=None,
              restriction=None,
              errors_status=None,
              page=1,
              contributor=None,
              order_by=relations.INDEX_ORDER_BY.UPDATED_AT):
        templates_query = prototypes.TemplatePrototype._db_all().order_by(
            'raw_template')

        if contributor is not None:
            entities_ids = prototypes.ContributionPrototype._db_filter(
                type=relations.CONTRIBUTION_TYPE.TEMPLATE,
                account_id=contributor.id).values_list('entity_id', flat=True)
            templates_query = templates_query.filter(
                models.Q(id__in=entities_ids)
                | models.Q(author_id=contributor.id))

        if key:
            templates_query = templates_query.filter(key=key)

        if state:
            templates_query = templates_query.filter(state=state)

        if errors_status:
            templates_query = templates_query.filter(
                errors_status=errors_status)

        if restriction:
            templates_query = templates_query.filter(
                templaterestriction__restriction_id=restriction.id)

        if filter:
            templates_query = templates_query.filter(
                raw_template__icontains=filter)

        if order_by.is_UPDATED_AT:
            templates_query = templates_query.order_by('-updated_at')
        elif order_by.is_TEXT:
            templates_query = templates_query.order_by('raw_template')

        page = int(page) - 1

        templates_count = templates_query.count()

        url_builder = UrlBuilder(
            reverse('linguistics:templates:'),
            arguments={
                'state': state.value if state else None,
                'errors_status':
                errors_status.value if errors_status else None,
                'contributor': contributor.id if contributor else None,
                'order_by': order_by.value,
                'filter': filter,
                'restriction':
                restriction.id if restriction is not None else None,
                'key': key.value if key is not None else None
            })

        index_filter = TemplatesIndexFilter(
            url_builder=url_builder,
            values={
                'state': state.value if state else None,
                'errors_status':
                errors_status.value if errors_status else None,
                'contributor': contributor.nick if contributor else None,
                'order_by': order_by.value,
                'filter': filter,
                'restriction':
                restriction.id if restriction is not None else None,
                'key': key.value if key is not None else None,
                'count': templates_query.count()
            })

        paginator = Paginator(page, templates_count,
                              linguistics_settings.TEMPLATES_ON_PAGE,
                              url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        template_from, template_to = paginator.page_borders(page)

        templates = prototypes.TemplatePrototype.from_query(
            templates_query[template_from:template_to])

        authors = {
            account.id: account
            for account in AccountPrototype.from_query(
                AccountPrototype.get_list_by_id(
                    [template.author_id for template in templates]))
        }
        clans = {
            clan.id: clan
            for clan in ClanPrototype.from_query(
                ClanPrototype.get_list_by_id(
                    [author.clan_id for author in authors.values()]))
        }

        return self.template(
            'linguistics/templates/index.html', {
                'key': key,
                'templates': templates,
                'index_filter': index_filter,
                'page_type': 'all-templates',
                'paginator': paginator,
                'authors': authors,
                'clans': clans,
                'LEXICON_KEY': keys.LEXICON_KEY
            })
예제 #6
0
    def index(self,
              page=1,
              state=None,
              type=None,
              filter=None,
              contributor=None,
              order_by=relations.INDEX_ORDER_BY.UPDATED_AT):

        words_query = prototypes.WordPrototype._db_all().order_by(
            'normal_form')

        if contributor is not None:
            entities_ids = prototypes.ContributionPrototype._db_filter(
                type=relations.CONTRIBUTION_TYPE.WORD,
                account_id=contributor.id).values_list('entity_id', flat=True)
            words_query = words_query.filter(
                models.Q(id__in=entities_ids)
                | models.Q(author_id=contributor.id))

        if state:
            words_query = words_query.filter(state=state)

        if type:
            words_query = words_query.filter(type=type.utg_type)

        if filter:
            words_query = words_query.filter(forms__icontains=filter.lower())

        if order_by.is_UPDATED_AT:
            words_query = words_query.order_by('-updated_at')
        elif order_by.is_TEXT:
            words_query = words_query.order_by('normal_form')

        words_count = words_query.count()

        url_builder = UrlBuilder(reverse('linguistics:words:'),
                                 arguments={
                                     'state':
                                     state.value if state else None,
                                     'type':
                                     type.value if type else None,
                                     'contributor':
                                     contributor.id if contributor else None,
                                     'order_by':
                                     order_by.value,
                                     'filter':
                                     filter
                                 })

        index_filter = WordsIndexFilter(
            url_builder=url_builder,
            values={
                'state': state.value if state else None,
                'type': type.value if type else None,
                'filter': filter,
                'contributor': contributor.nick if contributor else None,
                'order_by': order_by.value,
                'count': words_count
            })

        page = int(page) - 1

        paginator = Paginator(page, words_count,
                              linguistics_settings.WORDS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        words_from, words_to = paginator.page_borders(page)

        words = prototypes.WordPrototype.from_query(
            words_query[words_from:words_to])

        authors = {
            account.id: account
            for account in AccountPrototype.from_query(
                AccountPrototype.get_list_by_id(
                    [word.author_id for word in words]))
        }
        clans = {
            clan.id: clan
            for clan in ClanPrototype.from_query(
                ClanPrototype.get_list_by_id(
                    [author.clan_id for author in authors.values()]))
        }

        return self.template(
            'linguistics/words/index.html', {
                'words': words,
                'page_type': 'dictionary',
                'paginator': paginator,
                'authors': authors,
                'clans': clans,
                'ALLOWED_WORD_TYPE': relations.ALLOWED_WORD_TYPE,
                'index_filter': index_filter
            })
예제 #7
0
파일: views.py 프로젝트: lshestov/the-tale
    def index(
        self,
        key=None,
        state=None,
        filter=None,
        restriction=None,
        errors_status=None,
        page=1,
        contributor=None,
        order_by=relations.INDEX_ORDER_BY.UPDATED_AT,
    ):
        templates_query = prototypes.TemplatePrototype._db_all().order_by("raw_template")

        if contributor is not None:
            entities_ids = prototypes.ContributionPrototype._db_filter(
                type=relations.CONTRIBUTION_TYPE.TEMPLATE, account_id=contributor.id
            ).values_list("entity_id", flat=True)
            templates_query = templates_query.filter(models.Q(id__in=entities_ids) | models.Q(author_id=contributor.id))

        if key:
            templates_query = templates_query.filter(key=key)

        if state:
            templates_query = templates_query.filter(state=state)

        if errors_status:
            templates_query = templates_query.filter(errors_status=errors_status)

        if restriction:
            templates_query = templates_query.filter(templaterestriction__restriction_id=restriction.id)

        if filter:
            templates_query = templates_query.filter(raw_template__icontains=filter)

        if order_by.is_UPDATED_AT:
            templates_query = templates_query.order_by("-updated_at")
        elif order_by.is_TEXT:
            templates_query = templates_query.order_by("raw_template")

        page = int(page) - 1

        templates_count = templates_query.count()

        url_builder = UrlBuilder(
            reverse("linguistics:templates:"),
            arguments={
                "state": state.value if state else None,
                "errors_status": errors_status.value if errors_status else None,
                "contributor": contributor.id if contributor else None,
                "order_by": order_by.value,
                "filter": filter,
                "restriction": restriction.id if restriction is not None else None,
                "key": key.value if key is not None else None,
            },
        )

        index_filter = TemplatesIndexFilter(
            url_builder=url_builder,
            values={
                "state": state.value if state else None,
                "errors_status": errors_status.value if errors_status else None,
                "contributor": contributor.nick if contributor else None,
                "order_by": order_by.value,
                "filter": filter,
                "restriction": restriction.id if restriction is not None else None,
                "key": key.value if key is not None else None,
                "count": templates_query.count(),
            },
        )

        paginator = Paginator(page, templates_count, linguistics_settings.TEMPLATES_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        template_from, template_to = paginator.page_borders(page)

        templates = prototypes.TemplatePrototype.from_query(templates_query[template_from:template_to])

        authors = {
            account.id: account
            for account in AccountPrototype.from_query(
                AccountPrototype.get_list_by_id([template.author_id for template in templates])
            )
        }
        clans = {
            clan.id: clan
            for clan in ClanPrototype.from_query(
                ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()])
            )
        }

        return self.template(
            "linguistics/templates/index.html",
            {
                "key": key,
                "templates": templates,
                "index_filter": index_filter,
                "page_type": "all-templates",
                "paginator": paginator,
                "authors": authors,
                "clans": clans,
                "LEXICON_KEY": keys.LEXICON_KEY,
            },
        )
예제 #8
0
파일: views.py 프로젝트: lshestov/the-tale
    def index(
        self, page=1, state=None, type=None, filter=None, contributor=None, order_by=relations.INDEX_ORDER_BY.UPDATED_AT
    ):

        words_query = prototypes.WordPrototype._db_all().order_by("normal_form")

        if contributor is not None:
            entities_ids = prototypes.ContributionPrototype._db_filter(
                type=relations.CONTRIBUTION_TYPE.WORD, account_id=contributor.id
            ).values_list("entity_id", flat=True)
            words_query = words_query.filter(models.Q(id__in=entities_ids) | models.Q(author_id=contributor.id))

        if state:
            words_query = words_query.filter(state=state)

        if type:
            words_query = words_query.filter(type=type.utg_type)

        if filter:
            words_query = words_query.filter(forms__icontains=filter.lower())

        if order_by.is_UPDATED_AT:
            words_query = words_query.order_by("-updated_at")
        elif order_by.is_TEXT:
            words_query = words_query.order_by("normal_form")

        words_count = words_query.count()

        url_builder = UrlBuilder(
            reverse("linguistics:words:"),
            arguments={
                "state": state.value if state else None,
                "type": type.value if type else None,
                "contributor": contributor.id if contributor else None,
                "order_by": order_by.value,
                "filter": filter,
            },
        )

        index_filter = WordsIndexFilter(
            url_builder=url_builder,
            values={
                "state": state.value if state else None,
                "type": type.value if type else None,
                "filter": filter,
                "contributor": contributor.nick if contributor else None,
                "order_by": order_by.value,
                "count": words_count,
            },
        )

        page = int(page) - 1

        paginator = Paginator(page, words_count, linguistics_settings.WORDS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        words_from, words_to = paginator.page_borders(page)

        words = prototypes.WordPrototype.from_query(words_query[words_from:words_to])

        authors = {
            account.id: account
            for account in AccountPrototype.from_query(
                AccountPrototype.get_list_by_id([word.author_id for word in words])
            )
        }
        clans = {
            clan.id: clan
            for clan in ClanPrototype.from_query(
                ClanPrototype.get_list_by_id([author.clan_id for author in authors.itervalues()])
            )
        }

        return self.template(
            "linguistics/words/index.html",
            {
                "words": words,
                "page_type": "dictionary",
                "paginator": paginator,
                "authors": authors,
                "clans": clans,
                "ALLOWED_WORD_TYPE": relations.ALLOWED_WORD_TYPE,
                "index_filter": index_filter,
            },
        )