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
piks3l
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 = (
(
'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
):
country
=
models
.
CharField
(
max_length
=
2
,
choices
=
COUNTRIES
)
operator
=
models
.
CharField
(
max_length
=
256
)
contract
=
models
.
CharField
(
max_length
=
256
)
comments
=
models
.
ForeignKey
(
Comment
)
resource
=
models
.
CharField
(
max_length
=
1
,
choices
=
RESOURCES
)
type
=
models
.
CharField
(
max_length
=
1
,
choices
=
TYPES
)
media
=
models
.
CharField
(
max_length
=
1
,
choices
=
MEDIA
)
...
...
@@ -69,3 +59,13 @@ class Violation(models.Model):
contractual
=
models
.
BooleanField
()
contract_excerpt
=
models
.
TextField
()
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
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
from
django.shortcuts
import
render_to_response
from
django.template
import
RequestContext
from
models
import
Violation
import
json
from
django.core.files
import
File
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
):
if
request
.
method
==
'POST'
:
# If the form has been submitted...
form
=
AddViolation
(
request
.
POST
)
# A form bound to the POST data
if
form
.
is_valid
():
# All validation rules pass
# Process the data in form.cleaned_data
# ...
print
'asdf'
,
form
.
cleaned_data
if
request
.
method
==
'POST'
:
form
=
AddViolation
(
request
.
POST
)
if
form
.
is_valid
():
v
=
Violation
(
country
=
form
.
cleaned_data
[
'country'
],
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
else
:
form
=
AddViolation
()
# An unbound form
form
=
AddViolation
()
return
render_to_response
(
'add.html'
,
{
'form'
:
form
,
},
context_instance
=
RequestContext
(
request
))
return
render_to_response
(
'add.html'
,
{
'form'
:
form
,
},
context_instance
=
RequestContext
(
request
))
def
ajax
(
request
,
country
=
None
,
operator
=
None
):
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