<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.http import Http404

from devilry.devilry_account.models import PeriodPermissionGroup
from devilry.devilry_admin.cradminextensions import devilry_crmenu_admin
from devilry.devilry_group.cradmin_instances import crinstance_base
from devilry.devilry_group.views.admin import feedbackfeed_admin
from devilry.devilry_group.views.download_files import batch_download_files
from devilry.devilry_group.views.download_files import feedbackfeed_bulkfiledownload


class Menu(devilry_crmenu_admin.Menu):
    def build_menu(self):
        group = self.request.cradmin_role
        self.add_headeritem(
            label=group.subject.long_name,
            url=self.appindex_url('feedbackfeed'))


class AdminCrInstance(crinstance_base.CrInstanceBase):
    """
    CrInstance class for admins.
    """
    menuclass = Menu
    apps = [
        ('feedbackfeed', feedbackfeed_admin.App),
        ('feedbackfeed', feedbackfeed_bulkfiledownload.App),
        ('feedbackfeed', batch_download_files.App)
    ]
    id = 'devilry_group_admin'

    @classmethod
    def matches_urlpath(cls, urlpath):
        return urlpath.startswith('/devilry_group/admin')

    def get_rolequeryset(self):
        """
        Get the base rolequeryset from
        :meth:`~devilry.devilry_group.cradmin_instances.CrInstanceBase._get_base_rolequeryset` and filter on user.

        Returns:
            QuerySet: A queryset of :class:`~devilry.apps.core.models.AssignmentGroup`s
                the ``request.user`` is admin on.
        """
        return self._get_base_rolequeryset()\
            .filter_user_is_admin(user=self.request.user)

    def __get_devilryrole_for_requestuser(self):
        """
        Checks the permission for the user via :class:`~devilry.devilry_account.models.PeriodPermissionGroup`.

        Returns:
            str: ``departmentadmin``, ``subjectadmin`` or ``periodadmin`` as devilryrole.

        Raises:<commit_msg>devilry_group: Added download api for admin.<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.http import Http404

from devilry.devilry_account.models import PeriodPermissionGroup
from devilry.devilry_admin.cradminextensions import devilry_crmenu_admin
from devilry.devilry_group.cradmin_instances import crinstance_base
from devilry.devilry_group.views.admin import feedbackfeed_admin
from devilry.devilry_group.views.download_files import batch_download_files
from devilry.devilry_group.views.download_files import feedbackfeed_bulkfiledownload


class Menu(devilry_crmenu_admin.Menu):
    def build_menu(self):
        group = self.request.cradmin_role
        self.add_headeritem(
            label=group.subject.long_name,
            url=self.appindex_url('feedbackfeed'))


class AdminCrInstance(crinstance_base.CrInstanceBase):
    """
    CrInstance class for admins.
    """
    menuclass = Menu
    apps = [
        ('feedbackfeed', feedbackfeed_admin.App),
        ('download', batch_download_files.App)
    ]
    id = 'devilry_group_admin'

    @classmethod
    def matches_urlpath(cls, urlpath):
        return urlpath.startswith('/devilry_group/admin')

    def get_rolequeryset(self):
        """
        Get the base rolequeryset from
        :meth:`~devilry.devilry_group.cradmin_instances.CrInstanceBase._get_base_rolequeryset` and filter on user.

        Returns:
            QuerySet: A queryset of :class:`~devilry.apps.core.models.AssignmentGroup`s
                the ``request.user`` is admin on.
        """
        return self._get_base_rolequeryset()\
            .filter_user_is_admin(user=self.request.user)

    def __get_devilryrole_for_requestuser(self):
        """
        Checks the permission for the user via :class:`~devilry.devilry_account.models.PeriodPermissionGroup`.

        Returns:
            str: ``departmentadmin``, ``subjectadmin`` or ``periodadmin`` as devilryrole.

        Raises:
{'fraction_non_alphanumeric': 0.08851554663991976, 'fraction_numerical': 0.0020060180541624875, 'mean_word_length': 3.5022573363431153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '254786', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1200, 'n_words': 226}