Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
Respect My Net
Commits
af4e394e
Commit
af4e394e
authored
Jan 15, 2012
by
stef
Browse files
[enh] added ods export in ec_berec_tm_questionnaire.xls format, go to /ods
parent
be6cd5c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
bt/sheet.py
0 → 100755
View file @
af4e394e
#!/usr/bin/python
import
os
os
.
environ
[
'DJANGO_SETTINGS_MODULE'
]
=
"nnmon.settings"
from
django.conf
import
settings
from
bt.models
import
Violation
import
ooolib
from
django.utils.html
import
strip_tags
import
re
,
htmlentitydefs
##
# Removes HTML or XML character references and entities from a text string.
#
# @param text The HTML (or XML) source text.
# @return The plain text, as a Unicode string, if necessary.
# source: http://effbot.org/zone/re-sub.htm
def
unescape
(
text
):
text
=
strip_tags
(
text
)
def
fixup
(
m
):
text
=
m
.
group
(
0
)
if
text
[:
2
]
==
"&#"
:
# character reference
try
:
if
text
[:
3
]
==
"&#x"
:
return
unichr
(
int
(
text
[
3
:
-
1
],
16
))
else
:
return
unichr
(
int
(
text
[
2
:
-
1
]))
except
ValueError
:
pass
else
:
# named entity
try
:
text
=
unichr
(
htmlentitydefs
.
name2codepoint
[
text
[
1
:
-
1
]])
except
KeyError
:
pass
return
text
# leave as is
return
re
.
sub
(
"&#?\w+;"
,
fixup
,
text
)
def
save_ods
():
# Create your document
doc
=
ooolib
.
Calc
()
col
=
1
row
=
2
doc
.
set_cell_property
(
'bold'
,
True
)
doc
.
set_row_property
(
row
,
'height'
,
'16.5pt'
)
for
heading
,
width
in
[(
'Country'
,
'73pt'
),
(
'Operator'
,
'77pt'
),
(
'Type of measure*'
,
'355pt'
),
(
''
,
'355pt'
),
(
'Description of the measure'
,
'148pt'
),
(
'Objective'
,
''
),
(
'Method of implementation (if applicable)'
,
''
),
(
'Number of subscribers having a subscription where this measure is implemented'
,
''
),
(
'How is the user informed?'
,
'148pt'
),
(
'Can the user activate/deactivate the measure? How?'
,
'148pt'
),
(
'Protection of business secret'
,
'239pt'
)]:
if
width
:
doc
.
set_column_property
(
col
,
'width'
,
width
)
doc
.
set_cell_value
(
col
,
row
,
"string"
,
heading
)
col
+=
1
doc
.
set_cell_property
(
'bold'
,
False
)
row
=
3
for
v
in
Violation
.
objects
.
filter
(
activationid
=
''
).
exclude
(
state__in
=
[
'closed'
,
'ooscope'
,
'duplicate'
]):
doc
.
set_row_property
(
row
,
'height'
,
'16.5pt'
)
doc
.
set_cell_property
(
'wrap-option'
,
'wrap'
)
doc
.
set_cell_value
(
1
,
row
,
"string"
,
v
.
country
)
doc
.
set_cell_value
(
2
,
row
,
"string"
,
v
.
operator
)
doc
.
set_cell_value
(
3
,
row
,
"string"
,
"%s %s"
%
(
v
.
type
,
v
.
resource_name
))
doc
.
set_cell_value
(
5
,
row
,
"string"
,
"%s
\n\n
%s"
%
(
v
.
editorial
,
unescape
(
v
.
comment_set
.
get
().
comment
)))
doc
.
set_cell_value
(
9
,
row
,
"string"
,
"%s %s"
%
(
"Contractual"
if
v
.
contractual
else
""
,
unescape
(
v
.
contract_excerpt
)))
doc
.
set_cell_value
(
10
,
row
,
"string"
,
"can update to a different dataplan"
if
v
.
loophole
else
""
)
row
+=
1
#(v.state, v.country, v.operator, v.contract, v.resource, v.resource_name, v.type, v.media, v.temporary, v.contractual, v.contract_excerpt, v.loophole, v.editorial,v.comment_set.get().comment)
# Save the document to the file you want to create
doc
.
save
(
"/tmp/ec_berec_tm_questionnaire.ods"
)
bt/views.py
View file @
af4e394e
...
...
@@ -315,3 +315,13 @@ def ascsv(request):
})
response
.
write
(
t
.
render
(
c
))
return
response
from
sheet
import
save_ods
def
asods
(
request
):
response
=
HttpResponse
(
mimetype
=
'application/vnd.oasis.opendocument.spreadsheet'
)
response
[
'Content-Disposition'
]
=
'attachment; filename=respectmynet-ec_berec_tm_questionnaire.ods'
save_ods
()
f
=
open
(
'/tmp/ec_berec_tm_questionnaire.ods'
,
'r'
)
response
.
write
(
f
.
read
())
f
.
close
()
return
response
urls.py
View file @
af4e394e
...
...
@@ -18,6 +18,7 @@ urlpatterns = patterns('',
(
r
'^attach/(?P<id>[0-9]*)$'
,
bt
.
get_attach
),
(
r
'^(?P<id>[0-9]*)$'
,
bt
.
view
),
(
r
'^csv$'
,
bt
.
ascsv
),
(
r
'^ods$'
,
bt
.
asods
),
(
r
'^rss/$'
,
RssSiteNewsFeed
()),
(
r
'^atom/$'
,
AtomSiteNewsFeed
()),
(
r
'^activate/$'
,
bt
.
activate
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment