Clone Repository https://github.com/CodeCrow/talesofvalor_python
$ git clone https://github.com/CodeCrow/talesofvalor_python.git
$ cd talesofvalor_python
Send your git username to Rob Archer so he can give you write permission to the repo.
[Install pipenv](pip install --user pipenv) (if it isn't installed already)
*Nix/OS X:
pip install --user pipenv
Windows:
Most of the windows commands are the same except you have to add python -m
to the front of the command for instance to install pipenv use:
python -m pip install --user pipenv
When the installation is done, open a new shell/terminal window. You should now be able to see the result of this command:
pipenv --version
This installs libraries and modules that support our specific code:
pipenv install
pipenv shell
First, make sure you have a database named talesofvalor
with a character set of utf8
.
$ mysql
mysql> create database `talesofvalor` character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> exit
- Install direnv for your machine: https://direnv.net/docs/installation.html
- copy the contents in "envrc_template" into the ".envrc" file in the base directory of the code.
Allow the code to run:
$ direnv allow .
Copy the "local.py" file and update it with your requirements for accessing the database.
cd talesofvalor/settings
cp stage.py local.py
vi local.py
You can replace vi
with an editor of your choice.
Change the areas marked with ######### to values for your database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'talesofvalor',
'USER': '############',
'PASSWORD': '############',
'HOST': '',
'PORT': '', # Set to empty string for default.
'OPTIONS': {
}
}
}
# email back end for development only
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Pull down the database and media files from the development server not needed yet:
$ fab sync_all:dev,yourname -u wgbh
Run the initial migrations in case there are differences between the development server database and the code currently in the development repository.
$ ./manage.py migrate --settings=talesofvalor.settings.local
To be able to log in for the first time (or if you forget your logins!) you have to create a "superuser".
$ ./manage.py createsuperuser --settings=talesofvalor.settings.local
So you can now develop locally.
Make sure you have your pipenv shell running:
pipenv shell
Then activate the server:
$ ./manage.py runserver --settings=talesofvalor.settings.local
Open a browser and go to http://127.0.0.1:8000/admin/
You should now see a login screen!
So you don't have to set up a local SMTP server, make sure the following is added to your local settings file (local.py).
# email back end for development only
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
This will display the emails sent in the server log rather than trying to send emails.
The CSS files are created using SASS using the gulp workflow.
To use gulp, you have to install node and the node package manager if it is not there already:
$ brew install node
Now, install all the needed packages:
$ npm install
This will read package.json
file and install the required packages.
Now you can run gulp
and any changes that you make to the SASS
files will be detected and built into the master css file. This command will continue running until it is stopped.
$ gulp
Deployment uses Fabric 2.0. If you are used to Fabric < 2, sending CLI variables looks a little different.
fab deploy --environment {{ environment_name}} [--migrate][--updaterequirements][--branch {{ branch_name }} ]
Where “environment” is “stage”, “production”, “development”, and “branch_name” is the branch that should be deployed.
Example:
fab deploy --environment stage --migrate
This would would deploy the latest default staging branch to the 'stage' environment and run existing migrations.
MySQL now defaults to using INNO DB as the storage engine, which is awesome, except it throws constraints around like candy, which doesn't play well with plugins. So we sometimes have to remove the constraints.
Example Error:
IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`spldjangocms`.`video_splvideoasset`, CONSTRAINT `cmsplugin_ptr_id_refs_id_20f5c1c6` FOREIGN KEY (`cmsplugin_ptr_id`) REFERENCES `cms_cmsplugin` (`id`))')
To fix the error, you can either remove the constrait using a GUI such as Sequel Pro or the following command:
ALTER TABLE video_splvideoasset DROP FOREIGN KEY 'cmsplugin_ptr_id';
- go to paypal.com
- click "developer"
- log in with regular account
- Test users are under "accounts"
Once you have everything working, how do you restart everything when you've been away for a few days
In separate terminal windows, activate the venv and then run:
- ./manage.py runserver --settings=talesofvalor.settings.local
- gulp and then on github, look at the Projects page to see the todo list: https://github.com/CodeCrow/talesofvalor_python/projects or at the more granular level, the Issues list: https://github.com/CodeCrow/talesofvalor_python/issues
If you change a model and need to migrate the changes to the database: $ ./manage.py makemigrations --settings=talesofvalor.settings.local
Nuking and re-creating the database: in mysql using a db snapshot:
drop database talesofvalor source path/to/filename or use migrate to minimally repopulate: $ ./manage.py migrate --settings=talesofvalor.settings.local
Importing an exported db:
- Download the exported file
- Fire up mysql ("mysql" at the prompt)
- If you want to see what dbs exist: show databases;
- Back at the mysql prompt: mysql> create database new_database_name;
- mysql> use new_database_name
- mysql> source path/to/export/file
- Go to the local settings file (typically ROOT/talesofvalor/settings/local.py ) and update the database's NAME
- Navigate to where you have the code.
- Pull the newest code from the repository:
git pull
This loads the correct modules and prepares the code libraries
- Navigate to where you have the code.
pipenv shell
- Navigate to where you have the code.
- Start the compiler:
3.
gulp
- Navigate to where you have the code.
- Start the server:
./manage.py migrate --settings=talesofvalor.settings.local
- Create the migration files:
./manage.py makemigrations --settings.talesofvalor.local
- Run the migration files:
./manage.py migrate --settings.talesofvalor.local
You are basically going to run the last step of updating the database, because other people have already created the migration files.
- Navigate to where you have the code.
- Run the migration
./manage.py migrate --settings.talesofvalor.local
If something has gone wrong, or you want start from scratch, data-wise, you can recreate the database.
- Log into your local mysql server
mysql -u username -p
- Drop the database:
DROP DATABASE databasename;
- Exit mysql:
exit;
- Create the database again:
./manage.py migrate --settings=talesofvalor.settings.local
Remember, this gets rid of the entire database. You'll have to recreate your superuser to log in again. And there is no going back . . .
If you need a module to help with development, you would use pipenv to install it.
- Make sure you are in the code director
- Add the module:
3.
pipenv install modulename
- commit the changes that it makes to the
Pipfile
file.
If you want to get the database from the production site, so you can look at something or test something with valid data, you can log into the database online and export that.
- Enter 'mysql.talesofvalor.com' in your browser.
- Enter the username and password (Contact Rob Archer for that information)
- Choose 'talesof_rhiven' from the left hand list.
- Click 'Export' from the top navigation.
- Format the export as SQL and click the "Go" button.
- You can change export method to 'custom' if you want more control.
- Save the SQL file somewhere on your machine and take note of the location.
- Open the command line on your machine.
- Log into your local mysql.
mysql -u username -p
- Create a new database.
create database `talesofvalor_test` character set utf8;
- You can name it whatever you want.
- Indicate that you want to use that database:
use talesofvalor_test;
- Load the data into the new database:
source path/to/exported/database;
- Update the settings file to point to the new database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'talesofvalor_test',
'USER': '############',
'PASSWORD': '############',
'HOST': '',
'PORT': '', # Set to empty string for default.
'OPTIONS': {
}
}
}
- make sure the 'NAME' here matches the name of the database you created.
- Restart the server.
if you have not already, in the virtual environment that you have created for TOV, run the following pip install commands
pip install selenium
pip install --upgrade mailosaur
This will install the packaged needed to interface with a webdriver. For now there is a instance of chrome included in the repo.
- Open project in VSCode
- Click 'View' > 'Terminal'
- In the terminal that opens in VSCode start the server using above method
- In the upper right hand side of the terminal click the dropdown and start a new terminal of your choice (I typically use CMD, but Powershell will also work)
- In the new terminal run
python .\talesofvalor\tests\SimpleTests.py
- A instance of chrome should then open and attempt to log in to the sever as well as run other tests
- At the end of the tests you will see something to the effect of the following if all the tests passed otherwise you will get messages saying which tests failed.
----------------------------------------------------------------------
Ran 3 tests in 14.240s
OK