1. Andres Vargas
  2. trident

Commits

Andres Vargas  committed 917c9e3

trying to solve the restore

  • Participants
  • Parent commits 197bcc8
  • Branches default

Comments (0)

Files changed (4)

File trident/__init__.py

View file
  • Ignore whitespace
         self.result = result
 
     def __str__(self):
-        return self.result
+        return "".join(self.result)
 
 class AdminTryton(object):
 
             self._tryton_admin_password)
 
     def restore(self, database_name, data):
+        exist = self.db_exist(database_name)
+        if exist:
+            self.drop_db(database_name)
         return self.__execute("restore", database_name,self._tryton_admin_password,\
             data)
     def __execute(self, method, *args):
 
 
     def __result(self):
-        a = json.loads( jsonrpclib.history.response)
+        a = json.loads(jsonrpclib.history.response)
+        self.response = a
         return a.get("result", a.get("error"))
 
 if __name__ == "__main__":
     try:
         a = AdminTryton("http://localhost:8000", "admin")
         print a.list_database()
+        print a.response
         #print a.drop_db("m1")
         #print a.list_lang()
-        #print a.db_exist("aa1eeeeeeeee")
         #print a.dump_to_string("aa1")
        # a.dump("aa1")
         #print a.create_db("test123","admin","en_EN")

File trident/accounts/admin.py

View file
  • Ignore whitespace
 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
-import base64
 from tempfile import mkstemp
 import os
 
             if f.is_valid():
                 db = f.cleaned_data.get("name")
                 file_ = request.FILES["file"]
-                do_restore(db.name, base64.encodestring(file_.file.getvalue()))
+                handle, tmp = mkstemp()
+                with open(tmp,"wb") as f:
+                    f.write(file_.file.getvalue())
+                with open(tmp,"rb") as f:
+                    file_content = f.read()
+                    do_restore(db.name,file_content)
+                f.close()
+                os.close(handle)
+                messages.info(request, result)
         d = dict(form = f)
         return render(request,"restore.html",d)
 

File trident/accounts/signals.py

View file
  • Ignore whitespace
         dump_database.delay(instance)
 
 def do_restore( db_name,files ):
-    restore_database(db_name, files)    
+    return restore_database(db_name, files)    
     

File trident/tasks.py

View file
  • Ignore whitespace
 @task
 def restore_database(db_name,file):
     t = AdminTryton()
-    try:
-        t.restore(db_name,file)
-    except AdminTrytonException as e:
-        pass
+    t.restore(db_name,file)
 
-