def handle_noargs(self, **options): script_path = os.path.join(openode.get_install_directory(), 'search', 'postgresql', 'thread_and_post_models_01162012.plsql') setup_full_text_search(script_path) script_path = os.path.join(openode.get_install_directory(), 'search', 'postgresql', 'user_profile_search_16102012.plsql') setup_full_text_search(script_path)
def handle_noargs(self, **options): script_path = os.path.join( openode.get_install_directory(), 'search', 'postgresql', 'thread_and_post_models_01162012.plsql' ) setup_full_text_search(script_path) script_path = os.path.join( openode.get_install_directory(), 'search', 'postgresql', 'user_profile_search_16102012.plsql' ) setup_full_text_search(script_path)
def get_available_skins(selected=None): """Returns a dictionary of skin name --> directory where "templates" and "media" subdirectories can be found. selected is a name of preferred skin if it's None, then information about all skins will be returned otherwise, only data about selected and default skins will be returned selected skin is guaranteed to be the first item in the dictionary """ skins = SortedDict() if hasattr(django_settings, 'OPENODE_EXTRA_SKINS_DIR'): skins.update(get_skins_from_dir(django_settings.OPENODE_EXTRA_SKINS_DIR)) if 'default' in skins: raise ValueError('"default" is not an acceptable name for a custom skin') if selected in skins: selected_dir = skins[selected] skins.clear() skins[selected] = selected_dir elif selected == 'default': skins = SortedDict() elif selected: raise ValueError( 'skin ' + str(selected) + \ ' not found, please check OPENODE_EXTRA_SKINS_DIR setting ' + \ 'or in the corresponding directory' ) #insert default as a last item skins['default'] = openode.get_install_directory() return skins
def test_new_skins(): """tests that there are no directories in the `openode/skins` because we've moved skin files a few levels up""" openode_root = openode.get_install_directory() for item in os.listdir(os.path.join(openode_root, 'skins')): item_path = os.path.join(openode_root, 'skins', item) if os.path.isdir(item_path): raise OpenodeConfigError( ('Time to move skin files from %s.\n' 'Now we have `openode/templates` and `openode/media`') % item_path )
def test_new_skins(): """tests that there are no directories in the `openode/skins` because we've moved skin files a few levels up""" openode_root = openode.get_install_directory() for item in os.listdir(os.path.join(openode_root, 'skins')): item_path = os.path.join(openode_root, 'skins', item) if os.path.isdir(item_path): raise OpenodeConfigError( ('Time to move skin files from %s.\n' 'Now we have `openode/templates` and `openode/media`') % item_path)
def get_available_skins(selected=None): """Returns a dictionary of skin name --> directory where "templates" and "media" subdirectories can be found. selected is a name of preferred skin if it's None, then information about all skins will be returned otherwise, only data about selected and default skins will be returned selected skin is guaranteed to be the first item in the dictionary """ skins = SortedDict() if hasattr(django_settings, 'OPENODE_EXTRA_SKINS_DIR'): skins.update( get_skins_from_dir(django_settings.OPENODE_EXTRA_SKINS_DIR)) if 'default' in skins: raise ValueError( '"default" is not an acceptable name for a custom skin') if selected in skins: selected_dir = skins[selected] skins.clear() skins[selected] = selected_dir elif selected == 'default': skins = SortedDict() elif selected: raise ValueError( 'skin ' + str(selected) + \ ' not found, please check OPENODE_EXTRA_SKINS_DIR setting ' + \ 'or in the corresponding directory' ) #insert default as a last item skins['default'] = openode.get_install_directory() return skins
def test_staticfiles(): """tests configuration of the staticfiles app""" errors = list() import django django_version = django.VERSION if django_version[0] == 1 and django_version[1] < 3: staticfiles_app_name = 'staticfiles' wrong_staticfiles_app_name = 'django.contrib.staticfiles' try_import('staticfiles', 'django-staticfiles') import staticfiles if staticfiles.__version__[0] != 1: raise OpenodeConfigError( 'Please use the newest available version of ' 'django-staticfiles app, type\n' 'pip install --upgrade django-staticfiles' ) if not hasattr(django_settings, 'STATICFILES_STORAGE'): raise OpenodeConfigError( 'Configure STATICFILES_STORAGE setting as desired, ' 'a reasonable default is\n' "STATICFILES_STORAGE = 'staticfiles.storage.StaticFilesStorage'" ) else: staticfiles_app_name = 'django.contrib.staticfiles' wrong_staticfiles_app_name = 'staticfiles' if staticfiles_app_name not in django_settings.INSTALLED_APPS: errors.append( 'Add to the INSTALLED_APPS section of your settings.py:\n' " '%s'," % staticfiles_app_name ) if wrong_staticfiles_app_name in django_settings.INSTALLED_APPS: errors.append( 'Remove from the INSTALLED_APPS section of your settings.py:\n' " '%s'," % wrong_staticfiles_app_name ) static_url = django_settings.STATIC_URL or '' if static_url is None or str(static_url).strip() == '': errors.append( 'Add STATIC_URL setting to your settings.py file. ' 'The setting must be a url at which static files ' 'are accessible.' ) url = urlparse(static_url).path if not (url.startswith('/') and url.endswith('/')): #a simple check for the url errors.append( 'Path in the STATIC_URL must start and end with the /.' ) if django_settings.ADMIN_MEDIA_PREFIX != static_url + 'admin/': errors.append( 'Set ADMIN_MEDIA_PREFIX as: \n' " ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'" ) # django_settings.STATICFILES_DIRS can have strings or tuples staticfiles_dirs = [d[1] if isinstance(d, tuple) else d for d in django_settings.STATICFILES_DIRS] default_skin_tuple = None openode_root = openode.get_install_directory() old_default_skin_dir = os.path.abspath(os.path.join(openode_root, 'skins')) for dir_entry in django_settings.STATICFILES_DIRS: if isinstance(dir_entry, tuple): if dir_entry[0] == 'default/media': default_skin_tuple = dir_entry elif isinstance(dir_entry, str): if os.path.abspath(dir_entry) == old_default_skin_dir: errors.append( 'Remove from STATICFILES_DIRS in your settings.py file:\n' + dir_entry ) openode_root = os.path.dirname(openode.__file__) default_skin_media_dir = os.path.abspath(os.path.join(openode_root, 'media')) if default_skin_tuple: media_dir = default_skin_tuple[1] if default_skin_media_dir != os.path.abspath(media_dir): errors.append( 'Add to STATICFILES_DIRS the following entry: ' "('default/media', os.path.join(OPENODE_ROOT, 'media'))," ) extra_skins_dir = getattr(django_settings, 'OPENODE_EXTRA_SKINS_DIR', None) if extra_skins_dir is not None: if not os.path.isdir(extra_skins_dir): errors.append( 'Directory specified with settning OPENODE_EXTRA_SKINS_DIR ' 'must exist and contain your custom skins for openode.' ) if extra_skins_dir not in staticfiles_dirs: errors.append( 'Add OPENODE_EXTRA_SKINS_DIR to STATICFILES_DIRS entry in ' 'your settings.py file.\n' 'NOTE: it might be necessary to move the line with ' 'OPENODE_EXTRA_SKINS_DIR just above STATICFILES_DIRS.' ) if django_settings.STATICFILES_STORAGE == \ 'django.contrib.staticfiles.storage.StaticFilesStorage': if os.path.dirname(django_settings.STATIC_ROOT) == '': #static root is needed only for local storoge of #the static files raise OpenodeConfigError( 'Specify the static files directory ' 'with setting STATIC_ROOT' ) if errors: errors.append( 'Run command (after fixing the above errors)\n' ' python manage.py collectstatic\n' ) print_errors(errors) if django_settings.STATICFILES_STORAGE == \ 'django.contrib.staticfiles.storage.StaticFilesStorage': if not os.path.isdir(django_settings.STATIC_ROOT): openode_warning( 'Please run command\n\n' ' python manage.py collectstatic' )
def test_staticfiles(): """tests configuration of the staticfiles app""" errors = list() import django django_version = django.VERSION if django_version[0] == 1 and django_version[1] < 3: staticfiles_app_name = 'staticfiles' wrong_staticfiles_app_name = 'django.contrib.staticfiles' try_import('staticfiles', 'django-staticfiles') import staticfiles if staticfiles.__version__[0] != 1: raise OpenodeConfigError( 'Please use the newest available version of ' 'django-staticfiles app, type\n' 'pip install --upgrade django-staticfiles') if not hasattr(django_settings, 'STATICFILES_STORAGE'): raise OpenodeConfigError( 'Configure STATICFILES_STORAGE setting as desired, ' 'a reasonable default is\n' "STATICFILES_STORAGE = 'staticfiles.storage.StaticFilesStorage'" ) else: staticfiles_app_name = 'django.contrib.staticfiles' wrong_staticfiles_app_name = 'staticfiles' if staticfiles_app_name not in django_settings.INSTALLED_APPS: errors.append( 'Add to the INSTALLED_APPS section of your settings.py:\n' " '%s'," % staticfiles_app_name) if wrong_staticfiles_app_name in django_settings.INSTALLED_APPS: errors.append( 'Remove from the INSTALLED_APPS section of your settings.py:\n' " '%s'," % wrong_staticfiles_app_name) static_url = django_settings.STATIC_URL or '' if static_url is None or str(static_url).strip() == '': errors.append('Add STATIC_URL setting to your settings.py file. ' 'The setting must be a url at which static files ' 'are accessible.') url = urlparse(static_url).path if not (url.startswith('/') and url.endswith('/')): #a simple check for the url errors.append('Path in the STATIC_URL must start and end with the /.') if django_settings.ADMIN_MEDIA_PREFIX != static_url + 'admin/': errors.append('Set ADMIN_MEDIA_PREFIX as: \n' " ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'") # django_settings.STATICFILES_DIRS can have strings or tuples staticfiles_dirs = [ d[1] if isinstance(d, tuple) else d for d in django_settings.STATICFILES_DIRS ] default_skin_tuple = None openode_root = openode.get_install_directory() old_default_skin_dir = os.path.abspath(os.path.join(openode_root, 'skins')) for dir_entry in django_settings.STATICFILES_DIRS: if isinstance(dir_entry, tuple): if dir_entry[0] == 'default/media': default_skin_tuple = dir_entry elif isinstance(dir_entry, str): if os.path.abspath(dir_entry) == old_default_skin_dir: errors.append( 'Remove from STATICFILES_DIRS in your settings.py file:\n' + dir_entry) openode_root = os.path.dirname(openode.__file__) default_skin_media_dir = os.path.abspath( os.path.join(openode_root, 'media')) if default_skin_tuple: media_dir = default_skin_tuple[1] if default_skin_media_dir != os.path.abspath(media_dir): errors.append( 'Add to STATICFILES_DIRS the following entry: ' "('default/media', os.path.join(OPENODE_ROOT, 'media')),") extra_skins_dir = getattr(django_settings, 'OPENODE_EXTRA_SKINS_DIR', None) if extra_skins_dir is not None: if not os.path.isdir(extra_skins_dir): errors.append( 'Directory specified with settning OPENODE_EXTRA_SKINS_DIR ' 'must exist and contain your custom skins for openode.') if extra_skins_dir not in staticfiles_dirs: errors.append( 'Add OPENODE_EXTRA_SKINS_DIR to STATICFILES_DIRS entry in ' 'your settings.py file.\n' 'NOTE: it might be necessary to move the line with ' 'OPENODE_EXTRA_SKINS_DIR just above STATICFILES_DIRS.') if django_settings.STATICFILES_STORAGE == \ 'django.contrib.staticfiles.storage.StaticFilesStorage': if os.path.dirname(django_settings.STATIC_ROOT) == '': #static root is needed only for local storoge of #the static files raise OpenodeConfigError('Specify the static files directory ' 'with setting STATIC_ROOT') if errors: errors.append('Run command (after fixing the above errors)\n' ' python manage.py collectstatic\n') print_errors(errors) if django_settings.STATICFILES_STORAGE == \ 'django.contrib.staticfiles.storage.StaticFilesStorage': if not os.path.isdir(django_settings.STATIC_ROOT): openode_warning('Please run command\n\n' ' python manage.py collectstatic')
import subprocess, os from django.core.management.base import NoArgsCommand import openode DOC_DIR = os.path.join(openode.get_install_directory(), 'doc') class Command(NoArgsCommand): def handle_noargs(self, **options): os.chdir(DOC_DIR) subprocess.call(['make', 'html'])