How to use the devilry.devilry_group.models.FeedbackSet function in devilry

To help you get started, we’ve selected a few devilry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devilry / devilry-django / not_for_deploy / sysadmin_example_scripts / usage_statistics.py View on Github external
def get_number_of_deliveries(from_datetime, to_datetime):
    """
    Get the number of deliveries made.

    Simply counts the number of comments posted by students with files on
    all FeedbackSets with deadlines within the from and to datetime arguments.
    """
    from devilry.devilry_comment.models import CommentFile
    from devilry.devilry_group.models import GroupComment, FeedbackSet

    #: Get all `FeedbackSets` with deadlines within the from and to datetime range.
    feedbackset_queryset = FeedbackSet.objects\
        .filter(deadline_datetime__gte=from_datetime,
                deadline_datetime__lte=to_datetime)

    #: UNCOMMENT THIS IF YOU WANT TO:
    #:
    #: Filter only the last FeedbackSet for the AssignmentGroup.
    # feedbackset_queryset = feedbackset_queryset \
    #     .filter(group__cached_data__last_feedbackset_id=models.F('id'))

    # Get all comments for all `FeedbackSet`s with deadline within the
    # from and to datetime posted by a student.
    group_comment_queryset = GroupComment.objects\
        .filter(user_role=GroupComment.USER_ROLE_STUDENT)\
        .filter(feedback_set_id__in=feedbackset_queryset.values_list('id', flat=True))

    #: UNCOMMENT THIS IF YOU WANT TO:
github devilry / devilry-django / devilry / devilry_deadlinemanagement / views / manage_deadline_view.py View on Github external
def __create_feedbackset(self, group_id, deadline, created_datetime):
        """
        Creates a :class:`~.devilry.devilry_group.models.FeedbackSet` entry for a given ``AssignmentGroup``.

        Args:
            group_id: ``FeedbackSet`` for.
            deadline: the new deadline.
            created_datetime: when the FeedbackSet was created.

        Returns:
            (int): ID of the created ``FeedbackSet``.
        """
        feedbackset = group_models.FeedbackSet.objects.create(
            group_id=group_id,
            deadline_datetime=deadline,
            created_by=self.request.user,
            last_updated_by=self.request.user,
            created_datetime=created_datetime
        )
        return feedbackset.id
github devilry / devilry-django / devilry / devilry_group / devilry_group_mommy_factories.py View on Github external
Defaults to ``1``.
        kwargs: Other attributes for FeedbackSet.

    Returns:
        FeedbackSet: The created FeedbackSet.
    """
    if not group:
        raise ValueError('A FeedbackSet as a new attempt must have a pre-existing group!')
    kwargs.setdefault('deadline_datetime', timezone.now())
    if 'grading_published_by' not in kwargs:
        examiner = mommy.make('core.Examiner', assignmentgroup=group)
        kwargs['grading_published_by'] = examiner.relatedexaminer.user
    feedbackset = mommy.prepare(
        'devilry_group.FeedbackSet',
        group=group,
        feedbackset_type=FeedbackSet.FEEDBACKSET_TYPE_NEW_ATTEMPT,
        grading_published_datetime=grading_published_datetime or timezone.now(),
        grading_points=grading_points,
        **kwargs
    )
    feedbackset.full_clean()
    feedbackset.save()
    return feedbackset
github devilry / devilry-django / devilry / devilry_group / views / download_files / batch_download_api.py View on Github external
self._set_archive_meta_ready_for_delete(compressed_archive_meta=compressed_archive_meta)
                self.start_compression_task(content_object_id=content_object_id)
                return JsonResponse(self.get_status_dict(context_object_id=content_object_id))
            ready_for_download_status = self.get_ready_for_download_status(content_object_id=content_object_id)
            return JsonResponse(ready_for_download_status)

        # Start compression task and return status.
        self.start_compression_task(content_object_id=content_object_id)
        return JsonResponse(self.get_status_dict(context_object_id=content_object_id))


class BatchCompressionAPIFeedbackSetView(AbstractBatchCompressionAPIView):
    """
    API for checking if a compressed ``FeedbackSet`` is ready for download.
    """
    model_class = group_models.FeedbackSet
    batchoperation_type = 'batchframework_compress_feedbackset'

    def has_no_files(self):
        return not group_models.FeedbackSet.objects\
            .filter_public_comment_files_from_students()\
            .filter(id=self.content_object.id)\
            .exists()

    def get_assignment_group_ids(self):
        return [self.content_object.group.id]

    def new_files_added(self, latest_compressed_datetime):
        group_comment_ids = group_models.GroupComment.objects \
            .filter(feedback_set=self.content_object).values_list('id', flat=True)
        if CommentFile.objects.filter(
                comment_id__in=group_comment_ids, created_datetime__gt=latest_compressed_datetime
github devilry / devilry-django / devilry / devilry_api / feedbackset / serializers / serializer_base.py View on Github external
class DeadlineDatetime(serializers.DateTimeField):

    def get_attribute(self, instance):
        """
        returns the current deadline of the feedbackset

        Args:
            instance: :obj:`devilry_group.Feedbackset`

        Returns:
            :method:`devilry_group.Feedbackset.current_deadline`
        """
        return instance.current_deadline()

class BaseFeedbacksetSerializer(serializers.Serializer):
    FEEDBACKSET_CHOICES = FeedbackSet.FEEDBACKSET_TYPE_CHOICES

    #: Id of feedbackset.
    id = serializers.IntegerField(required=False, read_only=True)

    #: Id of related group.
    group_id = serializers.IntegerField(required=True)

    #: Feedbackset created datetime.
    created_datetime = serializers.DateTimeField(read_only=True)

    #: Feedbackset type
    feedbackset_type = serializers.ChoiceField(choices=FEEDBACKSET_CHOICES, required=True)

    #: Feedbackset deadline datetime
    deadline_datetime = DeadlineDatetime(required=True)
github devilry / devilry-django / devilry / devilry_group / views / examiner / feedbackfeed_examiner.py View on Github external
def save_object(self, form, commit=False):
        comment = super(ExaminerWithAdminsDiscussView, self).save_object(form=form)
        comment.visibility = group_models.GroupComment.VISIBILITY_VISIBLE_TO_EXAMINER_AND_ADMINS
        comment.published_datetime = timezone.now()
        return super(ExaminerWithAdminsDiscussView, self).save_object(form=form, commit=True)

    def perform_after_save(self, comment):
        self.__send_email_to_examiners(comment=comment)

    def get_success_url(self):
        return self.request.cradmin_app.reverse_appurl(viewname='examiner-admin-discuss')


class EditGradeForm(forms.ModelForm):
    class Meta:
        model = group_models.FeedbackSet
        fields = [
            'grading_points',
        ]

    def __init__(self, *args, **kwargs):
        self.feedbackset = kwargs.get('instance')
        super(EditGradeForm, self).__init__(*args, **kwargs)


class EditGradePointsForm(EditGradeForm):
    def __init__(self, *args, **kwargs):
        super(EditGradePointsForm, self).__init__(*args, **kwargs)
        self.fields['grading_points'] = forms.IntegerField(
            min_value=0,
            max_value=self.feedbackset.group.parentnode.max_points,
            initial=self.feedbackset.grading_points)
github devilry / devilry-django / devilry / devilry_group / views / download_files / batch_download_api.py View on Github external
assignment_group_ids = self.get_assignment_group_ids()

        # Check if any changes has been made in context to examiners on the groups.
        if ExaminerAssignmentGroupHistory.objects.filter(
                assignment_group_id__in=assignment_group_ids,
                created_datetime__gt=latest_compressed_datetime).exists():
            return True

        # Check if any changes has been made in context to candidates on the groups.
        if CandidateAssignmentGroupHistory.objects.filter(
                assignment_group_id__in=assignment_group_ids,
                created_datetime__gt=latest_compressed_datetime).exists():
            return True

        # Check if a new feedbackset has been created for any of the groups.
        if group_models.FeedbackSet.objects.filter(
                group_id__in=assignment_group_ids,
                created_datetime__gt=latest_compressed_datetime).exists():
            return True

        # Check if a deadline has been moved for any of the groups.
        if group_models.FeedbackSetDeadlineHistory.objects.filter(
                feedback_set__group_id__in=assignment_group_ids,
                changed_datetime__gt=latest_compressed_datetime).exists():
            return True

        # Check if any new files are added. Implemented in subclass.
        if self.new_files_added(latest_compressed_datetime=latest_compressed_datetime):
            return True
        return False
github devilry / devilry-django / devilry / apps / core / models / assignment_group.py View on Github external
"""
        Merge feedbacksets from self to target.

        Algorithm:
            - Merge self feedbacksets into target AssignmentGroup and set feedbackset type to merge prefix
            - For first Feedbackset we have to set the deadline since it's None by default

        Args:
            target: :class:`~core.AssignmentGroup` to be merged into
        """
        from devilry.devilry_group.models import FeedbackSet

        # Map feedbackset_type to merge prefix
        feedbackset_type_merge_map = {
            FeedbackSet.FEEDBACKSET_TYPE_FIRST_ATTEMPT: FeedbackSet.FEEDBACKSET_TYPE_MERGE_FIRST_ATTEMPT,
            FeedbackSet.FEEDBACKSET_TYPE_NEW_ATTEMPT: FeedbackSet.FEEDBACKSET_TYPE_MERGE_NEW_ATTEMPT,
            FeedbackSet.FEEDBACKSET_TYPE_RE_EDIT: FeedbackSet.FEEDBACKSET_TYPE_MERGE_RE_EDIT
        }

        feedbacksets = self.feedbackset_set.order_by_deadline_datetime()\
            .select_related('group__parentnode')

        for feedbackset in feedbacksets:
            # change feedbackset_type to merge prefix
            if feedbackset.feedbackset_type in list(feedbackset_type_merge_map.keys()):
                feedbackset.feedbackset_type = feedbackset_type_merge_map[feedbackset.feedbackset_type]
            feedbackset.group = target
            feedbackset.save()
github devilry / devilry-django / devilry / devilry_merge_v3database / utils / feedbackset_merger.py View on Github external
def __get_feedback_set_from_temp_merge_id(self, from_db_obj):
        temp_merge_id = TempMergeId.objects.get_from_label_and_merge_from_obj_id(
            model_name='devilry_group_feedbackset',
            from_id=from_db_obj.feedback_set_id
        )
        try:
            return group_models.FeedbackSet.objects.get(id=temp_merge_id.to_id)
        except group_models.FeedbackSet.DoesNotExist:
            return None