<commit_before>from django import forms
from django_fixmystreet.fixmystreet.models import FMSUser, getLoggedInUserId
from django.contrib.auth.models import User
from django.conf import settings
from django.utils.translation import ugettext_lazy
from django.contrib.sessions.models import Session

class ManagersChoiceField (forms.fields.ChoiceField):
	def __init__(self,  *args, **kwargs):
		# assemble the opt groups.
		choices = []
		choices.append(('', ugettext_lazy("Select a manager")))
		currentUserOrganisationId = FMSUser.objects.get(pk=getLoggedInUserId(Session.objects.all()[0].session_key)).organisation
		managers = FMSUser.objects.filter(manager=True)
		managers = managers.filter(organisation_id=currentUserOrganisationId)

		for manager in managers:
			choices.append((manager.pk,manager.first_name+manager.last_name))

		super(ManagersChoiceField,self).__init__(choices,*args,**kwargs)

	def clean(self, value):
		super(ManagersChoiceField,self).clean(value)
		try:
			model = FMSUser.objects.get(pk=value)
		except FMSUser.DoesNotExist:
			raise ValidationError(self.error_messages['invalid_choice'])
		return model

class ManagersListForm(forms.Form):
	manager=ManagersChoiceField(label="")<commit_msg>Fix user not defined error for not logged in users<commit_after>from django import forms
from django_fixmystreet.fixmystreet.models import FMSUser, getLoggedInUserId
from django.contrib.auth.models import User
from django.conf import settings
from django.utils.translation import ugettext_lazy
from django.contrib.sessions.models import Session
from django.contrib.auth.decorators import login_required


class ManagersChoiceField (forms.fields.ChoiceField):
	def __init__(self,  *args, **kwargs):
		choices = []
		choices.append(('', ugettext_lazy("Select a manager")))
		currentUserOrganisationId = 1
		if Session.objects.all()[0].session_key:
			currentUserOrganisationId = FMSUser.objects.get(pk=getLoggedInUserId(Session.objects.all()[0].session_key)).organisation
		managers = FMSUser.objects.filter(manager=True)
		managers = managers.filter(organisation_id=currentUserOrganisationId)

		for manager in managers:
			choices.append((manager.pk,manager.first_name+manager.last_name))

		super(ManagersChoiceField,self).__init__(choices,*args,**kwargs)

	def clean(self, value):
		super(ManagersChoiceField,self).clean(value)
		try:
			model = FMSUser.objects.get(pk=value)
		except FMSUser.DoesNotExist:
			raise ValidationError(self.error_messages['invalid_choice'])
		return model


class ManagersListForm(forms.Form):
	manager=ManagersChoiceField(label="")
{'fraction_non_alphanumeric': 0.1044891640866873, 'fraction_numerical': 0.0015479876160990713, 'mean_word_length': 6.8810975609756095, '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': '115323', 'n_tokens_mistral': 840, 'n_tokens_neox': 781, 'n_words': 150}