예제 #1
0
def view(request):
    siteconfig = load_site_config()
    response = {}
    if request.POST:
        setting_form = GeneralSettingsForm(siteconfig, data=request.POST)
        if setting_form.is_valid():
            setting_form.save()
            load_site_config()
            response = {
                    "intro": setting_form.cleaned_data['DESCRIPTION'],
                    "valid": True,
            }
        if request.is_ajax():
            context = {
                    "form": setting_form,
                    "form_action": "/admin/general.html"
            }
            t = loader.get_template('admin/general_settings_form.html')
            c = RequestContext(request, context)
            response['form'] = t.render(c)

            return HttpResponse(jsonify(response), mimetype="application/json")
    else:
        setting_form = GeneralSettingsForm(siteconfig)

    template = 'admin/admin_general_settings.html'
    template_vars = {
        'form': setting_form,
        }
    return render_to_response(template, template_vars, context_instance=RequestContext(request))
예제 #2
0
def view(request):
    siteconfig = load_site_config()
    response = {}
    if request.POST:
        setting_form = GeneralSettingsForm(siteconfig, data=request.POST)
        if setting_form.is_valid():
            setting_form.save()
            load_site_config()
            response = {
                "intro": setting_form.cleaned_data['DESCRIPTION'],
                "valid": True,
            }
        if request.is_ajax():
            context = {
                "form": setting_form,
                "form_action": "/admin/general.html"
            }
            t = loader.get_template('admin/general_settings_form.html')
            c = RequestContext(request, context)
            response['form'] = t.render(c)

            return HttpResponse(jsonify(response), mimetype="application/json")
    else:
        setting_form = GeneralSettingsForm(siteconfig)

    template = 'admin/admin_general_settings.html'
    template_vars = {
        'form': setting_form,
    }
    return render_to_response(template,
                              template_vars,
                              context_instance=RequestContext(request))
예제 #3
0
def view(request):
    siteconfig = load_site_config()
    if request.POST:
        setting_form = GeneralSettingsForm(siteconfig, data=request.POST)
        if setting_form.is_valid():
            setting_form.save()
            load_site_config()
    else:
        setting_form = GeneralSettingsForm(siteconfig)

    template = "admin/admin_general_settings.html"
    template_vars = {"form": setting_form}
    return render_to_response(template, template_vars, context_instance=RequestContext(request))
예제 #4
0
    def handle_noargs(self, **options):
        config = siteconfig.load_site_config()
        db_buildversion = config.get("BUILDVERSION", None)

        if db_buildversion and db_buildversion < DEFAULT_POOTLE_BUILDVERSION:
            logging.info(
                "Upgrading Pootle database from schema version " "%d to %d",
                db_buildversion,
                DEFAULT_POOTLE_BUILDVERSION,
            )

            from pootle_misc.upgrade.schema import staggered_update

            staggered_update(db_buildversion)

            logging.info("Database upgrade done.")
        elif db_buildversion:
            logging.info("No database upgrades required.")

        if db_buildversion:
            new_buildversion = max(db_buildversion, DEFAULT_POOTLE_BUILDVERSION)
            logging.info("Current schema version: %d", new_buildversion)
        else:
            # Oh, the admin tried to run updatedb but there is no
            # BUILDVERSION recorded in its Pootle installation. That means
            # it's not a legacy installation.
            logging.info("Your installation is newer than Pootle 2.5.\n" "You do not need to run this.")

        logging.info("THIS UPGRADE SCRIPT HAS BEEN DEPRECATED!")
        logging.info(
            "If you are trying to upgrade Pootle from version 2.5\n"
            "or older, please read the upgrade instructions at\n"
            "http://docs.translatehouse.org/projects/pootle/en/latest/server/upgrading.html"
        )
예제 #5
0
def edit_settings(request):
    """Saves the site's general settings."""
    siteconfig = load_site_config()
    form = GeneralSettingsForm(siteconfig, data=request.POST)

    response = {}
    rcode = 400

    if form.is_valid():
        form.save()
        rcode = 200

        the_html = u"".join(
            [u"<div>", form.cleaned_data['DESCRIPTION'], "</div>"])

        response["description_html"] = the_html

    context = {"form": form, "form_action": "/admin/edit_settings.html"}
    t = loader.get_template('admin/general_settings_form.html')
    c = RequestContext(request, context)
    response['form'] = t.render(c)

    return HttpResponse(jsonify(response),
                        status=rcode,
                        mimetype="application/json")
예제 #6
0
    def process_request(self, request):
        """Calculate settings.BASEURL based on HTTP headers."""
        domain = None

        if 'HTTP_HOST' in request.META:
            domain = request.get_host()

        if 'SCRIPT_NAME' in request.META:
            settings.SCRIPT_NAME = request.META['SCRIPT_NAME']
            if domain is not None:
                domain += request.META['SCRIPT_NAME']

        if domain is not None:
            if request.is_secure():
                settings.BASE_URL = 'https://' + domain
            else:
                settings.BASE_URL = 'http://' + domain

            #FIXME: DIRTY HACK ALERT: if this works then something is
            # wrong with the universe.
            #
            # Poison sites cache using detected domain.
            from django.contrib.sites import models as sites_models
            from pootle_misc.siteconfig import load_site_config

            siteconfig = load_site_config()
            new_site = sites_models.Site(settings.SITE_ID, request.get_host(),
                                         siteconfig.get('TITLE'))
            sites_models.SITE_CACHE[settings.SITE_ID] = new_site
예제 #7
0
def post_syncdb_handler(sender, created_models, **kwargs):
    try:
        # create default cache table
        call_command('createcachetable', 'pootlecache')
    except:
        pass

    if PootleProfile in created_models:
        create_essential_users()
    if Directory in created_models:
        create_root_directory()
    if Language in created_models:
        create_template_language()
    if Project in created_models:
        create_terminology_project()
    if PermissionSet in created_models:
        create_pootle_permissions()
        create_pootle_permission_sets()

    config = siteconfig.load_site_config()
    if not config.get('BUILDVERSION', None):
        config.set('BUILDVERSION', code_buildversion)
    if not config.get('TT_BUILDVERSION', None):
        config.set('TT_BUILDVERSION', code_tt_buildversion)
    config.save()
예제 #8
0
파일: initdb.py 프로젝트: a-covar/pootle
def initdb():
    """Populate the database with default initial data.

    This provides a working Pootle installation.
    """

    try:
        # create default cache table
        call_command('createcachetable', 'pootlecache')
    except:
        pass

    create_essential_users()
    create_root_directories()
    create_template_languages()
    create_terminology_project()
    create_pootle_permissions()
    create_pootle_permission_sets()

    create_default_db()

    config = siteconfig.load_site_config()
    if not config.get('POOTLE_BUILDVERSION', None):
        config.set('POOTLE_BUILDVERSION', code_buildversion)
    if not config.get('TT_BUILDVERSION', None):
        config.set('TT_BUILDVERSION', code_tt_buildversion)
    config.save()
예제 #9
0
def pootle_context(request):
    """Exposes settings to templates."""
    siteconfig = load_site_config()
    #FIXME: maybe we should expose relevant settings only?
    context = {
        'settings': {
            'TITLE': siteconfig.get('TITLE'),
            'DESCRIPTION':  siteconfig.get('DESCRIPTION'),
            'CAN_REGISTER': settings.CAN_REGISTER,
            'CAN_CONTACT': settings.CAN_CONTACT and settings.CONTACT_EMAIL,
            'SCRIPT_NAME': settings.SCRIPT_NAME,
            'POOTLE_VERSION': sver,
            'CACHE_TIMEOUT': settings.CACHE_MIDDLEWARE_SECONDS,
            'DEBUG': settings.DEBUG,
        },
        'custom': settings.CUSTOM_TEMPLATE_CONTEXT,
    }

    context.update({
        'ALL_LANGUAGES': Language.live.cached(),
        'ALL_PROJECTS': Project.objects.cached(),
    })

    context.update(_agreement_context(request))

    return context
예제 #10
0
def edit_settings(request):
    """Saves the site's general settings."""
    siteconfig = load_site_config()
    form = GeneralSettingsForm(siteconfig, data=request.POST)

    response = {}
    rcode = 400

    if form.is_valid():
        form.save()
        rcode = 200

        the_html = u"".join([
            u"<div>", form.cleaned_data['DESCRIPTION'], "</div>"
        ])

        response["description"] = the_html

    context = {
        "form": form,
        "form_action": "/admin/edit_settings.html"
    }
    t = loader.get_template('admin/general_settings_form.html')
    c = RequestContext(request, context)
    response['form'] = t.render(c)

    return HttpResponse(jsonify(response), status=rcode,
                        mimetype="application/json")
예제 #11
0
def view(request):
    siteconfig = load_site_config()
    ctx = {
        'description':
        _(siteconfig.get('DESCRIPTION')),
        'keywords': [
            'Pootle',
            'locamotion',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
        ],
        'pootle_version':
        _(
            "Pootle %(pootle_ver)s is powered by Translate "
            "Toolkit %(toolkit_ver)s", {
                'pootle_ver': pootleversion.sver,
                'toolkit_ver': toolkitversion.sver
            }),
        'version_details':
        "\n".join([
            "Django %s" % django.get_version(),
            "Python %s" % sys.version,
            "Running on %s" % sys.platform,
        ]),
    }
    return render_to_response('about/about.html',
                              ctx,
                              context_instance=RequestContext(request))
예제 #12
0
    def handle_noargs(self, **options):
        config = siteconfig.load_site_config()
        db_buildversion = config.get('BUILDVERSION', None)

        if db_buildversion and db_buildversion < DEFAULT_POOTLE_BUILDVERSION:
            from pootle_misc.upgrade.schema import staggered_update

            logging.info('Upgrading Pootle database from schema version '
                         '%d to %d', db_buildversion,
                         DEFAULT_POOTLE_BUILDVERSION)
            staggered_update(db_buildversion)
            logging.info('Database upgrade done.')
        elif db_buildversion:
            logging.info('No database upgrades required.')

        if db_buildversion:
            new_buildversion = max(db_buildversion,
                                   DEFAULT_POOTLE_BUILDVERSION)
            logging.info('Current schema version: %d', new_buildversion)
        else:
            # Oh, the admin tried to run updatedb but there is no BUILDVERSION
            # recorded in its Pootle installation. That means it's not a legacy
            # installation.
            logging.info('Your installation is newer than Pootle 2.5.\n'
                         'You do not need to run this.')

        logging.info('THIS UPGRADE SCRIPT HAS BEEN DEPRECATED!')
        logging.info('If you are trying to upgrade Pootle from version 2.5\n'
                     'or older, please read the upgrade instructions at\n'
                     'http://docs.translatehouse.org/projects/pootle/en/'
                     'latest/server/upgrading.html'))
예제 #13
0
파일: updatedb.py 프로젝트: SinSiXX/pootle
def update_db():
    # Get current database build versions
    config = siteconfig.load_site_config()
    db_buildversion = config.get('BUILDVERSION', DEFAULT_BUILDVERSION)
    db_tt_buildversion = int(config.get('TT_BUILDVERSION', DEFAULT_TT_BUILDVERSION))

    if (db_buildversion < code_buildversion or
        db_tt_buildversion < code_tt_buildversion):

        if db_buildversion < code_buildversion:
            logging.info("Upgrading Pootle database from schema version "
                         "%d to %d", db_buildversion, code_buildversion)

        if db_tt_buildversion < code_tt_buildversion:
            logging.info("Upgrading TT database from schema version %d to %d",
                         db_tt_buildversion, code_tt_buildversion)

        from pootle_misc.dbupdate import staggered_update
        for i in staggered_update(db_buildversion, db_tt_buildversion):
            pass

        logging.info("Database upgrade done, current schema versions:\n"
                     "- Pootle: %d\n- Translate Toolkit: %d",
                     code_buildversion, code_tt_buildversion)
    else:
        logging.info("No database upgrades required, current schema "
                     "versions:\n- Pootle: %d\n- Translate Toolkit: %d",
                     db_buildversion, db_tt_buildversion)
예제 #14
0
파일: about.py 프로젝트: JMassapina/pootle
def view(request):
    siteconfig = load_site_config()
    ctx = {
        'description': _(siteconfig.get('DESCRIPTION')),
        'keywords': [
            'Pootle',
            'locamotion',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
        ],
        'pootle_version': _("Pootle %(pootle_ver)s is powered by Translate "
                            "Toolkit %(toolkit_ver)s",
                            {'pootle_ver': pootleversion.sver,
                             'toolkit_ver': toolkitversion.sver}),
        'version_details': "\n".join([
            "Django %s" % django.get_version(),
            "Python %s" % sys.version,
            "Running on %s" % sys.platform,
        ]),
    }
    return render_to_response('about/about.html', ctx,
                              context_instance=RequestContext(request))
예제 #15
0
파일: updatedb.py 프로젝트: notz/pootle
def update_db():
    # Get current database build versions
    config = siteconfig.load_site_config()
    db_buildversion = config.get('BUILDVERSION', DEFAULT_BUILDVERSION)
    db_tt_buildversion = int(
        config.get('TT_BUILDVERSION', DEFAULT_TT_BUILDVERSION))

    if (db_buildversion < code_buildversion
            or db_tt_buildversion < code_tt_buildversion):

        if db_buildversion < code_buildversion:
            logging.info(
                "Upgrading Pootle database from schema version "
                "%d to %d", db_buildversion, code_buildversion)

        if db_tt_buildversion < code_tt_buildversion:
            logging.info("Upgrading TT database from schema version %d to %d",
                         db_tt_buildversion, code_tt_buildversion)

        from pootle_misc.dbupdate import staggered_update
        for i in staggered_update(db_buildversion, db_tt_buildversion):
            pass

        logging.info(
            "Database upgrade done, current schema versions:\n"
            "- Pootle: %d\n- Translate Toolkit: %d", code_buildversion,
            code_tt_buildversion)
    else:
        logging.info(
            "No database upgrades required, current schema "
            "versions:\n- Pootle: %d\n- Translate Toolkit: %d",
            db_buildversion, db_tt_buildversion)
예제 #16
0
    def handle_noargs(self, **options):
        config = siteconfig.load_site_config()
        db_buildversion = config.get('BUILDVERSION', None)

        if db_buildversion and db_buildversion < DEFAULT_POOTLE_BUILDVERSION:
            from pootle_misc.upgrade.schema import staggered_update

            logging.info(
                'Upgrading Pootle database from schema version '
                '%d to %d', db_buildversion, DEFAULT_POOTLE_BUILDVERSION)
            staggered_update(db_buildversion)
            logging.info('Database upgrade done.')
        elif db_buildversion:
            logging.info('No database upgrades required.')

        if db_buildversion:
            new_buildversion = max(db_buildversion,
                                   DEFAULT_POOTLE_BUILDVERSION)
            logging.info('Current schema version: %d', new_buildversion)
        else:
            # Oh, the admin tried to run updatedb but there is no BUILDVERSION
            # recorded in its Pootle installation. That means it's not a legacy
            # installation.
            logging.info('Your installation is newer than Pootle 2.5.\n'
                         'You do not need to run this.')

        logging.info('THIS UPGRADE SCRIPT HAS BEEN DEPRECATED!')
        logging.info('If you are trying to upgrade Pootle from version 2.5\n'
                     'or older, please read the upgrade instructions at\n'
                     'http://docs.translatehouse.org/projects/pootle/en/'
                     'latest/server/upgrading.html')
예제 #17
0
파일: initdb.py 프로젝트: JMassapina/pootle
def initdb():
    """Populate the database with default initial data.

    This creates the default database to get a working Pootle installation.
    """

    try:
        #FIXME: Should be called only if using cache on DB.
        # Create default cache table.
        call_command('createcachetable', 'pootlecache')
    except:
        pass

    create_essential_users()
    create_root_directories()
    create_template_languages()
    create_terminology_project()
    create_pootle_permissions()
    create_pootle_permission_sets()

    create_default_projects()
    create_default_languages()
    create_default_admin()

    create_local_tm()

    config = siteconfig.load_site_config()
    if not config.get('POOTLE_BUILDVERSION', None):
        config.set('POOTLE_BUILDVERSION', code_buildversion)
    if not config.get('TT_BUILDVERSION', None):
        config.set('TT_BUILDVERSION', code_tt_buildversion)
    config.save()
예제 #18
0
def pootle_context(request):
    """Exposes settings to templates."""
    siteconfig = load_site_config()
    #FIXME: maybe we should expose relevant settings only?
    context = {
        'settings': {
            'TITLE': siteconfig.get('TITLE'),
            'DESCRIPTION':  siteconfig.get('DESCRIPTION'),
            'CAN_REGISTER': settings.CAN_REGISTER,
            'CAN_CONTACT': settings.CAN_CONTACT and settings.CONTACT_EMAIL,
            'SCRIPT_NAME': settings.SCRIPT_NAME,
            'POOTLE_VERSION': sver,
            'CACHE_TIMEOUT': settings.CACHE_MIDDLEWARE_SECONDS,
            'DEBUG': settings.DEBUG,
        },
        'custom': settings.CUSTOM_TEMPLATE_CONTEXT,
    }

    context.update({
        'ALL_LANGUAGES': Language.live.cached(),
        'ALL_PROJECTS': Project.objects.cached(),
    })

    context.update(_agreement_context(request))

    return context
예제 #19
0
def post_syncdb_handler(sender, created_models, **kwargs):
    try:
        # create default cache table
        call_command('createcachetable', 'pootlecache')
    except:
        pass

    if PootleProfile in created_models:
        create_essential_users()
    if Directory in created_models:
        create_root_directories()
    if Language in created_models:
        create_template_languages()
    if Project in created_models:
        create_terminology_project()
    if PermissionSet in created_models:
        create_pootle_permissions()
        create_pootle_permission_sets()

    config = siteconfig.load_site_config()
    if not config.get('BUILDVERSION', None):
        config.set('BUILDVERSION', code_buildversion)
    if not config.get('TT_BUILDVERSION', None):
        config.set('TT_BUILDVERSION', code_tt_buildversion)
    config.save()
예제 #20
0
    def process_request(self, request):
        """Calculate settings.BASEURL based on HTTP headers."""
        domain = None

        if "HTTP_HOST" in request.META:
            domain = request.get_host()

        if "SCRIPT_NAME" in request.META:
            settings.SCRIPT_NAME = request.META["SCRIPT_NAME"]
            if domain is not None:
                domain += request.META["SCRIPT_NAME"]

        if domain is not None:
            if request.is_secure():
                settings.BASE_URL = "https://" + domain
            else:
                settings.BASE_URL = "http://" + domain

            # FIXME: DIRTY HACK ALERT: if this works then something is
            # wrong with the universe.
            #
            # Poison sites cache using detected domain.
            from django.contrib.sites import models as sites_models
            from pootle_misc.siteconfig import load_site_config

            siteconfig = load_site_config()
            new_site = sites_models.Site(settings.SITE_ID, request.get_host(), siteconfig.get("TITLE"))
            sites_models.SITE_CACHE[settings.SITE_ID] = new_site
예제 #21
0
def view(request):
    siteconfig = load_site_config()
    if request.POST:
        setting_form = GeneralSettingsForm(siteconfig, data=request.POST)
        if setting_form.is_valid():
            setting_form.save()
            load_site_config()
    else:
        setting_form = GeneralSettingsForm(siteconfig)

    template = 'admin/admin_general_settings.html'
    template_vars = {
        'form': setting_form,
    }
    return render_to_response(template,
                              template_vars,
                              context_instance=RequestContext(request))
예제 #22
0
def save_toolkit_version(build=None):
    from pootle_misc import siteconfig
    if not build:
        from translate.__version__ import build

    config = siteconfig.load_site_config()
    config.set('TT_BUILDVERSION', build)
    config.save()
    logging.info("Database now at Toolkit build %d" % build)
예제 #23
0
def save_pootle_version(build=None):
    from pootle_misc import siteconfig
    if not build:
        from pootle.__version__ import build

    config = siteconfig.load_site_config()
    config.set('BUILDVERSION', build)
    config.save()
    logging.info("Database now at Pootle build %d" % build)
예제 #24
0
파일: initdb.py 프로젝트: fourks/pootle
def save_build_versions():
    """Save the Pootle and Translate Toolkit build versions on the database.

    The build versions are used to upgrade only what has to be upgraded.
    """
    config = load_site_config()
    config.set('POOTLE_BUILDVERSION', CODE_PTL_BUILD_VERSION)
    config.set('TT_BUILDVERSION', CODE_TTK_BUILD_VERSION)
    config.save()
예제 #25
0
파일: dbupdate.py 프로젝트: peterbe/pootle
def save_toolkit_version(build=None):
    from pootle_misc import siteconfig
    if not build:
        from translate.__version__ import build

    config = siteconfig.load_site_config()
    config.set('TT_BUILDVERSION', build)
    config.save()
    logging.info("Database now at Toolkit build %d" % build)
예제 #26
0
def view(request, path):
    siteconfig = load_site_config()
    if request.POST:
        setting_form = GeneralSettingsForm(siteconfig, data=request.POST)
        if setting_form.is_valid():
            setting_form.save()
            load_site_config()
    else:
        setting_form = GeneralSettingsForm(siteconfig)

    template = 'admin/admin_general_settings.html'
    template_vars = {
        'form': setting_form,
        'required': required_depcheck(),
        'optional': optional_depcheck(),
        'optimal': optimal_depcheck(),
        }
    return render_to_response(template, template_vars, context_instance=RequestContext(request))
예제 #27
0
파일: dbupdate.py 프로젝트: peterbe/pootle
def save_pootle_version(build=None):
    from pootle_misc import siteconfig
    if not build:
        from pootle.__version__ import build

    config = siteconfig.load_site_config()
    config.set('BUILDVERSION', build)
    config.save()
    logging.info("Database now at Pootle build %d" % build)
예제 #28
0
파일: index.py 프로젝트: JMassapina/pootle
def view(request, root_dir):
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   root_dir)
    can_edit = request.user.is_superuser

    languages = getlanguages(request)
    languages_table_fields = ['language', 'progress', 'activity']
    languages_table = {
        'id': 'index-languages',
        'proportional': False,
        'fields': languages_table_fields,
        'headings': get_table_headings(languages_table_fields),
        'items': languages,
    }

    projects = getprojects(request)
    projects_table_fields = ['project', 'progress', 'activity']
    projects_table = {
        'id': 'index-projects',
        'proportional': False,
        'fields': projects_table_fields,
        'headings': get_table_headings(projects_table_fields),
        'items': projects,
    }

    siteconfig = load_site_config()
    ctx = {
        'description': _(siteconfig.get('DESCRIPTION')),
        'keywords': [
            'Pootle',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
        ],
        'topstats': gentopstats_root(),
        'permissions': request.permissions,
        'can_edit': can_edit,
        'languages_table': languages_table,
        'projects_table': projects_table,
        'resource_obj': request.resource_obj,
        'moreprojects': (len(projects) > len(languages))
    }

    if can_edit:
        from pootle_app.forms import GeneralSettingsForm
        ctx.update({
            'form': GeneralSettingsForm(siteconfig),
            'form_action': reverse('pootle-admin-edit-settings'),
        })

    return render_to_response('home/home.html', ctx,
                              RequestContext(request))
예제 #29
0
def get_legacy_ttk_build():
    """Retrieve a Toolkit build version stored using djblets."""
    from pootle_misc.siteconfig import load_site_config

    try:
        build = int(load_site_config().get('TT_BUILDVERSION', 0))
    except DatabaseError:
        build = 0

    return build
예제 #30
0
파일: index.py 프로젝트: co310/pootle
def view(request, root_dir):
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   root_dir)
    can_edit = request.user.is_superuser

    languages = getlanguages(request)
    languages_table_fields = ['language', 'progress', 'activity']
    languages_table = {
        'id': 'index-languages',
        'proportional': False,
        'fields': languages_table_fields,
        'headings': get_table_headings(languages_table_fields),
        'items': languages,
    }

    projects = getprojects(request)
    projects_table_fields = ['project', 'progress', 'activity']
    projects_table = {
        'id': 'index-projects',
        'proportional': False,
        'fields': projects_table_fields,
        'headings': get_table_headings(projects_table_fields),
        'items': projects,
    }

    templatevars = {
        'description': _(settings.DESCRIPTION),
        'keywords': [
            'Pootle',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
        ],
        'topstats': gentopstats_root(),
        'permissions': request.permissions,
        'can_edit': can_edit,
        'languages_table': languages_table,
        'projects_table': projects_table,
        'resource_obj': request.resource_obj,
    }
    templatevars['moreprojects'] = (len(projects) > len(languages))

    if can_edit:
        from pootle_misc.siteconfig import load_site_config
        from pootle_app.forms import GeneralSettingsForm
        siteconfig = load_site_config()
        setting_form = GeneralSettingsForm(siteconfig)
        templatevars['form'] = setting_form

    return render_to_response('index/index.html', templatevars,
                              RequestContext(request))
예제 #31
0
def view(request):
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   Directory.objects.root)
    can_edit = request.user.is_superuser

    topstats = gentopstats_root()
    languages = getlanguages(request)

    templatevars = {
        'description':
        _(settings.DESCRIPTION),
        'keywords': [
            'Pootle',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
        ],
        'languages':
        languages,
        'projects':
        getprojects(request),
        'topstats':
        topstats,
        'translationlegend': {
            'translated':
            _('Translations are complete'),
            'fuzzy':
            _("Translations need to be checked "
              "(they are marked fuzzy)"),
            'untranslated':
            _('Untranslated')
        },
        'permissions':
        request.permissions,
        'can_edit':
        can_edit,
    }
    visible_langs = [l for l in languages if l['stats']['total']['words'] != 0]
    templatevars['moreprojects'] = (len(templatevars['projects']) >
                                    len(visible_langs))

    if can_edit:
        from pootle_misc.siteconfig import load_site_config
        from pootle_app.forms import GeneralSettingsForm
        siteconfig = load_site_config()
        setting_form = GeneralSettingsForm(siteconfig)
        templatevars['form'] = setting_form

    return render_to_response('index/index.html', templatevars,
                              RequestContext(request))
예제 #32
0
def get_legacy_ttk_build():
    """Retrieve a Toolkit build version stored using djblets."""
    from pootle_misc.siteconfig import load_site_config

    try:
        config = load_site_config()
        build = int(config.get('TT_BUILDVERSION', 0))
    except DatabaseError:
        build = 0

    return build
예제 #33
0
    def process_request(self, request):
        """
        load site config, return a dummy response if database seems
        uninitialized
        """
        #FIXME: can't we find a more efficient method?
        try:
            response = HttpResponse()
            response.status_code = UPDATE_STATUS_CODE

            config = siteconfig.load_site_config()
            db_buildversion = int(config.get(
                'BUILDVERSION', DEFAULT_BUILDVERSION))
            if db_buildversion < code_buildversion:
                response.db_buildversion = db_buildversion
                response.tt_buildversion = sys.maxint
            else:
                response.db_buildversion = sys.maxint

            db_tt_buildversion = int(config.get(
                'TT_BUILDVERSION', DEFAULT_TT_BUILDVERSION))
            if db_tt_buildversion < code_tt_buildversion:
                """
                Toolkit build version changed. clear stale quality checks data
                """
                logging.info(
                    "New Translate Toolkit version, flushing quality checks")
                dbupdate.flush_quality_checks()
                config.set('TT_BUILDVERSION', code_tt_buildversion)
                config.save()
                response.tt_buildversion = db_tt_buildversion

            if (response.db_buildversion, response.tt_buildversion) != (
                sys.maxint, sys.maxint):
                return response

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if e.__class__.__name__ in (
                'OperationalError', 'ProgrammingError', 'DatabaseError'):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response
예제 #34
0
def update_db():
    # get current database buildversion
    config = siteconfig.load_site_config()
    db_buildversion = config.get('BUILDVERSION', DEFAULT_BUILDVERSION)
    if db_buildversion < code_buildversion:
        logging.info("Upgrading database from schema version %d to %d", db_buildversion, code_buildversion)
        for i in staggered_update(db_buildversion):
            pass
        logging.info("Database upgrade done, current schema version %d", code_buildversion)
    else:
        logging.info("No database upgrades required, current schema version %d", db_buildversion)
예제 #35
0
def update_db():
    # get current database buildversion
    config = siteconfig.load_site_config()
    db_buildversion = config.get("BUILDVERSION", DEFAULT_BUILDVERSION)
    if db_buildversion < code_buildversion:
        logging.info("Upgrading database from schema version %d to %d", db_buildversion, code_buildversion)
        for i in staggered_update(db_buildversion, sys.maxint):
            pass
        logging.info("Database upgrade done, current schema version %d", code_buildversion)
    else:
        logging.info("No database upgrades required, current schema version %d", db_buildversion)
예제 #36
0
파일: setup.py 프로젝트: JMassapina/pootle
    def get_current_buildversion(self):
        try:
            config = siteconfig.load_site_config()
            current_buildversion = config.get('POOTLE_BUILDVERSION', None)

            if current_buildversion is None:
                # Old Pootle versions used BUILDVERSION instead.
                current_buildversion = config.get('BUILDVERSION', None)
        except DatabaseError:
            # Assume that the DatabaseError is because we have a blank database
            # from a new install, is there a better way to do this?
            current_buildversion = None

        return current_buildversion
예제 #37
0
파일: setup.py 프로젝트: Chipcius/pootle
    def handle_noargs(self, **options):
        try:
            config = siteconfig.load_site_config()
            current_buildversion = config.get('POOTLE_BUILDVERSION', None)

            if current_buildversion is None:
                # Old Pootle versions used BUILDVERSION instead.
                current_buildversion = config.get('BUILDVERSION', None)
        except DatabaseError:
            # Assume that the DatabaseError is because we have a blank database
            # from a new install, is there a better way to do this?
            current_buildversion = None

        if current_buildversion is None:
            logging.info('Setting up a new Pootle installation.')

            call_command('syncdb', interactive=False)
            call_command('migrate')
            call_command('initdb')

            logging.info('Successfully deployed new Pootle.')
        elif current_buildversion < NEW_POOTLE_BUILD:
            logging.info('Upgrading existing Pootle installation.')

            from .upgrade import DEFAULT_POOTLE_BUILDVERSION

            if current_buildversion < DEFAULT_POOTLE_BUILDVERSION:
                # Run only if Pootle is < 2.5.0.
                call_command('updatedb')

            call_command('syncdb', interactive=False)

            if current_buildversion < 25100:
                # We are upgrading from a pre-South installation (before Pootle
                # 2.5.1), so it is necessary to fake the first migration for
                # some apps.
                OLD_APPS = ("pootle_app", "pootle_language",
                            "pootle_notifications", "pootle_profile",
                            "pootle_project", "pootle_statistics",
                            "pootle_store", "pootle_translationproject",
                            "staticpages")
                for app in OLD_APPS:
                    call_command("migrate", app, "0001", fake=True)

            call_command('migrate')
            call_command('upgrade')

            logging.info('Successfully upgraded Pootle.')
        else:
            logging.info('Pootle is already up-to-date.')
예제 #38
0
파일: siteconfig.py 프로젝트: ENuge/pootle
    def process_request(self, request):
        """Load site config, return a dummy response if database seems
        uninitialized.
        """
        #FIXME: can't we find a more efficient method?
        try:
            response = HttpResponse()
            response.status_code = UPDATE_STATUS_CODE

            config = siteconfig.load_site_config()
            db_buildversion = int(config.get('BUILDVERSION',
                                             DEFAULT_BUILDVERSION))
            if db_buildversion < code_buildversion:
                response.db_buildversion = db_buildversion
                response.tt_buildversion = sys.maxint
            else:
                response.db_buildversion = sys.maxint

            db_tt_buildversion = int(config.get('TT_BUILDVERSION',
                                                DEFAULT_TT_BUILDVERSION))
            if (response.db_buildversion == sys.maxint and
                db_tt_buildversion < code_tt_buildversion):
                # Toolkit build version changed. Stale quality checks need to
                # be cleared. We can only do that safely when the db schema is
                # already up to date. The new toolkit version will be set by
                # dbupdate after it fixed things.
                response.tt_buildversion = db_tt_buildversion

            if ((response.db_buildversion, response.tt_buildversion) !=
                (sys.maxint, sys.maxint)):
                return response

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if (e.__class__.__name__ in
                ('OperationalError', 'ProgrammingError', 'DatabaseError')):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response
예제 #39
0
def post_syncdb_handler(sender, created_models, **kwargs):
    if PootleProfile in created_models:
        create_essential_users()
    if Directory in created_models:
        create_root_directory()
    if Language in created_models:
        create_template_language()
    if Project in created_models:
        create_terminology_project()
    if PermissionSet in created_models:
        create_pootle_permissions()
        create_pootle_permission_sets()
    config = siteconfig.load_site_config()
    config.set('BUILDVERSION', code_buildversion)
    config.set('TT_BUILDVERSION', code_tt_buildversion)
    config.save()
예제 #40
0
파일: adminpages.py 프로젝트: fourks/pootle
def view(request):
    siteconfig = load_site_config()

    if request.POST:
        setting_form = GeneralSettingsForm(siteconfig, data=request.POST)

        if setting_form.is_valid():
            setting_form.save()
    else:
        setting_form = GeneralSettingsForm(siteconfig)

    ctx = {
        'form': setting_form,
    }
    return render_to_response('admin/settings.html', ctx,
                              context_instance=RequestContext(request))
예제 #41
0
파일: siteconfig.py 프로젝트: notz/pootle
    def process_request(self, request):
        """load site config, return a dummy response if database seems uninitialized"""
        #FIXME: can't we find a more efficient method?
        try:
            response = HttpResponse()
            response.status_code = UPDATE_STATUS_CODE

            config = siteconfig.load_site_config()
            db_buildversion = int(
                config.get('BUILDVERSION', DEFAULT_BUILDVERSION))
            if db_buildversion < code_buildversion:
                response.db_buildversion = db_buildversion
                response.tt_buildversion = sys.maxint
            else:
                response.db_buildversion = sys.maxint

            db_tt_buildversion = int(
                config.get('TT_BUILDVERSION', DEFAULT_TT_BUILDVERSION))
            if response.db_buildversion == sys.maxint and db_tt_buildversion < code_tt_buildversion:
                # Toolkit build version changed. Stale quality checks need to
                # be cleared. We can only do that safely when the db schema is
                # already up to date. The new toolkit version will be set by
                # dbupdate after it fixed things.
                response.tt_buildversion = db_tt_buildversion

            if (response.db_buildversion,
                    response.tt_buildversion) != (sys.maxint, sys.maxint):
                return response

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if e.__class__.__name__ in ('OperationalError', 'ProgrammingError',
                                        'DatabaseError'):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response
예제 #42
0
    def handle(self, *args, **options):
        config = siteconfig.load_site_config()
        db_ptl_buildversion = config.get('POOTLE_BUILDVERSION',
                                         DEFAULT_POOTLE_BUILDVERSION)
        db_tt_buildversion = int(
            config.get('TT_BUILDVERSION', DEFAULT_TT_BUILDVERSION))
        ptl_changed = db_ptl_buildversion < code_ptl_buildversion
        tt_changed = db_tt_buildversion < code_tt_buildversion

        if ptl_changed or tt_changed:

            if ptl_changed:
                logging.info('Detected new Pootle version: %d.',
                             code_ptl_buildversion)
            else:
                db_ptl_buildversion = None

            if tt_changed:
                logging.info('Detected new Translate Toolkit version: %d.',
                             code_tt_buildversion)
            else:
                db_tt_buildversion = None

            logging.info('Running the upgrade machinery...')

            from pootle_misc.upgrade import run_upgrade
            run_upgrade(db_ptl_buildversion, code_ptl_buildversion,
                        db_tt_buildversion, code_tt_buildversion)

            if options['calculate_stats']:
                from pootle_misc.upgrade import calculate_stats
                calculate_stats()

            if options['flush_qc']:
                from pootle_misc.upgrade import flush_checks
                flush_checks()

            logging.info('Done.')
        else:
            logging.info(
                'You are already up to date! Current build versions:\n'
                '- Pootle: %s\n'
                '- Translate Toolkit: %s',
                code_ptl_buildversion,
                code_tt_buildversion,
            )
예제 #43
0
    def handle(self, *args, **options):
        config = siteconfig.load_site_config()
        db_ptl_buildversion = config.get('POOTLE_BUILDVERSION',
                                         DEFAULT_POOTLE_BUILDVERSION)
        db_tt_buildversion = int(config.get('TT_BUILDVERSION',
                                            DEFAULT_TT_BUILDVERSION))
        ptl_changed = db_ptl_buildversion < code_ptl_buildversion
        tt_changed = db_tt_buildversion < code_tt_buildversion

        if ptl_changed or tt_changed:

            if ptl_changed:
                logging.info('Detected new Pootle version: %d.',
                             code_ptl_buildversion)
            else:
                db_ptl_buildversion = None

            if tt_changed:
                logging.info('Detected new Translate Toolkit version: %d.',
                             code_tt_buildversion)
            else:
                db_tt_buildversion = None

            logging.info('Running the upgrade machinery...')

            from pootle_misc.upgrade import run_upgrade
            run_upgrade(db_ptl_buildversion, code_ptl_buildversion,
                        db_tt_buildversion, code_tt_buildversion)

            if options['calculate_stats']:
                from pootle_misc.upgrade import calculate_stats
                calculate_stats()

            if options['flush_qc']:
                from pootle_misc.upgrade import flush_checks
                flush_checks()

            logging.info('Done.')
        else:
            logging.info(
                    'You are already up to date! Current build versions:\n'
                    '- Pootle: %s\n'
                    '- Translate Toolkit: %s',
                code_ptl_buildversion, code_tt_buildversion,
            )
예제 #44
0
파일: index.py 프로젝트: qdinar/pootle
def view(request, root_dir):
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   root_dir)
    languages = getlanguages(request)
    languages_table_fields = ['language', 'progress', 'activity']
    languages_table = {
        'id': 'index-languages',
        'proportional': False,
        'fields': languages_table_fields,
        'headings': get_table_headings(languages_table_fields),
        'items': languages,
    }

    projects = getprojects(request)
    projects_table_fields = ['project', 'progress', 'activity']
    projects_table = {
        'id': 'index-projects',
        'proportional': False,
        'fields': projects_table_fields,
        'headings': get_table_headings(projects_table_fields),
        'items': projects,
    }

    siteconfig = load_site_config()
    ctx = {
        'description': _(siteconfig.get('DESCRIPTION')),
        'keywords': [
            'Pootle',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
        ],
        'topstats': gentopstats_root(),
        'permissions': request.permissions,
        'languages_table': languages_table,
        'projects_table': projects_table,
        'resource_obj': request.resource_obj,
        'moreprojects': (len(projects) > len(languages))
    }
    return render_to_response('home/home.html', ctx, RequestContext(request))
예제 #45
0
def get_legacy_ptl_build():
    """Retrieve a Pootle build version stored using djblets.

    This allows to retrieve build versions stored using the old
    POOTLE_BUILDVERSION or the even older BUILDVERSION.
    """
    from pootle_misc.siteconfig import load_site_config

    try:
        config = load_site_config()
        build = config.get('POOTLE_BUILDVERSION', 0)

        if not build:
            # Ancient Pootle versions used BUILDVERSION instead.
            build = config.get('BUILDVERSION', 0)
    except DatabaseError:
        build = 0

    return int(build)
예제 #46
0
def get_legacy_ptl_build():
    """Retrieve a Pootle build version stored using djblets.

    This allows to retrieve build versions stored using the old
    POOTLE_BUILDVERSION or the even older BUILDVERSION.
    """
    from pootle_misc.siteconfig import load_site_config

    try:
        config = load_site_config()
        build = config.get('POOTLE_BUILDVERSION', 0)

        if not build:
            # Ancient Pootle versions used BUILDVERSION instead.
            build = config.get('BUILDVERSION', 0)
    except DatabaseError:
        build = 0

    return int(build)
예제 #47
0
파일: index.py 프로젝트: SinSiXX/pootle
def view(request):
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   Directory.objects.root)
    can_edit = request.user.is_superuser

    topstats = gentopstats_root()
    languages = getlanguages(request)

    templatevars = {
        'description': _(settings.DESCRIPTION),
        'keywords': [
            'Pootle',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
            ],
        'languages': languages,
        'projects': getprojects(request),
        'topstats': topstats,
        'translationlegend': {'translated': _('Translations are complete'),
                              'fuzzy': _("Translations need to be checked "
                                         "(they are marked fuzzy)"),
                              'untranslated': _('Untranslated')},
        'permissions': request.permissions,
        'can_edit': can_edit,
        }
    visible_langs = [l for l in languages if l['stats']['total']['words'] != 0]
    templatevars['moreprojects'] = (len(templatevars['projects']) >
                                    len(visible_langs))

    if can_edit:
        from pootle_misc.siteconfig import load_site_config
        from pootle_app.forms import GeneralSettingsForm
        siteconfig = load_site_config()
        setting_form = GeneralSettingsForm(siteconfig)
        templatevars['form'] = setting_form

    return render_to_response('index/index.html', templatevars,
                              RequestContext(request))
예제 #48
0
    def process_request(self, request):
        """load site config, return a dummy response if database seems uninitialized"""
        #FIXME: can't we find a more efficient method?
        try:
            config = siteconfig.load_site_config()
            db_buildversion = config.get('BUILDVERSION', DEFAULT_BUILDVERSION)
            if db_buildversion < code_buildversion:
                response = HttpResponse()
                response.status_code = UPDATE_STATUS_CODE
                response.db_buildversion = db_buildversion
                return response

            db_tt_buildversion = config.get('TT_BUILDVERSION',
                                            DEFAULT_TT_BUILDVERSION)
            if db_tt_buildversion < code_tt_buildversion:
                """Toolkit build version changed. clear stale quality checks data"""
                logging.info(
                    "New Translate Toolkit version, flushing quality checks")
                from pootle_store.models import Store, QualityCheck, CHECKED, PARSED
                Store.objects.filter(state=CHECKED).update(state=PARSED)
                QualityCheck.objects.filter(false_positive=False).delete()
                config.set('TT_BUILDVERSION', code_tt_buildversion)
                config.save()

        except Exception, e:
            #HACKISH: since exceptions thrown by different databases
            # do not share the same class heirarchy (DBAPI2 sucks) we
            # have to check the class name instead (since python uses
            # duck typing I will call this
            # poking-the-duck-until-it-quacks-like-a-duck-test

            if e.__class__.__name__ in ('OperationalError', 'ProgrammingError',
                                        'DatabaseError'):
                # we can't build the database here cause caching
                # middleware won't allow progressive loading of
                # response so instead return an empty response marked
                # with special status code INSTALL_STATUS_CODE

                response = HttpResponse()
                response.status_code = INSTALL_STATUS_CODE
                response.exception = e
                return response
예제 #49
0
파일: initdb.py 프로젝트: Chipcius/pootle
def initdb():
    """Populate the database with default initial data.

    This creates the default database to get a working Pootle installation.
    """

    try:
        #FIXME: Should be called only if using cache on DB.
        # Create default cache table.
        call_command('createcachetable', 'pootlecache')
    except:
        pass

    create_essential_users()
    create_root_directories()
    create_template_languages()
    create_terminology_project()
    create_pootle_permissions()
    create_pootle_permission_sets()

    with transaction.commit_manually():
        try:
            create_default_projects()
            create_default_languages()
            create_default_admin()
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

    create_local_tm()

    config = siteconfig.load_site_config()
    if not config.get('POOTLE_BUILDVERSION', None):
        config.set('POOTLE_BUILDVERSION', code_buildversion)
    if not config.get('TT_BUILDVERSION', None):
        config.set('TT_BUILDVERSION', code_tt_buildversion)
    config.save()
예제 #50
0
def get_legacy_site_title():
    """Retrieve the site title from the database as stored by djblets."""
    from pootle_misc.siteconfig import load_site_config

    siteconfig = load_site_config()
    return siteconfig.get('TITLE')
예제 #51
0
 def save(self):
     super(GeneralSettingsForm, self).save()
     load_site_config()
예제 #52
0
    def update_against_templates(self, pootle_path=None):
        """Update translation project from templates."""

        if self.is_template_project:
            return

        template_translation_project = self.project \
                                           .get_template_translationproject()

        if (template_translation_project is None
                or template_translation_project == self):
            return

        monolingual = self.project.is_monolingual

        if not monolingual:
            self.sync()

        from pootle_app.project_tree import (convert_template,
                                             get_translated_name,
                                             get_translated_name_gnu)

        for store in template_translation_project.stores.iterator():
            if self.file_style == 'gnu':
                new_pootle_path, new_path = get_translated_name_gnu(
                    self, store)
            else:
                new_pootle_path, new_path = get_translated_name(self, store)

            if pootle_path is not None and new_pootle_path != pootle_path:
                continue

            try:
                from pootle.scripts import hooks
                relative_po_path = os.path.relpath(new_path,
                                                   settings.PODIRECTORY)
                if not hooks.hook(self.project.code, "pretemplateupdate",
                                  relative_po_path):
                    continue
            except:
                # Assume hook is not present.
                pass

            convert_template(self, store, new_pootle_path, new_path,
                             monolingual)

        all_files, new_files = self.scan_files(vcs_sync=False)

        from pootle_misc import versioncontrol
        project_path = self.project.get_real_path()

        if new_files and versioncontrol.hasversioning(project_path):
            from pootle.scripts import hooks
            siteconfig = load_site_config()
            message = ("New files added from %s based on templates" %
                       siteconfig.get('TITLE'))

            filestocommit = []
            for new_file in new_files:
                try:
                    hook_files = hooks.hook(self.project.code,
                                            "precommit",
                                            new_file.file.name,
                                            author=None,
                                            message=message)
                    filestocommit.extend(hook_files)
                except ImportError:
                    # Failed to import the hook - we're going to assume there
                    # just isn't a hook to import. That means we'll commit the
                    # original file.
                    filestocommit.append(new_file.file.name)

            success = True
            try:
                output = versioncontrol.add_files(project_path, filestocommit,
                                                  message)
            except Exception:
                logging.exception(u"Failed to add files")
                success = False

            for new_file in new_files:
                try:
                    hooks.hook(self.project.code,
                               "postcommit",
                               new_file.file.name,
                               success=success)
                except:
                    #FIXME: We should not hide the exception - makes
                    # development impossible
                    pass

        if pootle_path is None:
            from pootle_app.models.signals import post_template_update
            post_template_update.send(sender=self)
예제 #53
0
    def commit_dir(self, user, directory, request=None):
        """Commits files under a directory to version control.

        This does not do permission checking.
        """
        self.sync()
        total = directory.get_total_wordcount()
        translated = directory.get_translated_wordcount()
        fuzzy = directory.get_fuzzy_wordcount()
        author = user.username

        siteconfig = load_site_config()
        message = stats_message_raw(
            "Commit from %s by user %s." % (siteconfig.get('TITLE'), author),
            total, translated, fuzzy)

        # Try to append email as well, since some VCS does not allow omitting
        # it (ie. Git).
        if user.is_authenticated() and len(user.email):
            author += " <%s>" % user.email

        if directory.is_translationproject():
            stores = list(self.stores.exclude(file=""))
        else:
            stores = list(directory.stores.exclude(file=""))

        filestocommit = []

        from pootle.scripts import hooks
        for store in stores:
            try:
                filestocommit.extend(
                    hooks.hook(self.project.code,
                               "precommit",
                               store.file.name,
                               author=author,
                               message=message))
            except ImportError:
                # Failed to import the hook - we're going to assume there just
                # isn't a hook to import. That means we'll commit the original
                # file.
                filestocommit.append(store.file.name)

        success = True
        try:
            from pootle_misc import versioncontrol
            project_path = self.project.get_real_path()
            versioncontrol.add_files(project_path, filestocommit, message,
                                     author)
            # FIXME: This belongs to views
            if request is not None:
                msg = _(
                    "Committed all files under <em>%(path)s</em> to "
                    "version control", {'path': directory.pootle_path})
                messages.success(request, msg)
        except Exception as e:
            logging.exception(u"Failed to commit directory")

            # FIXME: This belongs to views
            if request is not None:
                msg = _("Failed to commit to version control: %(error)s",
                        {'error': e})
                messages.error(request, msg)

            success = False

        for store in stores:
            try:
                hooks.hook(self.project.code,
                           "postcommit",
                           store.file.name,
                           success=success)
            except:
                #FIXME: We should not hide the exception - makes development
                # impossible
                pass

        from pootle_app.models.signals import post_vc_commit
        post_vc_commit.send(sender=self,
                            path_obj=directory,
                            user=user,
                            success=success)

        return success
예제 #54
0
def update_tables_22000():
    logging.info("Updating existing database tables")

    from django.db import models

    from south.db import db

    from pootle_language.models import Language
    from pootle_misc.siteconfig import load_site_config
    from pootle_project.models import Project
    from pootle_statistics.models import Submission
    from pootle_store.models import QualityCheck, Store, Suggestion, Unit
    from pootle_translationproject.models import TranslationProject

    # For the sake of South bug 313, we set the default for these fields here:
    # See http://south.aeracode.org/ticket/313
    table_name = Suggestion._meta.db_table
    field = Suggestion._meta.get_field('translator_comment_f')
    field.default = u''
    db.add_column(table_name, field.name, field)

    table_name = Language._meta.db_table
    field = Language._meta.get_field('description')
    field.default = u''
    db.add_column(table_name, field.name, field)

    field = models.TextField(default=u'', editable=False, blank=True)
    db.add_column(table_name, 'description_html', field)

    table_name = TranslationProject._meta.db_table
    field = TranslationProject._meta.get_field('description')
    field.default = u''
    db.add_column(table_name, field.name, field)

    field = models.TextField(default=u'', editable=False, blank=True)
    db.add_column(table_name, 'description_html', field)

    table_name = Project._meta.db_table
    field = Project._meta.get_field('report_target')
    field.default = u''
    db.add_column(table_name, field.name, field)

    field = models.TextField(default=u'', editable=False, blank=True)
    db.add_column(table_name, 'description_html', field)

    table_name = QualityCheck._meta.db_table
    field = QualityCheck._meta.get_field('category')
    db.add_column(table_name, field.name, field)
    # Delete all 'hassuggestion' failures, since we don't actually use them
    # See bug 2412.
    QualityCheck.objects.filter(name="hassuggestion").delete()

    table_name = Submission._meta.db_table
    for field_name in ('unit', 'field', 'type', 'old_value', 'new_value'):
        field = Submission._meta.get_field(field_name)
        db.add_column(table_name, field.name, field)

    table_name = Unit._meta.db_table
    for field_name in ('submitted_by', 'submitted_on', 'commented_by',
                       'commented_on'):
        field = Unit._meta.get_field(field_name)
        db.add_column(table_name, field.name, field)

    table_name = Store._meta.db_table
    field = Store._meta.get_field('sync_time')
    db.add_column(table_name, field.name, field)

    # Save the legacy buildversion using djblets.
    config = load_site_config()
    config.set('POOTLE_BUILDVERSION', 22000)
    config.save()
    logging.info("Database now at Pootle build 22000")
예제 #55
0
def view(request, root_dir):
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   root_dir)
    can_edit = request.user.is_superuser

    languages = getlanguages(request)
    languages_table_fields = ['language', 'progress', 'activity']
    languages_table = {
        'id': 'index-languages',
        'proportional': False,
        'fields': languages_table_fields,
        'headings': get_table_headings(languages_table_fields),
        'items': filter(lambda x: x['stats']['total']['words'] != 0,
                        languages),
    }

    projects = getprojects(request)
    projects_table_fields = ['project', 'progress', 'activity']
    projects_table = {
        'id': 'index-projects',
        'proportional': False,
        'fields': projects_table_fields,
        'headings': get_table_headings(projects_table_fields),
        'items': projects,
    }

    templatevars = {
        'description':
        _(settings.DESCRIPTION),
        'keywords': [
            'Pootle',
            'translate',
            'translation',
            'localisation',
            'localization',
            'l10n',
            'traduction',
            'traduire',
        ],
        'topstats':
        gentopstats_root(),
        'permissions':
        request.permissions,
        'can_edit':
        can_edit,
        'languages_table':
        languages_table,
        'projects_table':
        projects_table,
    }
    visible_langs = [l for l in languages if l['stats']['total']['words'] != 0]
    templatevars['moreprojects'] = (len(projects) > len(visible_langs))

    if can_edit:
        from pootle_misc.siteconfig import load_site_config
        from pootle_app.forms import GeneralSettingsForm
        siteconfig = load_site_config()
        setting_form = GeneralSettingsForm(siteconfig)
        templatevars['form'] = setting_form

    return render_to_response('index/index.html', templatevars,
                              RequestContext(request))
예제 #56
0
def import_sitesettings(parsed_data):
    data = parsed_data.__root__._assignments
    siteconfig = load_site_config()
    siteconfig.set('TITLE', data.get('Pootle.title'))
    siteconfig.set('DESCRIPTION', data.get('Pootle.description'))
    siteconfig.save()
예제 #57
0
    def commit_file(self, user, store, request=None):
        """Commits an individual file to version control.

        This does not do permission checking.
        """
        store.sync(update_structure=False,
                   update_translation=True,
                   conservative=True)
        total = store.get_total_wordcount()
        translated = store.get_translated_wordcount()
        fuzzy = store.get_fuzzy_wordcount()
        author = user.username

        siteconfig = load_site_config()
        message = stats_message_raw("Commit from %s by user %s." % \
                (siteconfig.get('TITLE'), author), total, translated, fuzzy)

        # Try to append email as well, since some VCS does not allow omitting
        # it (ie. Git).
        if user.is_authenticated() and len(user.email):
            author += " <%s>" % user.email

        from pootle.scripts import hooks
        try:
            filestocommit = hooks.hook(self.project.code,
                                       "precommit",
                                       store.file.name,
                                       author=author,
                                       message=message)
        except ImportError:
            # Failed to import the hook - we're going to assume there just
            # isn't a hook to import. That means we'll commit the original
            # file.
            filestocommit = [store.file.name]

        success = True
        try:
            from pootle_misc import versioncontrol
            for file in filestocommit:
                versioncontrol.commit_file(file,
                                           message=message,
                                           author=author)

                # FIXME: This belongs to views
                if request is not None:
                    msg = _(
                        "Committed file <em>%(filename)s</em> to version "
                        "control", {'filename': file})
                    messages.success(request, msg)
        except Exception as e:
            logging.exception(u"Failed to commit file")

            # FIXME: This belongs to views
            if request is not None:
                msg_params = {
                    'filename': filename,
                    'error': e,
                }
                msg = _(
                    "Failed to commit <em>%(filename)s</em> to version "
                    "control: %(error)s", msg_params)
                messages.error(request, msg)

            success = False

        try:
            hooks.hook(self.project.code,
                       "postcommit",
                       store.file.name,
                       success=success)
        except:
            #FIXME: We should not hide the exception - makes development
            # impossible
            pass

        from pootle_app.models.signals import post_vc_commit
        post_vc_commit.send(sender=self,
                            path_obj=store,
                            user=user,
                            success=success)

        return success
예제 #58
0
def get_legacy_site_description():
    """Retrieve the site description from the database as stored by djblets."""
    from pootle_misc.siteconfig import load_site_config

    siteconfig = load_site_config()
    return siteconfig.get('DESCRIPTION')