Database Reference
In-Depth Information
Social Graph Model
This section explores the social graph model and a few of the operations that typically accompany it. In particular, this
section looks at the following:
Sign-up and login
Updating a user
Creating a relationship type through a user by following other users
Managing user content, such as displaying, adding, updating, and removing status updates
The sample graph database used for these examples is loaded with data, so you can immediately begin work-
ing with representative data in each of the graph models. In the case of the social graph—and for other graph models,
as well—you will login with the user ajordan . Going forward, please login with ajordan to see each of the working
examples.
Note
Sign-Up
The HTML required for the user sign-up form is shown in Listing 9-14 and can be found in the {PROJECTROOT}/app/
public/templates/home/index.html file.
Listing 9-14. HTML Snippet of Sign-Up Form
<form class="navbar-form navbar-left" action="/signup/add" role="form"
id="createaccountform" method="post">
<div class="form-group">
<input type="text" placeholder="Username" name="username"
class="form-control">
</div>
<button type="submit" class="btn btn-success">Create Account</button> &nbsp;
</form>
While the sample application creates a user without a password, I am certainly not suggesting or advocating
this approach for a production application. excluding the password property was done in order to create a simple sign-up
and login that helps keep the focus on the more salient aspects of the Py2Neo library.
Note
Sign-Up Route
In the sign-up route, start by doing a lookup on the username passed in the request and see if it already exists in the
database using the get_user_by_username method found in the User class, as provided in Listing 9-15. If no match is
found, the username is passed on to the save_user method within else statement.
If no errors are returned during the save attempt, the request is redirected via redirect and a message is passed
to thank the user for signing up. Otherwise, the error message back to the home view informs the user of the problem.
 
 
Search WWH ::




Custom Search