diff --git a/src/accounts/templates/accounts/user_detail.html b/src/accounts/templates/accounts/user_detail.html
index bd10f05..8c296eb 100644
--- a/src/accounts/templates/accounts/user_detail.html
+++ b/src/accounts/templates/accounts/user_detail.html
@@ -109,7 +109,7 @@
{% for badge in user_.badge_set.all %}
{% translate badge as badge_trans %}
-

+

{% endfor %}
diff --git a/src/badger/admin.py b/src/badger/admin.py
index 0962c81..c0d0b0d 100644
--- a/src/badger/admin.py
+++ b/src/badger/admin.py
@@ -3,6 +3,7 @@
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
+from .forms import BadgeForm
from .models import Badge, BadgeI18N
@@ -11,6 +12,7 @@ class BadgeI18NInline(admin.TabularInline):
class BadgeAdmin(admin.ModelAdmin):
+ form = BadgeForm
inlines = [BadgeI18NInline, ]
list_display = ['title', 'description', 'order']
list_editable = ['order', ]
diff --git a/src/badger/fixtures/badges.json b/src/badger/fixtures/badges.json
deleted file mode 100644
index b700d0b..0000000
--- a/src/badger/fixtures/badges.json
+++ /dev/null
@@ -1,502 +0,0 @@
-[
-{
- "pk": 6,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 10000 Messages",
- "title": "Diamond Messenger",
- "image": "badges/diamond_messenger.png",
- "value": 10000,
- "user_attr": "messages",
- "type": "auto",
- "order": 4
- }
-},
-{
- "pk": 8,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 100 messages",
- "title": "Brass Messenger",
- "image": "badges/brass_messenger.png",
- "value": 100,
- "user_attr": "messages",
- "type": "auto",
- "order": 1
- }
-},
-{
- "pk": 9,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 500 Messages",
- "title": "Silver Messenger",
- "image": "badges/silver_messenger.png",
- "value": 500,
- "user_attr": "messages",
- "type": "auto",
- "order": 2
- }
-},
-{
- "pk": 10,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 1000 Messages",
- "title": "Gold Messenger",
- "image": "badges/gold_messenger.png",
- "value": 1000,
- "user_attr": "messages",
- "type": "auto",
- "order": 3
- }
-},
-{
- "pk": 11,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 10 Tickets",
- "title": "Brass Tracker",
- "image": "badges/brass_tracker.png",
- "value": 10,
- "user_attr": "tickets",
- "type": "auto",
- "order": 5
- }
-},
-{
- "pk": 12,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 50 Tickets",
- "title": "Silver Tracker",
- "image": "badges/silver_tracker.png",
- "value": 50,
- "user_attr": "tickets",
- "type": "auto",
- "order": 6
- }
-},
-{
- "pk": 13,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "Mais que 100 Tickets",
- "title": "Gold Tracker",
- "image": "badges/gold_tracker.png",
- "value": 100,
- "user_attr": "tickets",
- "type": "auto",
- "order": 7
- }
-},
-{
- "pk": 14,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "Mais que 500 Tickets",
- "title": "Diamond Tracker",
- "image": "badges/diamond_tracker.png",
- "value": 500,
- "user_attr": "tickets",
- "type": "auto",
- "order": 8
- }
-},
-{
- "pk": 15,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 100 Changesets",
- "title": "Brass Coder",
- "image": "badges/brass_coder.png",
- "value": 100,
- "user_attr": "revisions",
- "type": "auto",
- "order": 9
- }
-},
-{
- "pk": 16,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 500 Changesets",
- "title": "Silver Coder",
- "image": "badges/silver_coder.png",
- "value": 500,
- "user_attr": "revisions",
- "type": "auto",
- "order": 10
- }
-},
-{
- "pk": 17,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 1000 Changesets",
- "title": "Gold Coder",
- "image": "badges/gold_coder.png",
- "value": 1000,
- "user_attr": "revisions",
- "type": "auto",
- "order": 11
- }
-},
-{
- "pk": 18,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 10000 Changesets",
- "title": "Diamond Coder",
- "image": "badges/diamond_coder.png",
- "value": 10000,
- "user_attr": "revisions",
- "type": "auto",
- "order": 12
- }
-},
-{
- "pk": 19,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 10 Wikis",
- "title": "Brass Writer",
- "image": "badges/brass_writer.png",
- "value": 10,
- "user_attr": "wikis",
- "type": "auto",
- "order": 13
- }
-},
-{
- "pk": 20,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 50 Wikis",
- "title": "Silver Writer",
- "image": "badges/silver_writer.png",
- "value": 50,
- "user_attr": "wikis",
- "type": "auto",
- "order": 14
- }
-},
-{
- "pk": 21,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 100 Wikis",
- "title": "Gold Writer",
- "image": "badges/gold_writer.png",
- "value": 100,
- "user_attr": "wikis",
- "type": "auto",
- "order": 15
- }
-},
-{
- "pk": 22,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 500 Wikis",
- "title": "Diamond Writer",
- "image": "badges/diamond_writer.png",
- "value": 500,
- "user_attr": "wikis",
- "type": "auto",
- "order": 16
- }
-},
-{
- "pk": 23,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 500 Contributions",
- "title": "Brass Contributor",
- "image": "badges/brass_contributor.png",
- "value": 500,
- "user_attr": "contributions",
- "type": "auto",
- "order": 17
- }
-},
-{
- "pk": 24,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 1000 Contributions",
- "title": "Silver Contributor",
- "image": "badges/silver_contributor.png",
- "value": 1000,
- "user_attr": "contributions",
- "type": "auto",
- "order": 18
- }
-},
-{
- "pk": 25,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 3000 Contributions",
- "title": "Gold Contributor",
- "image": "badges/gold_contributor.png",
- "value": 3000,
- "user_attr": "contributions",
- "type": "auto",
- "order": 19
- }
-},
-{
- "pk": 26,
- "model": "badger.badge",
- "fields": {
- "awardees": [],
- "comparison": "gte",
- "description": "More than 5000 Contributions",
- "title": "Diamond Contributor",
- "image": "badges/diamond_contributor.png",
- "value": 5000,
- "user_attr": "contributions",
- "type": "auto",
- "order": 20
- }
-},
-{
- "pk": 1,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 8,
- "description": "Mais que 100 Mensagens",
- "title": "Mensageiro Bronze"
- }
-},
-{
- "pk": 2,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 9,
- "description": "Mais que 500 Mensagens",
- "title": "Mensageiro Prata"
- }
-},
-{
- "pk": 3,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 6,
- "description": "Mais que 10000 Mensagens",
- "title": "Mensageiro Diamante"
- }
-},
-{
- "pk": 4,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 10,
- "description": "Mais que 1000 Mensagens",
- "title": "Mensageiro Ouro"
- }
-},
-{
- "pk": 5,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 11,
- "description": "Mais que 10 T\u00edquetes",
- "title": "Rastreador Bronze"
- }
-},
-{
- "pk": 6,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 12,
- "description": "Mais que 50 T\u00edquetes",
- "title": "Rastreador Prata"
- }
-},
-{
- "pk": 7,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 13,
- "description": "Mais que 100 T\u00edquetes",
- "title": "Rastreador Ouro"
- }
-},
-{
- "pk": 8,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 14,
- "description": "Mais que 500 T\u00edquetes",
- "title": "Rastreador Diamante"
- }
-},
-{
- "pk": 9,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 15,
- "description": "Mais que 100 Modifica\u00e7\u00f5es de c\u00f3digo",
- "title": "Programador Bronze"
- }
-},
-{
- "pk": 10,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 16,
- "description": "Mais que 500 Modifica\u00e7\u00f5es de c\u00f3digo",
- "title": "Programador Prata"
- }
-},
-{
- "pk": 11,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 17,
- "description": "Mais que 1000 Modifica\u00e7\u00f5es de c\u00f3digo",
- "title": "Programador Ouro"
- }
-},
-{
- "pk": 12,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 18,
- "description": "Mais que 10000 Modifica\u00e7\u00f5es de c\u00f3digo",
- "title": "Programador Diamante"
- }
-},
-{
- "pk": 13,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 19,
- "description": "Escreveu mais que 10 Wikis",
- "title": "Escritor Bronze"
- }
-},
-{
- "pk": 14,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 20,
- "description": "Escreveu mais que 50 Wikis",
- "title": "Escritor Prata"
- }
-},
-{
- "pk": 15,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 21,
- "description": "Escreveu mais que 100 Wikis",
- "title": "Escritor Ouro"
- }
-},
-{
- "pk": 16,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 22,
- "description": "Escreveu mais que 500 Wikis",
- "title": "Escritor Diamante"
- }
-},
-{
- "pk": 17,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 23,
- "description": "Mais que 500 Contribui\u00e7\u00f5es",
- "title": "Contribuidor Bronze"
- }
-},
-{
- "pk": 18,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 24,
- "description": "Mais que 1000 Contribui\u00e7\u00f5es",
- "title": "Contribuidor Prata"
- }
-},
-{
- "pk": 19,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 25,
- "description": "Mais que 3000 Contribui\u00e7\u00f5es",
- "title": "Contribuidor Ouro"
- }
-},
-{
- "pk": 20,
- "model": "badger.badgei18n",
- "fields": {
- "i18n_language": "pt-br",
- "i18n_source": 26,
- "description": "Mais que 5000 Contribui\u00e7\u00f5es",
- "title": "Contribuidor Diamante"
- }
-}
-]
diff --git a/src/badger/fixtures/images/brass_coder.png b/src/badger/fixtures/images/brass_coder.png
deleted file mode 100644
index aeafd3f..0000000
Binary files a/src/badger/fixtures/images/brass_coder.png and /dev/null differ
diff --git a/src/badger/fixtures/images/brass_contributor.png b/src/badger/fixtures/images/brass_contributor.png
deleted file mode 100644
index ab903c7..0000000
Binary files a/src/badger/fixtures/images/brass_contributor.png and /dev/null differ
diff --git a/src/badger/fixtures/images/brass_messenger.png b/src/badger/fixtures/images/brass_messenger.png
deleted file mode 100644
index 5f814db..0000000
Binary files a/src/badger/fixtures/images/brass_messenger.png and /dev/null differ
diff --git a/src/badger/fixtures/images/brass_tracker.png b/src/badger/fixtures/images/brass_tracker.png
deleted file mode 100644
index 5e364cc..0000000
Binary files a/src/badger/fixtures/images/brass_tracker.png and /dev/null differ
diff --git a/src/badger/fixtures/images/brass_writer.png b/src/badger/fixtures/images/brass_writer.png
deleted file mode 100644
index 75ddb0f..0000000
Binary files a/src/badger/fixtures/images/brass_writer.png and /dev/null differ
diff --git a/src/badger/fixtures/images/diamond_coder.png b/src/badger/fixtures/images/diamond_coder.png
deleted file mode 100644
index 2a3240a..0000000
Binary files a/src/badger/fixtures/images/diamond_coder.png and /dev/null differ
diff --git a/src/badger/fixtures/images/diamond_contributor.png b/src/badger/fixtures/images/diamond_contributor.png
deleted file mode 100644
index 253823f..0000000
Binary files a/src/badger/fixtures/images/diamond_contributor.png and /dev/null differ
diff --git a/src/badger/fixtures/images/diamond_messenger.png b/src/badger/fixtures/images/diamond_messenger.png
deleted file mode 100644
index 361609e..0000000
Binary files a/src/badger/fixtures/images/diamond_messenger.png and /dev/null differ
diff --git a/src/badger/fixtures/images/diamond_tracker.png b/src/badger/fixtures/images/diamond_tracker.png
deleted file mode 100644
index 3a8f8f1..0000000
Binary files a/src/badger/fixtures/images/diamond_tracker.png and /dev/null differ
diff --git a/src/badger/fixtures/images/diamond_writer.png b/src/badger/fixtures/images/diamond_writer.png
deleted file mode 100644
index 55755d5..0000000
Binary files a/src/badger/fixtures/images/diamond_writer.png and /dev/null differ
diff --git a/src/badger/fixtures/images/gold_coder.png b/src/badger/fixtures/images/gold_coder.png
deleted file mode 100644
index 6cfaa38..0000000
Binary files a/src/badger/fixtures/images/gold_coder.png and /dev/null differ
diff --git a/src/badger/fixtures/images/gold_contributor.png b/src/badger/fixtures/images/gold_contributor.png
deleted file mode 100644
index 6f4f70e..0000000
Binary files a/src/badger/fixtures/images/gold_contributor.png and /dev/null differ
diff --git a/src/badger/fixtures/images/gold_messenger.png b/src/badger/fixtures/images/gold_messenger.png
deleted file mode 100644
index 7680171..0000000
Binary files a/src/badger/fixtures/images/gold_messenger.png and /dev/null differ
diff --git a/src/badger/fixtures/images/gold_tracker.png b/src/badger/fixtures/images/gold_tracker.png
deleted file mode 100644
index 91c6ab3..0000000
Binary files a/src/badger/fixtures/images/gold_tracker.png and /dev/null differ
diff --git a/src/badger/fixtures/images/gold_writer.png b/src/badger/fixtures/images/gold_writer.png
deleted file mode 100644
index e4c4e41..0000000
Binary files a/src/badger/fixtures/images/gold_writer.png and /dev/null differ
diff --git a/src/badger/fixtures/images/silver_coder.png b/src/badger/fixtures/images/silver_coder.png
deleted file mode 100644
index c705375..0000000
Binary files a/src/badger/fixtures/images/silver_coder.png and /dev/null differ
diff --git a/src/badger/fixtures/images/silver_contributor.png b/src/badger/fixtures/images/silver_contributor.png
deleted file mode 100644
index 07945e1..0000000
Binary files a/src/badger/fixtures/images/silver_contributor.png and /dev/null differ
diff --git a/src/badger/fixtures/images/silver_messenger.png b/src/badger/fixtures/images/silver_messenger.png
deleted file mode 100644
index 94786c3..0000000
Binary files a/src/badger/fixtures/images/silver_messenger.png and /dev/null differ
diff --git a/src/badger/fixtures/images/silver_tracker.png b/src/badger/fixtures/images/silver_tracker.png
deleted file mode 100644
index 7ec01e7..0000000
Binary files a/src/badger/fixtures/images/silver_tracker.png and /dev/null differ
diff --git a/src/badger/fixtures/images/silver_writer.png b/src/badger/fixtures/images/silver_writer.png
deleted file mode 100644
index 83992ca..0000000
Binary files a/src/badger/fixtures/images/silver_writer.png and /dev/null differ
diff --git a/src/badger/forms.py b/src/badger/forms.py
new file mode 100644
index 0000000..582f303
--- /dev/null
+++ b/src/badger/forms.py
@@ -0,0 +1,36 @@
+import base64
+import StringIO
+
+from django import forms
+from django.utils.translation import ugettext_lazy as _
+
+from PIL import Image
+
+from .models import Badge
+
+
+class BadgeForm(forms.ModelForm):
+ image = forms.ImageField(label=_(u'Image'))
+
+ class Meta:
+ model = Badge
+ fields = (
+ 'title', 'description', 'image', 'user_attr', 'comparison',
+ 'value', 'awardees'
+ )
+
+ def save(self, commit=True):
+
+ instance = super(BadgeForm, self).save(commit=False)
+
+ img = Image.open(self.cleaned_data['image'])
+ img = img.resize((50, 50), Image.ANTIALIAS)
+ f = StringIO.StringIO()
+ img.save(f, 'png')
+ instance.image_base64 = f.getvalue().encode('base64')
+ f.close()
+
+ if commit:
+ instance.save()
+
+ return instance
diff --git a/src/badger/migrations/0005_auto__add_field_badge_image_base64.py b/src/badger/migrations/0005_auto__add_field_badge_image_base64.py
new file mode 100644
index 0000000..19eba57
--- /dev/null
+++ b/src/badger/migrations/0005_auto__add_field_badge_image_base64.py
@@ -0,0 +1,91 @@
+# -*- coding: 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 'Badge.image_base64'
+ db.add_column(u'badger_badge', 'image_base64',
+ self.gf('django.db.models.fields.TextField')(default=''),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'Badge.image_base64'
+ db.delete_column(u'badger_badge', 'image_base64')
+
+
+ models = {
+ u'accounts.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75', 'blank': 'True'}),
+ 'facebook': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'google_talk': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'institution': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': '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'}),
+ 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'role': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'twitter': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
+ 'verification_hash': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'webpage': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
+ },
+ u'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ u'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': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ u'auth.permission': {
+ 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'badger.badge': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'Badge'},
+ 'awardees': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['accounts.User']", 'null': 'True', 'blank': 'True'}),
+ 'comparison': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
+ 'image_base64': ('django.db.models.fields.TextField', [], {}),
+ 'order': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '100'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'user_attr': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'value': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'})
+ },
+ u'badger.badgei18n': {
+ 'Meta': {'unique_together': "(('i18n_source', 'i18n_language'),)", 'object_name': 'BadgeI18N'},
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'i18n_language': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
+ 'i18n_source': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'to': u"orm['badger.Badge']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
+ },
+ u'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'}),
+ u'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 = ['badger']
\ No newline at end of file
diff --git a/src/badger/migrations/0006_imgpath_to_base64_field.py b/src/badger/migrations/0006_imgpath_to_base64_field.py
new file mode 100644
index 0000000..b1884ac
--- /dev/null
+++ b/src/badger/migrations/0006_imgpath_to_base64_field.py
@@ -0,0 +1,94 @@
+# -*- coding: utf-8 -*-
+import base64
+import os
+
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+from django.conf import settings
+
+class Migration(DataMigration):
+
+ def forwards(self, orm):
+ for obj in orm.Badge.objects.all():
+ img = open(os.path.join(settings.MEDIA_ROOT, obj.image.path))
+ obj.image_base64 = base64.b64encode(img.read())
+ obj.save()
+
+ def backwards(self, orm):
+ for obj in orm.Badge.objects.all():
+ obj.image_base64 = ''
+ obj.save()
+
+ models = {
+ u'accounts.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75', 'blank': 'True'}),
+ 'facebook': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'google_talk': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'institution': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': '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'}),
+ 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'role': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'twitter': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
+ 'verification_hash': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'webpage': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
+ },
+ u'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ u'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': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ u'auth.permission': {
+ 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'badger.badge': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'Badge'},
+ 'awardees': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['accounts.User']", 'null': 'True', 'blank': 'True'}),
+ 'comparison': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
+ 'image_base64': ('django.db.models.fields.TextField', [], {}),
+ 'order': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '100'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'user_attr': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'value': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'})
+ },
+ u'badger.badgei18n': {
+ 'Meta': {'unique_together': "(('i18n_source', 'i18n_language'),)", 'object_name': 'BadgeI18N'},
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'i18n_language': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
+ 'i18n_source': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'to': u"orm['badger.Badge']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
+ },
+ u'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'}),
+ u'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 = ['badger']
+ symmetrical = True
diff --git a/src/badger/migrations/0007_auto__del_field_badge_image.py b/src/badger/migrations/0007_auto__del_field_badge_image.py
new file mode 100644
index 0000000..963a336
--- /dev/null
+++ b/src/badger/migrations/0007_auto__del_field_badge_image.py
@@ -0,0 +1,90 @@
+# -*- coding: 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):
+ # Deleting field 'Badge.image'
+ db.delete_column(u'badger_badge', 'image')
+
+
+ def backwards(self, orm):
+ # Adding field 'Badge.image'
+ db.add_column(u'badger_badge', 'image',
+ self.gf('django.db.models.fields.files.ImageField')(default='', max_length=100),
+ keep_default=False)
+
+
+ models = {
+ u'accounts.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75', 'blank': 'True'}),
+ 'facebook': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'google_talk': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'institution': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': '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'}),
+ 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'role': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'twitter': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
+ 'verification_hash': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'webpage': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
+ },
+ u'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ u'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': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ u'auth.permission': {
+ 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'badger.badge': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'Badge'},
+ 'awardees': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['accounts.User']", 'null': 'True', 'blank': 'True'}),
+ 'comparison': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image_base64': ('django.db.models.fields.TextField', [], {}),
+ 'order': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '100'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'user_attr': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'value': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'})
+ },
+ u'badger.badgei18n': {
+ 'Meta': {'unique_together': "(('i18n_source', 'i18n_language'),)", 'object_name': 'BadgeI18N'},
+ 'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'i18n_language': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
+ 'i18n_source': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'to': u"orm['badger.Badge']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
+ },
+ u'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'}),
+ u'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 = ['badger']
\ No newline at end of file
diff --git a/src/badger/models.py b/src/badger/models.py
index 6f51a6a..721bdd2 100644
--- a/src/badger/models.py
+++ b/src/badger/models.py
@@ -4,7 +4,6 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.utils.translation import ugettext_lazy as _
-from PIL import Image
from i18n_model.models import I18nModel
@@ -38,7 +37,7 @@ class Badge(models.Model):
null=True)
description = models.CharField(_(u'Description'), max_length=200,
blank=True, null=True)
- image = models.ImageField(upload_to='badges')
+ image_base64 = models.TextField(_(u'Image'))
type = models.CharField(_(u'Type'), max_length=200, choices=TYPE_CHOICES)
user_attr = models.CharField(
_(u'User attribute'),max_length=100,
@@ -71,16 +70,6 @@ class Badge(models.Model):
verbose_name_plural = _(u'Badges')
ordering = ['order', ]
- def get_badge_url(self):
- return u'{}{}'.format(settings.MEDIA_URL, self.image)
-
- def save(self, *args, **kwargs):
- img = Image.open(self.image)
- (width, height) = img.size
- img = img.resize((50, 50), Image.ANTIALIAS)
- super(Badge, self).save(*args, **kwargs)
- img.save(self.image.path)
-
def __unicode__(self):
return u'{} ({}, {})'.format(
self.title,
--
libgit2 0.21.2