Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def reset_password_set(request):
"""Perform actual password reset."""
user = User.objects.get(pk=request.session['perform_reset'])
if user.has_usable_password():
request.session.flush()
request.session.set_expiry(None)
messages.error(request, _('Password reset has been already completed!'))
return redirect('login')
if request.method == 'POST':
form = SetPasswordForm(user, request.POST)
if form.is_valid():
request.session.set_expiry(None)
form.save(request, delete_session=True)
return redirect('login')
else:
form = SetPasswordForm(user)
return render(
request,
'accounts/reset.html',
{
'title': _('Password reset'),
'form': form,
'captcha_form': None,
def _get_queryset_language(self):
"""Filtering by language"""
if self.translation is None and 'lang' in self.request.GET:
try:
self.language = Language.objects.get(
code=self.request.GET['lang']
)
except Language.DoesNotExist:
messages.error(
self.request,
_('Failed to find matching language!')
)
def tools(request):
emailform = TestMailForm(initial={'email': request.user.email})
if request.method == 'POST':
if 'email' in request.POST:
emailform = TestMailForm(request.POST)
if emailform.is_valid():
try:
send_test_mail(**emailform.cleaned_data)
messages.success(request, _('Test e-mail sent.'))
except Exception as error:
report_error(error, request)
messages.error(request, _('Failed to send test e-mail: %s') % error)
return render(
request,
"manage/tools.html",
{'menu_items': MENU, 'menu_page': 'tools', 'email_form': emailform},
)
def remove_component(request, project, component):
obj = get_component(request, project, component)
if not request.user.has_perm('component.edit', obj):
raise PermissionDenied()
form = DeleteForm(obj, request.POST)
if not form.is_valid():
show_form_errors(request, form)
return redirect_param(obj, '#delete')
component_removal.delay(obj.pk, request.user.pk)
messages.success(
request, _('Translation component was scheduled for removal.')
)
return redirect(obj.project)
def logout(self, request, extra_context=None):
if request.method == 'POST':
messages.info(request, _('Thank you for using Weblate.'))
request.current_app = self.name
return LogoutView.as_view(next_page=reverse('admin:login'))(request)
context = self.each_context(request)
context['title'] = _('Logout')
return render(request, 'admin/logout-confirm.html', context)
try:
self.log_info("pushing to remote repo")
with self.repository.lock:
self.repository.push()
if self.id:
self.delete_alert("PushFailure")
except RepositoryException as error:
report_error(error, prefix="Could not to push the repo")
error_text = self.error_text(error)
Change.objects.create(
action=Change.ACTION_FAILED_PUSH,
component=self,
target=error_text,
user=request.user if request else None,
)
messages.error(
request, _("Could not push to remote branch on %s.") % force_text(self)
)
if self.id:
self.add_alert("PushFailure", error=error_text)
return False
Change.objects.create(
action=Change.ACTION_PUSH,
component=self,
user=request.user if request else None,
)
vcs_post_push.send(sender=self.__class__, component=self)
for component in self.linked_childs:
vcs_post_push.send(sender=component.__class__, component=component)
self.delete_alert("RepositoryChanges")
def import_message(request, count, message_none, message_ok):
if count == 0:
messages.warning(request, message_none)
else:
messages.success(request, message_ok % count)
def show_form_errors(request, form):
"""Show all form errors as a message."""
for error in form.non_field_errors():
messages.error(request, error)
for field in form:
for error in field.errors:
messages.error(
request,
_('Error in parameter %(field)s: %(error)s') % {
'field': field.name,
'error': error
}
def handle_merge(translation, request, next_unit_url):
"""Handle unit merging."""
mergeform = MergeForm(translation, request.GET)
if not mergeform.is_valid():
messages.error(request, _('Invalid merge request!'))
return None
unit = mergeform.cleaned_data['unit']
merged = mergeform.cleaned_data['merge_unit']
if not request.user.has_perm('unit.edit', unit):
messages.error(request, _('Insufficient privileges for saving translations.'))
return None
# Store unit
unit.translate(request.user, merged.target, merged.state)
# Redirect to next entry
return HttpResponseRedirect(next_unit_url)
def home(request):
"""Home page handler serving different views based on user."""
user = request.user
# This is used on Hosted Weblate to handle removed translation projects.
# The redirect itself is done in the http server.
if 'removed' in request.GET:
messages.warning(
request,
_(
'The project you were looking for has been removed, '
'however you are welcome to contribute to other ones.'
)
)
if 'show_set_password' in request.session:
messages.warning(
request,
_(
'You have activated your account, now you should set '
'the password to be able to login next time.'
)
)
return redirect('password')