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

import os

from django.template import defaultfilters

from devilry.devilry_group.tasks import AbstractBaseBatchAction, FeedbackSetBatchMixin


class AssignmentBatchMixin(object):
    """
    Mixin for adding FeedbackSet files to zipfile for all AssignmentGroups in the Assignment.

    Must be included in class together with :class:`~.FeedbackSetBatchMixin`.
    """
    def add_assignment_groups(self, user, zipfile_backend, assignment):
        for group in assignment.assignmentgroups.filter_examiner_has_access(user=user):
            group_path = '{}'.format(group.get_short_displayname())
            for feedback_set in group.feedbackset_set.all():
                feedback_set_path = 'deadline-{}'.format(defaultfilters.date(feedback_set.current_deadline(), 'b.j.Y-H:i'))
                self.zipfile_add_feedbackset(
                    zipfile_backend=zipfile_backend,
                    feedback_set=feedback_set,
                    sub_path=os.path.join(group_path, feedback_set_path)
                )


class AssignmentCompressAction(AbstractBaseBatchAction, AssignmentBatchMixin, FeedbackSetBatchMixin):
    backend_id = 'devilry_admin_local'

    def execute(self):
        assignment = self.kwargs.get('context_object')
        started_by_user = self.kwargs.get('started_by')

        from devilry.devilry_group import models as group_models
        feedback_sets_with_public_student_comments = group_models.FeedbackSet.objects \
            .filter_public_comment_files_from_students()\
            .filter(group__parentnode=assignment)
        if not feedback_sets_with_public_student_comments.exists():
            # Do nothing
            return

        # Create name for the actual archive
        from django.utils import timezone
        archive_name = '{}.{}.{}.{}.zip'.format(<commit_msg>devilry_admin: Filter admin.<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os

from django.template import defaultfilters

from devilry.devilry_group.tasks import AbstractBaseBatchAction, FeedbackSetBatchMixin


class AssignmentBatchMixin(object):
    """
    Mixin for adding FeedbackSet files to zipfile for all AssignmentGroups in the Assignment.

    Must be included in class together with :class:`~.FeedbackSetBatchMixin`.
    """
    def add_assignment_groups(self, user, zipfile_backend, assignment):
        for group in assignment.assignmentgroups.filter_user_is_admin(user=user):
            group_path = '{}'.format(group.get_short_displayname())
            for feedback_set in group.feedbackset_set.all():
                feedback_set_path = 'deadline-{}'.format(defaultfilters.date(feedback_set.current_deadline(), 'b.j.Y-H:i'))
                self.zipfile_add_feedbackset(
                    zipfile_backend=zipfile_backend,
                    feedback_set=feedback_set,
                    sub_path=os.path.join(group_path, feedback_set_path)
                )


class AssignmentCompressAction(AbstractBaseBatchAction, AssignmentBatchMixin, FeedbackSetBatchMixin):
    backend_id = 'devilry_admin_local'

    def execute(self):
        assignment = self.kwargs.get('context_object')
        started_by_user = self.kwargs.get('started_by')

        from devilry.devilry_group import models as group_models
        feedback_sets_with_public_student_comments = group_models.FeedbackSet.objects \
            .filter_public_comment_files_from_students()\
            .filter(group__parentnode=assignment)
        if not feedback_sets_with_public_student_comments.exists():
            # Do nothing
            return

        # Create name for the actual archive
        from django.utils import timezone
        archive_name = '{}.{}.{}.{}.zip'.format(
{'fraction_non_alphanumeric': 0.08353033884948778, 'fraction_numerical': 0.0005253480430785396, 'mean_word_length': 3.175438596491228, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3077940', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1046, 'n_words': 209}