Skip to content
Snippets Groups Projects
Commit 6cbf0e47 authored by Jacek Lebioda's avatar Jacek Lebioda Committed by Valentin Groues
Browse files

Docx processing

parent 704051a5
No related branches found
No related tags found
1 merge request!45Resolve "Automatic post mail creation"
......@@ -3,7 +3,7 @@
[![coverage report](https://git-r3lab.uni.lu/piotr.atyjaszyk/scheduling-system/badges/master/coverage.svg)](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`
......@@ -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
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment