Skip to content

Commit

Permalink
Add attached files to report. Fix mozillahispano#26
Browse files Browse the repository at this point in the history
  • Loading branch information
bbotella committed Nov 9, 2013
1 parent 618d588 commit 73ff61e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mozbuzz/buzz/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Meta:
fields = ('link', 'origin', 'source_name', 'text', 'type', 'feedback', 'country',
'author_expertise', 'previous_product_comments', 'product',
'estimated_audience', 'relevant_audience', 'update_rate',
'remarks')
'remarks', 'file1', 'file2', 'file3')
widgets = {
"source_name": TextInput
}
Expand Down
3 changes: 3 additions & 0 deletions mozbuzz/buzz/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def forwards(self, orm):
('relevant_audience', self.gf('django.db.models.fields.BooleanField')(default=False)),
('update_rate', self.gf('django.db.models.fields.IntegerField')(max_length=1)),
('remarks', self.gf('django.db.models.fields.TextField')()),
('file1', self.gf('django.db.models.fields.TextField')()),
('file2', self.gf('django.db.models.fields.TextField')()),
('file3', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal('buzz', ['Mention'])

Expand Down
3 changes: 3 additions & 0 deletions mozbuzz/buzz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class Mention(SoftDeletableModel):
relevant_audience = models.BooleanField()
update_rate = models.IntegerField(max_length=1, choices=UPDATE_RATE)
remarks = models.TextField(null=True, blank=True)
file1 = models.FileField(upload_to='report_files/', blank=True, null=True)
file2 = models.FileField(upload_to='report_files/', blank=True, null=True)
file3 = models.FileField(upload_to='report_files/', blank=True, null=True)

def __unicode__(self):
return "%s @ %s" %(self.type, self.source_name)
Expand Down
2 changes: 1 addition & 1 deletion mozbuzz/buzz/templates/buzz/mention.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}{% load i18n query %}

{% block main_content %}
<form method="post"
<form method="post" enctype="multipart/form-data",
{% if pk %}
action="{% url "edit" pk %}"
{% else %}
Expand Down
18 changes: 18 additions & 0 deletions mozbuzz/buzz/templates/buzz/mention_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@
<span>{%trans "Relevant audience"%}</span>
</li>
{% endif %}
{% if mention.file1 != None %}
<li>
<span>{%trans "File 1"%}</span>
<a href="../media/{{ mention.file1 }}">{{ mention.file1 }}</a>
</li>
{% endif %}
{% if mention.file2 != '' %}
<li>
<span>{%trans "File 2"%}</span>
<a href="../media/{{ mention.file2 }}">{{ mention.file2 }}</a>
</li>
{% endif %}
{% if mention.file3 != None %}
<li>
<span>{%trans "File 3"%}</span>
<a href="../media/{{ mention.file3 }}">{{ mention.file3 }}</a>
</li>
{% endif %}
</ul>
<div style="display:none" class="followups">
{% for followup in mention.followups %}
Expand Down
15 changes: 13 additions & 2 deletions mozbuzz/buzz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def about(request):
pass #TODO



def handle_uploaded_file(f):
with open(str(f), 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)

@login_required
@mozview
def mention(request, pk=None):
Expand All @@ -45,12 +51,17 @@ def mention(request, pk=None):
instance = Mention(creation_user=request.user)
else:
instance = Mention.enabled.get(pk=pk)
form = MentionForm(request.POST, instance=instance)
form = MentionForm(request.POST, request.FILES, instance=instance)
if form.is_valid():
instance = form.save(commit=False)
instance.last_update_user = request.user
if 'file1' in request.FILES:
instance.file1.save(request.FILES['file1'].name, request.FILES['file1'])
if 'file2' in request.FILES:
instance.file2.save(request.FILES['file2'].name, request.FILES['file2'])
if 'file3' in request.FILES:
instance.file3.save(request.FILES['file3'].name, request.FILES['file3'])
instance.save()

if "rsspost_hide" in request.POST:
RSSPost.objects.filter(pk=int(request.POST["rsspost_hide"])).delete()

Expand Down

0 comments on commit 73ff61e

Please sign in to comment.