How to use the weblate.utils.views.get_project function in weblate

To help you get started, we’ve selected a few weblate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WeblateOrg / weblate / weblate / trans / views / acl.py View on Github external
def check_user_form(request, project, verbose=False, form_class=UserManageForm):
    """Check project permission and UserManageForm.

    This is simple helper to perform needed validation for all
    user management views.
    """
    obj = get_project(request, project)

    if (not request.user.has_perm('project.permissions', obj)
            or obj.access_control == obj.ACCESS_CUSTOM):
        raise PermissionDenied()

    form = form_class(request.POST)

    if form.is_valid():
        return obj, form
    if verbose:
        show_form_errors(request, form)
    return obj, None
github WeblateOrg / weblate / weblate / trans / views / files.py View on Github external
def download_project(request, project):
    obj = get_project(request, project)
    obj.commit_pending("download", None)
    return download_multi(
        Translation.objects.filter(component__project=obj), request.GET.get("format")
    )
github WeblateOrg / weblate / weblate / trans / views / basic.py View on Github external
def data_project(request, project):
    obj = get_project(request, project)
    return render(
        request,
        'data.html',
        {
            'object': obj,
            'components': obj.component_set.order(),
            'project': obj,
        }
github WeblateOrg / weblate / weblate / trans / views / git.py View on Github external
def reset_project(request, project):
    obj = get_project(request, project)

    if not request.user.has_perm('vcs.reset', obj):
        raise PermissionDenied()

    return perform_reset(request, obj)
github WeblateOrg / weblate / weblate / trans / views / dictionary.py View on Github external
def download_dictionary(request, project, lang):
    """Export dictionary into various formats."""
    prj = get_project(request, project)
    lang = get_object_or_404(Language, code=lang)

    # Parse parameters
    export_format = None
    if 'format' in request.GET:
        export_format = request.GET['format']
    if export_format not in ('csv', 'po', 'tbx', 'xliff'):
        export_format = 'csv'

    # Grab all words
    words = Dictionary.objects.filter(
        project=prj,
        language=lang
    ).order()

    # Translate toolkit based export
github WeblateOrg / weblate / weblate / trans / views / basic.py View on Github external
def show_engage(request, project, lang=None):
    # Get project object, skipping ACL
    obj = get_project(request, project, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        language = get_object_or_404(Language, code=lang)
    else:
        language = None
    full_stats = obj.stats
    if language:
        try_set_language(lang)
        stats_obj = full_stats.get_single_language_stats(language)
    else:
        stats_obj = full_stats

    return render(
        request,
        'engage.html',
github WeblateOrg / weblate / weblate / accounts / views.py View on Github external
def mute_project(request, project):
    obj = get_project(request, project)
    mute_real(request.user, scope=SCOPE_PROJECT, component=None, project=obj)
    return redirect(
        '{}?notify_project={}#notifications'.format(reverse('profile'), obj.pk)
    )
github WeblateOrg / weblate / weblate / trans / feeds.py View on Github external
def get_object(self, request, project):
        return get_project(request, project)
github WeblateOrg / weblate / weblate / trans / views / acl.py View on Github external
def change_access(request, project):
    obj = get_project(request, project)

    if not request.user.has_perm('billing:project.permissions', obj):
        raise PermissionDenied()

    form = ProjectAccessForm(request.POST, instance=obj)

    if not form.is_valid():
        for error in form.errors:
            for message in form.errors[error]:
                messages.error(request, message)
    else:
        form.save()
        Change.objects.create(
            project=obj,
            action=Change.ACTION_ACCESS_EDIT,
            user=request.user,
github WeblateOrg / weblate / weblate / trans / views / search.py View on Github external
def parse_url(request, project, component=None, lang=None):
    context = {}
    if component is None:
        obj = get_project(request, project)
        unit_set = Unit.objects.filter(translation__component__project=obj)
        context['project'] = obj
    elif lang is None:
        obj = get_component(request, project, component)
        unit_set = Unit.objects.filter(translation__component=obj)
        context['component'] = obj
        context['project'] = obj.project
    else:
        obj = get_translation(request, project, component, lang)
        unit_set = obj.unit_set.all()
        context['translation'] = obj
        context['component'] = obj.component
        context['project'] = obj.component.project

    if not request.user.has_perm('unit.edit', obj):
        raise PermissionDenied()