예제 #1
0
def run_domain(checks, request):
    """Check for domain configuration"""
    checks.append((
        _('Site domain'),
        check_domain(get_site_domain()),
        'production-site',
        get_site_url(),
    ))
예제 #2
0
def run_domain(checks, request):
    """Check for domain configuration"""
    checks.append((
        _('Site domain'),
        check_domain(get_site_domain()),
        'production-site',
        get_site_url(),
    ))
예제 #3
0
파일: changesite.py 프로젝트: nijel/weblate
 def handle(self, *args, **options):
     if options["set_name"]:
         if not check_domain(options["set_name"]):
             raise CommandError("Please provide valid domain name!")
         site, created = Site.objects.get_or_create(
             pk=options["site_id"], defaults={"domain": options["set_name"], "name": options["set_name"]}
         )
         if not created:
             site.domain = options["set_name"]
             site.name = options["set_name"]
             site.save()
     elif options["get_name"]:
         try:
             site = Site.objects.get(pk=options["site_id"])
             self.stdout.write(site.domain)
         except Site.DoesNotExist:
             raise CommandError("Site does not exist!")
     else:
         raise CommandError("Please specify desired action!")
예제 #4
0
 def handle(self, *args, **options):
     if options['set_name']:
         if not check_domain(options['set_name']):
             raise CommandError('Please provide valid domain name!')
         site, created = Site.objects.get_or_create(
             pk=options['site_id'],
             defaults={
                 'domain': options['set_name'],
                 'name': options['set_name']
             }
         )
         if not created:
             site.domain = options['set_name']
             site.name = options['set_name']
             site.save()
     elif options['get_name']:
         try:
             site = Site.objects.get(pk=options['site_id'])
             self.stdout.write(site.domain)
         except Site.DoesNotExist:
             raise CommandError('Site does not exist!')
     else:
         raise CommandError('Please specify desired action!')
예제 #5
0
파일: changesite.py 프로젝트: saily/weblate
 def handle(self, *args, **options):
     if options['set_name']:
         if not check_domain(options['set_name']):
             raise CommandError('Please provide valid domain name!')
         site, created = Site.objects.get_or_create(
             pk=options['site_id'],
             defaults={
                 'domain': options['set_name'],
                 'name': options['set_name']
             }
         )
         if not created:
             site.domain = options['set_name']
             site.name = options['set_name']
             site.save()
     elif options['get_name']:
         try:
             site = Site.objects.get(pk=options['site_id'])
             self.stdout.write(site.domain)
         except Site.DoesNotExist:
             raise CommandError('Site does not exist!')
     else:
         raise CommandError('Please specify desired action!')
예제 #6
0
def performance(request, admin_site):
    """Show performance tuning tips."""
    if request.method == 'POST':
        return handle_dismiss(request)
    checks = []
    # Check for debug mode
    checks.append((
        _('Debug mode'),
        not settings.DEBUG,
        'production-debug',
        settings.DEBUG,
    ))
    # Check for domain configuration
    checks.append((
        _('Site domain'),
        check_domain(get_site_domain()),
        'production-site',
        get_site_url(),
    ))
    # Check database being used
    checks.append((
        _('Database backend'),
        "sqlite" not in settings.DATABASES['default']['ENGINE'],
        'production-database',
        settings.DATABASES['default']['ENGINE'],
    ))
    # Check configured admins
    checks.append((
        _('Site administrator'),
        len(settings.ADMINS) > 0
        or '*****@*****.**' in [x[1] for x in settings.ADMINS],
        'production-admins',
        ', '.join([x[1] for x in settings.ADMINS]),
    ))
    # Check offloading indexing
    checks.append((
        # Translators: Indexing is postponed to cron job
        _('Indexing offloading'),
        settings.OFFLOAD_INDEXING,
        'production-indexing',
        settings.OFFLOAD_INDEXING))
    if settings.OFFLOAD_INDEXING:
        if IndexUpdate.objects.count() < 20:
            index_updates = True
        elif IndexUpdate.objects.count() < 200:
            index_updates = None
        else:
            index_updates = False

        checks.append((
            # Translators: Indexing is postponed to cron job
            _('Indexing offloading processing'),
            index_updates,
            'production-indexing',
            IndexUpdate.objects.count(),
        ))
    # Check for sane caching
    caches = settings.CACHES['default']['BACKEND'].split('.')[-1]
    if caches in GOOD_CACHE:
        # We consider these good
        caches = True
    elif caches in ['DummyCache']:
        # This one is definitely bad
        caches = False
    else:
        # These might not be that bad
        caches = None
    checks.append((
        _('Django caching'),
        caches,
        'production-cache',
        settings.CACHES['default']['BACKEND'],
    ))
    # Avatar caching
    checks.append((
        _('Avatar caching'),
        'avatar' in settings.CACHES,
        'production-cache-avatar',
        settings.CACHES['avatar']['BACKEND']
        if 'avatar' in settings.CACHES else '',
    ))
    # Check email setup
    default_mails = ('root@localhost', 'webmaster@localhost',
                     '*****@*****.**'
                     '*****@*****.**')
    checks.append((
        _('Email addresses'),
        (settings.SERVER_EMAIL not in default_mails
         and settings.DEFAULT_FROM_EMAIL not in default_mails),
        'production-email',
        ', '.join((settings.SERVER_EMAIL, settings.DEFAULT_FROM_EMAIL)),
    ))
    # libravatar library
    checks.append((
        _('Federated avatar support'),
        HAS_LIBRAVATAR,
        'production-avatar',
        HAS_LIBRAVATAR,
    ))
    # pyuca library
    checks.append((
        _('pyuca library'),
        HAS_PYUCA,
        'production-pyuca',
        HAS_PYUCA,
    ))
    # Cookie signing key
    checks.append((
        _('Secret key'),
        settings.SECRET_KEY != settings_example.SECRET_KEY,
        'production-secret',
        '',
    ))
    # Allowed hosts
    checks.append((
        _('Allowed hosts'),
        len(settings.ALLOWED_HOSTS) > 0,
        'production-hosts',
        ', '.join(settings.ALLOWED_HOSTS),
    ))

    loader = get_first_loader()
    # Cached template loader
    checks.append((
        _('Cached template loader'),
        'cached.Loader' in loader,
        'production-templates',
        loader,
    ))

    # Check for serving static files
    checks.append((
        _('Admin static files'),
        os.path.exists(
            os.path.join(settings.STATIC_ROOT, 'admin', 'js', 'core.js')),
        'production-admin-files',
        settings.STATIC_ROOT,
    ))

    context = admin_site.each_context(request)
    context['checks'] = checks
    context['errors'] = ConfigurationError.objects.filter(ignored=False)

    return render(
        request,
        "admin/performance.html",
        context,
    )
예제 #7
0
def performance(request):
    """
    Shows performance tuning tips.
    """
    checks = []
    # Check for debug mode
    checks.append((
        _('Debug mode'),
        not settings.DEBUG,
        'production-debug',
        settings.DEBUG,
    ))
    # Check for domain configuration
    domain = Site.objects.get_current().domain
    checks.append((
        _('Site domain'),
        check_domain(domain),
        'production-site',
        domain,
    ))
    # Check database being used
    checks.append((
        _('Database backend'),
        "sqlite" not in settings.DATABASES['default']['ENGINE'],
        'production-database',
        settings.DATABASES['default']['ENGINE'],
    ))
    # Check configured admins
    checks.append((
        _('Site administrator'),
        len(settings.ADMINS) > 0 or
        '*****@*****.**' in [x[1] for x in settings.ADMINS],
        'production-admins',
        ', '.join([x[1] for x in settings.ADMINS]),
    ))
    # Check offloading indexing
    checks.append((
        # Translators: Indexing is postponed to cron job
        _('Indexing offloading'),
        appsettings.OFFLOAD_INDEXING,
        'production-indexing',
        appsettings.OFFLOAD_INDEXING
    ))
    if appsettings.OFFLOAD_INDEXING:
        if IndexUpdate.objects.count() < 20:
            index_updates = True
        elif IndexUpdate.objects.count() < 200:
            index_updates = None
        else:
            index_updates = False

        checks.append((
            # Translators: Indexing is postponed to cron job
            _('Indexing offloading processing'),
            index_updates,
            'production-indexing',
            IndexUpdate.objects.count(),
        ))
    # Check for sane caching
    caches = settings.CACHES['default']['BACKEND'].split('.')[-1]
    if caches in ['MemcachedCache', 'PyLibMCCache', 'DatabaseCache']:
        # We consider these good
        caches = True
    elif caches in ['DummyCache']:
        # This one is definitely bad
        caches = False
    else:
        # These might not be that bad
        caches = None
    checks.append((
        _('Django caching'),
        caches,
        'production-cache',
        settings.CACHES['default']['BACKEND'],
    ))
    # Avatar caching
    checks.append((
        _('Avatar caching'),
        'avatar' in settings.CACHES,
        'production-cache-avatar',
        settings.CACHES['avatar']['BACKEND']
        if 'avatar' in settings.CACHES else '',
    ))
    # Check email setup
    default_mails = (
        'root@localhost',
        'webmaster@localhost',
        '*****@*****.**'
    )
    checks.append((
        _('Email addresses'),
        (
            settings.SERVER_EMAIL not in default_mails and
            settings.DEFAULT_FROM_EMAIL not in default_mails
        ),
        'production-email',
        ', '.join((settings.SERVER_EMAIL, settings.DEFAULT_FROM_EMAIL)),
    ))
    # libravatar library
    checks.append((
        _('Federated avatar support'),
        HAS_LIBRAVATAR,
        'production-avatar',
        HAS_LIBRAVATAR,
    ))
    # pyuca library
    checks.append((
        _('pyuca library'),
        HAS_PYUCA,
        'production-pyuca',
        HAS_PYUCA,
    ))
    # Cookie signing key
    checks.append((
        _('Secret key'),
        settings.SECRET_KEY != settings_example.SECRET_KEY,
        'production-secret',
        settings.SECRET_KEY,
    ))
    # Allowed hosts
    checks.append((
        _('Allowed hosts'),
        len(settings.ALLOWED_HOSTS) > 0,
        'production-hosts',
        ', '.join(settings.ALLOWED_HOSTS),
    ))

    loader = get_first_loader()
    # Cached template loader
    checks.append((
        _('Cached template loader'),
        'cached.Loader' in loader,
        'production-templates',
        loader,
    ))

    # Check for serving static files
    checks.append((
        _('Admin static files'),
        os.path.exists(
            os.path.join(settings.STATIC_ROOT, 'admin', 'js', 'core.js')
        ),
        'production-admin-files',
        settings.STATIC_ROOT,
    ))

    context = admin_context(request)
    context['checks'] = checks
    context['errors'] = get_configuration_errors()

    return render(
        request,
        "admin/performance.html",
        context,
    )