diff --git a/readme.md b/readme.md index 42b1f415c237d3a92fa4a132e7b8e1e6cf5eb6eb..901118ed48af950c3283b7c5d12d01c951095e48 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ [](https://git-r3lab.uni.lu/piotr.atyjaszyk/scheduling-system/commits/master) ## Required software (on ubuntu's OS family): - - `sudo apt-get install libpq-dev python-dev postgresql postgresql-contrib python virtualenv python-virtualenv gcc` + - `sudo apt-get install libpq-dev python-dev postgresql postgresql-contrib python virtualenv python-virtualenv gcc python-lxml libxml2-dev` ## Postgres installation - If you don't have postgres installed, complete step seven from [https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn) (remember to save all the credentials, they will be necessary to run the application). @@ -30,9 +30,9 @@ ## Production deployment - git pull and other project installation should be performed in a dir where this django app should be installed, in this tutorial it's /var/www/scheduling-system/ - install nginx: `apt-get install nginx` - - create gunicorn service in systemd (http://docs.gunicorn.org/en/stable/deploy.html#systemd): + - create gunicorn service in systemd (http://docs.gunicorn.org/en/stable/deploy.html#systemd): -### /etc/systemd/system/gunicorn.service +### /etc/systemd/system/gunicorn.service ``` [Unit] @@ -67,7 +67,7 @@ ListenStream=[::]:8000 [Install] WantedBy=sockets.target - + - modify nginx configuration # /etc/nginx/nginx.conf @@ -173,4 +173,4 @@ server { } ``` - extract static files and make them available via nginx: `./manage.py collectstatic` - - you start application by starting gunicorn and nginx: `service gunicorn start`, `service nginx start` \ No newline at end of file + - you start application by starting gunicorn and nginx: `service gunicorn start`, `service nginx start` diff --git a/requirements.txt b/requirements.txt index 72e849e28c5189314ff7943b733264979c9a153a..c251252a67d6228fe679c6716ab5f18a9b347f41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ gunicorn==19.6.0 Pillow==3.4.2 psycopg2==2.6.2 pytz==2016.10 +lxml==3.7.3 +python-docx==0.8.6 \ No newline at end of file diff --git a/smash/web/docx_helper.py b/smash/web/docx_helper.py new file mode 100644 index 0000000000000000000000000000000000000000..b3c0d5e74acfe804028570a52c15daa13fe4889b --- /dev/null +++ b/smash/web/docx_helper.py @@ -0,0 +1,30 @@ +import copy +from docx import Document + +def dfs_update(node, replace_dict): + # If this is a non-empty text node + if node.text != None and len(node.text) > 0: + # Apply transformations to node's text + for what_to_replace in replace_dict: + node.text = node.text.replace(what_to_replace, replace_dict[what_to_replace]) + # Update child elements + for child in node: + dfs_update(child, replace_dict) + + +def process_file(path_to_docx, path_to_new_docx, changes_to_apply): + """ + Tries to open the docx document using given path to file. + Then, applies the transformations- replaces template tags + in format of ##name## to values specified in the second + argument. + """ + generated = Document() + doc = Document(path_to_docx) + for c in changes_to_apply: + for element in doc.part.element[0]: + w = copy.deepcopy(element) + dfs_update(w, c) + generated._body._element.append(w) + + generated.save(path_to_new_docx)