How to use the devilry.devilry_group.models.GroupComment 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 / devilry / devilry_compressionutil / batchjob_mixins / feedbackset_mixin.py View on Github external
def zipfile_add_feedbackset(self, zipfile_backend, feedback_set, sub_path=''):
        from devilry.devilry_group import models as group_models

        comment_file_tree = {}
        for group_comment in feedback_set.groupcomment_set.all().order_by('-created_datetime'):
            # Don't add files from comments that are not visible to everyone.
            if group_comment.visibility == group_models.GroupComment.VISIBILITY_VISIBLE_TO_EVERYONE and \
                    group_comment.user_role == group_models.GroupComment.USER_ROLE_STUDENT:
                for comment_file in group_comment.commentfile_set.all().order_by('-created_datetime'):
                    filename = comment_file.filename
                    if comment_file.filename not in comment_file_tree:
                        comment_file_tree[filename] = {
                            'before_deadline': {
                                'last': None,
                                'old_duplicates': []
                            },
                            'after_deadline': {
                                'last': None,
                                'old_duplicates': []
                            }
                        }

                    if group_comment.published_datetime <= feedback_set.deadline_datetime:
                        # Before the deadline expired
github devilry / devilry-django / devilry / devilry_group / timeline_builder / feedbackfeed_timeline_builder.py View on Github external
List of :class:`devilry.devilry_group.models.GroupComment` objects.

        """
        commentfile_queryset = CommentFile.objects\
            .select_related('comment__user')\
            .order_by('filename')
        groupcomment_queryset = group_models.GroupComment.objects\
            .exclude_private_comments_from_other_users(user=self.requestuser)\
            .select_related(
                'user',
                'feedback_set__created_by',
                'feedback_set__grading_published_by')\
            .prefetch_related(models.Prefetch('commentfile_set', queryset=commentfile_queryset))
        if self.devilryrole == 'student':
            groupcomment_queryset = groupcomment_queryset\
                .filter(visibility=group_models.GroupComment.VISIBILITY_VISIBLE_TO_EVERYONE)\
                .exclude_is_part_of_grading_feedbackset_unpublished()
        return group_models.FeedbackSet.objects\
            .filter(group=self.group)\
            .prefetch_related(models.Prefetch('groupcomment_set', queryset=groupcomment_queryset))\
            .order_by('created_datetime')
github devilry / devilry-django / devilry / devilry_group / models.py View on Github external
def copy_comment_into_feedbackset(self, feedbackset):
        """
        Creates a new GroupComment, copies all fields in self into
        the new comment and sets feedback_set foreign key to ``feedbackset``
        Args:
            feedbackset: :class:`~devilry_group.FeedbackSet`

        Returns:
            :class:`~devilry_group.GroupComment` a new group comment
        """
        commentcopy = GroupComment(
            part_of_grading=self.part_of_grading,
            feedback_set=feedbackset,
            text=self.text,
            draft_text=self.draft_text,
            user=self.user,
            parent=self.parent,
            created_datetime=self.created_datetime,
            published_datetime=self.published_datetime,
            user_role=self.user_role,
            comment_type=self.comment_type,
        )
        commentcopy.save()
        for commentfile in self.commentfile_set.all():
            commentfile.copy_into_comment(commentcopy)
        return commentcopy
github devilry / devilry-django / devilry / devilry_group / feedbackfeed_builder / builder_base.py View on Github external
Get a queryset containing prefetched :class:`~devilry.devilry_group.models.FeedbackSets`,
    :class:`~devilry.devilry_group.models.GroupComments` and :class:`~devilry.devilry_comment.models.CommentFiles`
    the requestuser har access to.

    Args:
        group (AssignmentGroup): The cradmin role.
        requestuser (User): The requestuser.
        devilryrole (str): Role for the requestuser.

    Returns:
        QuerySet: FeedbackSet queryset.
    """
    commentfile_queryset = comment_models.CommentFile.objects\
        .select_related('comment__user')\
        .order_by('filename')
    groupcomment_queryset = group_models.GroupComment.objects \
        .exclude_private_comments_from_other_users(user=requestuser) \
        .annotate_with_last_edit_history(requestuser_devilryrole=devilryrole)\
        .select_related(
            'user',
            'feedback_set',
            'feedback_set__created_by',
            'feedback_set__grading_published_by') \
        .prefetch_related(
            models.Prefetch(
                'commentfile_set',
                queryset=commentfile_queryset))
    feedbackset_deadline_history_queryset = group_models.FeedbackSetDeadlineHistory.objects.all()
    if devilryrole == 'student':
        groupcomment_queryset = groupcomment_queryset\
            .filter(visibility=group_models.GroupComment.VISIBILITY_VISIBLE_TO_EVERYONE)\
            .exclude_is_part_of_grading_feedbackset_unpublished()
github devilry / devilry-django / devilry / devilry_group / models.py View on Github external
def annotate_with_last_edit_history(self, requestuser_devilryrole):
        edit_history_subquery = GroupCommentEditHistory.objects \
            .filter(group_comment_id=OuterRef('id'))

        if requestuser_devilryrole == 'student':
            edit_history_subquery = edit_history_subquery\
                .filter(visibility=GroupComment.VISIBILITY_VISIBLE_TO_EVERYONE)

        edit_history_subquery = edit_history_subquery\
            .order_by('-edited_datetime')\
            .values('edited_datetime')[:1]
        return self.annotate(
            last_edithistory_datetime=models.Subquery(
                edit_history_subquery, output_field=models.DateTimeField()
            )
github devilry / devilry-django / devilry / devilry_group / views / cradmin_comment_history.py View on Github external
def dispatch(self, request, *args, **kwargs):
        if 'group_comment_id' not in kwargs:
            raise Http404()
        try:
            self.group_comment = group_models.GroupComment.objects.get(id=kwargs['group_comment_id'])
        except group_models.GroupComment.DoesNotExist:
            raise Http404()

        # If the comment is private, only the user that created the comment can access the history view.
        if self.group_comment.visibility == group_models.GroupComment.VISIBILITY_PRIVATE \
                and self.group_comment.user != request.user:
            raise Http404()
        return super(CommentHistoryView, self).dispatch(request, *args, **kwargs)
github devilry / devilry-django / devilry / devilry_api / group_comment / views / groupcomment_examiner.py View on Github external
def get_object(self):
        """
        This is only used to get a drafted comment

        Returns:
            :obj:`devilry_group.GroupComment`
        """
        if 'feedback_set' not in self.kwargs:
            raise ValidationError(ugettext_lazy('Url path parameter feedback_set required'))
        id = self.request.query_params.get('id', None)
        if not id:
            raise ValidationError(ugettext_lazy('Queryparam id required.'))
        try:
            comment = self.get_role_query_set().get(feedback_set__id=self.kwargs['feedback_set'], id=id)
        except GroupComment.DoesNotExist:
            raise NotFound
        if comment.feedback_set.grading_published_datetime is not None:
            raise PermissionDenied(ugettext_lazy('Cannot delete published comment.'))
        if comment.visibility != GroupComment.VISIBILITY_PRIVATE:
            raise PermissionDenied(ugettext_lazy('Cannot delete a comment that is not private.'))
        if not comment.part_of_grading:
            raise PermissionDenied(ugettext_lazy('Cannot delete a comment that is not a draft.'))
        return comment
github devilry / devilry-django / devilry / devilry_group / views / student / group_comment_history.py View on Github external
def get_queryset_for_role(self, role):
        return group_models.GroupCommentEditHistory.objects \
            .filter(group_comment_id=self.group_comment.id,
                    visibility=group_models.GroupComment.VISIBILITY_VISIBLE_TO_EVERYONE,
                    group_comment__feedback_set__group=self.request.cradmin_role) \
            .order_by('-edited_datetime')
github devilry / devilry-django / devilry / devilry_group / management / commands / devilry_build_feed.py View on Github external
feedback_set=last_feedbackset,
                                     user=student_user,
                                     user_role=group_models.GroupComment.USER_ROLE_STUDENT,
                                     created_datetime=student_comment_publish_time,
                                     published_datetime=student_comment_publish_time)
        student_comment_file = mommy.make('devilry_comment.CommentFile',
                                          comment=student_comment, filename='delivery.py', filesize=0,
                                          created_datetime=student_comment_publish_time)

        # examiner correct first attempt.
        examiner_feedback_comment1 = mommy.make('devilry_group.GroupComment',
                                               text='Failed because... Try again',
                                               part_of_grading=True,
                                               feedback_set=last_feedbackset,
                                               user=related_examiner.user,
                                               user_role=group_models.GroupComment.USER_ROLE_EXAMINER)
        last_feedbackset.publish(published_by=related_examiner.user, grading_points=0)
        last_feedbackset.grading_published_datetime = datetime(year=2018, month=4, day=29, hour=15, minute=1, tzinfo=timezone.get_current_timezone())
        last_feedbackset.save()
        group_models.GroupComment.objects.filter(id=examiner_feedback_comment1.id)\
            .update(published_datetime=datetime(year=2018, month=4, day=29, hour=15, minute=2, tzinfo=timezone.get_current_timezone()))
        group_models.GroupComment.objects.filter(id=examiner_feedback_comment1.id)\
            .update(created_datetime=datetime(year=2018, month=4, day=29, hour=15, minute=2, tzinfo=timezone.get_current_timezone()))
        asd = group_models.GroupComment.objects.filter(id=examiner_feedback_comment1.id).get()
        print(asd.created_datetime)
        print(timezone.now())
        asd.created_datime = timezone.now()
        asd.save()
        print(asd.created_datetime)
        # examiner_feedback_comment1.published_datetime = first_deadline_datetime + timezone.timedelta(hours=4)
        # examiner_feedback_comment1.created_datetime = first_deadline_datetime + timezone.timedelta(hours=4)
        # examiner_feedback_comment1.save()
github devilry / devilry-django / not_for_deploy / sysadmin_example_scripts / usage_statistics.py View on Github external
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:
    #:
    #: Filter only comments posted before the deadline expired on the
    #: feedbackset the comment belongs to.
    # group_comment_queryset = group_comment_queryset\
    #     .filter(published_datetime__gte=models.F('feedback_set__deadline_datetime'))

    #: Get all Comments with files from the fetched comments.
    comment_file_queryset = CommentFile.objects\
        .filter(comment_id__in=group_comment_queryset.values_list('id', flat=True))

    return comment_file_queryset.count()