Commits

Andres Vargas committed eae0c73

rename the app

  • Participants
  • Parent commits 8d0ac8f

Comments (0)

Files changed (31)

trident/accounts/__init__.py

Empty file removed.

trident/accounts/admin.py

-from django.contrib import admin
-from django.contrib import messages
-from .models import Profile, Database, Dump
-from .forms import FormAdmin, RestoreForm
-from django.conf import settings
-from django.shortcuts import render
-from django.conf.urls import patterns, url
-from .signals import do_restore
-from tempfile import mkstemp
-import os
-
-
-class DumpAdmin(admin.ModelAdmin):
-    list_display = ("__unicode__","created","download")
-    form = FormAdmin
-    readonly_fields = ("file","created")
-
-    def formfield_for_foreignkey(self, db_field, request, **kwargs):
-        if request.user.is_superuser:
-            return super(DumpAdmin,self).formfield_for_foreignkey(db_field, request, **kwargs)
-        if db_field.name =="database":
-            profile = request.user.get_profile()
-            kwargs["queryset"] = Database.objects.filter(profile=profile)
-        return super(DumpAdmin,self).formfield_for_foreignkey(db_field, request, **kwargs)
-
-    def download(self, obj):
-        a = u"%s/%s" %(settings.MEDIA_URL,obj.file)
-        a = u"<a href='%(path)s'>download</a>" % dict(path=str(a))
-        return a
-    download.allow_tags = True
-
-    def get_urls(self):
-        urls = super(DumpAdmin,self).get_urls()
-        my_urls = patterns('',
-            url(r'^restore/$',self.admin_site.admin_view(self.do_restore), name="db-restore")
-        )
-        return  my_urls + urls
-    def do_restore(self,request):
-        f = RestoreForm()
-        if request.POST:
-            f = RestoreForm(request.POST, request.FILES)
-            if f.is_valid():
-                db = f.cleaned_data.get("name")
-                file_ = request.FILES["file"]
-                handle, tmp = mkstemp()
-                with open(tmp,"wb") as f:
-                    f.write(file_.file.getvalue())
-                with open(tmp,"rb") as f:
-                    file_content = f.read()
-                    result = do_restore(db.name,buffer(file_content))
-                f.close()
-                os.close(handle)
-                messages.info(request, result)
-        d = dict(form = f)
-        return render(request,"restore.html",d)
-
-
-
-class DatabaseAdmin(admin.ModelAdmin):
-
-    def formfield_for_foreignkey(self, db_field, request, **kwargs):
-        if request.user.is_superuser:
-            return super(DatabaseAdmin,self).formfield_for_foreignkey(db_field, request, **kwargs)
-        if db_field.name =="profile":
-            profile = request.user.get_profile()
-            kwargs["queryset"] = Profile.objects.filter(id = profile.id)
-        return super(DatabaseAdmin,self).formfield_for_foreignkey(db_field, request, **kwargs)
-
-    def queryset(self, request):
-        qs = super(DatabaseAdmin, self).queryset(request)
-        if not request.user.is_superuser:
-            profile = request.user.get_profile()
-            return qs.filter(profile=profile)
-        else:
-            return qs
-
-admin.site.register(Dump, DumpAdmin)
-admin.site.register(Database, DatabaseAdmin)
-admin.site.register(Profile)

trident/accounts/enums.py

-# encoding=utf8
-
-LANG_CHOICES = (
-     ('bg_BG', 'Български'),
-    ('ca_ES', 'Català'),
-    ('cs_CZ', 'Čeština'),
-('de_DE', 'Deutsch'),
-            ('en_US', 'English'),
-                ('es_ES', 'Español (España)'),
-                ('es_CO', 'Español (Colombia)'),
-                ('fr_FR', 'Français'),
-                ('nl_NL', 'Nederlands'),
-                ('ru_RU', 'Russian'),
-
- )

trident/accounts/forms.py

-from django import forms
-from .models import Dump, Database
-
-
-class RestoreForm(forms.Form):
-    file = forms.FileField()
-    name = forms.ModelChoiceField(queryset=Database.objects.all())
-
-class FormAdmin(forms.ModelForm):
-    class Meta:
-        model = Dump
-        exclude = ("file")

trident/accounts/migrations/0001_initial.py

-# -*- 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 model 'Profile'
-        db.create_table('accounts_profile', (
-            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)),
-        ))
-        db.send_create_signal('accounts', ['Profile'])
-
-        # Adding model 'Database'
-        db.create_table('accounts_database', (
-            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
-            ('password', self.gf('django.db.models.fields.CharField')(max_length=100)),
-            ('profile', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounts.Profile'])),
-        ))
-        db.send_create_signal('accounts', ['Database'])
-
-    def backwards(self, orm):
-        # Deleting model 'Profile'
-        db.delete_table('accounts_profile')
-
-        # Deleting model 'Database'
-        db.delete_table('accounts_database')
-
-    models = {
-        'accounts.database': {
-            'Meta': {'object_name': 'Database'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
-        },
-        'accounts.profile': {
-            'Meta': {'object_name': 'Profile'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
-        },
-        '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'})
-        },
-        '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 = ['accounts']

trident/accounts/migrations/0002_auto__add_field_database_lang.py

-# -*- 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 'Database.lang'
-        db.add_column('accounts_database', 'lang',
-                      self.gf('django.db.models.fields.CharField')(default='en_EU', max_length=4),
-                      keep_default=False)
-
-    def backwards(self, orm):
-        # Deleting field 'Database.lang'
-        db.delete_column('accounts_database', 'lang')
-
-    models = {
-        'accounts.database': {
-            'Meta': {'object_name': 'Database'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'lang': ('django.db.models.fields.CharField', [], {'max_length': '4'}),
-            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
-        },
-        'accounts.profile': {
-            'Meta': {'object_name': 'Profile'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
-        },
-        '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'})
-        },
-        '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 = ['accounts']

trident/accounts/migrations/0003_auto__chg_field_database_lang__add_unique_database_name.py

-# -*- 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):
-
-        # Changing field 'Database.lang'
-        db.alter_column('accounts_database', 'lang', self.gf('django.db.models.fields.CharField')(max_length=6))
-        # Adding unique constraint on 'Database', fields ['name']
-        db.create_unique('accounts_database', ['name'])
-
-    def backwards(self, orm):
-        # Removing unique constraint on 'Database', fields ['name']
-        db.delete_unique('accounts_database', ['name'])
-
-
-        # Changing field 'Database.lang'
-        db.alter_column('accounts_database', 'lang', self.gf('django.db.models.fields.CharField')(max_length=4))
-    models = {
-        'accounts.database': {
-            'Meta': {'object_name': 'Database'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'lang': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
-            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
-            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
-        },
-        'accounts.profile': {
-            'Meta': {'object_name': 'Profile'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
-        },
-        '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'})
-        },
-        '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 = ['accounts']

trident/accounts/migrations/0004_auto__add_dump.py

-# -*- 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 model 'Dump'
-        db.create_table('accounts_dump', (
-            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('file', self.gf('django.db.models.fields.files.FileField')(max_length=100)),
-            ('created', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime(2012, 4, 2, 0, 0))),
-        ))
-        db.send_create_signal('accounts', ['Dump'])
-
-    def backwards(self, orm):
-        # Deleting model 'Dump'
-        db.delete_table('accounts_dump')
-
-    models = {
-        'accounts.database': {
-            'Meta': {'object_name': 'Database'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'lang': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
-            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
-            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
-        },
-        'accounts.dump': {
-            'Meta': {'object_name': 'Dump'},
-            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 4, 2, 0, 0)'}),
-            'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
-        },
-        'accounts.profile': {
-            'Meta': {'object_name': 'Profile'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
-        },
-        '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'})
-        },
-        '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 = ['accounts']

trident/accounts/migrations/0005_auto__add_field_dump_database.py

-# -*- 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 'Dump.database'
-        db.add_column('accounts_dump', 'database',
-                      self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['accounts.Database']),
-                      keep_default=False)
-
-    def backwards(self, orm):
-        # Deleting field 'Dump.database'
-        db.delete_column('accounts_dump', 'database_id')
-
-    models = {
-        'accounts.database': {
-            'Meta': {'object_name': 'Database'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'lang': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
-            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
-            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
-        },
-        'accounts.dump': {
-            'Meta': {'object_name': 'Dump'},
-            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 4, 2, 0, 0)'}),
-            'database': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Database']"}),
-            'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
-        },
-        'accounts.profile': {
-            'Meta': {'object_name': 'Profile'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
-        },
-        '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'})
-        },
-        '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 = ['accounts']

trident/accounts/migrations/__init__.py

Empty file removed.

trident/accounts/models.py

-# encoding=utf8
-from django.db import models
-from django.contrib.auth.models import User
-from .enums import LANG_CHOICES
-from .signals import post_save_database, post_delete_database
-from .signals import post_save_dump
-from django.db.models import signals
-import datetime
-
-class Profile(models.Model):
-    user = models.OneToOneField(User)
-
-    def __unicode__(self):
-        return u"<Profile of %s>" % self.user.username
-
-def file_dir(instance, filename):
-    """ Cambia el nombre del archivo para que no sea descargable """
-    #name =  DIR_FILES_GUIAS +date.strftime("%Y_%m_%d_%s_") + filename.encode("utf-8")
-    import time
-    import hashlib
-    def timestamp():
-        lt = time.localtime(time.time())
-        return "%02d%02d%04d%02d%02d%02d" % (lt[2], lt[1], lt[0], lt[3], lt[4], lt[5])
-
-    return "%s%s.%s" % ("dumps/", hashlib.sha1("%s-%s" % ( timestamp(), instance.pk)).hexdigest(), filename.split('.')[-1])
-
-
-class Dump(models.Model):
-    file = models.FileField(upload_to=file_dir, blank = True, null = True)
-    created = models.DateTimeField(default = datetime.datetime.now())
-    database = models.ForeignKey("Database")
-    
-    def __unicode__(self):
-        return u"<dump of %s>" % self.database.name
-
-signals.post_save.connect(post_save_dump, sender = Dump)
-
-class Database(models.Model):
-    name =  models.CharField(max_length=100, unique = True)
-    password = models.CharField(max_length=100)
-    lang = models.CharField(max_length=6, choices = LANG_CHOICES)
-    profile = models.ForeignKey("Profile")
-
-    def __unicode__(self):
-        return u"<Database %s of %s>" %(self.name, self.profile.user.username)
-
-signals.post_save.connect(post_save_database, sender=Database)
-signals.post_delete.connect(post_delete_database, sender=Database)

trident/accounts/signals.py

-from trident.tasks import create_database, delete_database, dump_database
-from trident.tasks import restore_database
-
-def post_save_database(sender,instance, **kwargs):
-    created = kwargs.get("created")
-    if created:
-       create_database.delay(instance) 
-
-def post_delete_database(sender, **kwargs):
-    instance = kwargs.get("instance")
-    delete_database.delay(instance)
-
-
-def post_save_dump(sender, **kwargs):
-    instance = kwargs.get("instance")
-    created = kwargs.get("created")
-    if created:
-        dump_database.delay(instance)
-
-def do_restore( db_name,files ):
-    return restore_database(db_name, files)    
-    

trident/accounts/templates/restore.html

-{% extends 'admin/change_form.html'%}
-{% block breadcrumbs %}
-{% endblock %}
-{%block content %}
-
-<form method="post" action=""  enctype="multipart/form-data">
-   {% csrf_token %}
-<table>
-  {{form}}
-  <tr>
-    <td colspan="2">
-      <input type="submit" />
-    </td>
-  </tr>
-</table>
-</form>
-{% endblock %}

trident/accounts/tests.py

-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-
-class SimpleTest(TestCase):
-    def test_basic_addition(self):
-        """
-        Tests that 1 + 1 always equals 2.
-        """
-        self.assertEqual(1 + 1, 2)

trident/accounts/views.py

-# Create your views here.

trident/databases/__init__.py

Empty file added.

trident/databases/admin.py

+from django.contrib import admin
+from django.contrib import messages
+from .models import Profile, Database, Dump
+from .forms import FormAdmin, RestoreForm
+from django.conf import settings
+from django.shortcuts import render
+from django.conf.urls import patterns, url
+from .signals import do_restore
+from tempfile import mkstemp
+import os
+
+
+class DumpAdmin(admin.ModelAdmin):
+    list_display = ("__unicode__","created","download")
+    form = FormAdmin
+    readonly_fields = ("file","created")
+
+
+    def download(self, obj):
+        a = u"%s/%s" %(settings.MEDIA_URL,obj.file)
+        a = u"<a href='%(path)s'>download</a>" % dict(path=str(a))
+        return a
+    download.allow_tags = True
+
+    def get_urls(self):
+        urls = super(DumpAdmin,self).get_urls()
+        my_urls = patterns('',
+            url(r'^restore/$',self.admin_site.admin_view(self.do_restore), name="db-restore")
+        )
+        return  my_urls + urls
+    def do_restore(self,request):
+        f = RestoreForm()
+        if request.POST:
+            f = RestoreForm(request.POST, request.FILES)
+            if f.is_valid():
+                db = f.cleaned_data.get("name")
+                file_ = request.FILES["file"]
+                handle, tmp = mkstemp()
+                with open(tmp,"wb") as f:
+                    f.write(file_.file.getvalue())
+                with open(tmp,"rb") as f:
+                    file_content = f.read()
+                    result = do_restore(db.name,buffer(file_content))
+                f.close()
+                os.close(handle)
+                messages.info(request, result)
+        d = dict(form = f)
+        return render(request,"restore.html",d)
+
+
+
+class DatabaseAdmin(admin.ModelAdmin):
+    pass
+
+admin.site.register(Dump, DumpAdmin)
+admin.site.register(Database, DatabaseAdmin)
+admin.site.register(Profile)

trident/databases/enums.py

+# encoding=utf8
+
+LANG_CHOICES = (
+     ('bg_BG', 'Български'),
+    ('ca_ES', 'Català'),
+    ('cs_CZ', 'Čeština'),
+('de_DE', 'Deutsch'),
+            ('en_US', 'English'),
+                ('es_ES', 'Español (España)'),
+                ('es_CO', 'Español (Colombia)'),
+                ('fr_FR', 'Français'),
+                ('nl_NL', 'Nederlands'),
+                ('ru_RU', 'Russian'),
+
+ )

trident/databases/forms.py

+from django import forms
+from .models import Dump, Database
+
+
+class RestoreForm(forms.Form):
+    file = forms.FileField()
+    name = forms.ModelChoiceField(queryset=Database.objects.all())
+
+class FormAdmin(forms.ModelForm):
+    class Meta:
+        model = Dump
+        exclude = ("file")

trident/databases/migrations/0001_initial.py

+# -*- 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 model 'Profile'
+        db.create_table('accounts_profile', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)),
+        ))
+        db.send_create_signal('accounts', ['Profile'])
+
+        # Adding model 'Database'
+        db.create_table('accounts_database', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('password', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('profile', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounts.Profile'])),
+        ))
+        db.send_create_signal('accounts', ['Database'])
+
+    def backwards(self, orm):
+        # Deleting model 'Profile'
+        db.delete_table('accounts_profile')
+
+        # Deleting model 'Database'
+        db.delete_table('accounts_database')
+
+    models = {
+        'accounts.database': {
+            'Meta': {'object_name': 'Database'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
+        },
+        'accounts.profile': {
+            'Meta': {'object_name': 'Profile'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+        },
+        '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'})
+        },
+        '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 = ['accounts']

trident/databases/migrations/0002_auto__add_field_database_lang.py

+# -*- 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 'Database.lang'
+        db.add_column('accounts_database', 'lang',
+                      self.gf('django.db.models.fields.CharField')(default='en_EU', max_length=4),
+                      keep_default=False)
+
+    def backwards(self, orm):
+        # Deleting field 'Database.lang'
+        db.delete_column('accounts_database', 'lang')
+
+    models = {
+        'accounts.database': {
+            'Meta': {'object_name': 'Database'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lang': ('django.db.models.fields.CharField', [], {'max_length': '4'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
+        },
+        'accounts.profile': {
+            'Meta': {'object_name': 'Profile'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+        },
+        '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'})
+        },
+        '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 = ['accounts']

trident/databases/migrations/0003_auto__chg_field_database_lang__add_unique_database_name.py

+# -*- 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):
+
+        # Changing field 'Database.lang'
+        db.alter_column('accounts_database', 'lang', self.gf('django.db.models.fields.CharField')(max_length=6))
+        # Adding unique constraint on 'Database', fields ['name']
+        db.create_unique('accounts_database', ['name'])
+
+    def backwards(self, orm):
+        # Removing unique constraint on 'Database', fields ['name']
+        db.delete_unique('accounts_database', ['name'])
+
+
+        # Changing field 'Database.lang'
+        db.alter_column('accounts_database', 'lang', self.gf('django.db.models.fields.CharField')(max_length=4))
+    models = {
+        'accounts.database': {
+            'Meta': {'object_name': 'Database'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lang': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
+        },
+        'accounts.profile': {
+            'Meta': {'object_name': 'Profile'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+        },
+        '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'})
+        },
+        '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 = ['accounts']

trident/databases/migrations/0004_auto__add_dump.py

+# -*- 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 model 'Dump'
+        db.create_table('accounts_dump', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('file', self.gf('django.db.models.fields.files.FileField')(max_length=100)),
+            ('created', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime(2012, 4, 2, 0, 0))),
+        ))
+        db.send_create_signal('accounts', ['Dump'])
+
+    def backwards(self, orm):
+        # Deleting model 'Dump'
+        db.delete_table('accounts_dump')
+
+    models = {
+        'accounts.database': {
+            'Meta': {'object_name': 'Database'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lang': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
+        },
+        'accounts.dump': {
+            'Meta': {'object_name': 'Dump'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 4, 2, 0, 0)'}),
+            'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        },
+        'accounts.profile': {
+            'Meta': {'object_name': 'Profile'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+        },
+        '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'})
+        },
+        '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 = ['accounts']

trident/databases/migrations/0005_auto__add_field_dump_database.py

+# -*- 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 'Dump.database'
+        db.add_column('accounts_dump', 'database',
+                      self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['accounts.Database']),
+                      keep_default=False)
+
+    def backwards(self, orm):
+        # Deleting field 'Dump.database'
+        db.delete_column('accounts_dump', 'database_id')
+
+    models = {
+        'accounts.database': {
+            'Meta': {'object_name': 'Database'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lang': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Profile']"})
+        },
+        'accounts.dump': {
+            'Meta': {'object_name': 'Dump'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 4, 2, 0, 0)'}),
+            'database': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['accounts.Database']"}),
+            'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        },
+        'accounts.profile': {
+            'Meta': {'object_name': 'Profile'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+        },
+        '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'})
+        },
+        '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 = ['accounts']

trident/databases/migrations/__init__.py

Empty file added.

trident/databases/models.py

+# encoding=utf8
+from django.db import models
+from django.contrib.auth.models import User
+from .enums import LANG_CHOICES
+from .signals import post_save_database, post_delete_database
+from .signals import post_save_dump
+from django.db.models import signals
+import datetime
+
+
+def file_dir(instance, filename):
+    """ Cambia el nombre del archivo para que no sea descargable """
+    #name =  DIR_FILES_GUIAS +date.strftime("%Y_%m_%d_%s_") + filename.encode("utf-8")
+    import time
+    import hashlib
+    def timestamp():
+        lt = time.localtime(time.time())
+        return "%02d%02d%04d%02d%02d%02d" % (lt[2], lt[1], lt[0], lt[3], lt[4], lt[5])
+
+    return "%s%s.%s" % ("dumps/", hashlib.sha1("%s-%s" % ( timestamp(), instance.pk)).hexdigest(), filename.split('.')[-1])
+
+
+class Dump(models.Model):
+    file = models.FileField(upload_to=file_dir, blank = True, null = True)
+    created = models.DateTimeField(default = datetime.datetime.now())
+    database = models.ForeignKey("Database")
+    
+    def __unicode__(self):
+        return u"<dump of %s>" % self.database.name
+
+signals.post_save.connect(post_save_dump, sender = Dump)
+
+class Database(models.Model):
+    name =  models.CharField(max_length=100, unique = True)
+    password = models.CharField(max_length=100)
+    lang = models.CharField(max_length=6, choices = LANG_CHOICES)
+
+    def __unicode__(self):
+        return u"<Database %s of %s>" %(self.name, self.profile.user.username)
+
+signals.post_save.connect(post_save_database, sender=Database)
+signals.post_delete.connect(post_delete_database, sender=Database)

trident/databases/signals.py

+from trident.tasks import create_database, delete_database, dump_database
+from trident.tasks import restore_database
+
+def post_save_database(sender,instance, **kwargs):
+    created = kwargs.get("created")
+    if created:
+       create_database.delay(instance) 
+
+def post_delete_database(sender, **kwargs):
+    instance = kwargs.get("instance")
+    delete_database.delay(instance)
+
+
+def post_save_dump(sender, **kwargs):
+    instance = kwargs.get("instance")
+    created = kwargs.get("created")
+    if created:
+        dump_database.delay(instance)
+
+def do_restore( db_name,files ):
+    return restore_database(db_name, files)    
+    

trident/databases/templates/restore.html

+{% extends 'admin/change_form.html'%}
+{% block breadcrumbs %}
+{% endblock %}
+{%block content %}
+
+<form method="post" action=""  enctype="multipart/form-data">
+   {% csrf_token %}
+<table>
+  {{form}}
+  <tr>
+    <td colspan="2">
+      <input type="submit" />
+    </td>
+  </tr>
+</table>
+</form>
+{% endblock %}

trident/databases/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

trident/databases/views.py

+# Create your views here.

trident/settings.py

     'south',
     'djcelery',
     'djkombu',
-    'trident.accounts',
+    'trident.databases',
     'djcelery',
     'djkombu',
 )