<commit_before>from django import template
from studlan.competition.models import Competition, Team

register = template.Library()

#--- For competition ---



#--- For sidebar ---

def do_num_of_competitions(parser, token):
	#tag_name, format_string = token.split_contents()
	
	return Competition_Renderer(len(Competition.objects.all()))

def get_competitions_user_is_participating_in(parser, token):
	return Competition_Participation_Renderer()

class Competition_Renderer(template.Node):
	def __init__(self, num_of_competitions):
		self.num_of_competitions = num_of_competitions
	def render(self, context):
		return self.num_of_competitions

class Competition_Participation_Renderer(template.Node):
	#def __init__(self):
	def render(self, context):
		user_in = ''
		#try:
		for c in Competition.objects.all():
			if c.use_teams:
				for t in c.teams.all():
					if context['request'].user == t.leader or context['request'].user in t.members:
						user_in += '''
							<dt><a href="%s">%s</a></dt>
							<dd>
							''' % ('/competitions/'+str(c.id)+'/', c.title)
						user_in += 'As [%s]%s<br/>' % (t.tag, t.title)
						user_in += '''
							<span class="label %s">%s</span></dd>
							''' % (c.status_label(), c.status_text_verbose())
			else:
				if context['request'].user in c.participants.all():
					user_in += '''
				    	<dt><a href="%s">%s</a></dt>
						<dd>As self<br/><span class="label %s">%s</span></dd>
						''' % ('/competitions/'+str(c.id)+'/', c.title, c.status_label(), c.status_text_verbose())
		#except:
		#		pass
		return user_in

register.tag('num_of_competitions', do_num_of_competitions)
register.tag('user_in', get_competitions_user_is_participating_in)<commit_msg>Try/Caught an error I don't get. Functionality is as expected though.<commit_after>from django import template
from studlan.competition.models import Competition, Team

register = template.Library()

#--- For competition ---



#--- For sidebar ---

def do_num_of_competitions(parser, token):
	#tag_name, format_string = token.split_contents()
	
	return Competition_Renderer(len(Competition.objects.all()))

def get_competitions_user_is_participating_in(parser, token):
	return Competition_Participation_Renderer()

class Competition_Renderer(template.Node):
	def __init__(self, num_of_competitions):
		self.num_of_competitions = num_of_competitions
	def render(self, context):
		return self.num_of_competitions

class Competition_Participation_Renderer(template.Node):
	#def __init__(self):
	def render(self, context):
		user_in = ' '
		# TODO Fix this derp
		try:
			for c in Competition.objects.all():
				if c.use_teams:
					for t in c.teams.all():
						if context['request'].user == t.leader or context['request'].user in t.members:
							user_in += '''
								<dt><a href="%s">%s</a></dt>
								<dd>
								''' % ('/competitions/'+str(c.id)+'/', c.title)
							user_in += 'As [%s]%s<br/>' % (t.tag, t.title)
							user_in += '''
								<span class="label %s">%s</span></dd>
								''' % (c.status_label(), c.status_text_verbose())
				else:
					if context['request'].user in c.participants.all():
						user_in += '''
					    	<dt><a href="%s">%s</a></dt>
							<dd>As self<br/><span class="label %s">%s</span></dd>
							''' % ('/competitions/'+str(c.id)+'/', c.title, c.status_label(), c.status_text_verbose())
		except:
			pass
		finally:
			return user_in

register.tag('num_of_competitions', do_num_of_competitions)
register.tag('user_in', get_competitions_user_is_participating_in)
{'fraction_non_alphanumeric': 0.16552706552706553, 'fraction_numerical': 0.0, 'mean_word_length': 4.037302725968436, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '5929346', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1210, 'n_words': 228}