Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def login(request, template):
"""Try to log the user in."""
if request.method == 'GET' and not request.MOBILE:
url = reverse('users.auth') + '?' + request.GET.urlencode()
return HttpResponsePermanentRedirect(url)
next_url = get_next_url(request) or reverse('home')
form = handle_login(request)
if request.user.is_authenticated():
# Add a parameter so we know the user just logged in.
# fpa = "first page authed" or something.
next_url = urlparams(next_url, fpa=1)
res = HttpResponseRedirect(next_url)
max_age = (None if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE
else settings.SESSION_COOKIE_AGE)
res.set_cookie(settings.SESSION_EXISTS_COOKIE,
'1',
secure=False,
max_age=max_age)
return res
if request.MOBILE:
return render(request, template, {
'form': form})
return user_auth(request, login_form=form)
Return value is a dict: {'found': boolean, 'url': string}.
found is False if the document does not exist.
"""
from kuma.wiki.models import Document
d = get_object_fallback(Document, locale=locale, title=title,
is_template=False)
if d:
return {'found': True, 'url': d.get_absolute_url(), 'text': d.title}
# To avoid circular imports, wiki.models imports wiki_to_html
from sumo.helpers import urlparams
return {'found': False,
'text': title,
'url': urlparams(reverse('wiki.new_document', locale=locale),
title=title)}
if d:
# If the article redirects use its destination article
while d.redirect_document():
d = d.redirect_document()
# The locale in the link urls should always match the current
# document's locale even if the document/slug being linked to
# is in the default locale.
url = reverse('wiki.document', locale=locale, args=[d.slug])
return {'found': True, 'url': url, 'text': d.title}
# To avoid circular imports, wiki.models imports wiki_to_html
from sumo.helpers import urlparams
return {'found': False,
'text': title,
'url': urlparams(reverse('wiki.new_document', locale=locale),
title=title)}
def get_remove_url(self):
"""Get the URL to remove an EventWatch."""
from sumo.helpers import urlparams
url_ = reverse('notifications.remove', args=[self.key])
return urlparams(url_, email=self.email)
doc_form.instance.locale = request.LANGUAGE_CODE
doc_form.instance.parent = parent_doc
if which_form == 'both':
rev_form = RevisionForm(request.POST)
# If we are submitting the whole form, we need to check that
# the Revision is valid before saving the Document.
if doc_form.is_valid() and (which_form == 'doc' or
rev_form.is_valid()):
doc = doc_form.save(parent_doc)
# Possibly schedule a rebuild.
_maybe_schedule_rebuild(doc_form)
if which_form == 'doc':
url = urlparams(reverse('wiki.edit_document',
args=[doc.slug]),
opendescription=1)
return HttpResponseRedirect(url)
doc_slug = doc_form.cleaned_data['slug']
else:
doc_form_invalid = True
else:
doc_slug = doc.slug
if doc and user_has_rev_perm and which_form in ['rev', 'both']:
rev_form = RevisionForm(request.POST)
rev_form.instance.document = doc # for rev_form.clean()
if rev_form.is_valid() and not doc_form_invalid:
if 'no-update' in request.POST:
def link(self, tag):
return urlparams(reverse('questions.questions'), tagged=tag.slug)
def private_message(user):
"""Return a link to private message the user."""
url = urlparams(reverse('messages.new'), to=user.username)
msg = _('Private message')
return Markup(u'<p class="pm"><a href="{url}">{msg}</a></p>'.format(
url=url, msg=msg))