Commit 0a0ae097 authored by stef's avatar stef

[enh] storage of reports

parent 2905e87d
......@@ -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)
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment