Beispiel #1
0
    def test_fields(self):
        form = PersonForm()
        self.assertEquals(form.fields["first_name"].label, "First Name*")
        self.assertEquals(form.fields["middle_name"].label, "Middle Name")
        self.assertEquals(form.fields["last_name"].label, "Last Name*")
        self.assertEquals(form.fields["affiliation"].label, "Affiliation")
        self.assertEquals(form.fields["website"].label, "Website")

        for visible in form.visible_fields():
            self.assertEquals(visible.field.widget.attrs["class"],
                              "form-control")
            self.assertEquals(visible.field.widget.attrs["style"],
                              "width:25em")
Beispiel #2
0
 def test_clean_website(self):
     data = {
         "first_name": "f",
         "middle_name": "m",
         "last_name": "l",
         "affiliation": "a",
         "website": "w"
     }
     form = PersonForm(data)
     if form.is_valid():
         x = form.clean_website()
         self.assertTrue(x == "w")
         self.assertTrue(form.fields['website'].label is None
                         or form.fields['website'].label == 'Website')
Beispiel #3
0
def person_update(request, id):
    # retrieve paper by ID
    # https://github.com/neo4j-contrib/neomodel/issues/199
    query = "MATCH (a) WHERE ID(a)={id} RETURN a"
    results, meta = db.cypher_query(query, dict(id=id))
    if len(results) > 0:
        all_people = [Person.inflate(row[0]) for row in results]
        person_inst = all_people[0]
    else:
        person_inst = Person()

    # if this is POST request then process the Form data
    if request.method == "POST":
        form = PersonForm(request.POST)
        if form.is_valid():
            person_inst.first_name = form.cleaned_data["first_name"]
            person_inst.middle_name = form.cleaned_data["middle_name"]
            person_inst.last_name = form.cleaned_data["last_name"]
            person_inst.affiliation = form.cleaned_data["affiliation"]
            person_inst.website = form.cleaned_data["website"]
            person_inst.save()

            return HttpResponseRedirect(reverse("persons_index"))
    # GET request
    else:
        query = "MATCH (a) WHERE ID(a)={id} RETURN a"
        results, meta = db.cypher_query(query, dict(id=id))
        if len(results) > 0:
            all_people = [Person.inflate(row[0]) for row in results]
            person_inst = all_people[0]
        else:
            person_inst = Person()
        form = PersonForm(
            initial={
                "first_name": person_inst.first_name,
                "middle_name": person_inst.middle_name,
                "last_name": person_inst.last_name,
                "affiliation": person_inst.affiliation,
                "website": person_inst.website,
            })

    return render(request, "person_update.html", {
        "form": form,
        "person": person_inst
    })
Beispiel #4
0
def person_create(request):
    user = request.user

    if request.method == "POST":
        person = Person()
        person.created_by = user.id
        form = PersonForm(instance=person, data=request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("persons_index"))
    else:  # GET
        form = PersonForm()

    return render(request, "person_form.html", {"form": form})