Commits

Andres Vargas  committed 5fecf14

update proyecto to get dump ready

  • Participants
  • Parent commits a2ccc3a

Comments (0)

Files changed (6)

File trident/__init__.py

             return self.__execute("drop", database_name, self._tryton_admin_password)
 
     def db_exist(self, db_name):
-        return self.__execute(method="db_exist")
+        return self.__execute("db_exist", db_name, self._tryton_admin_password)
 
     def list_lang(self):
         return self.__execute(method="list_lang")
             self._tryton_admin_password)
 
     def restore(self, database_name, data):
-        exist = self.db_exist(database_name)
-        if exist:
-            try:
-                self.drop_db(database_name)
-            except:
-                pass
         return self.__execute("restore", database_name,self._tryton_admin_password,\
-            data, False)
+            data, True)
 
     def __execute(self, method, *args):
         server_exec = getattr(self._server.common.db, method)
     try:
         a = AdminTryton("http://localhost:8000", "admin")
         res = a.list_database()
-        if "test123" in res:
-            print a.drop_db("test123")
-        print a.create_db("test123","admin","en_EN")
-        print a.list_lang()
-        print a.dump_to_dict("test123")
-        a.dump("test123")
-        print a.drop_db("test123")
+        print res
+        print ('test123',a.db_exist("test123"))
+        print ('test123123123',a.db_exist("test123123123"))
+       # if "test123" in res:
+       #     print a.drop_db("test123")
+       # print a.create_db("test123","admin","en_EN")
+       # print a.list_lang()
+        #print a.dump_to_dict("test123")
+       # a.dump("test123")
+        #print a.drop_db("test123")
     except AdminTrytonException as e:
         print e

File trident/databases/admin.py

 from django.conf.urls import patterns, url
 from .signals import do_restore
 from tempfile import mkstemp
-import os
 
 
 class DumpAdmin(admin.ModelAdmin):
         )
         return  my_urls + urls
     def do_restore(self,request):
-        f = RestoreForm()
+        fo = RestoreForm()
         if request.POST:
-            f = RestoreForm(request.POST, request.FILES)
-            if f.is_valid():
-                db = f.cleaned_data.get("name")
+            fo = RestoreForm(request.POST, request.FILES)
+            if fo.is_valid():
+                db = fo.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)
+                    content = f.read().encode("base64")
+                    do_restore(db.name,content)
+        d = dict(form = fo)
         return render(request,"restore.html",d)
 
 
 
 class DatabaseAdmin(admin.ModelAdmin):
-    pass
+    list_display = ("__unicode__", "created")
 
 admin.site.register(Dump, DumpAdmin)
 admin.site.register(Database, DatabaseAdmin)

File trident/databases/models.py

 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)
+    lang = models.CharField(max_length=6, choices = LANG_CHOICES, default ="en_US")
     created = models.BooleanField(default = False)
 
     def __unicode__(self):

File trident/databases/signals.py

         dump_database.delay(instance)
 
 def do_restore( db_name,files ):
-    return restore_database(db_name, files)    
-    
+    restore_database.delay(db_name, files)

File trident/jsonrpc.py

 class Fault(xmlrpclib.Fault):
 
     def __init__(self, faultCode, faultString='', **extra):
+        print faultCode
         super(Fault, self).__init__(faultCode, faultString, **extra)
         self.args = faultString
 
             raise ResponseError('Invalid response id (%s) excpected %s' %
                 (response['id'], id_))
         if response.get('error'):
-            raise Fault(*response['error'])
+            error = "".join(response['error'])
+            raise Fault(error)
         return response['result']
 
     def close(self):

File trident/tasks.py

 @task
 def restore_database(db_name,file):
     t = AdminTryton()
-    return t.restore(db_name,file)
+    file = file.decode("base64")
+    success =  t.restore(db_name,buffer(file))
+    return success