Skip to content
GitLab
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
0a0ae097
Commit
0a0ae097
authored
Apr 30, 2011
by
stef
Browse files
[enh] storage of reports
parent
2905e87d
Changes
2
Hide whitespace changes
Inline
Side-by-side
bt/models.py
View file @
0a0ae097
...
@@ -48,20 +48,10 @@ MEDIA = (
...
@@ -48,20 +48,10 @@ MEDIA = (
(
'mobile'
,
_
(
'Mobile'
)),
(
'mobile'
,
_
(
'Mobile'
)),
)
)
class
Attachment
(
models
.
Model
):
attachment
=
models
.
FileField
(
upload_to
=
'static'
)
class
Comment
(
models
.
Model
):
submitter
=
models
.
EmailField
()
comment
=
models
.
TextField
()
date
=
models
.
DateField
()
attachments
=
models
.
ForeignKey
(
Attachment
)
class
Violation
(
models
.
Model
):
class
Violation
(
models
.
Model
):
country
=
models
.
CharField
(
max_length
=
2
,
choices
=
COUNTRIES
)
country
=
models
.
CharField
(
max_length
=
2
,
choices
=
COUNTRIES
)
operator
=
models
.
CharField
(
max_length
=
256
)
operator
=
models
.
CharField
(
max_length
=
256
)
contract
=
models
.
CharField
(
max_length
=
256
)
contract
=
models
.
CharField
(
max_length
=
256
)
comments
=
models
.
ForeignKey
(
Comment
)
resource
=
models
.
CharField
(
max_length
=
1
,
choices
=
RESOURCES
)
resource
=
models
.
CharField
(
max_length
=
1
,
choices
=
RESOURCES
)
type
=
models
.
CharField
(
max_length
=
1
,
choices
=
TYPES
)
type
=
models
.
CharField
(
max_length
=
1
,
choices
=
TYPES
)
media
=
models
.
CharField
(
max_length
=
1
,
choices
=
MEDIA
)
media
=
models
.
CharField
(
max_length
=
1
,
choices
=
MEDIA
)
...
@@ -69,3 +59,13 @@ class Violation(models.Model):
...
@@ -69,3 +59,13 @@ class Violation(models.Model):
contractual
=
models
.
BooleanField
()
contractual
=
models
.
BooleanField
()
contract_excerpt
=
models
.
TextField
()
contract_excerpt
=
models
.
TextField
()
loophole
=
models
.
BooleanField
()
loophole
=
models
.
BooleanField
()
class
Comment
(
models
.
Model
):
submitter
=
models
.
EmailField
()
comment
=
models
.
TextField
()
timestamp
=
models
.
DateField
()
violation
=
models
.
ForeignKey
(
Violation
)
class
Attachment
(
models
.
Model
):
storage
=
models
.
FileField
(
upload_to
=
'static'
)
comment
=
models
.
ForeignKey
(
Comment
)
bt/views.py
View file @
0a0ae097
...
@@ -2,23 +2,49 @@ from forms import AddViolation
...
@@ -2,23 +2,49 @@ from forms import AddViolation
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
from
django.shortcuts
import
render_to_response
from
django.shortcuts
import
render_to_response
from
django.template
import
RequestContext
from
django.template
import
RequestContext
from
models
import
Violation
from
django.core.files
import
File
import
json
from
django.conf
import
settings
from
models
import
Violation
,
Attachment
,
Comment
from
tempfile
import
mkstemp
from
datetime
import
datetime
import
hashlib
,
os
def
add
(
request
):
def
add
(
request
):
if
request
.
method
==
'POST'
:
# If the form has been submitted...
if
request
.
method
==
'POST'
:
form
=
AddViolation
(
request
.
POST
)
# A form bound to the POST data
form
=
AddViolation
(
request
.
POST
)
if
form
.
is_valid
():
# All validation rules pass
if
form
.
is_valid
():
# Process the data in form.cleaned_data
v
=
Violation
(
# ...
country
=
form
.
cleaned_data
[
'country'
],
print
'asdf'
,
form
.
cleaned_data
operator
=
form
.
cleaned_data
[
'operator'
],
contract
=
form
.
cleaned_data
[
'contract'
],
resource
=
form
.
cleaned_data
[
'resource'
],
type
=
form
.
cleaned_data
[
'type'
],
media
=
form
.
cleaned_data
[
'media'
],
temporary
=
form
.
cleaned_data
[
'temporary'
],
contractual
=
form
.
cleaned_data
[
'contractual'
],
contract_excerpt
=
form
.
cleaned_data
[
'contract_excerpt'
],
loophole
=
form
.
cleaned_data
[
'loophole'
]
)
v
.
save
()
c
=
Comment
(
comment
=
form
.
cleaned_data
[
'comment'
],
submitter
=
form
.
cleaned_data
[
'email'
],
timestamp
=
datetime
.
now
(),
violation
=
v
,
)
c
.
save
()
for
f
in
request
.
FILES
.
getlist
(
'attachments[]'
):
a
=
Attachment
(
comment
=
c
)
a
.
storage
.
save
(
f
.
name
,
f
)
a
.
save
()
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
else
:
else
:
form
=
AddViolation
()
# An unbound form
form
=
AddViolation
()
return
render_to_response
(
'add.html'
,
return
render_to_response
(
{
'form'
:
form
,
},
'add.html'
,
context_instance
=
RequestContext
(
request
))
{
'form'
:
form
,
},
context_instance
=
RequestContext
(
request
))
def
ajax
(
request
,
country
=
None
,
operator
=
None
):
def
ajax
(
request
,
country
=
None
,
operator
=
None
):
if
not
operator
:
if
not
operator
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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