Exemple #1
0
 def add_carto_app(self):
     with apps_orm.session() as session:
         if not CartoApps.app_exists(self.name):
             carto_app = CartoApps(name=self.name,
                                   active=True,
                                   order=self.get_app_order(),
                                   pending=True)
             session.add(carto_app)
             session.commit()
         else:
             carto_app = session.query(CartoApps).filter(
                 CartoApps.name == self.name).update({"pending": True})
             session.commit()
Exemple #2
0
 def reorder(self, request, **kwargs):
     ids_list = request.POST.get("apps", None)
     if ids_list is not None:
         ids_list = ids_list.split(",")
     else:
         ids_list = json.loads(request.body)["apps"]
     for i in range(0, len(ids_list)):
         app = App.objects.get(id=ids_list[i])
         app.order = i + 1
         app.save()
         CartoApps.set_app_order(app.name, app.order)
         if i == (len(ids_list) - 1):
             app.apps_config.save()
     self.log_throttled_access(request)
     return self.create_response(request, {'success': True})
Exemple #3
0
 def execute_pending(self):
     with apps_orm.session() as session:
         pending_apps = session.query(CartoApps).filter(
             CartoApps.pending == True).all()  # noqa
         for app in pending_apps:
             try:
                 if not settings.DEBUG:
                     call_command("collectstatic",
                                  interactive=False,
                                  ignore=['node_modules', '.git'])
                 call_command("migrate", app.name, interactive=False)
                 CartoApps.set_app_pending(app.name, False)
             except CommandError as e:
                 error = e.message
                 logger.error(error)
                 if "you cannot selectively sync unmigrated apps"\
                         not in error:
                     self.delete_application_on_fail(app.name)
Exemple #4
0
def pre_delete_app(sender, instance, using, **kwargs):
    CartoApps.delete_app(instance.name)
Exemple #5
0
 def config(self):
     return CartoApps.get_app_by_name(self.name)
Exemple #6
0
 def set_active(self, active=True):
     # self.config.active = active
     # self.apps_config.save()
     # return App._apps_config
     return CartoApps.set_app_active(self.name, active)
Exemple #7
0
 def _rollback(self):
     CartoApps.delete_app(self.name)
     self.delete_app_dir()