Esempio n. 1
0
    def _create_or_add_assignmentgroup(self, group_name, parentnode, extras):
        if AssignmentGroup.objects.filter(parentnode=parentnode,
                                          name=group_name).count() == 1:
            group = AssignmentGroup.objects.get(parentnode=parentnode,
                                                name=group_name)
        else:
            group = AssignmentGroup(parentnode=parentnode, name=group_name)
            try:
                group.full_clean()
                group.save()
            except ValidationError as e:
                raise ValueError("Assignmentgroup not created!: {}".format(e))

        # add the extras (only admins allowed in subject)
        for candidate in extras['candidate']:

            try:
                candidate_name, cid = candidate.split(';', 1)
            except ValueError:
                candidate_name = candidate
                cid = None

            group.candidates.add(
                Candidate(student=self._create_or_add_user(candidate_name)))
            cand = group.candidates.order_by('-id')[0]
            # cand.candidate_id = cid if cid != None else str(cand.student.id)
            cand.candidate_id = cid
            cand.full_clean()
            cand.save()

        for examiner in extras['examiner']:
            group.examiners.create(user=self._create_or_add_user(examiner))

        for tag in extras['tags']:
            group.tags.create(tag=tag)

        group.full_clean()
        group.save()

        vars(self)[parentnode.parentnode.parentnode.short_name +
                   '_' +  # subject_
                   parentnode.parentnode.short_name + '_' +  # period_
                   parentnode.short_name + '_' +  # assignment_
                   group_name] = group

        # # create the default deadline, deadline0, variable
        # vars(self)[parentnode.parentnode.parentnode.short_name + '_' +  # subject_
        #            parentnode.parentnode.short_name + '_' +             # period_
        #            parentnode.short_name + '_' +                        # assignment_
        #            group_name + '_deadline0'] = group.deadlines.all()[0]
        return group
Esempio n. 2
0
    def _create_or_add_assignmentgroup(self, group_name, parentnode, extras):
        if AssignmentGroup.objects.filter(parentnode=parentnode, name=group_name).count() == 1:
            group = AssignmentGroup.objects.get(parentnode=parentnode, name=group_name)
        else:
            group = AssignmentGroup(parentnode=parentnode, name=group_name)
            try:
                group.full_clean()
                group.save()
            except ValidationError:
                raise ValueError("Assignmentgroup not created!")

        # add the extras (only admins allowed in subject)
        for candidate in extras['candidate']:

            try:
                candidate_name, cid = candidate.split(';', 1)
            except ValueError:
                candidate_name = candidate
                cid = None

            group.candidates.add(Candidate(student=self._create_or_add_user(candidate_name)))
            cand = group.candidates.order_by('-id')[0]
            #cand.candidate_id = cid if cid != None else str(cand.student.id)
            cand.candidate_id = cid
            cand.update_identifier(parentnode.anonymous)
            cand.full_clean()
            cand.save()

        for examiner in extras['examiner']:
            group.examiners.create(user=self._create_or_add_user(examiner))

        for tag in extras['tags']:
            group.tags.create(tag=tag)

        group.full_clean()
        group.save()

        vars(self)[parentnode.parentnode.parentnode.short_name + '_' +  # subject_
                   parentnode.parentnode.short_name + '_' +             # period_
                   parentnode.short_name + '_' +                        # assignment_
                   group_name] = group

        # # create the default deadline, deadline0, variable
        # vars(self)[parentnode.parentnode.parentnode.short_name + '_' +  # subject_
        #            parentnode.parentnode.short_name + '_' +             # period_
        #            parentnode.short_name + '_' +                        # assignment_
        #            group_name + '_deadline0'] = group.deadlines.all()[0]
        return group
Esempio n. 3
0
def create_from_path(path):
    """ Create a Node, Subject, Period, Assignment or AssignmentGroup from
    ``path``.

    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('.')
    for nodename in nodes:
        node = Node(short_name=nodename, long_name=nodename.capitalize())
        try:
            node.clean()
            node.save()
        except:
            node = Node.objects.get(short_name=nodename)
        last = node

    if len(split) != 2:
        return last
    pathsplit = split[1].split('.')

    # Subject
    subjectname = pathsplit[0]
    subject = Subject(parentnode=node, 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=datetime.now(),
                end_time=datetime.now() + timedelta(10))
        try:
            period.clean()
            period.save()
        except:
            period = Period.objects.get(parentnode=subject,
                    short_name=periodname)
        last = period

    # Assignment
    if len(pathsplit) > 2:
        assignmentname = pathsplit[2]
        assignment = Assignment(parentnode=period, short_name=assignmentname,
                long_name=assignmentname.capitalize(), publishing_time=datetime.now())
        
        assignment.clean()
        try:
            assignment.save()
        except:
            assignment = Assignment.objects.get(parentnode=period,
                    short_name=assignmentname)
        last = assignment

    # Candidates
    if len(pathsplit) > 3:
        usernames = pathsplit[3].split(',')
        users = []
        for u in usernames:
            user = User(username=u)
            try:
                user.save()
            except:
                user = User.objects.get(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
Esempio n. 4
0
def create_from_path(path):
    """ Create a Node, Subject, Period, Assignment or AssignmentGroup from
    ``path``.

    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('.')
    for nodename in nodes:
        node = Node(short_name=nodename, long_name=nodename.capitalize())
        try:
            node.clean()
            node.save()
        except:
            node = Node.objects.get(short_name=nodename)
        last = node

    if len(split) != 2:
        return last
    pathsplit = split[1].split('.')

    # Subject
    subjectname = pathsplit[0]
    subject = Subject(parentnode=node,
                      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=datetime.now(),
                        end_time=datetime.now() + timedelta(10))
        try:
            period.clean()
            period.save()
        except:
            period = Period.objects.get(parentnode=subject,
                                        short_name=periodname)
        last = period

    # Assignment
    if len(pathsplit) > 2:
        assignmentname = pathsplit[2]
        assignment = Assignment(parentnode=period,
                                short_name=assignmentname,
                                long_name=assignmentname.capitalize(),
                                publishing_time=datetime.now())

        assignment.clean()
        try:
            assignment.save()
        except:
            assignment = Assignment.objects.get(parentnode=period,
                                                short_name=assignmentname)
        last = assignment

    # 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