Skip to content
Browse files

final triage of downstream workflow to download the zip content

  • Loading branch information...
1 parent 0028a33 commit 0fa81ea7bdf4e353a4707f78182c7c5033b8ded0 @kausikram kausikram committed Aug 1, 2011
View
81 make_my_badge/badge/migrations/0003_event_file_field.py
@@ -0,0 +1,81 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'Event.zipped_content'
+ db.add_column('badge_event', 'zipped_content', self.gf('django.db.models.fields.files.FileField')(max_length=100, null=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Event.zipped_content'
+ db.delete_column('badge_event', 'zipped_content')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'badge.badgetemplate': {
+ 'Meta': {'object_name': 'BadgeTemplate'},
+ 'event': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['badge.Event']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'template_image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'})
+ },
+ 'badge.event': {
+ 'Meta': {'object_name': 'Event'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'zipped_content': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
+ },
+ 'badge.item': {
+ 'Meta': {'object_name': 'Item'},
+ 'event': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['badge.Event']", 'null': 'True'}),
+ 'generated_image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'properties': ('django.db.models.fields.TextField', [], {})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ }
+ }
+
+ complete_apps = ['badge']
View
1 make_my_badge/badge/models.py
@@ -5,6 +5,7 @@
class Event(models.Model):
name = models.CharField(max_length=128)
user = models.ForeignKey(User)
+ zipped_content = models.FileField(null=True,blank=True,upload_to="zipped_content")
def __unicode__(self):
return "Event: " + self.name
View
16 make_my_badge/badge/tasks.py
@@ -1,4 +1,6 @@
+import os
import StringIO
+import zipfile
from django.core.files.uploadedfile import InMemoryUploadedFile
@@ -18,4 +20,16 @@ def generate_badge(item):
badge_img.img.save(badge_io,"png")
badge_file = InMemoryUploadedFile(badge_io, None, 'temp_file.png', 'image/png',badge_io.len, None)
item.generated_image.save("badge_image_%d.png"%(item.id,),badge_file)
- item.save()
+ item.save()
+
+@task()
+def zip_file(event):
+ item_list = event.item_set.all()
+ zipped_io = StringIO.StringIO()
+ zip_obj = zipfile.ZipFile(zipped_io,mode="w")
+ for item in item_list:
+ zip_obj.write(item.generated_image.path, os.path.basename(item.generated_image.path))
+ zip_obj.close()
+ zipped_file = InMemoryUploadedFile(zipped_io, None, 'event_%d.zip'%(event.id,), 'application/x-zip-compressed',zipped_io.len, None)
+ event.zipped_content.save('event_%d.zip'%(event.id,),zipped_file)
+ event.save()
View
23 make_my_badge/badge/templates/item_list.html
@@ -6,6 +6,24 @@
{% block script %}
<script type="text/javascript">
+ function wait_for_zip_complete(){
+ jQuery.ajax({
+ type:"GET",
+ dataType:"json",
+ url:"/badge/event/{{item_list.0.event.id}}/is_zip_ready/",
+ success:function(data){
+ if(data["status"]["ready"]){
+ jQuery(".complete").toggle();
+ jQuery(".loading_2").toggle();
+ } else {
+ setTimeout(function(){
+ wait_for_zip_complete()
+ },2000);
+ }
+ }
+ });
+ }
+
function wait_for_badge_complete(){
jQuery.ajax({
type:"GET",
@@ -15,6 +33,7 @@
if(data["status"]["ready"]){
jQuery(".loading_1").toggle();
jQuery(".loading_2").toggle();
+ wait_for_zip_complete();
} else {
setTimeout(function(){
wait_for_badge_complete()
@@ -50,7 +69,7 @@
</script>
{% endblock %}
-{% block content %}
+{% block content %}
<ul>
{% for item in item_list %}
<li>{{item.name}} {% if item.generated_image %}<a href="{{ item.generated_image.url }}">Badge</a>{% else %}(Not yet generated){% endif %}</li>
@@ -60,7 +79,7 @@
<div class="complete success">
<img src="/static/images/loading.gif" />
<br />
- <span>Success!!</span>
+ <span>Success!! you can download the zip <a href="/uploads/zipped_content/event_{{item_list.0.event.id}}.zip">Here</a></span>
</div>
<div class="loading_2 notice">
<img src="/static/images/loading.gif" />
View
1 make_my_badge/badge/urls.py
@@ -5,4 +5,5 @@
url(r'^event/(?P<event_id>\d+)/$','make_my_badge.badge.views.item_list', name="item_list"),
url(r'^event/(?P<event_id>\d+)/generate/$','make_my_badge.badge.views.generate_badges', name="generate_badges"),
url(r'^event/(?P<event_id>\d+)/are_badges_ready/$','make_my_badge.badge.views.are_badges_ready', name="are-badges-ready"),
+ url(r'^event/(?P<event_id>\d+)/is_zip_ready/$','make_my_badge.badge.views.is_zip_ready', name="is-zip-ready"),
)
View
17 make_my_badge/badge/views.py
@@ -1,11 +1,12 @@
import simplejson
+import zipfile
from django.template.response import TemplateResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.generic.list_detail import object_list
from django.http import HttpResponse
from badge.models import Item, Event
-from badge.tasks import generate_badge
+from badge.tasks import generate_badge, zip_file
def event_list(request):
event_list = Event.objects.filter(user=request.user)
@@ -33,7 +34,8 @@ def are_badges_ready(request,event_id):
ready = True
if item_count > 0:
ready = False
-
+ if ready:
+ zip_file.delay(e)
response_obj = {"status":{"ready":ready}}
r = HttpResponse()
r.content = simplejson.dumps(response_obj)
@@ -42,3 +44,14 @@ def are_badges_ready(request,event_id):
return r
+def is_zip_ready(request, event_id):
+ e = Event.objects.get(id=int(event_id))
+ ready = False
+ if e.zipped_content:
+ ready = True
+ response_obj = {"status":{"ready":ready}}
+ r = HttpResponse()
+ r.content = simplejson.dumps(response_obj)
+ r["Content-Type"] = "application/json"
+ r.status_code = 200
+ return r

0 comments on commit 0fa81ea

Please sign in to comment.
Something went wrong with that request. Please try again.