Skip to content

Developing myRobogals on Windows

Sing edited this page Jan 14, 2017 · 9 revisions

Here's how to install a local development copy of myRobogals on Windows.

Pre-requisites We currently use Django 1.7.11 with Python 2.7.13. For maximum compatibility with what's running on the live server, it's recommended that you use these versions too. You will need these items to be installed on your machine in order to run myRobogals

  • Python
  • Django
  • pytz
  • tinymce
  • (Optional) Sequel Pro
  • (Optional) mySQL
  • (Optional) mysql-python

Check out the myRobogals repository

Fork the myRobogals repository from Github to create your own copy of it, then check out that copy. The following pages may be helpful:

Github: Set up git

Github: Fork a repo

myRobogals repo

(Optional) Installing mySQL

If you don't want to install mySQL, you can use the default SQLite that Django provides and skip all these steps. See "Generate the settings file" section for more information.

myRobogals is using a mySQL database. To be able to view the database in a meaningful way, download HeidiSQL and install it.

Next, you will need to instajll mySQL. Go to the mySQL downloads website and download the latest version of the mySQL MSI Installer. You can either choose to install it through the web (smaller MSI file, will download the mySQL products you choose to install) or just download it directly (bigger MSI file).

Open the MSI file choose the Developer Default to install. You can skip the prerequisites/dependencies because we won't be needing them. Finish the installation process to configure the product. In the Configuration Menu, select the following

Config Type: Development Machine

Connectivity: Tick - TCP/IP and Tick - Shared Memory. Leave the settings on default

Click next

MySQL Root Password: (choose an appropriate password and retype it in the next box)

Add user: myrobogals/myrobogals, role as DB admin This will be used to configure Django

Click next

Tick - Configure MySQL Server as a Windows Service

Tick/Untick - Start the MySQL Server at System Startup

This is dependent on whether or not you want to have MySQL running in the background when you start your computer. In most cases it's not nessassary, so we can just untick the checkbox for now.

Click next. Skip over plugins. Click Execute.

Finally, click next then execute to connect to server and apply server configurations. Follow the prompts to complete installation. Open up MySQL Workbench to confirm that the server is running by clicking Server Status.

Use the mySQL documentation for windows as a reference which provides additional installation information or troubleshooting guide if you get stuck.

If the installation was successful, open HeidiSQL and connect to the mySQL server by selecting the following:

  • Network type: MySQL (TCP/IP)
  • Hostname / IP: 127.0.0.1
  • User: root
  • Password: (what you've chosen above)
  • Port: 3306

Then click open. After it's conencted, you will need to create a database. Right click on the side column and go to create new... database called myrobogals. Make sure Unnamed is selected, or top tree view otherwise it won't let you.

Setting up Python and Django

Install the latest version of Python 2 off the official Python website. At the current time of writing, it is v2.7.13, and is what the production site is running off. When downloaded, double click on the installer and accept the default install path C:\Python27 to simplify the installation process.

After instaling, we will need to add Python to system's PATH environment variable. To do this, go to Control Panel -> System -> Advanced system settings. Under the Advanced tab, click on Environment Variables... Add ;C:\Python27;C:\Python27\Scripts to the end of the Path variable depending on whether or not you want Python installed for all the users on the computer or just yourself. Click Ok and close the windows. To test whether you've installed Python properly, open up a Command Window and type in python --version to confirm. If installed correctly, it will output the current Python version.

Installing virtualenv and virtualenvwrapper

Instead of installing the Django requirements on your computer which may have version and references collisions with what you've previously installed, it is best to use a virtual environment which counteracts this issue. Virtualenv creates a dedicated environment for each Django project we create and is considered a best practice. We will isntall both virtualenv and virtualenvwrapper.

pip install virtualenvwrapper-win

Create our new virtual environment in any directory you want as long as it's not in the myRobogals folders.

mkvirtualenv venv

The virtual environment will be activated automatically and you’ll see (venv) next to the command prompt. If you start a new command prompt, you’ll need to activate the environment again in any folder by

workon venv.

Installing Django

Make sure your venv is activated before installing Django and myRobogals requirements. This is to ensure that packages do not get mismanaged and stay in their own virtual environments. Now go to the cloned myRobogals directory and instal the required dependencies list under requirements.txt by typing into Command Prompt

cd (myRobogals folder path)
pip install -r requirements.txt

Generate the Settings File

In the "myrobogals" directory inside the "myrobogals" directory (yes you read that correctly), make a copy of the file "settings.py.sample" and rename it to "settings.py"

Edit the file and fill in the path to your myRobogals directory at the top of the file. This is to ensure that everything gets the proper path references in your project.

Find where DATABASES is defined and enter in your mySQL credentials to ensure that Django has access to the database. For those who want to use sqlite (or other databases), comment out the one for mySQL and uncomment the one for sqlite.

Generate a Sample Database

To create a sample database with a some mock users, chapters and workshops, first navigate to the directory containing the file manage.py. Create database structure by typing:

python manage.py migrate

Delete the timezone information, otherwise conflicts will occur when loading the sample data

python manage.py shell

In the python shell command line enter the following:

from myrobogals.rgmain.models import Timezone
Timezone.objects.all().delete()
quit()

Load in sample data

python manage.py loaddata sampledata

Start the Development Server

If you've got all the previous steps completed without failing you should be able to then type

python manage.py runserver

The development server will now be running on http://127.0.0.1:8000/ - click there and you'll see your very own local copy of myRobogals.

You can log in with the username "admin" and password "test" to get started. This account has admin privileges, so go ahead and create your own. All the other sample users have the password "abc123".

Now get coding, and contribute your changes back to us as a "Pull Request" on Github!

Things to remember for EACH coding session

  1. Activate your myRobogals virtual environment (see above)
  2. Update your fork from the original repo to ensure you are working off the latest code
  3. Install/upgrade required Python packages using 'pip install --upgrade -r requirements.txt'
  4. Ensure that mySQL has started on your local machine. Otherwise Django will throw an error.
  5. Run 'python manage.py migrate' to ensure your local database structure is up to date

Troubleshooting

Error information will be listed here once reported. If found, please report them to Sing (firew0rks) or the wiki directly!

References

https://docs.djangoproject.com/en/1.10/howto/windows/

Clone this wiki locally