How to use devilry - 10 common examples

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 / 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 / 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 / devilry / apps / core / testhelpers.py View on Github external
# Candidates
    if len(pathsplit) > 3:
        usernames = pathsplit[3].split(',')
        users = []
        for u in usernames:
            try:
                user = get_user_model().objects.get(shortname=u)
            except get_user_model().DoesNotExist:
                user = get_user_model().objects.create_user(username=u)
            users.append(user)
        assignment_group = AssignmentGroup(parentnode=assignment)
        assignment_group.clean()
        assignment_group.save()
        for user in users:
            assignment_group.candidates.add(Candidate(student=user))
        last = assignment_group
    return last
github devilry / devilry-django / devilry / apps / core / testhelpers.py View on Github external
Examples::

        assignmentgroup = create_from_path(
                'ifi:inf1100.spring05.oblig1.student1,student2')
        oblig1 = create_from_path(
                'ifi:inf1100.spring05.oblig1')
    """
    split = path.split(':', 1)
    nodes = split[0].split('.')

    pathsplit = split[1].split('.')

    # Subject
    subjectname = pathsplit[0]
    subject = Subject(short_name=subjectname,
                      long_name=subjectname.capitalize())
    try:
        subject.clean()
        subject.save()
    except:
        subject = Subject.objects.get(short_name=subjectname)
    last = subject

    # Period
    if len(pathsplit) > 1:
        periodname = pathsplit[1]
        period = Period(parentnode=subject, short_name=periodname,
                long_name=periodname.capitalize(), start_time=timezone.now(),
                end_time=timezone.now() + timedelta(10))
        try:
            period.clean()
github devilry / devilry-django / devilry / apps / core / testhelpers.py View on Github external
'ifi:inf1100.spring05.oblig1')
    """
    split = path.split(':', 1)
    nodes = split[0].split('.')

    pathsplit = split[1].split('.')

    # Subject
    subjectname = pathsplit[0]
    subject = Subject(short_name=subjectname,
                      long_name=subjectname.capitalize())
    try:
        subject.clean()
        subject.save()
    except:
        subject = Subject.objects.get(short_name=subjectname)
    last = subject

    # Period
    if len(pathsplit) > 1:
        periodname = pathsplit[1]
        period = Period(parentnode=subject, short_name=periodname,
                long_name=periodname.capitalize(), start_time=timezone.now(),
                end_time=timezone.now() + timedelta(10))
        try:
            period.clean()
            period.save()
        except:
            period = Period.objects.get(parentnode=subject,
                    short_name=periodname)
        last = period
github devilry / devilry-django / src / devilry_developer / devilry_developer / testhelpers / corebuilder.py View on Github external
def add_students(self, *users):
        candidates = [Candidate(student=user) for user in users]
        self.add_candidates(*candidates)
        return self
github devilry / devilry-django / devilry / project / develop / management / commands / devilry_developer_performance_test_db.py View on Github external
def __create_assignmentgroups_for_assignment(self, assignment):
        """
        Generate AssignmentGroups for Assignment and
        GroupComments for FeedbackSet
        """
        groups = []
        for num in range(RelatedStudent.objects.filter(period=assignment.parentnode).count()):
            assignmentgroup = mommy.prepare('core.AssignmentGroup', parentnode=assignment)
            groups.append(assignmentgroup)
        AssignmentGroup.objects.bulk_create(groups)

        relatedstudents = [relatedstudent for relatedstudent
                           in RelatedStudent.objects.filter(period=assignment.parentnode)]
        relatedexaminers = [relatedexaminer for relatedexaminer
                           in RelatedExaminer.objects.filter(period=assignment.parentnode)]
        assignmentgroups = [assignmentgroup for assignmentgroup
                            in AssignmentGroup.objects.filter(parentnode=assignment)]

        candidates = []
        list_index = 0
        for relatedstudent in relatedstudents:
            candidate = mommy.prepare(
                'core.Candidate',
github devilry / devilry-django / devilry / project / develop / testhelpers / corebuilder.py View on Github external
def add_relatedstudents(self, *users):
        relatedstudents = []
        for user in users:
            if isinstance(user, RelatedStudent):
                relatedstudent = user
            else:
                relatedstudent = RelatedStudent(
                    user=user)
            relatedstudent.period = self.period
            relatedstudents.append(relatedstudent)
        RelatedStudent.objects.bulk_create(relatedstudents)
        return self
github devilry / devilry-django / devilry / project / develop / testhelpers / corebuilder.py View on Github external
def add_relatedstudents(self, *users):
        relatedstudents = []
        for user in users:
            if isinstance(user, RelatedStudent):
                relatedstudent = user
            else:
                relatedstudent = RelatedStudent(
                user=user)
            relatedstudent.period = self.period
            relatedstudents.append(relatedstudent)
        RelatedStudent.objects.bulk_create(relatedstudents)
        return self
github devilry / devilry-django / devilry / apps / extjshelpers / tests.py View on Github external
score = models.IntegerField()
    introtext = models.TextField()
    text = models.TextField()


@simplified_modelapi
class SimplifiedUser(object):
    #@classmethod
    #def read_authorize(cls, user, obj):
        #return True

    class Meta:
        model = User
        resultfields = FieldSpec('id', 'first', 'last', 'email', 'score',
                                 textfields=['introtext', 'text'])
        searchfields = FieldSpec('first', 'last')
        methods = []


@restful_modelapi
class RestUser(ModelRestfulView):
    class Meta:
        simplified = SimplifiedUser
        belongs_to = 'RestUser'
        has_many = 'RestUser'

    # Override to avoid having to add the rest as an url
    @classmethod
    def get_rest_url(cls, *args, **kwargs):
        return '/restuser'