예제 #1
0
    def save(self, request, file_relative_path, ROOT_DIR=THEME_ROOT):
        content = self.cleaned_data["content"]
        file_path = (os.path.join(ROOT_DIR,
                                  file_relative_path)).replace("\\", "/")
        if os.path.isfile(file_path) and content <> "":
            archive_file(request, file_relative_path, ROOT_DIR=ROOT_DIR)
            f = codecs.open(file_path, 'w', 'utf-8', 'replace')
            file = File(f)
            file.write(content)
            file.close()

            # copy to s3 storage
            if os.path.splitext(file_path)[1] == '.html':
                public = False
            else:
                public = True
            save_file_to_s3(file_path, public=public)

            if hasattr(settings,
                       'REMOTE_DEPLOY_URL') and settings.REMOTE_DEPLOY_URL:
                urllib.urlopen(settings.REMOTE_DEPLOY_URL)

            return True
        else:
            return False
예제 #2
0
파일: forms.py 프로젝트: kgayle/tendenci
    def save(self,
             request,
             file_relative_path,
             ROOT_DIR=THEME_ROOT,
             ORIG_ROOT_DIR=THEME_ROOT):
        content = self.cleaned_data["content"]
        file_path = (os.path.join(ROOT_DIR,
                                  file_relative_path)).replace("\\", "/")

        if settings.USE_S3_THEME:
            file_path = (os.path.join(ORIG_ROOT_DIR,
                                      file_relative_path)).replace("\\", "/")

        # write the theme file locally in case it was wiped by a restart
        if settings.USE_S3_THEME and not os.path.isfile(file_path):
            file_dir = os.path.dirname(file_path)
            if not os.path.isdir(file_dir):
                # if directory does not exist, create it
                os.makedirs(file_dir)
            new_file = open(file_path, 'w')
            new_file.write('')
            new_file.close()

        if os.path.isfile(file_path) and content != "":
            archive_file(request, file_relative_path, ROOT_DIR=ORIG_ROOT_DIR)

            # Save the file locally no matter the theme location.
            # The save to S3 reads from the local file, so we need to save it first.
            f = codecs.open(file_path, 'w', 'utf-8', 'replace')
            file = File(f)
            file.write(content)
            file.close()

            if settings.USE_S3_THEME:
                # copy to s3 storage
                if os.path.splitext(file_path)[1] == '.html':
                    public = False
                else:
                    public = True
                save_file_to_s3(file_path, public=public)

                cache_key = ".".join([
                    settings.SITE_CACHE_KEY, 'theme',
                    "%s/%s" % (get_theme(), file_relative_path)
                ])
                cache.delete(cache_key)

                if hasattr(settings,
                           'REMOTE_DEPLOY_URL') and settings.REMOTE_DEPLOY_URL:
                    urllib.urlopen(settings.REMOTE_DEPLOY_URL)

            return True
        else:
            return False
예제 #3
0
    def save(self, root_dir, theme, file_relative_path, request):
        content = self.cleaned_data["content"]
        file_path = os.path.join(root_dir, file_relative_path)

        # write the theme file locally in case it was wiped by a restart
        if settings.USE_S3_THEME and not os.path.isfile(file_path):
            file_dir = os.path.dirname(file_path)
            if not os.path.isdir(file_dir):
                # if directory does not exist, create it
                os.makedirs(file_dir)
            new_file = open(file_path, 'w')
            new_file.write('')
            new_file.close()

        if os.path.isfile(file_path) and content != '':
            archive_file(root_dir, file_relative_path, request)

            # Save the file locally no matter the theme location.
            # The save to S3 reads from the local file, so we need to save it first.
            f = codecs.open(file_path, 'w', 'utf-8', 'replace')
            file = File(f)
            file.write(content)
            file.close()

            if settings.USE_S3_THEME:
                # copy to s3 storage
                if os.path.splitext(file_relative_path)[1] == '.html':
                    public = False
                else:
                    public = True
                dest_path = os.path.join(theme, file_relative_path)
                dest_full_path = os.path.join(settings.THEME_S3_PATH,
                                              dest_path)
                save_file_to_s3(file_path,
                                dest_path=dest_full_path,
                                public=public)

                cache_key = '.'.join(
                    [settings.SITE_CACHE_KEY, 'theme', dest_path])
                cache.delete(cache_key)

                if hasattr(settings,
                           'REMOTE_DEPLOY_URL') and settings.REMOTE_DEPLOY_URL:
                    urlopen(settings.REMOTE_DEPLOY_URL)

            return True
        else:
            return False
예제 #4
0
    def save(self, request, file_relative_path, ROOT_DIR=THEME_ROOT, ORIG_ROOT_DIR=THEME_ROOT):
        content = self.cleaned_data["content"]
        file_path = (os.path.join(ROOT_DIR, file_relative_path)).replace("\\", "/")

        if settings.USE_S3_THEME:
            file_path = (os.path.join(ORIG_ROOT_DIR, file_relative_path)).replace("\\", "/")

        # write the theme file locally in case it was wiped by a restart
        if settings.USE_S3_THEME and not os.path.isfile(file_path):
            file_dir = os.path.dirname(file_path)
            if not os.path.isdir(file_dir):
                # if directory does not exist, create it
                os.makedirs(file_dir)
            new_file = open(file_path, "w")
            new_file.write("")
            new_file.close()

        if os.path.isfile(file_path) and content != "":
            archive_file(request, file_relative_path, ROOT_DIR=ORIG_ROOT_DIR)

            # Save the file locally no matter the theme location.
            # The save to S3 reads from the local file, so we need to save it first.
            f = codecs.open(file_path, "w", "utf-8", "replace")
            file = File(f)
            file.write(content)
            file.close()

            if settings.USE_S3_THEME:
                # copy to s3 storage
                if os.path.splitext(file_path)[1] == ".html":
                    public = False
                else:
                    public = True
                save_file_to_s3(file_path, public=public)

                cache_key = ".".join([settings.SITE_CACHE_KEY, "theme", "%s/%s" % (get_theme(), file_relative_path)])
                cache.delete(cache_key)

                if hasattr(settings, "REMOTE_DEPLOY_URL") and settings.REMOTE_DEPLOY_URL:
                    urllib.urlopen(settings.REMOTE_DEPLOY_URL)

            return True
        else:
            return False
예제 #5
0
 def save(self, request, file_relative_path, ROOT_DIR=THEME_ROOT):
     content = self.cleaned_data["content"]
     file_path = (os.path.join(ROOT_DIR, file_relative_path)).replace("\\", "/")
     if os.path.isfile(file_path) and content <> "":
         archive_file(request, file_relative_path, ROOT_DIR=ROOT_DIR)
         f = codecs.open(file_path, 'w', 'utf-8', 'replace')
         file = File(f)
         file.write(content)
         file.close()
         
         # copy to s3 storage
         if os.path.splitext(file_path)[1] == '.html':
             public = False
         else:
             public = True
         save_file_to_s3(file_path, public=public)
         
         return True
     else:
         return False