Project 4: implements a Twitter-like social network website for making posts and following users.
First, make sure you install a copy of Python. For this project, you should be using Python version 3.6 or higher. You’ll also need to install pip.
Download the project distribution directory from either: -
https://github.com/collinr3/cs50network.git
or
https://github.com/me50/collinr3.git/ on branch web50/projects/2020/x/network
In a terminal window, navigate into your project directory.
Run pip3 install -r requirements.txt in your terminal window to make sure that all of the necessary Python packages (Django, for instance) are installed.
Currently, there is no published API for the application.
Run python manage.py runserver to start up your Django application.
If you navigate to the URL provided by Django, you should see the Network Home Page.
- On the Network landing page, note the Welcome, option to Login, if already registered, or the option to Sign Up. Note also that a small number of Posts (Max 3) may be visible if previously registered users have submitted posts.
- Choose
Sign Upand provide a minimum ofUsernameandPassword. ClickRegister. - If successfully registered, Note that the Network landing page now provides the option to
Post somethingand also shows the latest posts (Max 10 per page), with a pagination option at the bottom, where more that 10 posts have been posted. - From the menu, click on
My Posts,All PostsandFollowingand note that the option toPost somethingis available on each page. - Whilst on
FollowingSubmit a Post - note that the display reverts to a display ofAll Posts. Note also that your new post appears at the top of the Latest Posts list. The same behaviour occurs onMy Postsand, logically,All Posts. - From the menu, click on
All Postsand note that all posts from all users are displayed with the most recent posts first. Note that for posts with a large amount of text, aMoreoption is displayed. - Click on the
usernamefor a post. Note that that the Profile for that username is shown. Note theFollowed byandFollowingnumbers. Note also that the posts for that username are displayed, with the most recent first. - Click the
Followbutton. Note that theFollowed bynumber increases by 1, and that the button now showsUnfollow. - From the menu, click on ‘Following`. Note the posts for the username you are now following, are displayed.
- Beneath each post, note the
heart symbolthis indicates whether you have liked a post, or not. Click the symbol toLikeorUnlikea post. Note that the colour changes and the number of Likes updates appropriately. Note that the entire page does not reload when doing this. - From the menu, click
My Posts. Note theFollowed byandFollowingnumbers for you. Note that there is no option toFollowyourself. Note also that you cannotLikeyour own posts. - Note the
edit symbolbeneath each of your posts. Click thesymbolbeneath one of the posts. Note that the post is now editable, with aSaveandCanceloption. ThisEditoris a React Component and it utilise the Django csrf token to validate the edit submission. The server also checks that the username that submits the edit is also the author of the post. - Without
SavingorCancellingthe edit, click theediticon of another post. Note the alert that advisesAlready editing - In the editor, make a change and
Save. Note that the edit is saved to your post, and theEditoris closed. - From the menu, click
Logout. Note that you are now logged out and that theFollowingmenu option is not visible. Note also that the Network landing page is now re-displayed with 3 of the latest posts. - From the menu, click
All Posts, note that you are re-directed top theLoginpage. - End.
Generally, the user interface is generated from Django templates, and styled with CSS.
Javascript is used to: -
- set the
likeicon colour for each post - detect a
likeevent so that the status can be updated asynchronously - add a
Moreoption to posts with large amounts of text. (Note thetext lengthis not limited in Network, unlike Twitter). - detect an edit post event and invoke a React editor.
JSX is used to define the React Editor components and manage the update of a post.
Currently, there are no test scripts developed for the application.
The application does include test users user1 user2 user3 and admin and also some test posts.
Note: Passwords are the same as username.
To start with a clean database, simply delete db.sqlite3 and re-run migrations python manage.py migrate
- Robert Collins - inspired by tuition from - the CS50 team at Harvard