SMS Course Website Development
From shopwiki
Software Installation
The following is a set of instruction on how to run and edit the PHAS SMS Course Website. The website was written in the programming language Python and using the web framework Django. This first section is a step-by-step guide on how to install and setup the proper software in order to read and edit the website code.
- Install last version of Python (3.5.4)
- Run the .exe file and check box Add Python 3.5 to PATH
- Installing Python also installs pip. Pip is a tool for installing Python packages. To make sure that you have the latest pip version:
- Open a windows command prompt (Windows 10: left-click Windows Icon, type Command Prompt, select it)
- In the command prompt type: python -m pip install –U pip
- To keep python packages contained, it is recommended to create and work from a virtual environment. To create and manage your virtual environments, we suggest to use virtualenvwrapper
- To install virtualvenvwrapper 4.7.1.dev27, in the Command Prompt, type pip install virtualenvwrapper-win
- To create a new virtual environment, use the command mkvirtualenv <NAME>. For our virtual environment, we chose the name smsvenv. In Command Prompt, type mkvirtualenv smsvenv
- The virtual environment will activate by itself upon creation. In the future, you don’t have to recreate the smsvenv virtual environment. To activate it, just type the command: workon smsvenv in the Command Prompt
- The next step is the installation of Django. The latest version is Django 2.0, but the website was created using Django 1.10 and some functionalities of 3rd party packages don’t work with Django 2.0. To avoid any issues, install Django 1.10. A quick install guide can be found at https://docs.djangoproject.com/en/1.10/intro/install/
- To install Django 1.10, type pip install Django==1.10 in Command Prompt
- The SMS Course website uses a list of 3rd party packages that can all be installed using pip. Before installing any of the packages, make sure that you are working in the virtual environment smsvenv.
- Crispy-Forms 1.7.0 (http://django-crispy-forms.readthedocs.io/en/d-0/index.html). To install Crispy-Forms, type pip install --upgrade django-crispy-forms in Command Prompt.
- Happenings 0.3.3 (https://pypi.python.org/pypi/django-happenings). Install happenings by typing pip install django-happenings in Command Prompt. Since the happenings package had to be modified to make it work with this newer version of Django, copy the happenings folder currently used for the website (ask IT) over the one that you just installed.
- Django_registration_redux 1.9 (https://django-registration-redux.readthedocs.io/en/latest/index.html). To install Django_registration_redux, type pip install django-registration-redux==1.9 in Command Prompt.
- Django_tables2 (https://django-tables2.readthedocs.io/en/latest/). To install django_tables2, type pip install django-tables2 in Command Prompt.
- A good script editor that supports Django is LiClipse. You can download it at https://www.liclipse.com/. When the LiClipse software is opened for the first time, it asks where your projects will be located. By default, it names this folder Workspace. Copy the current folder that contains the SMS Course Website files, named SMS_Course. In LiClipse, go to File --> Open Projects from File System. In the import source, browse for the SMS_Course directory. Click Finish. You can ignore the “Invalid external source folder specified” message.
Website Editing
All software and packages have now been properly installed. Work on the website can begin.
- To verify that the website looks and works the way it was intended to, you can load it locally using any web browser. To do so, open your windows explorer and select the folder SMS_Course located in the Workspace folder. Click on the address bar (the path should be highlighted) and type cmd. This will open a Command window with the right directory already selected. Make sure to start your virtual environment and type python manage.py runserver. Open a web browser and type http://127.0.0.1:8000/ in the address bar.
- Django automatically create an admin page associated with your project. To access the admin page, type http://127.0.0.1:8000/admin in your Web browser:
- Username: SMSadmin
- Password: phassmscourseadmin
- The database used for the website is SQLite. It’s the one that comes with Django. After doing any modification to the website that impacts the database structure (ex: modifying the models.py file), those changes need to be migrated to the database. To do so, use the command python manage.py makemigrations followed by the command python managa.py migrate.
- The website also uses static files (images, javascript, css). To deploy those files, use the command python manage.py collectstatic.
- The file structure and content in the SMS_Course folder is as follow:
- Manage.py file contains commands like runserver and migrate. Do not modify!
- Db.sqlite3 file is the database.
- Dashboard folder contains the core files of the app “dashboard”:
- admin.py contains the code for the admin page.
- apps.py is where your apps are managed.
- forms.py is where the forms are defined.
- models.py defines the type and behavior of your data.
- views.py contains the active code (or functions) that dictates how a webpage will respond to inputs.
- migrations folder contains the history of the database migrations.
- SMS_Course folder:
- settings.py contains the general settings of the project.
- urls.py is where the webpage addresses are defined.
- wsgi.py is related to website deployment code. Do not modify!
- static_in_pro folder contains the information about the static web design graphics
- templates folder contains the html information of each web page.
Reset Database
If, for some reason, the database has to be deleted, follow these steps to delete it and create a new one.
- To delete the old database, delete file db.sqlite3 located in the main SMS_Course folder
- Also, delete all .py files located in \SMS_Course\dashboard\migrations except __init__.py.
- To create a new database, open a command window and browse to the main SMS_Course folder.
- Start the virtual environment with the command:
- workon smsvenv
- Then write the commands:
- python manage.py makemigrations
- python manage.py migrate
- Create a new superuser with command:
- python manage.py createsuperuser
- Username = SMSadmin
- Password = phassmscourseadmin
- Go to the admin page: http://127.0.0.1:8000/admin/ and click on “Module Description”. Now, add all 10 modules (one at a time) by clicking on “Add module description” and enter the following information: