Due: Wednesday April 25, 11pm
Crowdgrader URL: https://www.crowdgrader.org/crowdgrader/venues/view_venue/3764
Reviewing starts: Thursday April 26, 8am
Reviewing ends: Monday April 30, 11pm
Use as starter code the branch hw2_starter_code_2018
of the start application.
To get it, you can do:
git fetch
git checkout hw2_starter_code_2018
The specific branch on the bitbucket site is described at this URL: https://bitbucket.org/luca_de_alfaro/web2py_start_2016/branch/hw2_starter_code_2018
Please build a site accessible from the /start/default/index.html
URL path.
You have to do the following modifications.
First, add to the database a boolean field that says whether a memo is public or not. Such a field can be defined via:
Field('is_public', 'boolean')
The field must be initialized to False. This field will not be managed via forms. Rather:
When one creates a new memo, the field must initially be False (use the default=
option for is_public, similarly to what we did for the user_email field).
In the index page, every memo should display clearly one of these two icons:
<i class="fa fa-users"></i>
<i class="fa fa-user"></i>
Clicking on the icon should toggle the public/private status of the memo (that is, the is_public
field of the memo). You can implement this writing a toggle_public method, similarly to how we wrote the delete method. The method must be able to read a record, and toggle the value of is_public. To do so, I recommend that you use:
Note that the icons above should be clickable only by the logged-in user who owns the underlying memos (as per the user_email
database field). If the icons are not clickable, they should appear as disabled (switch to a gray color, rather than black, for instance).
Note also that if an icon is not clickable, it is surely a public icon <i class="fa fa-users"></i>
, because private icons can only be seen in memos that belong to the currently logged in user.
To this end, you have to make two changes.
If a user is not logged in, in the index page you should show the list of all public memos. The button "add memo" should be absent from the index page if the user is not logged in.
After the above is done, you should ensure that for logged-in users, the user can see both all public memos, and all of her private memos. To this end, you will need to write a query that encodes an OR clause: either the memo is public, or it belongs to the currently logged in user. See the documentation for how to build such queries.
Please follow these instructions exactly.
Run web2py from the shell rather than from pycharm, doing python
web2py.py -e
(I cannot seem to be able to login in the admin console when starting web2py from pycharm), and go to the Admin app in web2py. You can do that by visiting the URL /admin/default/index
, or you can do that by going to the welcome app at /welcome/default/index
and clicking on the Admin button at the bottom. You have to enter the password you used when starting web2py. You will see a screen similar to the one below, and you have to select "pack all" for the start application:
This will create a file called web2py.app.start.w2p, which you have to download, and then upload to the following CrowdGrader assignment:
https://www.crowdgrader.org/crowdgrader/venues/view_venue/3764