Skip to content

Commit

Permalink
Adding basics.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Aug 25, 2015
1 parent 8b62f8d commit 4d43156
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 24 deletions.
60 changes: 58 additions & 2 deletions docs/basics.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
Basics
*********
******

Basic knowledge about the project will go here.
This project is pretty basic as far as Django projects go,
it has one main app named huntserver which does nearly everything.
Consult file_map.txt for a basic layout of the project.

Design
------
The design of this project is somewhat divided into two parts,
the staff experience and the hunter experience.
Staff is considered to be anyone logged in using an account with a username in the ADMIN_ACCTS setting.
(found in secret_settings)
These users have access to the /staff/ area of the site;
however, in order to access all functions and access the /admin/ area of the site,
the user must also be a superuser as designated by Django.

Dynamic Content
---------------
Dynamic content is created by using a combination of the model-view controller and the default Django templating engine.
Both are extensively documented on Django's website.
Both models and views used in this project are documented by later pages.

Static Content
------------
Static files are managed by Django with each app having it's own collection of static files.
These files are gathered in the main static directory (``{PROJECT FOLDER}/static/`` )
by running ``python manage.py collectstatic``.
This main static directory is not tracked by git,
and therefore you should not put any content directly into this folder.

Puzzles should not be checked into the github repository.
They should exist on some accessible online file source (we use dropbox)
and will be downloaded and converted when the admin choses to do so.
Once downloaded, the puzzle files live in ``{PROJECT FOLDER}/huntserver/static/huntserver/puzzles/``
named using the puzzle ids that are unique.

To protect users from being able to just go to ``/static/{Puzzle_id}.pdf`` and get puzzles,
the server comes included with a protected routing path.
The /protected/ URL will only allow a user to access puzzle files if they have unlocked the puzzle.
This routing path will automatically be used as long as access to static files
is done through the template command ``{STATIC_URL}``.
You should protect your static URL by only allowing access to /static/ from internal sources as
described in the "Setup: Nginx" portion of these docs.

Websockets
----------
This project accomplishes live page content with the use of websockets powered by ws4redis.
These websockets are controlled by a redis message passing server running alongside the django server.
This allows asychronous communication to the clients webpage,
however communication from the webpage is synchronous with respect to the django server.
This limitation is overcome by using POST requests as an asynchronous method of communication with the server from the client.

Database
--------
As noted in setup, the default database for this project is a MySQL database.
After setup the database should never need to be modified by hand,
additions or deletions should be done from the Django interactive shell or from the online admin GUI.
Modifications to the table structure should only be done by modifying models.py
and using the automatically created migration files.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Contents

setup
basics
models
hunt_creation
hunt_running
customization
Expand Down
30 changes: 30 additions & 0 deletions docs/models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Models
------

Hunt
This is the most important type of object. Each instance of the Hunt model
represents a different puzzlehunt.

Puzzle


Team


Person


Submission


Solve


Unlock


Message


Unlockable

41 changes: 22 additions & 19 deletions docs/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,26 @@ Install the following python packages using pip:
Code Setup
----------

If you haven't already, clone the repository to a location that the user running
the server will have access to.
If you haven't already,
clone the repository to a location that the user running the server will have access to.

Instantiate a copy of the secret settings file by copying the secret settings
template:
Instantiate a copy of the secret settings file by copying the secret settings template:
``cp puzzlehunt_server/secret_settings.py.template puzzlehunt_server/secret_settings.py``

Then replace the default settings such as the admin account username, the
database login details, and secret key. (If needed, look up instructions on how
to generate a new secret key)
Then replace the default settings such as the admin account username,
the database login details, and secret key.
(If needed, look up instructions on how to generate a new secret key)

Database setup
--------------

This project is configured to use a MySQL database. It can be configured to use
a different type of database by modifying settings in secret_settings.py, but
those modifications are out of the scope of this setup.
This project is configured to use a MySQL database.
It can be configured to use a different type of database by modifying settings in secret_settings.py,
but those modifications are out of the scope of this setup.

First we have to create the user and database that the application will use. To
do so, log into the mysql client as a superuser and enter the following
commands. (subsituting your password and username)
First we have to create the user and database that the application will use.
To do so, log into the mysql client as a superuser and enter the following commands.
(subsituting your password and username)

- ``CREATE DATABASE puzzlehunt_db;``
- ``CREATE USER 'nottherealusername'@'localhost' IDENTIFIED BY 'nottherealpassword';``
Expand All @@ -58,16 +57,20 @@ commands. (subsituting your password and username)
Redis setup
-----------

Start up the redis server using ``sudo service redis-server start``. You can
check if worked by running ``redis-cli ping`` and getting the response ``PONG``.
Start up the redis server using ``sudo service redis-server start``.
You can check if worked by running ``redis-cli ping`` and getting the response ``PONG``.

Django setup
------------

Migrate the database by running ``python manage.py migrate``.

Create a superuser for the project by running
``python manage.py createsuperuser`` and following the instructions. The
username here should match the setting ADMIN_ACCT in secret_settings.py.
Create a superuser for the project by running ``python manage.py createsuperuser`` and following the instructions.
The username here should be one of the usernames in the setting ADMIN_ACCTS in secret_settings.py.

Run ```python manage.py runserver 8080``` to start a server at http://127.0.0.1:8080/
Run ```python manage.py runserver 8080``` to start a server at http://127.0.0.1:8080/

Nginx setup
-----------

Coming soon! (Use the test server command above until then)
5 changes: 3 additions & 2 deletions huntserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def is_admin(request):
if request.user.is_authenticated():
if request.user.username == settings.ADMIN_ACCT:
if request.user.username in settings.ADMIN_ACCTS:
return True
return False

Expand All @@ -32,6 +32,7 @@ def protected_static(request, file_path):
puzzle = get_object_or_404(Puzzle, puzzle_id=puzzle_id)
team = Team.objects.get(login_info=request.user);
# Only allowed access to the image if the puzzle is unlocked
# TODO: add condition for hunt is over.
if puzzle in team.unlocked.all():
allowed = True
# At the moment, if it's not a puzzle file, it's allowed
Expand Down Expand Up @@ -151,7 +152,7 @@ def index(request):

@login_required
def puzzle(request, puzzle_id):
puzzle = get_object_or_404(Puzzle, puzzle_id=puzzle_id)
puzzle = get_object_or_404(Puzzle, puzzle_id__iexact=puzzle_id)
team = Team.objects.get(login_info=request.user);

# Create submission object and then rely on puzzle.py->respond_to_submission
Expand Down
2 changes: 1 addition & 1 deletion puzzlehunt_server/secret_settings.py.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADMIN_ACCT = 'nottherealusername'
ADMIN_ACCTS = ['nottherealusername']
SECRET_KEY = 'this is not the secret key, use your own'

DATABASES = {
Expand Down

0 comments on commit 4d43156

Please sign in to comment.