Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_affects_unrelated(self):
"""Unrelated objects test.
If I set an ACL on an object, it should not affect objects
that it doesn't match. (in this case, a different language)
"""
lang_cs = Language.objects.get(code='cs')
lang_de = Language.objects.get(code='de')
trans_cs = Translation.objects.create(
component=self.component, language=lang_cs,
plural=lang_cs.plural,
filename="this/is/not/a.template"
)
trans_de = Translation.objects.create(
component=self.component, language=lang_de,
plural=lang_de.plural,
filename="this/is/not/a.template"
)
acl = GroupACL.objects.create(language=lang_cs)
acl.groups.add(self.group)
self.assertTrue(can_edit(self.privileged, trans_cs, self.PERMISSION))
def test_profile(self):
# Get profile page
response = self.client.get(reverse('profile'))
self.assertContains(response, 'action="/accounts/profile/"')
# Save profile
response = self.client.post(
reverse('profile'),
{
'language': 'cs',
'languages': Language.objects.get(code='cs').id,
'secondary_languages': Language.objects.get(code='cs').id,
'first_name': 'First Last',
'email': 'noreply@weblate.org',
'username': 'testik',
}
)
self.assertRedirects(response, reverse('profile'))
def count_languages(self):
return (
Language.objects.filter(
translation__component__project__in=self.projects.all()
)
def show_languages(request):
if request.user.has_perm('language.edit'):
languages = Language.objects.all()
else:
languages = Language.objects.have_translation()
return render(
request,
'languages.html',
{
'allow_index': True,
'languages': prefetch_stats(sort_objects(languages)),
'title': _('Languages'),
'global_stats': GlobalStats(),
},
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
)
def update_languages(profile, userprofile):
"""Update user language preferences."""
profile.language = userprofile['language']
for lang in userprofile['secondary_languages']:
profile.secondary_languages.add(Language.objects.auto_get_or_create(lang))
for lang in userprofile['languages']:
profile.languages.add(Language.objects.auto_get_or_create(lang))
def handle(self, *args, **options):
"""Create default set of languages."""
kwargs = {}
if options["verbosity"] >= 1:
kwargs["logger"] = self.stdout.write
Language.objects.setup(options["update"], **kwargs)
return render(
request,
'component.html',
{
'allow_index': True,
'object': obj,
'project': obj.project,
'translations': sort_objects(
prefetch_stats(obj.translation_set.prefetch())
),
'reports_form': ReportsForm(),
'last_changes': last_changes,
'last_changes_url': urlencode(
{'component': obj.slug, 'project': obj.project.slug}
),
'language_count': Language.objects.filter(
translation__component=obj
).distinct().count(),
'replace_form': optional_form(ReplaceForm, user, 'unit.edit', obj),
'bulk_state_form': optional_form(
BulkStateForm, user, 'translation.auto', obj,
user=user, obj=obj
),
'whiteboard_form': optional_form(
WhiteboardForm, user, 'component.edit', obj
),
'delete_form': optional_form(
DeleteForm, user, 'component.edit', obj, obj=obj
),
'rename_form': optional_form(
ComponentRenameForm, user, 'component.edit', obj,
request=request, instance=obj
def __init__(self, component, *args, **kwargs):
super(MatrixLanguageForm, self).__init__(*args, **kwargs)
languages = Language.objects.filter(translation__component=component)
self.fields['lang'].choices = sort_choices(
[(l.code, '{0} ({1})'.format(force_text(l), l.code)) for l in languages]
)
)
if not self.discovery.matched_files:
raise CommandError('Your mask did not match any files!')
self.logger.info(
'Found %d components',
len(self.discovery.matched_components)
)
langs = set()
for match in self.discovery.matched_components.values():
langs.update(match['languages'])
self.logger.info('Found %d languages', len(langs))
# Do some basic sanity check on languages
if Language.objects.filter(code__in=langs).count() == 0:
raise CommandError(
'None of matched languages exists, maybe you have '
'mixed * and ** in the mask?'
)
return self.discovery