django.conf.settings.BASE_DIR - python examples

Here are the examples of the python api django.conf.settings.BASE_DIR taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : tasks.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@shared_task()
def test():
    print("Running periodic task!")
    individuals = Individual.objects.filter(user=None)
    for individual in individuals:
        time_difference = datetime.datetime.now()-individual.creation_date
        if time_difference.days > 0:
            #delete individuals
            os.system('rm -rf %s/genomes/public/%s' % (settings.BASE_DIR, individual_id))
            individual.delete()

3 View Complete Implementation : models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def get_upload_path(self, filename):
        if self.user != None:
            string = "%s/media/%s/%s/%s" % (settings.BASE_DIR, slugify(self.user.username), self.id, filename)
        else:
            string = "%s/media/public/%s/%s" % (settings.BASE_DIR, self.id, filename)
        return string

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def process_press():
    for file in press_scss_files():
        if file.endswith('material_override.css'):
            print('Copying material override file for press')
            override_css_dir = os.path.join(settings.BASE_DIR, 'static', 'material', 'css')
            override_css_file = os.path.join(override_css_dir, 'press_override.css')

            # test if the journal CSS directory exists and create it if not
            os.makedirs(override_css_dir, exist_ok=True)

            # copy file to static
            copy_file(file, override_css_file)

3 View Complete Implementation : tasks.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@shared_task()
def test():
    print("Running periodic task!")
    individuals = Individual.objects.filter(user=None)
    for individual in individuals:
        time_difference = datetime.datetime.now()-individual.creation_date
        if time_difference.days > 0:
            #delete individuals
            os.system('rm -rf %s/genomes/public/%s' % (settings.BASE_DIR, individual_id))
            individual.delete()

3 View Complete Implementation : models.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def press_text(type):
    file = open(os.path.join(settings.BASE_DIR, 'utils', 'install', 'press_text.json'), 'r')
    text = json.loads(file.read())[0]
    if type == 'registration':
        return text.get('registration')
    elif type == 'reset':
        return text.get('reset')
    else:
        return text.get(type)

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def process_default_override(override_css_dir, include_paths):
    scss_default_override = os.path.join(
            settings.BASE_DIR, 'files', 'styling',
            'journals', 'default', 'override.scss'
    )
    override_css_file = os.path.join(override_css_dir, 'default_override.css')

    if os.path.isfile(scss_default_override):
        compiled = sast.compile(
                filename=scss_default_override,
                include_paths=include_paths,
        )
        with open(override_css_file, "w") as f:
            f.write(compiled)

3 View Complete Implementation : models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def get_upload_path(self, filename):
        if self.user != None:
            string = "%s/genomes/%s/%s/%s" % (settings.BASE_DIR, slugify(self.user.username), self.id, filename)#.replace(' ', '_')
        else:
            string = "%s/genomes/public/%s/%s" % (settings.BASE_DIR, self.id, filename)#.replace(' ', '_')
            print('string',string)
        return string

3 View Complete Implementation : test_files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
    def tearDown(self):
        for file in self.files:
            os.unlink(
                os.path.join(
                    settings.BASE_DIR,
                    'files',
                    'articles',
                    self.pk_string,
                    file.uuid_filename,
                )
            )

3 View Complete Implementation : test_views.py
Copyright GNU General Public License v3.0
Author : Cloud-CV
    def test_tf_export(self):
        model_file = open(os.path.join(settings.BASE_DIR, 'example/keras',
                                       'AlexNet.json'), 'r')
        response = self.client.post(reverse('keras-import'), {'file': model_file})
        response = json.loads(response.content)
        net = get_shapes(response['net'])
        response = self.client.post(reverse('tf-export'), {'net': json.dumps(net),
                                                           'net_name': ''})
        response = json.loads(response.content)
        self.astertEqual(response['result'], 'success')

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def copy_file(source, destination):
    """
    :param source: The source of the folder for copying
    :param destination: The destination folder for the file
    :return:
    """

    destination_folder = os.path.join(settings.BASE_DIR, os.path.dirname(destination))

    if not os.path.exists(destination_folder):
        os.mkdir(destination_folder)

    shutil.copy(os.path.join(settings.BASE_DIR, source),
                os.path.join(settings.BASE_DIR, destination))

3 View Complete Implementation : files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def save_file_to_temp(file_to_handle):
    original_filename = str(file_to_handle.name)
    filename = str(uuid4()) + str(os.path.splitext(original_filename)[1])
    folder_structure = os.path.join(settings.BASE_DIR, 'files', 'temp')
    save_file_to_disk(file_to_handle, filename, folder_structure)

    return [filename, os.path.join(folder_structure, filename)]

3 View Complete Implementation : 0032_install_xsl_files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def install_xsl_files(apps, schema_editor):
    default_xsl_path = os.path.join(settings.BASE_DIR, "transform/xsl/default.xsl")
    install_xsl_file(
        apps,
        label=settings.DEFAULT_XSL_FILE_LABEL,
        path=default_xsl_path
    )

3 View Complete Implementation : files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def serve_journal_cover(request, file_to_serve):
    """Serve a file to the user using a StreamingHttpResponse.

    :param request: the active request
    :param file_to_serve: the file object to retrieve and serve
    :return: a StreamingHttpResponse object with the requested file or an HttpResponseRedirect if there is an IO or
    permission error
    """

    file_path = os.path.join(settings.BASE_DIR, 'files', 'journals', str(request.journal.id),
                             str(file_to_serve.uuid_filename))

    try:
        response = serve_file_to_browser(file_path, file_to_serve)
        return response
    except IOError:
        messages.add_message(request, messages.ERROR, 'File not found. {0}'.format(file_path))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

3 View Complete Implementation : tasks.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@shared_task()
def clean_individuals():
    print("Running periodic task!")
    individuals = Individual.objects.filter(user=None)
    for individual in individuals:
        time_difference = datetime.datetime.now()-individual.creation_date
        if time_difference.days > 0:
            #delete individuals
            os.system('rm -rf %s/genomes/public/%s' % (settings.BASE_DIR, individual_id))
            individual.delete()

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def get_available_elements(workflow):
    plugins = plugin_installed_apps.load_plugin_apps(settings.BASE_DIR)
    our_elements = list()
    elements = models.BASE_ELEMENTS

    for element in elements:
        our_elements.append(element)

    for plugin in plugins:
        module_name = "{0}.plugin_settings".format(plugin)
        plugin_settings = import_module(module_name)

        if hasattr(plugin_settings, 'IS_WORKFLOW_PLUGIN') and hasattr(plugin_settings, 'HANDSHAKE_URL'):
            if plugin_settings.IS_WORKFLOW_PLUGIN:
                our_elements.append(
                    {'name': plugin_settings.PLUGIN_NAME, 'handshake_url': plugin_settings.HANDSHAKE_URL,
                     'stage': plugin_settings.STAGE, 'article_url': plugin_settings.ARTICLE_PK_IN_HANDSHAKE_URL}
                )
    return clear_active_elements(our_elements, workflow, plugins)

3 View Complete Implementation : update_files.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def download_files(self):
        print('Download Files')
        file_list = open('%s/data/files/all_files.txt' % (settings.BASE_DIR), 'w')
        s3credentials = S3Credential.objects.all()
        for s3credential in s3credentials:
            print(s3credential.name)
            for bucket_name in s3credential.buckets.splitlines():
                session = boto3.Session(
                    aws_access_key_id=s3credential.access_key,
                    aws_secret_access_key=s3credential.secret_key
                )
                s3 = session.resource('s3')
                bucket = s3.Bucket(bucket_name)
                print(bucket)
                for key in bucket.objects.all():
                    if key.size != 0:
                        file = [str(key.last_modified), str(key.size), bucket.name, key.key]
                        file_list.writelines('%s\n' % ('\t'.join(file)))
        self.stdout.write(self.style.SUCCESS('Successfully downloaded files!'))

3 View Complete Implementation : files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def serve_any_file(request, file_to_serve, public=False, path_parts=()):
    # TODO: should rename to serve_file and the latter to serve_article_file
    # Or removed
    file_path = os.path.join(
            settings.BASE_DIR,
            'files',
            *(str(part) for part in path_parts),
            str(file_to_serve.uuid_filename),
    )
    try:
        return serve_file_to_browser(file_path, file_to_serve, public=public)
    except IOError:
        messages.add_message(request, messages.ERROR, 'File not found. {0}'.format(file_path))
        raise Http404

3 View Complete Implementation : models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def get_upload_path(self, filename):
        if self.user != None:
            string = "%s/genomes/%s/%s/%s" % (settings.BASE_DIR, slugify(self.user.username), self.id, filename)#.replace(' ', '_')
        else:
            string = "%s/genomes/public/%s/%s" % (settings.BASE_DIR, self.id, filename)#.replace(' ', '_')
            print('string',string)
        return string

3 View Complete Implementation : files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def unlink_journal_file(request, file=None, xslt=False):
    if xslt:
        filename = 'journal.xslt'
    else:
        filename = file.uuid_filename

    full_path = os.path.join(settings.BASE_DIR, 'files', 'journals', str(request.journal.id), filename)

    if os.path.isfile(full_path):
        os.unlink(full_path)

3 View Complete Implementation : test_logic.py
Copyright MIT License
Author : abelardopardo
    def test_do_import(self):
        """Test the do_import_action functionality."""
        user = get_user_model().objects.get(email='[email protected]')
        wflow = models.Workflow.objects.get(name=self.wflow_name)

        with open(os.path.join(
            settings.BASE_DIR(),
            'ontask',
            'fixtures',
            'survey_to_import.gz'
        ), 'rb') as file_obj:
            services.do_import_action(user, workflow=wflow, file_item=file_obj)

        models.Action.objects.get(name='Initial survey')

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def create_paths():
    base_path = os.path.join(settings.BASE_DIR, 'static', 'default')
    folders = ['css', 'js']

    for folder in folders:
        os.makedirs(os.path.join(base_path, folder), exist_ok=True)

3 View Complete Implementation : setting_handler.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def fetch_defaults_value(setting):
    with codecs.open(os.path.join(settings.BASE_DIR, 'utils/install/journal_defaults.json'), 'r+', encoding='utf-8') as json_data:
        default_data = json.load(json_data)
        for item in default_data:
            if item['setting']['name'] == setting.get('name'):
                return item['value']['default']

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@login_required
@has_request
@typesetting_user_or_production_user_or_editor_required
def castius_generate(request, galley_id):

    galley = get_object_or_404(core_models.Galley, pk=galley_id)

    temporary_directory = os.path.join(settings.BASE_DIR, 'files', 'temp')

    driver = CastiusDriver(temporary_directory, galley, request)
    driver.transform()

    return redirect(request.GET['return'])

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def process_fonts():
    """Processes fonts from the compile folder into Static astets"""
    fonts_path = os.path.join(settings.BASE_DIR, 'themes/OLH/astets/fonts/')
    static_fonts = os.path.join(settings.BASE_DIR, 'static/OLH/fonts/')

    copy_files(fonts_path, static_fonts)

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def list_scss(journal):
    """ Lists the SCSS override files for a journal

    :param journal: the journal in question
    :return: a list of SCSS files
    """
    scss_path = join(
            settings.BASE_DIR, 'files', 'styling', 'journals', str(journal.id))
    try:
        makedirs(scss_path, exist_ok=True)
        file_paths = [
                join(scss_path, f)
                for f in listdir(scss_path) if isfile(join(scss_path, f))
        ]
    except FileNotFoundError:
        logger.warning("Failed to load scss from %s" % scss_path)
        file_paths = []

    return file_paths

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def process_images():
    """Processes images from the compile folder into Static astets"""
    image_path = os.path.join(settings.BASE_DIR, 'themes/OLH/astets/img/')
    static_images = os.path.join(settings.BASE_DIR, 'static/OLH/img/')

    copy_files(image_path, static_images)

3 View Complete Implementation : shared.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def versions():
    file = open(os.path.join(settings.BASE_DIR, 'utils', 'upgrade', 'versions.json'))

    versions = json.loads(file.read())

    return versions

3 View Complete Implementation : backup.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def copy_file(source, destination):
    """
    :param source: The source of the folder for copying
    :param destination: The destination folder for the file
    :return:
    """

    destination_folder = os.path.join(settings.BASE_DIR, os.path.dirname(destination))

    if not os.path.exists(destination_folder):
        os.mkdir(destination_folder)

    print("Copying {0}".format(source))
    shutil.copy(os.path.join(settings.BASE_DIR, source),
                os.path.join(settings.BASE_DIR, destination))

3 View Complete Implementation : plugin_loader.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def get_dirs(directory):
    path = os.path.join(settings.BASE_DIR, directory)
    root, dirs, files = next(os.walk(path))

    dirs = [x for x in dirs if x != '__pycache__']

    return dirs

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def copy_file(source, destination):
    """
    :param source: The source of the folder for copying
    :param destination: The destination folder for the file
    :return:
    """

    destination_folder = os.path.join(settings.BASE_DIR, os.path.dirname(destination))

    if not os.path.exists(destination_folder):
        os.mkdir(destination_folder)

    shutil.copy(os.path.join(settings.BASE_DIR, source),
                os.path.join(settings.BASE_DIR, destination))

3 View Complete Implementation : tasks.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@shared_task()
def clean_individuals():
    print("Running periodic task!")
    individuals = Individual.objects.filter(user=None)
    for individual in individuals:
        time_difference = datetime.datetime.now()-individual.creation_date
        if time_difference.days > 0:
            #delete individuals
            os.system('rm -rf %s/genomes/public/%s' % (settings.BASE_DIR, individual_id))
            individual.delete()

3 View Complete Implementation : models.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
    @staticmethod
    def override_cover(request, absolute=True):
        if request.journal.press_image_override:
            if absolute:
                return os.path.join(settings.BASE_DIR, 'files', 'journals', str(request.journal.pk),
                                    str(request.journal.press_image_override.uuid_filename))
            else:
                return os.path.join('files', 'journals', str(request.journal.pk),
                                    str(request.journal.press_image_override.uuid_filename))
        else:
            return None

3 View Complete Implementation : update_files.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def download_files(self):
        print('Download Files')
        file_list = open('%s/data/files/all_files.txt' % (settings.BASE_DIR), 'w')
        s3credentials = S3Credential.objects.all()
        for s3credential in s3credentials:
            print(s3credential.name)
            for bucket_name in s3credential.buckets.splitlines():
                session = boto3.Session(
                    aws_access_key_id=s3credential.access_key,
                    aws_secret_access_key=s3credential.secret_key
                )
                s3 = session.resource('s3')
                bucket = s3.Bucket(bucket_name)
                print(bucket)
                for key in bucket.objects.all():
                    if key.size != 0:
                        file = [str(key.last_modified), str(key.size), bucket.name, key.key]
                        file_list.writelines('%s\n' % ('\t'.join(file)))
        self.stdout.write(self.style.SUCCESS('Successfully downloaded files!'))

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def process_js():
    """Copies JS from compile into static astets
    """
    source_paths = [
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/js/admin.js'),
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/js/app.js'),
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/js/footnotes.js'),
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/js/table_of_contents.js'),
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/js/text_resize.js'),
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/js/toastr.js'),
    ]
    dest_path = os.path.join(settings.BASE_DIR, 'static/OLH/js/app.js')
    min_path = os.path.join(settings.BASE_DIR, 'static/OLH/js/app.min.js')

    process_js_files(source_paths, dest_path, min_path)

3 View Complete Implementation : tasks.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@shared_task()
def clean_individuals():
    print("Running periodic task!")
    individuals = Individual.objects.filter(user=None)
    for individual in individuals:
        time_difference = datetime.datetime.now()-individual.creation_date
        if time_difference.days > 0:
            #delete individuals
            os.system('rm -rf %s/genomes/public/%s' % (settings.BASE_DIR, individual_id))
            individual.delete()

3 View Complete Implementation : files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def serve_press_cover(request, file_to_serve):
    """Serve a file to the user using a StreamingHttpResponse.

    :param request: the active request
    :param file_to_serve: the file to serve
    :return: a StreamingHttpResponse object with the requested file or an HttpResponseRedirect if there is an IO or
    permission error
    """

    file_path = os.path.join(settings.BASE_DIR, 'files', 'press', str(file_to_serve.uuid_filename))

    try:
        response = serve_file_to_browser(file_path, file_to_serve)
        return response
    except IOError:
        messages.add_message(request, messages.ERROR, 'File not found. {0}'.format(file_path))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

3 View Complete Implementation : update_files.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def download_files(self):
        print('Download Files')
        file_list = open('%s/data/files/all_files.txt' % (settings.BASE_DIR), 'w')
        s3credentials = S3Credential.objects.all()
        for s3credential in s3credentials:
            print(s3credential.name)
            for bucket_name in s3credential.buckets.splitlines():
                session = boto3.Session(
                    aws_access_key_id=s3credential.access_key,
                    aws_secret_access_key=s3credential.secret_key
                )
                s3 = session.resource('s3')
                bucket = s3.Bucket(bucket_name)
                print(bucket)
                for key in bucket.objects.all():
                    if key.size != 0:
                        file = [str(key.last_modified), str(key.size), bucket.name, key.key]
                        file_list.writelines('%s\n' % ('\t'.join(file)))
        self.stdout.write(self.style.SUCCESS('Successfully downloaded files!'))

3 View Complete Implementation : test_files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
    def test_save_file(self):
        helpers.create_test_file(self, self.test_file_one)

        expected_file_path = os.path.join(
            os.path.join(
                settings.BASE_DIR, 'files', 'articles', self.pk_string,
            )
        )

        file_check = os.path.exists(
            expected_file_path,
        )

        self.astertTrue(file_check)

3 View Complete Implementation : models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def get_upload_path(self, filename):
        if self.user != None:
            string = "%s/media/%s/%s/%s" % (settings.BASE_DIR, slugify(self.user.username), self.id, filename)
        else:
            string = "%s/media/public/%s/%s" % (settings.BASE_DIR, self.id, filename)
        return string

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def process_scss():
    """Compiles SCSS into CSS in the Static astets folder"""
    paths = [
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/foundation-sites/scss/'),
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/motion-ui/src/')
    ]

    # File dirs
    app_scss_file = os.path.join(settings.BASE_DIR, 'themes/OLH/astets/scss/app.scss')
    app_css_file = os.path.join(settings.BASE_DIR, 'static/OLH/css/app.css')

    compiled_css_from_file = sast.compile(filename=app_scss_file, include_paths=paths)

    # Open the CSS file and write into it
    write_file = open(app_css_file, 'w')
    write_file.write(compiled_css_from_file)

3 View Complete Implementation : models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def get_upload_path(self, filename):
        if self.user != None:
            string = "%s/genomes/%s/%s/%s" % (settings.BASE_DIR, slugify(self.user.username), self.id, filename)#.replace(' ', '_')
        else:
            string = "%s/genomes/public/%s/%s" % (settings.BASE_DIR, self.id, filename)#.replace(' ', '_')
            print('string',string)
        return string

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def build():
    override_css_dir = create_paths()
    print("Processing SCSS")
    process_scss()
    print("Processing JS")
    process_js()
    print("Processing journal overrides")
    include_paths = [
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/foundation-sites/scss/'),
        os.path.join(settings.BASE_DIR, 'themes/OLH/astets/motion-ui/src/')
    ]
    process_default_override(override_css_dir, include_paths)
    process_journals(override_css_dir, include_paths)
    call_command('collectstatic', '--noinput')

3 View Complete Implementation : models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
    def get_upload_path(self, filename):
        if self.user != None:
            string = "%s/media/%s/%s/%s" % (settings.BASE_DIR, slugify(self.user.username), self.id, filename)
        else:
            string = "%s/media/public/%s/%s" % (settings.BASE_DIR, self.id, filename)
        return string

3 View Complete Implementation : models.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
    @staticmethod
    def press_cover(request, absolute=True):
        if request.press.thumbnail_image:
            if absolute:
                return os.path.join(settings.BASE_DIR, 'files', 'press',
                                    str(request.press.thumbnail_image.uuid_filename))
            else:
                return os.path.join('files', 'press', str(request.press.thumbnail_image.uuid_filename))
        else:
            return None

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def copy_file(source, destination):
    """
    :param source: The source of the folder for copying
    :param destination: The destination folder for the file
    :return:
    """

    destination_folder = os.path.join(settings.BASE_DIR, os.path.dirname(destination))

    if not os.path.exists(destination_folder):
        os.mkdir(destination_folder)

    shutil.copy(os.path.join(settings.BASE_DIR, source),
                os.path.join(settings.BASE_DIR, destination))

3 View Complete Implementation : files.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def copy_article_file(article_to_copy_from, file_to_copy, article_to_copy_to):
    """
    Copies an article file to another article location.
    :param file_to_copy: A file object
    :param article_to_copy_to: An Article object
    :return: None
    """
    copy_to_folder_structure = os.path.join(settings.BASE_DIR,
                                            'files',
                                            'articles',
                                            str(article_to_copy_to.id))
    file_path = os.path.join(copy_to_folder_structure, file_to_copy.uuid_filename)
    mkdirs(copy_to_folder_structure)
    shutil.copy(file_to_copy.get_file_path(article_to_copy_from), file_path)

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def create_paths():
    base_path = os.path.join(settings.BASE_DIR, 'static', 'OLH')
    folders = ['css', 'js', 'fonts', 'img']

    for folder in folders:
        os.makedirs(os.path.join(base_path, folder), exist_ok=True)

    # test if the journal CSS directory exists and create it if not
    override_css_dir = os.path.join(settings.BASE_DIR, 'static', 'OLH', 'css')
    os.makedirs(override_css_dir, exist_ok=True)

    return override_css_dir

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def process_journals():
    journals = journal_models.Journal.objects.all()

    for journal in journals:
        for file in journal.scss_files:
            if file.endswith('material_override.css'):
                print('Copying material override file for {name}'.format(name=journal.name))
                override_css_dir = os.path.join(settings.BASE_DIR, 'static', 'material', 'css')
                override_css_file = os.path.join(override_css_dir, 'journal{0}_override.css'.format(str(journal.id)))

                # test if the journal CSS directory exists and create it if not
                os.makedirs(override_css_dir, exist_ok=True)

                # copy file to static
                copy_file(file, override_css_file)

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def get_iso_country_code(ip):
    db_path = os.path.join(
        settings.BASE_DIR,
        'metrics',
        'geolocation',
        'GeoLite2-Country.mmdb',
    )
    reader = geoip2.database.Reader(db_path)

    try:
        response = reader.country(ip)
        return response.country.iso_code if response.country.iso_code else 'OTHER'
    except AddressNotFoundError:
        if ip == '127.0.0.1':
            return "GB"
        return 'OTHER'

3 View Complete Implementation : build_assets.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def press_scss_files():
    try:
        scss_path = os.path.join(settings.BASE_DIR, 'files', 'styling', 'press')
        os.makedirs(scss_path, exist_ok=True)
        return [os.path.join(scss_path, f) for f in os.listdir(scss_path) if os.path.isfile(os.path.join(scss_path, f))]
    except FileNotFoundError:
        return []