<commit_before>import django.shortcuts
from django.conf import settings
import django.contrib.auth
import django.contrib.auth.forms
import django.core.exceptions
import django.core.urlresolvers
import django.utils.http
import django.views.generic

# pylint: disable=too-many-ancestors

class ViewDecoratorMixin(object):
	decorators = []

	@classmethod
	def as_view(cls, **initkwargs):
		view = super(ViewDecoratorMixin, cls).as_view(**initkwargs)

		for decorator in cls.get_decorators():
			view = decorator(view)

		return view

	@classmethod
	def get_decorators(cls):
		if not cls.decorators:
			raise django.core.exceptions.ImproperlyConfigured(
				"ViewDecoratorMixin requires you to either set the 'decorators'"
				" class attribute or override the 'get_decorators' method."
			)

		return cls.decorators

class LoginView(django.views.generic.FormView):
	form_class          = django.contrib.auth.forms.AuthenticationForm
	redirect_field_name = 'next'

	def get(self, request, *args, **kwargs):
		if request.user.is_authenticated():
			return django.shortcuts.redirect(self.get_success_url())

		return super(LoginView, self).get(request, *args, **kwargs)

	def get_success_url(self):
		request_params = self.request.POST

		default = settings.LOGIN_REDIRECT_URL

		if self.redirect_field_name in request_params:
			url = request_params[self.redirect_field_name]

			if not django.utils.http.is_safe_url(url, host = self.request.get_host()):
				url = default
		else:
			url = default<commit_msg>Include the redirect name for login in context<commit_after>import django.shortcuts
from django.conf import settings
import django.contrib.auth
import django.contrib.auth.forms
import django.core.exceptions
import django.core.urlresolvers
import django.utils.http
import django.views.generic

# pylint: disable=too-many-ancestors

class ViewDecoratorMixin(object):
	decorators = []

	@classmethod
	def as_view(cls, **initkwargs):
		view = super(ViewDecoratorMixin, cls).as_view(**initkwargs)

		for decorator in cls.get_decorators():
			view = decorator(view)

		return view

	@classmethod
	def get_decorators(cls):
		if not cls.decorators:
			raise django.core.exceptions.ImproperlyConfigured(
				"ViewDecoratorMixin requires you to either set the 'decorators'"
				" class attribute or override the 'get_decorators' method."
			)

		return cls.decorators

class LoginView(django.views.generic.FormView):
	form_class          = django.contrib.auth.forms.AuthenticationForm
	redirect_field_name = 'next'

	def get_context_data(self, **kwargs):
		context = super(LoginView, self).get_context_data(**kwargs)

		context[self.redirect_field_name] = self.request.GET[self.redirect_field_name]

		return context

	def get(self, request, *args, **kwargs):
		if request.user.is_authenticated():
			return django.shortcuts.redirect(self.get_success_url())

		return super(LoginView, self).get(request, *args, **kwargs)

	def get_success_url(self):
		request_params = self.request.POST

		default = settings.LOGIN_REDIRECT_URL

		if self.redirect_field_name in request_params:
			url = request_params[self.redirect_field_name]

			if not django.utils.http.is_safe_url(url, host = self.request.get_host()):
				url = default
		else:
			url = default
{'fraction_non_alphanumeric': 0.0986740672217083, 'fraction_numerical': 0.0, 'mean_word_length': 4.974217311233886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4396558', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1019, 'n_words': 226}