Ejemplo n.º 1
0
def comp_delete(request, competition=None):
    """
	Delete the competition and all related objects (teams, scores, injects, services)
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    comp_obj = Competition.objects.get(compurl=competition)
    # Gets and deletes all teams associated with the competition
    team_list = Team.objects.filter(compid=comp_obj.compid)
    for i in team_list:
        i.delete()
    # Gets and deletes all services associated with the competition
    serv_list = Service.objects.filter(compid=comp_obj.compid)
    for i in serv_list:
        i.delete()
    # Gets and deletes all inject responses associated with the competition (TODO: This doesn't delete any uploaded files associated with the response)
    resp_list = InjectResponse.objects.filter(compid=comp_obj.compid)
    for i in resp_list:
        i.delete()
    # Gets and deletes all injects associated with the competition
    ijct_list = Inject.objects.filter(compid=comp_obj.compid)
    for i in ijct_list:
        i.delete()
    # Gets and deletes all scores associated with the competition
    scor_list = Score.objects.filter(compid=comp_obj.compid)
    for i in scor_list:
        i.delete()
    # Deletes the competition itself
    comp_obj.delete()
    return HttpResponseRedirect("/admin/competitions/")
Ejemplo n.º 2
0
def injects_create(request, competition = None):
	"""
	Create injects in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["action"] = "create"
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c.update(csrf(request))
	# Just displays the form if we're not handling any input
	if request.method != "POST":
		c["form"] = CreateInjectForm()
		return render_to_response('CompConfig/injects_create-edit.html', c)
	form_dict = request.POST.copy().dict()
	print form_dict
	form_dict["compid"] = c["comp_obj"].compid
	form_dict.pop('csrfmiddlewaretoken', None)
	form_dict.pop('docfile', None)
	form_obj = CreateInjectForm(form_dict)
	if not form_obj.is_valid():
		c["messages"].new_info("Invalid field data in inject form: %s" % form_obj.errors, 1001)
		return render_to_response('CompConfig/injects_create-edit.html', c)
	# Start saving the inject!
	ijct_obj = Inject(**form_dict)
	ijct_obj.save()
	# Was there a file? If so, save it!
	if 'docfile' in request.FILES:
		save_document(request.FILES['docfile'], settings.CONTENT_INJECT_PATH, ijct_obj)
	return HttpResponseRedirect("/admin/competitions/%s/injects/" % competition)
Ejemplo n.º 3
0
def injects(request, competition=None):
    """
	Display inject list for selected competition
	"""
    c = getAuthValues(request, {})
    # If the user isn't authed as a Blue Team
    if c["auth_name"] != "auth_team_blue":
        c["message"] = "You must log in as a Blue Team to view this page."
        return HttpResponseForbidden(render_to_string('status_400.html', c))
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    # If the view is disabled
    if not c["comp_obj"].teams_view_injects_enabled:
        c["message"] = "This feature is disabled for this competition."
        return HttpResponseForbidden(render_to_string('status_400.html', c))
    c["inject_list"] = []
    for i in Inject.objects.filter(compid=request.user.compid,
                                   dt_delivery__lte=timezone.now()):
        c["inject_list"].append({
            "inject":
            i,
            "files":
            Document.objects.filter(inject=i),
            "display_state":
            get_inject_display_state(request.user, i)
        })
    return render_to_response('Comp/injects.html', c)
Ejemplo n.º 4
0
def injects_edit(request, competition = None, ijctid = None):
	"""
	Edit the inject in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["action"] = "edit"
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c.update(csrf(request))
	if request.method != "POST":
		# Have to use filter here, otherwise we get 'Inject object is not iterable' errors
		ijct_obj = Inject.objects.filter(compid = c["comp_obj"].compid, ijctid = int(ijctid))
		c["ijctid"] = ijct_obj[0].ijctid
		c["form"] = CreateInjectForm(initial = ijct_obj.values()[0])
		return render_to_response('CompConfig/injects_create-edit.html', c)
	# Note this will only work when there are no lists
	tmp_dict = request.POST.copy().dict()
	tmp_dict.pop('csrfmiddlewaretoken', None)
	tmp_dict.pop('docfile', None)
	ijct_obj = Inject.objects.filter(compid = c["comp_obj"].compid, ijctid = int(ijctid))
	ijct_obj.update(**tmp_dict)
	# Was there a file? If so, save it!
	if 'docfile' in request.FILES:
		save_document(request.FILES['docfile'], settings.CONTENT_INJECT_PATH, ijct_obj)
	return HttpResponseRedirect('/admin/competitions/%s/injects/' % competition)
Ejemplo n.º 5
0
def login(request):
    """
	Page for teams to login to for a competition
	"""
    c = {}
    c["messages"] = UserMessages()
    c = getAuthValues(request, c)
    c.update(csrf(request))
    # Checks if the user is submitting the form, or requesting the form
    if request.method != "POST":
        c["form"] = {'login': TeamLoginForm()}
        return render_to_response('Comp/login.html', c)
    username = request.POST.get('username')
    password = request.POST.get('password')
    compid = request.POST.get('compid')
    team = auth.authenticate(username=username,
                             password=password,
                             compid=compid)
    if team == None:
        c["messages"].new_info("Incorrect team credentials.", 4321)
        c["form"] = {'login': TeamLoginForm()}
        return HttpResponseBadRequest(render_to_string('Comp/login.html', c))
    auth.login(request, team)
    competition = Competition.objects.get(compid=compid)
    return HttpResponseRedirect("/competitions/%s/summary/" %
                                competition.compurl)
Ejemplo n.º 6
0
def servicemodule_delete(request, servmdulid=None):
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    servmdul_obj = ServiceModule.objects.get(servmdulid=servmdulid)
    servmdul_obj.delete()
    return HttpResponseRedirect("/admin/servicemodules/")
Ejemplo n.º 7
0
def teams_create(request, competition = None):
	"""
	Create the team in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["action"] = "create"
	c["form"] = CreateTeamForm()
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c.update(csrf(request))
	if request.method != "POST":
		# Get a list of the services
		c["service_configs_list"] = buildTeamServiceConfigForms(c["comp_obj"].compid)
		return render_to_response('CompConfig/teams_create-edit.html', c)
	form_dict = request.POST.copy()
	form_dict["compid"] = c["comp_obj"].compid
	form_dict["score_configs"] = buildTeamServiceConfigDict(c["comp_obj"].compid, form_dict)
	# Clean network address
	if form_dict['networkaddr'][-1] == ".":
		form_dict['networkaddr'] = form_dict['networkaddr'][:-1]
	if form_dict['networkaddr'][0] == ".":
		form_dict['networkaddr'] = form_dict['networkaddr'][1:]
	team = CreateTeamForm(form_dict)
	if not team.is_valid():
		return render_to_response('CompConfig/teams_create-edit.html', c)
	team.save()
	return HttpResponseRedirect("/admin/competitions/%s/teams/" % competition)
Ejemplo n.º 8
0
def teams_edit(request, competition=None, teamid=None):
    """
	Edit the team in the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["action"] = "edit"
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c.update(csrf(request))
    if request.method != "POST":
        team_obj = Team.objects.filter(compid=c["comp_obj"].compid,
                                       teamid=int(teamid))
        c["teamid"] = team_obj[0].teamid
        c["form"] = CreateTeamForm(initial=team_obj.values()[0])
        c["service_configs_list"] = buildTeamServiceConfigForms(
            c["comp_obj"].compid, team_obj[0].score_configs)
        return render_to_response('CompConfig/teams_create-edit.html', c)
    form_dict = request.POST.copy().dict()
    form_dict.pop('csrfmiddlewaretoken', None)
    form_dict["compid"] = c["comp_obj"].compid
    form_dict["score_configs"] = buildTeamServiceConfigDict(
        c["comp_obj"].compid, form_dict)
    # Clean network address
    if form_dict['networkaddr'][-1] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][:-1]
    if form_dict['networkaddr'][0] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][1:]
    team_obj = Team.objects.filter(compid=c["comp_obj"].compid,
                                   teamid=int(teamid))
    team_obj.update(**form_dict)
    return HttpResponseRedirect('/admin/competitions/%s/teams/' % competition)
Ejemplo n.º 9
0
def home(request):
	c = {}
	c["messages"] = UserMessages()
	c = getAuthValues(request, c)
	if c["auth_name"] == "auth_team_blue":
		c["competition_object"] = Competition.objects.get(compid = request.user.compid)
	return render_to_response('home.html', c)
Ejemplo n.º 10
0
def injects_edit(request, competition = None, ijctid = None):
	"""
	Edit the inject in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["action"] = "edit"
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c.update(csrf(request))
	if request.method != "POST":
		# Have to use filter here, otherwise we get 'Inject object is not iterable' errors
		ijct_obj = Inject.objects.filter(compid = c["comp_obj"].compid, ijctid = int(ijctid))
		c["ijctid"] = ijct_obj[0].ijctid
		c["form"] = CreateInjectForm(initial = ijct_obj.values()[0])
		return render_to_response('CompConfig/injects_create-edit.html', c)
	# Note this will only work when there are no lists
	form_dict = request.POST.copy().dict()
	form_dict.pop('csrfmiddlewaretoken', None)
	form_dict.pop('docfile', None)
	if 'require_response' in form_dict:
		form_dict['require_response'] = True
	else:
		form_dict['require_response'] = False
		form_dict['dt_response_due'] = None
		form_dict['dt_response_close'] = None
	ijct_obj = Inject.objects.filter(compid = c["comp_obj"].compid, ijctid = int(ijctid))
	ijct_obj.update(**form_dict)
	# Was there a file? If so, save it!
	if 'docfile' in request.FILES:
		save_document(request.FILES['docfile'], settings.CONTENT_INJECT_PATH, ijct_obj)
	return HttpResponseRedirect('/admin/competitions/%s/injects/' % competition)
Ejemplo n.º 11
0
def teams_create(request, competition=None):
    """
	Create the team in the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["action"] = "create"
    c["form"] = CreateTeamForm()
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c.update(csrf(request))
    if request.method != "POST":
        # Get a list of the services
        c["service_configs_list"] = buildTeamServiceConfigForms(
            c["comp_obj"].compid)
        return render_to_response('CompConfig/teams_create-edit.html', c)
    form_dict = request.POST.copy()
    form_dict["compid"] = c["comp_obj"].compid
    form_dict["score_configs"] = buildTeamServiceConfigDict(
        c["comp_obj"].compid, form_dict)
    # Clean network address
    if form_dict['networkaddr'][-1] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][:-1]
    if form_dict['networkaddr'][0] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][1:]
    team = CreateTeamForm(form_dict)
    if not team.is_valid():
        return render_to_response('CompConfig/teams_create-edit.html', c)
    team.save()
    return HttpResponseRedirect("/admin/competitions/%s/teams/" % competition)
Ejemplo n.º 12
0
def scoreboard(request, competition = None):
	"""
	Display the list of scores for the selected team of the selected competition
	"""
	c = getAuthValues(request, {})
	# If the user isn't authed as a Blue Team
	if c["auth_name"] != "auth_team_blue":
		c["message"] = "You must log in as a Blue Team to view this page."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	# If the view is disabled
	if not c["comp_obj"].teams_view_scoreboard_enabled:
		c["message"] = "This feature is disabled for this competition."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c.update(csrf(request))
	c["scores"] = []
	if request.POST and request.POST['service'] != u'-1' :
		c["form"] = ServiceSelectionForm(initial = {"service": request.POST['service']}, compid = request.user.compid)
		scores_obj_list = Score.objects.filter(compid = request.user.compid, teamid = request.user.teamid, servid = request.POST['service'])
		for i in scores_obj_list:
			c["scores"].append({
				"time": i.datetime,
				"name": Service.objects.get(servid = i.servid).name,
				"value": i.value
			})
	else:
		c["form"] = ServiceSelectionForm(compid = request.user.compid)
		scores_obj_list = Score.objects.filter(compid = request.user.compid, teamid = request.user.teamid)
		for i in scores_obj_list:
			c["scores"].append({
				"time": i.datetime,
				"name": Service.objects.get(servid = i.servid).name,
				"value": i.value
			})
	return render_to_response('Comp/scoreboard.html', c)
Ejemplo n.º 13
0
def servicemodule_edit(request, servmdulid = None):
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c.update(csrf(request))
	c["action"] = "edit"
	if request.method != "POST":
		servmdul_obj = ServiceModule.objects.filter(servmdulid = servmdulid)
		c["servmdulid"] = servmdul_obj[0].servmdulid
		c["docfile"] = Document.objects.get(servicemodule = servmdul_obj[0])
		c["form"] = CreateServiceModuleForm(initial = servmdul_obj.values()[0])
		return render_to_response('AdminConfig/servicemodule_create-edit.html', c)
	form_obj = CreateServiceModuleForm(request.POST, request.FILES)
	if 'docfile' in request.FILES and form_obj.is_valid():
		form_obj.cleaned_data.pop('docfile', None)
		servmdul_obj = ServiceModule.objects.filter(servmdulid = servmdulid)
		servmdul_obj.update(**form_obj.cleaned_data)
		docfile = Document.objects.get(servicemodule = servmdul_obj[0].servmdulid)
		docfile.delete()
		save_document(request.FILES['docfile'], settings.CONTENT_PLUGGINS_PATH, servmdul_obj[0], ashash = False)
		return HttpResponseRedirect('/admin/servicemodules/')
	else:
		# Not exactly giving the user an error message here (TODO)
		print "there were errors"
		c["form"] = CreateServiceModuleForm()
		return render_to_response('AdminConfig/servicemodule_create-edit.html', c)
Ejemplo n.º 14
0
def servicemodule_delete(request, servmdulid = None):
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	servmdul_obj = ServiceModule.objects.get(servmdulid = servmdulid)
	servmdul_obj.delete()
	return HttpResponseRedirect("/admin/servicemodules/")
Ejemplo n.º 15
0
def servicemodule_edit(request, servmdulid=None):
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c.update(csrf(request))
    c["action"] = "edit"
    if request.method != "POST":
        servmdul_obj = ServiceModule.objects.filter(servmdulid=servmdulid)
        c["servmdulid"] = servmdul_obj[0].servmdulid
        c["docfile"] = Document.objects.get(servicemodule=servmdul_obj[0])
        c["form"] = CreateServiceModuleForm(initial=servmdul_obj.values()[0])
        return render_to_response('AdminConfig/servicemodule_create-edit.html',
                                  c)
    form_obj = CreateServiceModuleForm(request.POST, request.FILES)
    if 'docfile' in request.FILES and form_obj.is_valid():
        form_obj.cleaned_data.pop('docfile', None)
        servmdul_obj = ServiceModule.objects.filter(servmdulid=servmdulid)
        servmdul_obj.update(**form_obj.cleaned_data)
        docfile = Document.objects.get(
            servicemodule=servmdul_obj[0].servmdulid)
        docfile.delete()
        save_document(request.FILES['docfile'],
                      settings.CONTENT_PLUGGINS_PATH,
                      servmdul_obj[0],
                      ashash=False)
        return HttpResponseRedirect('/admin/servicemodules/')
    else:
        # Not exactly giving the user an error message here (TODO)
        print "there were errors"
        c["form"] = CreateServiceModuleForm()
        return render_to_response('AdminConfig/servicemodule_create-edit.html',
                                  c)
Ejemplo n.º 16
0
def teams_edit(request, competition = None, teamid = None):
	"""
	Edit the team in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["action"] = "edit"
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c.update(csrf(request))
	if request.method != "POST":
		team_obj = Team.objects.filter(compid = c["comp_obj"].compid, teamid = int(teamid))
		c["teamid"] = team_obj[0].teamid
		c["form"] = CreateTeamForm(initial = team_obj.values()[0])
		c["service_configs_list"] = buildTeamServiceConfigForms(c["comp_obj"].compid, team_obj[0].score_configs)
		return render_to_response('CompConfig/teams_create-edit.html', c)
	form_dict = request.POST.copy().dict()
	form_dict.pop('csrfmiddlewaretoken', None)
	form_dict["compid"] = c["comp_obj"].compid
	form_dict["score_configs"] = buildTeamServiceConfigDict(c["comp_obj"].compid, form_dict)
	# Clean network address
	if form_dict['networkaddr'][-1] == ".":
		form_dict['networkaddr'] = form_dict['networkaddr'][:-1]
	if form_dict['networkaddr'][0] == ".":
		form_dict['networkaddr'] = form_dict['networkaddr'][1:]
	team_obj = Team.objects.filter(compid = c["comp_obj"].compid, teamid = int(teamid))
	team_obj.update(**form_dict)
	return HttpResponseRedirect('/admin/competitions/%s/teams/' % competition)
Ejemplo n.º 17
0
def servicemodule_create(request):
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    if request.method != "POST":
        c.update(csrf(request))
        c["action"] = "create"
        c["form"] = CreateServiceModuleForm()
        return render_to_response('AdminConfig/servicemodule_create-edit.html',
                                  c)
    form_obj = CreateServiceModuleForm(request.POST, request.FILES)
    if 'docfile' in request.FILES and form_obj.is_valid():
        form_obj.cleaned_data.pop('docfile', None)
        servmdul_obj = ServiceModule(**form_obj.cleaned_data)
        servmdul_obj.save()
        save_document(request.FILES['docfile'],
                      settings.CONTENT_PLUGGINS_PATH,
                      servmdul_obj,
                      ashash=False)
    else:
        # Not exactly giving the user an error message here (TODO)
        c.update(csrf(request))
        c["action"] = "create"
        c["form"] = CreateServiceModuleForm()
        return render_to_response('AdminConfig/servicemodule_create-edit.html',
                                  c)
    return HttpResponseRedirect('/admin/servicemodules/')
Ejemplo n.º 18
0
def comp_delete(request, competition = None):
	"""
	Delete the competition and all related objects (teams, scores, injects, services)
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	comp_obj = Competition.objects.get(compurl = competition)
	# Gets and deletes all teams associated with the competition
	team_list = Team.objects.filter(compid = comp_obj.compid)
	for i in team_list:
		i.delete()
	# Gets and deletes all services associated with the competition
	serv_list = Service.objects.filter(compid = comp_obj.compid)
	for i in serv_list:
		i.delete()
	# Gets and deletes all inject responses associated with the competition (TODO: This doesn't delete any uploaded files associated with the response)
	resp_list = InjectResponse.objects.filter(compid = comp_obj.compid)
	for i in resp_list:
		i.delete()
	# Gets and deletes all injects associated with the competition
	ijct_list = Inject.objects.filter(compid = comp_obj.compid)
	for i in ijct_list:
		i.delete()
	# Gets and deletes all scores associated with the competition
	scor_list = Score.objects.filter(compid = comp_obj.compid)
	for i in scor_list:
		i.delete()
	# Deletes the competition itself
	comp_obj.delete()
	return HttpResponseRedirect("/admin/competitions/")
Ejemplo n.º 19
0
def users_delete(request):
    """
	Delete site or competition administrative users
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    return HttpResponseRedirect('/admin/users/')
Ejemplo n.º 20
0
def home(request):
    """
	Page displayed after loggin in
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    return render_to_response('AdminConfig/home.html', c)
Ejemplo n.º 21
0
def logout(request, competition=None):
    """
	Page for teams to logout of a competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] == "auth_team_blue":
        auth.logout(request)
    return HttpResponseRedirect("/")
Ejemplo n.º 22
0
def users_delete(request):
	"""
	Delete site or competition administrative users
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	return HttpResponseRedirect('/admin/users/')
Ejemplo n.º 23
0
def site_config(request):
    """
	Displays configuration options for the overall site
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    return render_to_response('AdminConfig/home.html', c)
Ejemplo n.º 24
0
def site_config(request):
	"""
	Displays configuration options for the overall site
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	return render_to_response('AdminConfig/home.html', c)
Ejemplo n.º 25
0
def home(request):
	"""
	Page displayed after loggin in
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	return render_to_response('AdminConfig/home.html', c)
Ejemplo n.º 26
0
def users_create(request):
    """
	Create site or competition administrative users
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    return render_to_response('AdminConfig/users_create.html', c)
Ejemplo n.º 27
0
def logout(request, competition = None):
	"""
	Page for teams to logout of a competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] == "auth_team_blue":
		auth.logout(request)
	return HttpResponseRedirect("/")
Ejemplo n.º 28
0
def home(request):
    c = {}
    c["messages"] = UserMessages()
    c = getAuthValues(request, c)
    if c["auth_name"] == "auth_team_blue":
        c["competition_object"] = Competition.objects.get(
            compid=request.user.compid)
    return render_to_response('home.html', c)
Ejemplo n.º 29
0
def users_create(request):
	"""
	Create site or competition administrative users
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	return render_to_response('AdminConfig/users_create.html', c)
Ejemplo n.º 30
0
def comp_list(request):
	"""
	Displays list of competitions, add and remove competition options
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["competition_list"] = Competition.objects.all()
	return render_to_response('AdminConfig/competition_list.html', c)
Ejemplo n.º 31
0
def comp_list(request):
    """
	Displays list of competitions, add and remove competition options
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["competition_list"] = Competition.objects.all()
    return render_to_response('AdminConfig/competition_list.html', c)
Ejemplo n.º 32
0
def details(request, competition = None):
	"""
	Display details about the selected competition
	"""
	c = getAuthValues(request, {})
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c["services"] = Service.objects.filter(compid = c["comp_obj"].compid)
	c["teams"] = Team.objects.filter(compid = c["comp_obj"].compid)
	return render_to_response('Comp/details.html', c)
Ejemplo n.º 33
0
def details(request, competition=None):
    """
	Display details about the selected competition
	"""
    c = getAuthValues(request, {})
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c["services"] = Service.objects.filter(compid=c["comp_obj"].compid)
    c["teams"] = Team.objects.filter(compid=c["comp_obj"].compid)
    return render_to_response('Comp/details.html', c)
Ejemplo n.º 34
0
def injects_respond(request, competition = None, ijctid = None):
	"""
	Displays a specific inject and provides either upload or text entry for inject response
	"""
	c = getAuthValues(request, {})
	# If the user isn't authed as a Blue Team
	if c["auth_name"] != "auth_team_blue":
		c["message"] = "You must log in as a Blue Team to view this page."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	# If the view is disabled
	if not c["comp_obj"].teams_view_injects_enabled:
		c["message"] = "This feature is disabled for this competition."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c.update(csrf(request))
	# If we're not getting POST data, serve the page normally
	if request.method != "POST":
		ijct_obj = Inject.objects.get(compid = c["comp_obj"].compid, ijctid = ijctid)
		if not ijct_obj.require_response:
			return HttpResponseRedirect('/competitions/%s/injects/' % (competition))
		c["inject"] = {
			"ijct_obj": ijct_obj,
			"files": Document.objects.filter(inject = ijctid),
			"display_state": get_inject_display_state(request.user, ijct_obj)
		}
		c["response_list"] = []
		for i in InjectResponse.objects.filter(compid = c["comp_obj"].compid, teamid = request.user.teamid, ijctid = ijctid):
			c["response_list"].append({
				"response": i,
				"files": Document.objects.filter(injectresponse = i)
			})
		if c["inject"]["ijct_obj"].dt_response_close <= timezone.now():
			c["response_locked"] = True
		else:
			c["response_locked"] = False
			c["responseform"] = InjectResponseForm()
		return render_to_response('Comp/injects_view_respond.html', c)
	# Check if we're allowed to take the submission (time restrictions)
	ijct_obj = Inject.objects.get(compid = c["comp_obj"].compid, ijctid = ijctid)
	if not ijct_obj.require_response:
		return HttpResponseRedirect('/competitions/%s/injects/' % (competition))
	if ijct_obj.dt_response_close <= timezone.now():
		# Very clever person - submission form was closed, but they're attempting to POST anyway
		return HttpResponseRedirect('/competitions/%s/injects/%s/' % (competition, ijctid))
	# Determine if we're handling text entry or file upload
	tmp_dict = request.POST.copy().dict()
	tmp_dict.pop('csrfmiddlewaretoken', None)
	tmp_dict.pop('docfile', None)
	tmp_dict['compid'] = request.user.compid
	tmp_dict['teamid'] = request.user.teamid
	tmp_dict['ijctid'] = int(ijctid)
	ijct_resp_obj = InjectResponse(**tmp_dict)
	ijct_resp_obj.save()
	# Checks if we were given a file
	if 'docfile' in request.FILES:
		save_document(request.FILES['docfile'], settings.CONTENT_INJECT_REPONSE_PATH, ijct_resp_obj)
	return HttpResponseRedirect('/competitions/%s/injects/%s/' % (competition, ijctid))
Ejemplo n.º 35
0
def verify_user(ad, id_name):
	c = getAuthValues(ad['request'], {})
	# Only white team and blue team may access these files
	if c["auth_name"] != "auth_team_white" and c["auth_name"] != "auth_team_blue":
		print "you're not properly authenticated"
		return HttpResponse()
	# Limits blue teams to accessing only their own inject files
	if c["auth_name"] == "auth_team_blue" and ad['request'].user.compid != int(ad['compid']):
		print "you're blue team, trying to access other peoples documents"
		return HttpResponse()
Ejemplo n.º 36
0
def teams_list(request, competition=None):
    """
	Lists the teams in the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c["teams"] = Team.objects.filter(compid=c["comp_obj"].compid)
    return render_to_response('CompConfig/teams_list.html', c)
Ejemplo n.º 37
0
def teams_list(request, competition = None):
	"""
	Lists the teams in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c["teams"] = Team.objects.filter(compid = c["comp_obj"].compid)
	return render_to_response('CompConfig/teams_list.html', c)
Ejemplo n.º 38
0
def services_delete(request, competition = None, servid = None):
	"""
	Deletes the service from the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	comp_obj = Competition.objects.get(compurl = competition)
	serv_obj = Service.objects.get(compid = comp_obj.compid, servid = int(servid))
	serv_obj.delete()
	return HttpResponseRedirect("/admin/competitions/%s/services/" % competition)
Ejemplo n.º 39
0
def servicemodule_list(request):
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["module_list"] = []
	for i in ServiceModule.objects.all():
		c["module_list"].append({
			"module": i,
			"file": Document.objects.get(servicemodule = i)
		})
	return render_to_response('AdminConfig/servicemodule_list.html', c)
Ejemplo n.º 40
0
def services_list(request, competition = None):
	"""
	Lists the services in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c["service_list"] = Service.objects.filter(compid = c["comp_obj"].compid)
	c["available_modules"] = bool(len(ServiceModule.objects.all()))
	return render_to_response('CompConfig/services_list.html', c)
Ejemplo n.º 41
0
def services_delete(request, competition = None, servid = None):
	"""
	Deletes the service from the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	comp_obj = Competition.objects.get(compurl = competition)
	serv_obj = Service.objects.get(compid = comp_obj.compid, servid = int(servid))
	serv_obj.delete()
	return HttpResponseRedirect("/admin/competitions/%s/services/" % competition)
Ejemplo n.º 42
0
def servicemodule_list(request):
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["module_list"] = []
    for i in ServiceModule.objects.all():
        c["module_list"].append({
            "module": i,
            "file": Document.objects.get(servicemodule=i)
        })
    return render_to_response('AdminConfig/servicemodule_list.html', c)
Ejemplo n.º 43
0
def teams_delete(request, competition = None, teamid = None):
	"""
	Delete the team from the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	comp_obj = Competition.objects.get(compurl = competition)
	team_obj = Team.objects.get(compid=comp_obj.compid, teamid=int(teamid))
	team_obj.delete()
	return HttpResponseRedirect("/admin/competitions/%s/teams/" % competition)
Ejemplo n.º 44
0
def teams_delete(request, competition=None, teamid=None):
    """
	Delete the team from the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    comp_obj = Competition.objects.get(compurl=competition)
    team_obj = Team.objects.get(compid=comp_obj.compid, teamid=int(teamid))
    team_obj.delete()
    return HttpResponseRedirect("/admin/competitions/%s/teams/" % competition)
Ejemplo n.º 45
0
def services_list(request, competition=None):
    """
	Lists the services in the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c["service_list"] = Service.objects.filter(compid=c["comp_obj"].compid)
    c["available_modules"] = bool(len(ServiceModule.objects.all()))
    return render_to_response('CompConfig/services_list.html', c)
Ejemplo n.º 46
0
def summary(request, competition=None):
    """
	Display summary information for selected competition
	"""
    current_url = request.build_absolute_uri()
    if request.build_absolute_uri()[-8:] != "summary/":
        return HttpResponseRedirect(current_url + "summary/")
    c = getAuthValues(request, {})
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c["services"] = Service.objects.filter(compid=c["comp_obj"].compid)
    c["teams"] = Team.objects.filter(compid=c["comp_obj"].compid)
    return render_to_response('Comp/summary.html', c)
Ejemplo n.º 47
0
def comp_summary(request, competition = None):
	"""
	Displays general competitions configurations form
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	current_url = request.build_absolute_uri()
	if request.build_absolute_uri()[-8:] != "summary/":
		return HttpResponseRedirect(current_url + "summary/")
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	return render_to_response('CompConfig/summary.html', c)
Ejemplo n.º 48
0
def verify_user(ad, id_name):
    c = getAuthValues(ad['request'], {})
    # Only white team and blue team may access these files
    if c["auth_name"] != "auth_team_white" and c[
            "auth_name"] != "auth_team_blue":
        print "you're not properly authenticated"
        return HttpResponse()
    # Limits blue teams to accessing only their own inject files
    if c["auth_name"] == "auth_team_blue" and ad['request'].user.compid != int(
            ad['compid']):
        print "you're blue team, trying to access other peoples documents"
        return HttpResponse()
Ejemplo n.º 49
0
def summary(request, competition = None):
	"""
	Display summary information for selected competition
	"""
	current_url = request.build_absolute_uri()
	if request.build_absolute_uri()[-8:] != "summary/":
		return HttpResponseRedirect(current_url + "summary/")
	c = getAuthValues(request, {})
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c["services"] = Service.objects.filter(compid = c["comp_obj"].compid)
	c["teams"] = Team.objects.filter(compid = c["comp_obj"].compid)
	return render_to_response('Comp/summary.html', c)
Ejemplo n.º 50
0
def comp_summary(request, competition=None):
    """
	Displays general competitions configurations form
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    current_url = request.build_absolute_uri()
    if request.build_absolute_uri()[-8:] != "summary/":
        return HttpResponseRedirect(current_url + "summary/")
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    return render_to_response('CompConfig/summary.html', c)
Ejemplo n.º 51
0
def incidentresponse_respond(request, competition=None, intrspid=None):
    c = getAuthValues(request, {})
    # If the user isn't authed as a Blue Team
    if c["auth_name"] != "auth_team_blue":
        c["message"] = "You must log in as a Blue Team to view this page."
        return HttpResponseForbidden(render_to_string('status_400.html', c))
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    # If the view is disabled
    if not c["comp_obj"].teams_view_incidentresponse_enabled:
        c["message"] = "This feature is disabled for this competition."
        return HttpResponseForbidden(render_to_string('status_400.html', c))
    c.update(csrf(request))
    # Get any already opened intrusion responses
    c["responseform"] = IncidentResponseReplyForm()
    c["firstpost"] = {
        "response": IncidentResponse.objects.get(intrspid=intrspid),
        "files": Document.objects.filter(incidentresponse=intrspid)
    }
    c["response_list"] = []
    for i in IncidentResponse.objects.filter(compid=request.user.compid,
                                             teamid=request.user.teamid,
                                             replyto=intrspid):
        c["response_list"].append({
            "response":
            i,
            "files":
            Document.objects.filter(incidentresponse=i)
        })
    # If we're not getting POST data, serve the page normally
    if request.method != "POST":
        c["responseform"] = IncidentResponseReplyForm()
        return render_to_response('Comp/incidentresponse_view_respond.html', c)
    # Checks if form is valid, and if so, builds model
    form = IncidentResponseReplyForm(request.POST)
    if not form.is_valid():
        print form.errors
        #TODO: This is technically failing without raising an error for the user
        return render_to_response('Comp/incidentresponse_view_respond.html', c)
    intresp_obj = IncidentResponse()
    intresp_obj.compid = c["comp_obj"].compid
    intresp_obj.teamid = request.user.teamid
    intresp_obj.datetime = timezone.now()
    intresp_obj.textentry = form.cleaned_data['textentry']
    intresp_obj.replyto = intrspid
    intresp_obj.save()
    # Was there a file? If so, save it!
    if 'docfile' in request.FILES:
        save_document(request.FILES['docfile'],
                      settings.CONTENT_INCIDENT_REPONSE_PATH, intresp_obj)
    return HttpResponseRedirect('/competitions/%s/incidentresponse/%s/' %
                                (c["comp_obj"].compurl, str(intrspid)))
Ejemplo n.º 52
0
def servicestatistics(request, competition = None):
	"""
	Display status timeline of services for selected team in selected competition
	"""
	c = getAuthValues(request, {})
	# If the user isn't authed as a Blue Team
	if c["auth_name"] != "auth_team_blue":
		c["message"] = "You must log in as a Blue Team to view this page."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	# If the view is disabled
	if not c["comp_obj"].teams_view_servicestatistics_enabled:
		c["message"] = "This feature is disabled for this competition."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	# Prepare page for statistics view selector
	c.update(csrf(request))
	c["form"] = ServiceSelectionForm(compid = c["comp_obj"].compid)
	score_obj_list = []
	if request.POST and request.POST['service'] != u'-1':
		c["form"] = ServiceSelectionForm(initial = {"service": request.POST['service']}, compid = c["comp_obj"].compid)
		comp_seconds = int((c["comp_obj"].datetime_finish - c["comp_obj"].datetime_start).total_seconds())
		score_obj_list = Score.objects.filter(compid = request.user.compid, teamid = request.user.teamid, servid = request.POST['service'])
		if len(score_obj_list) > 0:
			prev_date = score_obj_list[0].datetime
			total_percent = 0
			c["score_vals"] = []
			for i in score_obj_list[1:]:
				diff = int((i.datetime - prev_date).total_seconds())
				percentage = 100 * float(diff) / float(comp_seconds)
				if total_percent + percentage > 100:
					percentage = 100 - total_percent
				total_percent += percentage
				prev_date = i.datetime
				c["score_vals"].append({"value":i.value,"percentage": percentage})
	else:
		score_obj_list = Score.objects.filter(compid = request.user.compid, teamid = request.user.teamid)
	# Prepare data for chart_overall_uptime
	chart_score_up = 0
	chart_score_down = 0
	for i in score_obj_list:
		if i.value == 0:
			chart_score_down += 1
		else:
			chart_score_up += 1
	c["score_pie_chart"] = [
		{"value":chart_score_up,"color":"#46BFBD","highlight":"#5AD3D1","label":"Scored Up"},
		{"value":chart_score_down,"color":"#F7464A","highlight":"#FF5A5E","label":"Scored Down"}
	]
	total_scores = chart_score_up + chart_score_down
	return render_to_response('Comp/servicestatistics.html', c)
Ejemplo n.º 53
0
def injects_list(request, competition = None):
	"""
	Lists the injects in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c["inject_list"] = []
	for i in Inject.objects.filter(compid = c["comp_obj"].compid):
		c["inject_list"].append({
			"inject": i,
			"files": Document.objects.filter(inject = i)
		})
	return render_to_response('CompConfig/injects_list.html', c)
Ejemplo n.º 54
0
def injects_list(request, competition=None):
    """
	Lists the injects in the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c["inject_list"] = []
    for i in Inject.objects.filter(compid=c["comp_obj"].compid):
        c["inject_list"].append({
            "inject": i,
            "files": Document.objects.filter(inject=i)
        })
    return render_to_response('CompConfig/injects_list.html', c)
Ejemplo n.º 55
0
def injects_delete(request, competition = None, ijctid = None):
	"""
	Deletes the inject from the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	comp_obj = Competition.objects.get(compurl = competition)
	# Delete any responses to the inject (TODO: this doesn't delete uploaded files)
	response_objs = InjectResponse.objects.filter(compid = comp_obj.compid, ijctid = int(ijctid))
	for i in response_objs:
		i.delete()
	# Deletes the inject itself
	ijct_obj = Inject.objects.filter(compid = comp_obj.compid, ijctid = int(ijctid))
	ijct_obj.delete()
	return HttpResponseRedirect("/admin/competitions/%s/injects/" % competition)
Ejemplo n.º 56
0
def injects_delete(request, competition = None, ijctid = None):
	"""
	Deletes the inject from the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	comp_obj = Competition.objects.get(compurl = competition)
	# Delete any responses to the inject (TODO: this doesn't delete uploaded files)
	response_objs = InjectResponse.objects.filter(compid = comp_obj.compid, ijctid = int(ijctid))
	for i in response_objs:
		i.delete()
	# Deletes the inject itself
	ijct_obj = Inject.objects.filter(compid = comp_obj.compid, ijctid = int(ijctid))
	ijct_obj.delete()
	return HttpResponseRedirect("/admin/competitions/%s/injects/" % competition)
Ejemplo n.º 57
0
def comp_settings(request, competition=None):
    """
	Displays competitions details form
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c.update(csrf(request))
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    form_initial = Competition.objects.filter(
        compid=c['comp_obj'].compid).values()[0]
    c["forms"] = {
        "general_settings":
        CompetitionSettingsGeneralForm(initial=form_initial),
        "scoring_settings":
        CompetitionSettingsScoringForm(initial=form_initial),
        "service_settings":
        CompetitionSettingsServiceForm(initial=form_initial),
        "team_settings": CompetitionSettingsTeamForm(initial=form_initial)
    }
    if request.POST:
        forms_list = [
            CompetitionSettingsGeneralForm, CompetitionSettingsScoringForm,
            CompetitionSettingsServiceForm, CompetitionSettingsTeamForm
        ]
        f = forms_list[int(request.POST['form_num'])](request.POST)
        if f.is_valid():
            comp_obj = Competition.objects.filter(compid=c['comp_obj'].compid)
            clean_copy = f.cleaned_data
            for i in clean_copy:
                if clean_copy[i] == u'':
                    clean_copy[i] = None
            comp_obj.update(**clean_copy)
            # Schedules the job to start the scoring engine
            sec_until_start = (comp_obj[0].datetime_start -
                               timezone.now()).seconds
            result = run_comp.apply_async((comp_obj[0].compid, ),
                                          countdown=int(sec_until_start))
            logger.debug(
                'Scheduled competition: Seconds until start: %s, Event UUID: %s'
                % (str(sec_until_start), str(result.id)))
        else:
            logger.error("is not valid")
        return HttpResponseRedirect('/admin/competitions/%s/settings/' %
                                    c["comp_obj"].compurl)
    return render_to_response('CompConfig/settings.html', c)
Ejemplo n.º 58
0
def incidentresponse_respond(request, competition = None, intrspid = None):
	c = getAuthValues(request, {})
	# If the user isn't authed as a Blue Team
	if c["auth_name"] != "auth_team_blue":
		c["message"] = "You must log in as a Blue Team to view this page."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	# If the view is disabled
	if not c["comp_obj"].teams_view_incidentresponse_enabled:
		c["message"] = "This feature is disabled for this competition."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c.update(csrf(request))
	# Get any already opened intrusion responses
	c["responseform"] = IncidentResponseReplyForm()
	c["firstpost"] = {
		"response": IncidentResponse.objects.get(intrspid = intrspid),
		"files": Document.objects.filter(incidentresponse = intrspid)
		}
	c["response_list"] = []
	for i in IncidentResponse.objects.filter(compid = request.user.compid, teamid = request.user.teamid, replyto = intrspid):
		c["response_list"].append({
			"response": i,
			"files": Document.objects.filter(incidentresponse = i)
		})
	# If we're not getting POST data, serve the page normally
	if request.method != "POST":
		c["responseform"] = IncidentResponseReplyForm()
		return render_to_response('Comp/incidentresponse_view_respond.html', c)
	# Checks if form is valid, and if so, builds model
	form = IncidentResponseReplyForm(request.POST)
	if not form.is_valid():
		print form.errors
		#TODO: This is technically failing without raising an error for the user
		return render_to_response('Comp/incidentresponse_view_respond.html', c)
	intresp_obj = IncidentResponse()
	intresp_obj.compid = c["comp_obj"].compid
	intresp_obj.teamid = request.user.teamid
	intresp_obj.datetime = timezone.now()
	intresp_obj.textentry = form.cleaned_data['textentry']
	intresp_obj.replyto = intrspid
	intresp_obj.save()
	# Was there a file? If so, save it!
	if 'docfile' in request.FILES:
		save_document(request.FILES['docfile'], settings.CONTENT_INCIDENT_REPONSE_PATH, intresp_obj)
	return HttpResponseRedirect('/competitions/%s/incidentresponse/%s/' % (c["comp_obj"].compurl, str(intrspid)))
Ejemplo n.º 59
0
def ranking(request, competition = None):
	"""
	Display team rankings for selected competition
	"""
	c = getAuthValues(request, {})
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	# If the view is disabled
	if not c["comp_obj"].teams_view_ranking_enabled:
		c["message"] = "This feature is disabled for this competition."
		return HttpResponseForbidden(render_to_string('status_400.html', c))
	c["ranks"] = []
	team_objs = Team.objects.filter(compid = c["comp_obj"].compid)
	for i in team_objs:
		scores_objs = Score.objects.filter(compid = c["comp_obj"].compid, teamid = i.teamid)
		total = 0
		for k in scores_objs:
			total += k.value
		c["ranks"].append({"team": i.teamname, "score": total, "place":0})		
	return render_to_response('Comp/rankings.html', c)
Ejemplo n.º 60
0
def comp_create(request, competition=None):
	"""
	Creates a new competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	# Checks if the user is submitting the form, or requesting the form
	if request.method != "POST":
		c.update(csrf(request))
		c["form"] = CompetitionSettingsGeneralForm()
		return render_to_response('AdminConfig/competition_create.html', c)
	form_comp = CompetitionSettingsGeneralForm(request.POST)
	# Checks that submitted form data is valid
	if not form_comp.is_valid():
		print form_comp.errors
		return render(request, 'AdminConfig/competition_create.html', c)
	# Create the new competition
	Competition(**form_comp.cleaned_data).save()
	return HttpResponseRedirect('/admin/competitions/')