Exemplo n.º 1
0
    def setUp(self):
        p1 = Publication(guid="test-publication-1")
        p1.save()
        self.br1 = BibliographicRecord(
            publication=p1,
            publication_date=datetime.now()-timedelta(days=10)
            )
        self.br1.save()

        p = Person()
        p.save()
        r = Researcher(person=p)
        r.save()

        a1 = Authored(
            publication=p1,
            bibliographic_record=self.br1,
            researcher=r,
            visible=True
            )
        a1.save()

        p2 = Publication(guid="test-publication-2")
        p2.save()
        self.br2 = BibliographicRecord(
            publication=p2,
            publication_date=datetime.now()-timedelta(days=20)
            )
        self.br2.save()
Exemplo n.º 2
0
 def test_methods(self):
     smith = Person(given_name=u"Zöe")
     researcher = Researcher(person=smith)
     force_unicode(researcher)
     self.assertEquals(force_unicode(researcher), researcher.__unicode__())
     smith.save()
     smith.delete()
Exemplo n.º 3
0
    def test_set_items_for_person(self):
        p = Person()
        p.save()
        self.item1.please_contact.add(p)

        self.itemlist.person = p
        self.itemlist.set_items_for_person()

        self.assertEqual(list(self.itemlist.items), [self.item1])
Exemplo n.º 4
0
    def test_set_items_for_person_featuring(self):
        p = Person()
        p.save()
        self.item1.featuring.add(p)

        self.itemlist.person = p
        self.itemlist.set_items_for_person()

        self.assertEqual(list(self.itemlist.items), [self.item1])
    def test_set_items_for_person(self):
        p = Person()
        p.save()
        self.item1.please_contact.add(p)

        self.itemlist.person = p
        self.itemlist.set_items_for_person()

        self.assertEqual(
            list(self.itemlist.items),
            [self.item1]
        )
    def test_set_items_for_person_featuring(self):
        p = Person()
        p.save()
        self.item1.featuring.add(p)

        self.itemlist.person = p
        self.itemlist.set_items_for_person()

        self.assertEqual(
            list(self.itemlist.items),
            [self.item1]
        )
Exemplo n.º 7
0
    def setUp(self):

        p1 = Publication(guid="test-publication-1")
        p1.save()
        self.br1 = BibliographicRecord(
            publication=p1,
            publication_date=datetime.now()-timedelta(days=10)
            )
        self.br1.save()

        p2 = Publication(guid="test-publication-2")
        p2.save()
        self.br2 = BibliographicRecord(
            publication=p2,
            publication_date=datetime.now()-timedelta(days=20)
            )
        self.br2.save()

        e = Entity()
        e.save()

        p = Person()
        p.save()

        m = Membership(
            person=p,
            entity=e
            )
        m.save()

        r = Researcher(person=p)
        r.save()

        a2 = Authored(
            is_a_favourite=True, publication=p2, researcher=r,
            bibliographic_record=self.br2
            )
        a2.save()

        self.itemlist = PublicationsList()
        self.itemlist.items = BibliographicRecord.objects.all()

        self.ph = Placeholder(slot=u"some_slot")
        self.ph.save()
        self.pl = add_plugin(
            self.ph,
            u"CMSPublicationsPlugin",
            u"en",
            entity=e
            )
        self.pl.save()
    def test_set_items_for_person(self):
        p = Person()
        p.save()
        self.item1.please_contact.add(p)

        itemlist = ItemList()
        itemlist.items = TestModel.objects.all()
        itemlist.person = p
        itemlist.set_items_for_person()

        self.assertEqual(
            list(itemlist.items),
            [self.item1]
        )
Exemplo n.º 9
0
    def test_set_items_for_person(self):
        p = Person()
        p.save()
        self.item1.please_contact.add(p)

        itemlist = ItemList()
        itemlist.items = TestModel.objects.all()
        itemlist.person = p
        itemlist.set_items_for_person()

        self.assertEqual(
            list(itemlist.items),
            [self.item1]
        )
Exemplo n.º 10
0
    def setUp(self):
        p1 = Publication(guid="test-publication-1")
        p1.save()
        self.br1 = BibliographicRecord(
            publication=p1,
            publication_date=datetime.now()-timedelta(days=10)
            )
        self.br1.save()

        p2 = Publication(guid="test-publication-2")
        p2.save()
        self.br2 = BibliographicRecord(
            publication=p2,
            publication_date=datetime.now()-timedelta(days=20)
            )
        self.br2.save()

        e = Entity()
        e.save()

        p = Person()
        p.save()

        m = Membership(
            person=p,
            entity=e
            )
        m.save()

        r = Researcher(person=p)
        r.save()

        a2 = Authored(
            is_a_favourite=True, publication=p2, researcher=r,
            bibliographic_record=self.br2, visible=True
            )
        a2.save()

        self.itemlist = PublicationsList()
        self.itemlist.items = BibliographicRecord.objects.all()
        self.e = e
    def setUp(self):
        #  a geographical Site
        self.cardiff = Site(
            site_name="Main site",
            post_town="Cardiff",
            country="UK",
            )
        self.cardiff.save()

        #  a couple of Buildings on the Site
        self.main_building = Building(
            name="Main Building",
            street="St Mary's Street",
            site=self.cardiff,
            )
        self.main_building.save()

        self.heart_testing_centre = Building(
            name="Heart Testing Centre",
            street="Queen Street",
            site=self.cardiff,
            )
        self.heart_testing_centre.save()

        #  create some Entities in a hierarchy

        #    School of Medicine
        #        Departments (an abstract entity)
        #            Department of Cardiology
        #                Section of Heart Research
        #                Heart Testing Centre
        #                Department of Cardiology Student Centre
        #        Web editors (an abstract entity)

        self.school = Entity(
            name="School of Medicine",
            building=self.main_building,
            slug="medicine",
            )
        self.school.save()

        self.departments = Entity(
            name="departments",
            parent=self.school,
            slug="departments",
            abstract_entity=True,
            building=self.heart_testing_centre,
            # this should be ignored by everything!
            )
        self.departments.save()

        self.department = Entity(
            name="Department of Cardiology",
            parent=self.departments,
            slug="cardiology",
            )
        self.department.save()

        self.section = Entity(
            name="Section of Heart Research",
            parent=self.department,
            slug="heart-research",
            )
        self.section.save()

        self.testing_centre = Entity(
            name="Testing Centre",
            parent=self.department,
            slug="testing-centre",
            building_recapitulates_entity_name=True,
            building=self.heart_testing_centre,
            )
        self.testing_centre.save()

        self.student_centre = Entity(
            name="Department of Cardiology Student Centre",
            parent=self.department,
            slug="student-centre",
            display_parent=False,
            )
        self.student_centre.save()

        self.web_editors = Entity(
            name="Group of web editors",
            parent=self.school,
            slug="web-editors",
            abstract_entity=True,
            )
        self.web_editors.save()

        # set up a Person - we will add memberships later in the tests
        self.smith = Person(slug="smith")
        self.smith.save()
Exemplo n.º 12
0
    def setUp(self):
        #  a geographical Site
        self.cardiff = Site(
            site_name="Main site",
            post_town="Cardiff",
            country="UK",
        )
        self.cardiff.save()

        #  a couple of Buildings on the Site
        self.main_building = Building(
            name="Main Building",
            street="St Mary's Street",
            site=self.cardiff,
        )
        self.main_building.save()

        self.heart_testing_centre = Building(
            name="Heart Testing Centre",
            street="Queen Street",
            site=self.cardiff,
        )
        self.heart_testing_centre.save()

        #  create some Entities in a hierarchy

        #    School of Medicine
        #        Departments (an abstract entity)
        #            Department of Cardiology
        #                Section of Heart Research
        #                Heart Testing Centre
        #                Department of Cardiology Student Centre
        #        Web editors (an abstract entity)

        self.school = Entity(
            name="School of Medicine",
            building=self.main_building,
            slug="medicine",
        )
        self.school.save()

        self.departments = Entity(
            name="departments",
            parent=self.school,
            slug="departments",
            abstract_entity=True,
            building=self.heart_testing_centre,
            # this should be ignored by everything!
        )
        self.departments.save()

        self.department = Entity(
            name="Department of Cardiology",
            parent=self.departments,
            slug="cardiology",
        )
        self.department.save()

        self.section = Entity(
            name="Section of Heart Research",
            parent=self.department,
            slug="heart-research",
        )
        self.section.save()

        self.testing_centre = Entity(
            name="Testing Centre",
            parent=self.department,
            slug="testing-centre",
            building_recapitulates_entity_name=True,
            building=self.heart_testing_centre,
        )
        self.testing_centre.save()

        self.student_centre = Entity(
            name="Department of Cardiology Student Centre",
            parent=self.department,
            slug="student-centre",
            display_parent=False,
        )
        self.student_centre.save()

        self.web_editors = Entity(
            name="Group of web editors",
            parent=self.school,
            slug="web-editors",
            abstract_entity=True,
        )
        self.web_editors.save()

        # set up a Person - we will add memberships later in the tests
        self.smith = Person(slug="smith")
        self.smith.save()
Exemplo n.º 13
0
def upload_students(request):

    # empty defaults
    uploaded_document = None
    student_formset = StudentFormset(prefix="student")
    upload_form = DocumentForm()
    supervisor_formsets = [SupervisorFormset(prefix="%s-supervisor" % student.prefix) for student in student_formset]

    if request.method == "POST":
        # we're receiving the uploaded file
        if request.POST.get("upload"):
            upload_form = DocumentForm(request.POST, request.FILES)

            # receive the CSV file
            if upload_form.is_valid():
                uploaded_document = request.FILES["docfile"]
                uploaded_document.rows = unicodecsv.DictReader(uploaded_document, errors="replace")

                # get a list of unique students from the uploaded document
                unique_students = csv_to_list(uploaded_document.rows)

                # build a formset for each one
                unique_students, student_formset = convert_to_formset(unique_students)

                # and for each one a formset of supervisors
                student_formset, supervisor_formsets = process_formset(unique_students, student_formset)

        # we're processing the uploaded file
        if request.POST.get("reprocess"):

            student_formset = StudentFormset(request.POST, request.FILES, prefix="student")

            # there will be a supervisor_formset for each student
            supervisor_formsets = []

            # make a mutable copy of the formset data
            student_formset.data = student_formset.data.copy()

            # loop over students
            for student in student_formset:

                # create the supervisor_formset for this student
                # the prefix matches the prefixes in the form, so that the
                # correct supervisors can be matched to the student
                supervisor_formset = SupervisorFormset(
                    request.POST, request.FILES, prefix="%s-supervisor" % student.prefix
                )

                # make the supervisor_formset available on the student form for
                # processing in forms.py, and likewise the student form on the
                # supervisor_formset
                student.supervisor_formset = supervisor_formset
                supervisor_formset.student = student

                # make a mutable copy of the formset data
                supervisor_formset.data = supervisor_formset.data.copy()

                for supervisor in supervisor_formset:
                    supervisor.is_valid()

                    for k, v in supervisor.cleaned_data.items():
                        supervisor_formset.data[supervisor.prefix + "-" + k] = v

                # rebind the data to the formset
                supervisor_formset = SupervisorFormset(supervisor_formset.data, prefix="%s-supervisor" % student.prefix)

                # add this supervisor_formset to the list of formsets
                supervisor_formsets.append(supervisor_formset)

                # check the supervisors
                supervisor_formset.is_valid()

                # student.is_ready_to_save() calls is_valid() on both the
                # student form and the supervisor formset
                ready_to_save = student.is_ready_to_save()

                if ready_to_save and student.cleaned_data.get("confirm"):

                    cleaned_data = student.cleaned_data

                    # if the Person is provided in form, great - if not, we
                    # have to create a new one based on the name provided
                    person = cleaned_data.get("person")

                    if not person:
                        given_name = cleaned_data["given_name"]
                        surname = cleaned_data["surname"]
                        slug = cleaned_data["slug"]
                        email = cleaned_data["email"]
                        institutional_username = cleaned_data["username"]

                        person = Person(
                            given_name=given_name,
                            surname=surname,
                            slug=slug,
                            email=email,
                            institutional_username=institutional_username,
                            active=True,
                        )
                        person.save()
                        cleaned_data["person"] = person

                    # get or create a Researcher for the Person
                    researcher, created = Researcher.objects.get_or_create(
                        person=person, defaults={"publishes": True, "symplectic_access": True}
                    )

                    # get or create a Student for the Researcher
                    stud, created = Student.objects.get_or_create(
                        researcher=researcher,
                        defaults={
                            "student_id": cleaned_data["student_id"],
                            "thesis": cleaned_data["thesis"],
                            "programme": cleaned_data["programme"],
                            "start_date": cleaned_data["start_date"],
                        },
                    )

                    entity = cleaned_data["entity"]

                    # create the Student's Membership
                    m = Membership(
                        person=person,
                        entity=entity,
                        role="%s student" % cleaned_data["programme"],
                        importance_to_person=5,
                    )
                    m.save()

                    # if the Student was created, we'll add the supervisors
                    if created:

                        # loop over the supervisor forms that have data
                        for s in [s for s in supervisor_formset if s.cleaned_data]:

                            supervisor = s.cleaned_data["person"]

                            if not supervisor:
                                s_given_name = s.cleaned_data["given_name"]
                                s_surname = s.cleaned_data["surname"]
                                s_slug = s.cleaned_data["slug"]
                                s_entity = s.cleaned_data["entity"]

                                supervisor = Person(
                                    given_name=s_given_name, surname=s_surname, active=True, slug=s_slug
                                )
                                supervisor.save()
                                s.cleaned_data["person"] = supervisor
                                # create the Supervisor's Membership

                                m = Membership(person=supervisor, entity=s_entity, importance_to_person=5)
                                m.save()

                            # get or create a Researcher for the Person
                            researcher, c = Researcher.objects.get_or_create(person=supervisor)

                            # get or create an Supervisor for each Researcher
                            supervisor, c = Supervisor.objects.get_or_create(researcher=researcher)

                            # get or create a Supervision relationship for each
                            supervision, c = Supervision.objects.get_or_create(supervisor=supervisor, student=stud)

                for k, v in student.cleaned_data.items():
                    student_formset.data[student.prefix + "-" + k] = v

            # rebind the data to the formset
            student_formset = StudentFormset(student_formset.data, prefix="student")

    zipped_formsets = zip(student_formset, supervisor_formsets)

    for (student_form, supervisor_formset) in zipped_formsets:
        student_form.supervisor_formset = supervisor_formset
        # supervisor_formset.student_form = student_form

    # print "zipped length:", len(zipped_formsets)
    return shortcuts.render_to_response(
        "upload/students.html",
        {
            "base_template": settings.CMS_TEMPLATES[0][0],
            "upload_form": upload_form,
            "document": uploaded_document,
            "student_formset": student_formset,
            "zipped_formsets": zipped_formsets,
        },
        RequestContext(request),
    )