How to use the weblate.trans.models.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 / billing / tests.py View on Github external
def add_project(self):
        name = 'test{0}'.format(self.projectnum)
        self.projectnum += 1
        project = Project.objects.create(
            name=name, slug=name, access_control=Project.ACCESS_PROTECTED
        )
        self.billing.projects.add(project)
        project.add_user(self.user, '@Billing')
github WeblateOrg / weblate / weblate / trans / management / commands / import_project.py View on Github external
def handle(self, *args, **options):
        """Automatic import of project."""
        # Read params
        repo = options['repo']
        branch = options['branch']
        self.parse_options(repo, options)

        # Try to get project
        try:
            project = Project.objects.get(slug=options['project'])
        except Project.DoesNotExist:
            raise CommandError(
                'Project "{0}" not found, please create it first!'.format(
                    options['project']
                )
            )

        # Get or create main component
        if is_repo_link(repo):
            try:
                component = Component.objects.get_linked(repo)
                # Avoid operating on link
                if component.is_repo_link:
                    component = component.linked_component
            except Component.DoesNotExist:
                raise CommandError(
github WeblateOrg / weblate / weblate / trans / forms.py View on Github external
def clean(self):
        access = self.cleaned_data.get('access_control')
        if access in (Project.ACCESS_PUBLIC, Project.ACCESS_PROTECTED):
            unlicensed = self.instance.component_set.filter(license='')
            if unlicensed:
                raise ValidationError(_(
                    'You must specify a license for these components '
                    'to make them publicly accessible: %s'
                ) % ', '.join(unlicensed.values_list('name', flat=True)))
github WeblateOrg / weblate / weblate / wladmin / sites.py View on Github external
self.register(AuditLog, AuditLogAdmin)
        self.register(Profile, ProfileAdmin)
        self.register(VerifiedEmail, VerifiedEmailAdmin)

        # Languages
        self.register(Language, LanguageAdmin)

        # Screenshots
        self.register(Screenshot, ScreenshotAdmin)

        # Fonts
        self.register(Font, FontAdmin)
        self.register(FontGroup, FontGroupAdmin)

        # Translations
        self.register(Project, ProjectAdmin)
        self.register(Component, ComponentAdmin)
        self.register(WhiteboardMessage, WhiteboardMessageAdmin)
        self.register(ComponentList, ComponentListAdmin)
        self.register(ContributorAgreement, ContributorAgreementAdmin)

        # Show some controls only in debug mode
        if settings.DEBUG:
            self.register(Translation, TranslationAdmin)
            self.register(Unit, UnitAdmin)
            self.register(Suggestion, SuggestionAdmin)
            self.register(Comment, CommentAdmin)
            self.register(Check, CheckAdmin)
            self.register(Dictionary, DictionaryAdmin)
            self.register(Change, ChangeAdmin)

        if settings.BILLING_ADMIN:
github WeblateOrg / weblate / weblate / auth / permissions.py View on Github external
def check_permission(user, permission, obj):
    """Generic permission check for base classes"""
    if user.is_superuser:
        return True
    query = user.groups.filter(roles__permissions__codename=permission)
    if isinstance(obj, Project):
        return query.filter(projects=obj).exists()
    if isinstance(obj, Component):
        return query.filter(
            (Q(projects=obj.project) & Q(componentlist=None))
            | Q(componentlist__components=obj)
        ).exists()
    if isinstance(obj, Translation):
        return (
            query.filter(
                (Q(projects=obj.component.project) & Q(componentlist=None))
                | Q(componentlist__components=obj.component)
            )
            .filter(languages=obj.language)
            .exists()
        )
    raise ValueError(
github WeblateOrg / weblate / weblate / utils / render.py View on Github external
kwargs['url'] = get_site_url(translation.get_absolute_url())
        kwargs['filename'] = translation.filename
        component = translation.component
        kwargs.pop('translation', None)

    if isinstance(component, Component):
        kwargs['component_name'] = component.name
        kwargs['component_slug'] = component.slug
        kwargs['component_remote_branch'] = \
            component.repository.get_remote_branch_name()
        if 'url' not in kwargs:
            kwargs['url'] = get_site_url(component.get_absolute_url())
        project = component.project
        kwargs.pop('component', None)

    if isinstance(project, Project):
        kwargs['project_name'] = project.name
        kwargs['project_slug'] = project.slug
        if 'url' not in kwargs:
            kwargs['url'] = get_site_url(project.get_absolute_url())
        kwargs.pop('project', None)

    with override('en'):
        return Template(
            template,
            engine=RestrictedEngine(),
        ).render(
            Context(kwargs, autoescape=False),
        )
github WeblateOrg / weblate / weblate / auth / models.py View on Github external
def save(self, *args, **kwargs):
        super(Group, self).save(*args, **kwargs)
        if self.language_selection == SELECTION_ALL:
            self.languages.set(Language.objects.all())
        if self.project_selection == SELECTION_ALL:
            self.projects.set(Project.objects.all())
        elif self.project_selection == SELECTION_ALL_PUBLIC:
            self.projects.set(
                Project.objects.filter(access_control=Project.ACCESS_PUBLIC),
                clear=True
            )
        elif self.project_selection == SELECTION_ALL_PROTECTED:
            self.projects.set(
                Project.objects.filter(
                    access_control__in=(
                        Project.ACCESS_PUBLIC, Project.ACCESS_PROTECTED
                    )
                ),
                clear=True
            )
        elif self.project_selection == SELECTION_COMPONENT_LIST:
            self.projects.set(
                Project.objects.filter(
                    component__componentlist=self.componentlist
                ),
                clear=True
            )
github WeblateOrg / weblate / weblate / trans / forms.py View on Github external
zipfile = forms.FileField(
        label=_('ZIP file containing translations'),
        validators=[FileExtensionValidator(allowed_extensions=['zip'])],
        widget=forms.FileInput(attrs={'accept': '.zip,application/zip'}),
    )


class ComponentInitCreateForm(CleanRepoMixin, ComponentProjectForm):
    """Component creation form.

    This is mostly copy from Component model. Probably
    should be extracted to standalone Repository model...
    """

    project = forms.ModelChoiceField(
        queryset=Project.objects.none(), label=_('Project')
    )
    vcs = forms.ChoiceField(
        label=_('Version control system'),
        help_text=_(
            'Version control system to use to access your '
            'repository with translations.'
        ),
        choices=VCS_REGISTRY.get_choices(exclude={'local'}),
        initial=settings.DEFAULT_VCS,
    )
    repo = forms.CharField(
        label=_('Source code repository'),
        max_length=REPO_LENGTH,
        help_text=_(
            'URL of a repository, use weblate://project/component '
            'for sharing with other component.'
github WeblateOrg / weblate / weblate / auth / models.py View on Github external
def projects_with_perm(self, perm):
        if self.is_superuser:
            return Project.objects.all().order()
        groups = Group.objects.filter(
            user=self, roles__permissions__codename=perm
        )
        return Project.objects.filter(group__in=groups).distinct().order()
github WeblateOrg / weblate / weblate / trans / views.py View on Github external
def delete_dictionary(request, project, lang):
    prj = get_object_or_404(Project, slug=project)
    prj.check_acl(request)
    lang = get_object_or_404(Language, code=lang)
    word = get_object_or_404(
        Dictionary,
        project=prj,
        language=lang,
        id=request.POST.get('id')
    )

    word.delete()

    return HttpResponseRedirect(reverse(
        'weblate.trans.views.show_dictionary',
        kwargs={'project': prj.slug, 'lang': lang.code})
    )