diff --git a/.gitignore b/.gitignore index ad7a584..ef25be1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__/ .DS_Store demo/ans demo/students.db -LIXO \ No newline at end of file +LIXO +static/libs diff --git a/README.md b/README.md index 1cd438d..e60b10f 100644 --- a/README.md +++ b/README.md @@ -17,39 +17,44 @@ The webserver is a python application and requires `python3.7` and `pip` to be i - SQLAlchemy - bcrypt -These can be installed for a single user (recommended), in a python virtual environment or system wide. +These can be installed for a single user, in a python virtual environment or system wide. -#### Installing packages for a single user (recommended) +#### Installing packages for a single user ```.bash -pip3 install --user tornado mistune pyyaml pygments sqlalchemy bcrypt markdown +pip3 install --user tornado mistune pyyaml pygments sqlalchemy bcrypt ``` #### Installing packages in a virtual environment (alternative) ```bash -pyvenv-3.6 venv/perguntations # or other virtualenv directory -source venv/perguntations/bin/activate # activate virtualenv +python3 -m venv PATH/TO/VENV/perguntations +source PATH/TO/VENV/perguntations/bin/activate # activate virtualenv pip3 install tornado mistune pyyaml pygments sqlalchemy bcrypt markdown ``` #### Installing packages system wide (alternative) -I personally prefer python packages to be installed for a single user, but if a system wide installation is required, it is probably better to use the operating system package manager instead of `pip`: +I personally prefer python packages to be installed for a single user, but if a system wide installation is required, the operating system package manager should be used: Linux: ```bash -apt-get install py37-tornado py37-mistune? py37-yaml py37-pygments... +apt install python3-tornado python3-mistune python3-yaml python3-pygments... ``` macOS macports: ```bash -port install py37-py37-tornado py37-mistune? py37-yaml py37-pygments... +port install py37-tornado py37-mistune py37-yaml py37-pygments... ``` +FreeBSD: + +```bash +pkg install py37-tornado py37-mistune py37-yaml py37-pygments... +``` ### 1.2 Install and setup perguntations @@ -65,6 +70,22 @@ where USERNAME is your account on bitbucket. The server will run an https server and requires valid certificates. To generate certificates, there are two possibilities: public server with static IP address or a private server. +The thirdparty javascript libraries are not included in the repository. They should be downloaded and installed in the directory perguntations/static/lib. + +The following libraries are currently necessary (as of 24/1/2019): + +``` +DataTables +MDB-Free_4 +MathJax-2.7.5 +bootstrap-4.2.1-dist +codemirror-5.42.2 +fontawesome-free-5.6.3-web +jquery-3.3.1.min.js +popper.min.js +``` + + #### Generating certificates for a public server (FreeBSD) ```sh @@ -153,6 +174,7 @@ Ports 80 and 443 are reserved for the root user and and this software _should NO ```.bash iptables -t nat -I PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-ports 8080 +FIXME: also for port 443... ``` Explanation: @@ -176,7 +198,9 @@ Edit `/etc/pf.conf`: or `ext_if="vtnet0"` for guest additions under virtual box. -Edit `rc.conf` +Start firewall with `sudo service pf start`. + +Optionally, to activate pf on boot, edit `rc.conf`: pf_enable="YES" pf_flags="" @@ -187,11 +211,10 @@ Edit `rc.conf` pflog_flags="" pflog_logfile="/var/log/pflog" -Reboot. ## Troubleshooting -* The server tries to run `python3.6` so this command must be accessible from user accounts. +* The server tries to run `python3` so this command must be accessible from user accounts. Currently, the minimum supported python version is 3.6. * If you are getting any `UnicodeEncodeError` type of errors that's because the terminal is not supporting UTF-8. This error may occur when a unicode character is printed to the screen by the server or, when running question generator or correction scripts, a message is piped between the server and the scripts that includes unicode characters. Try running `locale` on the terminal and see if there are any error messages. Solutions: - debian: fix it with `sudo dpkg-reconfigure locales`, select your UTF-8 locales and try again. @@ -212,4 +235,4 @@ Try running `locale` on the terminal and see if there are any error messages. So ### Contacts ### -* Miguel Barão mjsb@uevora.pt \ No newline at end of file +* Miguel Barão mjsb@uevora.pt diff --git a/models.py b/models.py index d3f1a9c..8d2081b 100644 --- a/models.py +++ b/models.py @@ -21,7 +21,10 @@ class Student(Base): questions = relationship('Question', back_populates='student') def __repr__(self): - return 'Student:\n id: "{0}"\n name: "{1}"\n password: "{2}"'.format(self.id, self.name, self.password) + return f'Student:\n\ + id: "{self.id}"\n\ + name: "{self.name}"\n\ + password: "{self.password}"' # --------------------------------------------------------------------------- @@ -43,17 +46,17 @@ class Test(Base): questions = relationship('Question', back_populates='test') def __repr__(self): - return 'Test:\n\ - id: "{}"\n\ - ref="{}"\n\ - title="{}"\n\ - grade="{}"\n\ - state="{}"\n\ - comment="{}"\n\ - starttime="{}"\n\ - finishtime="{}"\n\ - filename="{}"\n\ - student_id="{}"\n'.format(self.id, self.ref, self.title, self.grade, self.state, self.comment, self.starttime, self.finishtime, self.filename, self.student_id) + return f'Test:\n\ + id: "{self.id}"\n\ + ref: "{self.ref}"\n\ + title: "{self.title}"\n\ + grade: "{self.grade}"\n\ + state: "{self.state}"\n\ + comment: "{self.comment}"\n\ + starttime: "{self.starttime}"\n\ + finishtime: "{self.finishtime}"\n\ + filename: "{self.filename}"\n\ + student_id: "{self.student_id}"\n' # --------------------------------------------------------------------------- @@ -72,14 +75,14 @@ class Question(Base): test = relationship('Test', back_populates='questions') def __repr__(self): - return 'Question:\n\ - id: "{}"\n\ - ref: "{}"\n\ - grade: "{}"\n\ - starttime: "{}"\n\ - finishtime: "{}"\n\ - student_id: "{}"\n\ - test_id: "{}"\n'.fotmat(self.id, self.ref, self.grade, self.starttime, self.finishtime, self.student_id, self.test_id) + return f'Question:\n\ + id: "{self.id}"\n\ + ref: "{self.ref}"\n\ + grade: "{self.grade}"\n\ + starttime: "{self.starttime}"\n\ + finishtime: "{self.finishtime}"\n\ + student_id: "{self.student_id}"\n\ + test_id: "{self.test_id}"\n' # --------------------------------------------------------------------------- diff --git a/serve.py b/serve.py index a4fd0c5..628a023 100755 --- a/serve.py +++ b/serve.py @@ -168,6 +168,7 @@ class FileHandler(BaseHandler): self.write(data) await self.flush() + break # for loop # ------------------------------------------------------------------------- # Test shown to students -- libgit2 0.21.2