<commit_before>
import logging

from django import template
from django.core.urlresolvers import reverse

from studlan.competition.models import Competition

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()

def get_sponsors(parser, token):
    return Sponsor_Renderer()

#TODO: MOVE OUT OF THIS APP
#TODO: Make something dynamic that can be configured in admin with pictures and whatnot :)
class Sponsor_Renderer(template.Node):
    def render(self, context):
        return """
<p><a href="http://datakjeden.no">Datakjeden</a></p>
<p><a href="http://outland.no">Outland</a></p>
<p><a href="http://fretex.no">Fretex</a></p>
<p><a href="http://online.ntnu.no">Online</a></p>
<p><a href="http://www.nabla.ntnu.no">Nabla</a></p>
"""

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>
								''' % (reverse("competition", args=[c.id]), unicode(c))
							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>
							''' % (reverse("competition", args=[c.id]), unicode(c), c.status_label(), c.status_text_verbose())
		except:
			#TODO: fix team participations in sidebar.
			print "TODO: fix team participations in sidebar."
			pass
		finally:
			if user_in != '':
				return '<h5>Participating in</h5>' + user_in
			else:
				return user_in

register.tag('num_of_competitions', do_num_of_competitions)
register.tag('user_in', get_competitions_user_is_participating_in)
register.tag('sponsors', get_sponsors)
<commit_msg>Removed temporary sponsor tag from competition templatetags.<commit_after>
import logging

from django import template
from django.core.urlresolvers import reverse

from studlan.competition.models import Competition

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>
								''' % (reverse("competition", args=[c.id]), unicode(c))
							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>
							''' % (reverse("competition", args=[c.id]), unicode(c), c.status_label(), c.status_text_verbose())
		except:
			#TODO: fix team participations in sidebar.
			print "TODO: fix team participations in sidebar."
			pass
		finally:
			if user_in != '':
				return '<h5>Participating in</h5>' + user_in
			else:
				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.15865800865800866, 'fraction_numerical': 0.0008658008658008658, 'mean_word_length': 4.078021978021978, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '5929345', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1558, 'n_words': 329}