How to use the devilry.apps.core.models.Delivery.objects.filter 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 / src / devilry / devilryadmin / create_random_exampledata.py View on Github external
def autocreate_delivery(group):
    active_deadline = group.get_active_deadline()

    cand = group.candidates.all()[0]
    delivery = active_deadline.deliveries.create(delivered_by=cand, successful=True)
    delivery.add_file('helloworld.txt', ['hello cruel world'])
    delivery.add_file('helloworld.py', ['print "hello world"'])
    delivery.add_file('helloworld.java', [
        '// Too much code for a sane "hello world"'])

    others = Delivery.objects.filter(deadline__assignment_group=group).order_by("-number")
    if others.count() == 1:
        if active_deadline.deadline < datetime.now():
            if randint(0, 100) <= 30:
                # 30% chance to get the first delivery after the deadline
                offset = timedelta(minutes=-randint(1, 20))
                logging.info("                (deliveries after deadline)")
            else:
                offset = timedelta(hours=randint(0, 15),
                        minutes=randint(0, 59))
            delivery.time_of_delivery = active_deadline.deadline - offset
        else:
            # Deadline is in the future. Deliver a random time before
            # "now". They can not deliver more than 5 deliveries (see
            # create_example_deliveries_and_feedback), so if
            # we say 5*3 hours in the past as a minimum for the first
            # delivery, we will never get deliveries in the future
github devilry / devilry-django / src / devilry / devilry / apps / superadmin / management / commands / devilry_edit_delivery.py View on Github external
def _qry(self, unsuccessful_with_feedback, username=None):
        qry = Delivery.objects.filter()
        qry = qry.annotate(feedback_count=Count('feedbacks'))
        if unsuccessful_with_feedback:
            qry = qry.filter(feedback_count__gt=0,
                             successful=False)
        if username:
            user = self._get_or_error(User, username=username)
            qry = qry.filter(deadline__assignment_group__candidates__student=user)

        qry = qry.select_related('deadline', 'deadline__assignment_group', 'deadline__assignment_group__parentnode',
                                 'deadline__assignment_group__parentnode__parentnode',
                                 'deadline__assignment_group__parentnode__parentnode__parentnode')
        qry = qry.prefetch_related('deadline__assignment_group__candidates',
                                   'deadline__assignment_group__candidates__student',
                                   'deadline__assignment_group__candidates__student__devilryuserprofile')
        return qry
github devilry / devilry-django / src / devilry_subjectadmin / devilry_subjectadmin / rest / group.py View on Github external
def serialize_model(self, instance):
        data = super(GroupResource, self).serialize_model(instance)
        if not 'num_deliveries' in data:
            # This is used when working directly with the instance. The listing
            # (query) annotates this field instead of querying for each object
            data['num_deliveries'] = Delivery.objects.filter(deadline__assignment_group=instance).count()
        return data
github devilry / devilry-django / src / devilry / apps / administrator / simplified / simplifiedassignmentgroup.py View on Github external
def is_empty(cls, obj):
        """
        Return ``True`` if the given assignmentgroup contains no deliveries.
        """
        return models.Delivery.objects.filter(deadline__assignment_group=obj).count() == 0
github devilry / devilry-django / devilry / devilry_student / rest / open_groups.py View on Github external
def deliveries(self, instance):
        return Delivery.objects.filter(deadline__assignment_group=instance,
                                       successful=True).count()
github devilry / devilry-django / devilry / apps / administrator / simplified.py View on Github external
def is_empty(cls, obj):
        """
        Return ``True`` if the given assignmentgroup contains no deliveries.
        """
        return models.Delivery.objects.filter(deadline__assignment_group=obj).count() == 0
github devilry / devilry-django / src / devilry / apps / administrator / simplified / simplifiedassignmentgroup.py View on Github external
username
                The username of an existing user. This key,value pair is required.
                The user with the given username is created as a candidate.
            candidate_id
                The candidate_id. This is optional, and defaults to ``None``.

        If all usernames are valid, ``obj.candidates`` is cleared, and the
        given candidates are added (I.E.: All current candidates are replaced).
        """
        if hasattr(obj, 'fake_candidates') and obj.fake_candidates != None:
            new_candidates_usernames = [candidatespec['username'] for candidatespec in obj.fake_candidates]
            to_delete = []
            for candidate in obj.candidates.all():
                if not candidate.student.username in new_candidates_usernames:
                    if models.Delivery.objects.filter(deadline__assignment_group=obj, delivered_by=candidate).count() != 0:
                        raise PermissionDenied('You can not remove {0} from the group. Candidates that have made a delivery can not be removed.'.format(candidate.student.username))
                    to_delete.append(candidate)
            for candidate in to_delete:
                candidate.delete()

            create_kwargs = []
            update_candidates = []
            for candidatespec in obj.fake_candidates:
                username = candidatespec['username']
                try:
                    user = User.objects.get(username=username)
                except User.DoesNotExist:
                    raise InvalidUsername(username)
                else:
                    candidate_id = candidatespec.get('candidate_id', None)
                    try:
github devilry / devilry-django / devilry / apps / administrator / simplified / simplifiedassignmentgroup.py View on Github external
username
                The username of an existing user. This key,value pair is required.
                The user with the given username is created as a candidate.
            candidate_id
                The candidate_id. This is optional, and defaults to ``None``.

        If all usernames are valid, ``obj.candidates`` is cleared, and the
        given candidates are added (I.E.: All current candidates are replaced).
        """
        if hasattr(obj, 'fake_candidates') and obj.fake_candidates != None:
            new_candidates_usernames = [candidatespec['username'] for candidatespec in obj.fake_candidates]
            to_delete = []
            for candidate in obj.candidates.all():
                if not candidate.student.username in new_candidates_usernames:
                    if models.Delivery.objects.filter(deadline__assignment_group=obj, delivered_by=candidate).count() != 0:
                        raise PermissionDenied('You can not remove {0} from the group. Candidates that have made a delivery can not be removed.'.format(candidate.student.username))
                    to_delete.append(candidate)
            for candidate in to_delete:
                candidate.delete()

            create_kwargs = []
            update_candidates = []
            for candidatespec in obj.fake_candidates:
                username = candidatespec['username']
                try:
                    user = User.objects.get(username=username)
                except User.DoesNotExist:
                    raise InvalidUsername(username)
                else:
                    candidate_id = candidatespec.get('candidate_id', None)
                    try: