you can create and join team + eventplayer and team profile
This commit is contained in:
parent
46dbc7182d
commit
ba38df3b33
|
@ -41,7 +41,7 @@
|
|||
<div class="d-none d-md-block col-10 col-md-3 right-sidebar">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">{{ user.username }}</li>
|
||||
<li class="list-group-item">{% trans "Score" %} : {{ user.userprofileinfo.score }}</li>
|
||||
<li class="list-group-item">{% trans "Score" %} : {{ score }}</li>
|
||||
<li class="list-group-item">{% trans "Rank" %} : {{ rank }}</li>
|
||||
{% if user.userprofileinfo.portfolio_site %}
|
||||
<li class="list-group-item">
|
||||
|
|
|
@ -144,7 +144,7 @@ def profile(request, user_name):
|
|||
somme += s.ctf.points
|
||||
solved.append([s.flag_date.timestamp() * 1000,somme])
|
||||
|
||||
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas, 'rank': rank})
|
||||
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas, 'rank': rank, 'score' : somme})
|
||||
|
||||
def rank(request, token):
|
||||
all_users = UserProfileInfo.objects.filter(score__gt=0).select_related().order_by('-score', 'last_submission_date', 'user__username')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from .models import Event, Scores, EventPlayer, Team
|
||||
from .models import Event, EventPlayer, Team
|
||||
|
||||
#admin.site.register(Event)
|
||||
#admin.site.register(Scores)
|
||||
|
@ -11,7 +11,7 @@ class event(admin.ModelAdmin):
|
|||
# search list
|
||||
search_fields = ['name', 'slug', 'description', 'password']
|
||||
|
||||
@admin.register(Scores)
|
||||
@admin.register(EventPlayer)
|
||||
class score(admin.ModelAdmin):
|
||||
#list display
|
||||
list_display = ['user', 'event', 'score']
|
||||
|
@ -31,11 +31,11 @@ class team(admin.ModelAdmin):
|
|||
# search list
|
||||
search_fields = ['name']
|
||||
|
||||
@admin.register(EventPlayer)
|
||||
class eventplayer(admin.ModelAdmin):
|
||||
#list display
|
||||
list_display = ['user', 'event', 'team']
|
||||
#list Filter
|
||||
list_filter = ('event', 'team__name')
|
||||
# search list
|
||||
search_fields = ['user__username', 'event__name']
|
||||
# @admin.register(EventPlayer)
|
||||
# class eventplayer(admin.ModelAdmin):
|
||||
# #list display
|
||||
# list_display = ['user', 'event', 'team']
|
||||
# #list Filter
|
||||
# list_filter = ('event', 'team__name')
|
||||
# # search list
|
||||
# search_fields = ['user__username', 'event__name']
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.1.5 on 2021-12-15 21:05
|
||||
# Generated by Django 3.1.5 on 2021-12-27 15:40
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -14,6 +14,7 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel('Scores', 'EventPlayer'),
|
||||
migrations.CreateModel(
|
||||
name='Team',
|
||||
fields=[
|
||||
|
@ -23,20 +24,7 @@ class Migration(migrations.Migration):
|
|||
('size', models.PositiveIntegerField(default=1)),
|
||||
('score', models.PositiveIntegerField(db_index=True, default=0)),
|
||||
('last_submission_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Last Submission Date')),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='scores',
|
||||
name='id',
|
||||
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='EventPlayer',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.event')),
|
||||
('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.team')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('event', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='events.event')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1,19 +0,0 @@
|
|||
# Generated by Django 3.1.5 on 2021-12-15 21:24
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('events', '0004_auto_20211215_2105'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='eventplayer',
|
||||
name='team',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='events.team'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 3.1.5 on 2021-12-27 15:56
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('events', '0004_auto_20211227_1540'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='event',
|
||||
name='team_size',
|
||||
field=models.PositiveIntegerField(default=1),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='eventplayer',
|
||||
name='team',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='events.team'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='eventplayer',
|
||||
name='id',
|
||||
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
]
|
|
@ -1,19 +0,0 @@
|
|||
# Generated by Django 3.1.5 on 2021-12-15 22:16
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('events', '0005_auto_20211215_2124'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='team',
|
||||
name='event',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='events.event'),
|
||||
),
|
||||
]
|
|
@ -14,17 +14,10 @@ class Event(models.Model):
|
|||
end_date = models.DateTimeField()
|
||||
password = models.CharField(max_length=200, blank=True)
|
||||
slug = models.SlugField(max_length=55)
|
||||
team_size = models.PositiveIntegerField(default=1)
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Scores(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
score = models.PositiveIntegerField(default=0, db_index=True)
|
||||
last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
|
||||
class Meta:
|
||||
ordering = ['-score', 'last_submission_date', 'user__username']
|
||||
|
||||
class Team(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
password = models.CharField(max_length=200)
|
||||
|
@ -38,7 +31,10 @@ class Team(models.Model):
|
|||
class EventPlayer(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
# score = models.PositiveIntegerField(default=0, db_index=True)
|
||||
# last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
|
||||
score = models.PositiveIntegerField(default=0, db_index=True)
|
||||
last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
|
||||
team = models.ForeignKey(Team, on_delete=models.CASCADE, null=True)
|
||||
class Meta:
|
||||
ordering = ['-score', 'last_submission_date', 'user__username']
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="ctf-block">
|
||||
<div class="ctf-head">
|
||||
<h3>{{ event.name }}</h3>
|
||||
<small>{% trans "This event start at" %} : {{ event.start_date }}</small>
|
||||
<small>{% trans "This event starts at" %} : {{ event.start_date }}</small>
|
||||
</div>
|
||||
|
||||
<div class="ctf-footer">
|
||||
|
@ -18,6 +18,8 @@
|
|||
<span class="message error-msg">{% trans "Team does not exist." %}</span>
|
||||
{% elif wrongpwd == True %}
|
||||
<span class="message error-msg">{% trans "Wrong password submited." %}</span>
|
||||
{% elif max == True %}
|
||||
<span class="message error-msg">{% trans "Maximum size reached." %}</span>
|
||||
{% endif %}
|
||||
<h2>Create Team</h2>
|
||||
<form method="post" action="{% url 'events:create_team' event_slug=event.slug %}" class="create-team-form">
|
||||
|
@ -25,8 +27,6 @@
|
|||
<div class="form-group">
|
||||
<input class="form-control" type="text" name="teamname" placeholder="{% trans "Team name" %} *" maxlength="150" required="" id="id_teamname"></br>
|
||||
<input class="form-control" type="password" name="password" placeholder="{% trans "Password" %} *" required="" id="id_password"></br>
|
||||
<!-- <input class="form-control" type="email" name="email" placeholder="pleasedontgivemy@private.infos*" required="" maxlength="254" id="id_email"></br> -->
|
||||
<!-- <input class="form-control" type="url" name="portfolio_site" placeholder="{% trans "Personal website" %}"maxlength="200" id="id_portfolio_site"></br> -->
|
||||
<input type="submit" name="" class="form-control" value="{% trans "Create Team" %}">
|
||||
</div>
|
||||
</form>
|
||||
|
@ -36,8 +36,6 @@
|
|||
<div class="form-group">
|
||||
<input class="form-control" type="text" name="teamname" placeholder="{% trans "Team name" %} *" maxlength="150" required="" id="id_teamname"></br>
|
||||
<input class="form-control" type="password" name="password" placeholder="{% trans "Password" %} *" required="" id="id_password"></br>
|
||||
<!-- <input class="form-control" type="email" name="email" placeholder="pleasedontgivemy@private.infos*" required="" maxlength="254" id="id_email"></br> -->
|
||||
<!-- <input class="form-control" type="url" name="portfolio_site" placeholder="{% trans "Personal website" %}"maxlength="200" id="id_portfolio_site"></br> -->
|
||||
<input type="submit" name="" class="form-control" value="{% trans "Join Team" %}">
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -74,11 +74,19 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for s in solved_list %}
|
||||
{% if event.team_size == 1%}
|
||||
<tr>
|
||||
<th scope="row"><a class="profile_link" href="{% url 'accounts:profile' user_name=s.user.username %}"> {{ s.user.username }}</a></th>
|
||||
<td>{{ s.user.userprofileinfo.portfolio_site }}</td>
|
||||
<td>{{ s.flag_date }}</td>
|
||||
<th scope="row"><a class="profile_link" href="{% url 'events:profile' user_name=s.user.username %}"> {{ s.0.username }}</a></th>
|
||||
<td>{{ s.0.userprofileinfo.portfolio_site }}</td>
|
||||
<td>{{ s.1 }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<th scope="row"><a class="profile_link" href="{% url 'events:team_info' name=s.2 event_slug=event.slug %}"> {{ s.2 }}</a></th>
|
||||
<td></td>
|
||||
<td>{{ s.1 }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
<div>
|
||||
<h4>{% trans "ScoreBoard" %}</h4>
|
||||
{% if solved_list %}
|
||||
{% if event.team_size == 1 %}
|
||||
<table class="table table-dark">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -69,7 +70,7 @@
|
|||
<tr>
|
||||
<th scope="row"># {{ forloop.counter0|add:1 }}</th>
|
||||
<th scope="row">
|
||||
<a class="profile_link" href="{% url 'accounts:profile' user_name=s.user.username %}"> {{ s.user.username }}</a>
|
||||
<a class="profile_link" href="{% url 'events:profile' user_name=s.user.username event_slug=event.slug %}"> {{ s.user.username }}</a>
|
||||
</th>
|
||||
<td>{{ s.user.userprofileinfo.site }}</td>
|
||||
<td>{{ s.score }}</td>
|
||||
|
@ -78,6 +79,28 @@
|
|||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<table class="table table-dark">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{% trans "Rank" %}</th>
|
||||
<th scope="col">{% trans "Team" %}</th>
|
||||
<th scope="col">{% trans "Score" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for s in solved_list %}
|
||||
<tr>
|
||||
<th scope="row"># {{ forloop.counter0|add:1 }}</th>
|
||||
<th scope="row">
|
||||
<a class="profile_link" href="{% url 'events:team_info' name=s.name event_slug=event.slug %}"> {{ s.name }}</a>
|
||||
</th>
|
||||
<td>{{ s.score }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p>{% trans "No one have earn point yet, you gonna be the first ?" %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{% load i18n %}
|
||||
{% load key_value %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-9">
|
||||
<div>
|
||||
<h4>Challenges Solved by {{ team.name }}</h4>
|
||||
{% if solves%}
|
||||
|
||||
<div class="table table-dark">
|
||||
<div class="card-body">
|
||||
<div id="time-chart"></div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-dark">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{% trans "Challenge Name" %}</th>
|
||||
<th scope="col">{% trans "Category" %}</th>
|
||||
<th scope="col">{% trans "Points" %}</th>
|
||||
<th scope="col">{% trans "Date" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for s in solves %}
|
||||
<tr>
|
||||
<th scope="row"><a href="{% url 'ctf' cat_slug=s.ctf.category.slug ctf_slug=s.ctf.slug %}">{{ s.ctf.name }}</a></th>
|
||||
<td>{{ s.ctf.category.name}}</td>
|
||||
<td>{{ s.ctf.points }}</td>
|
||||
<td>{{ s.flag_date|date:"Y-m-d H:i:s" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>{% trans "It seems that this team has not solved any challenge yet..." %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-none d-md-block col-10 col-md-3 right-sidebar">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">{{ team.name }}</li>
|
||||
<li class="list-group-item">{% trans "Score" %} : {{ score }}</li>
|
||||
<li class="list-group-item">{% trans "Rank" %} : {{ rank }}</li>
|
||||
</ul>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">{% trans "Members" %}</li>
|
||||
{% for user in users %}
|
||||
<li class="list-group-item"><a class="profile_link" href="{% url 'accounts:profile' user_name=user.username %}">{{ user.username }}</a></li>
|
||||
{% endfor %}
|
||||
|
||||
</ul>
|
||||
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">{% trans "Categories stats" %}</li>
|
||||
{% for cat in catsDatas %}
|
||||
<li class="list-group-item" style="padding-bottom: 3;padding-top: 0;">
|
||||
<span>{{ cat.0 }}</span>
|
||||
<div class="progress">
|
||||
{% if cat.3 == '0' %}
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 0%;color:#d9d9d9;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0 %</div>
|
||||
{% else %}
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: {{ cat.3 }}%" aria-valuenow="{{ cat.3 }}" aria-valuemin="0" aria-valuemax="100">{{ cat.3 }} %</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://code.highcharts.com/highcharts.src.js"></script>
|
||||
<script>
|
||||
Highcharts.theme={colors:["#2b908f","#90ee7e","#f45b5b","#7798BF","#aaeeee","#ff0066","#eeaaee","#55BF3B","#DF5353","#7798BF","#aaeeee"],chart:{backgroundColor:{linearGradient:{x1:0,y1:0,x2:1,y2:1},stops:[[0,"#1D1D1D"],[1,"#1D1D1D"]]},style:{fontFamily:"'Unica One', sans-serif"},plotBorderColor:"#606063"},title:{style:{color:"#E0E0E3",textTransform:"uppercase",fontSize:"20px"}},subtitle:{style:{color:"#E0E0E3",textTransform:"uppercase"}},xAxis:{gridLineColor:"#707073",labels:{style:{color:"#E0E0E3"}},lineColor:"#707073",minorGridLineColor:"#505053",tickColor:"#707073",title:{style:{color:"#A0A0A3"}}},yAxis:{gridLineColor:"#707073",labels:{style:{color:"#E0E0E3"}},lineColor:"#707073",minorGridLineColor:"#505053",tickColor:"#707073",tickWidth:1,title:{style:{color:"#A0A0A3"}}},tooltip:{backgroundColor:"rgba(0, 0, 0, 0.85)",style:{color:"#F0F0F0"}},plotOptions:{series:{dataLabels:{color:"#F0F0F3",style:{fontSize:"13px"}},marker:{lineColor:"#333"}},boxplot:{fillColor:"#505053"},candlestick:{lineColor:"white"},errorbar:{color:"white"}},legend:{backgroundColor:"#1D1D1D",itemStyle:{color:"#E0E0E3"},itemHoverStyle:{color:"#FFF"},itemHiddenStyle:{color:"#606063"},title:{style:{color:"#C0C0C0"}}},credits:{style:{color:"#666"}},labels:{style:{color:"#707073"}},drilldown:{activeAxisLabelStyle:{color:"#F0F0F3"},activeDataLabelStyle:{color:"#F0F0F3"}},navigation:{buttonOptions:{symbolStroke:"#DDDDDD",theme:{fill:"#505053"}}},rangeSelector:{buttonTheme:{fill:"#505053",stroke:"#000000",style:{color:"#CCC"},states:{hover:{fill:"#707073",stroke:"#000000",style:{color:"white"}},select:{fill:"#000003",stroke:"#000000",style:{color:"white"}}}},inputBoxBorderColor:"#505053",inputStyle:{backgroundColor:"#333",color:"silver"},labelStyle:{color:"silver"}},navigator:{handles:{backgroundColor:"#666",borderColor:"#AAA"},outlineColor:"#CCC",maskFill:"rgba(255,255,255,0.1)",series:{color:"#7798BF",lineColor:"#A6C7ED"},xAxis:{gridLineColor:"#505053"}},scrollbar:{barBackgroundColor:"#808083",barBorderColor:"#808083",buttonArrowColor:"#CCC",buttonBackgroundColor:"#606063",buttonBorderColor:"#606063",rifleColor:"#FFF",trackBackgroundColor:"#404043",trackBorderColor:"#404043"}};
|
||||
|
||||
Highcharts.setOptions(Highcharts.theme);
|
||||
|
||||
Highcharts.chart('time-chart', {
|
||||
title: {
|
||||
text: 'Points earned for each category'
|
||||
},
|
||||
yAxis: {
|
||||
title: {
|
||||
text: 'Points earned'
|
||||
}
|
||||
},
|
||||
xAxis: {
|
||||
type: 'datetime',
|
||||
labels: {
|
||||
formatter: function() {
|
||||
return Highcharts.dateFormat('%d.%b %Y',
|
||||
this.value);
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
layout: 'vertical',
|
||||
align: 'right',
|
||||
verticalAlign: 'middle'
|
||||
},
|
||||
plotOptions: {
|
||||
pointStart: {{ event.start_date|timestamp_fromdate }},
|
||||
series: {
|
||||
label: {
|
||||
connectorAllowed: false
|
||||
},
|
||||
allowPointSelect: true,
|
||||
marker: {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: 'Total',
|
||||
data: {{ solved|safe }}
|
||||
},
|
||||
{% for cat in cats %}
|
||||
{
|
||||
name: '{{ cat.name }}',
|
||||
data: {{ pointDatas|keyvalue:cat.name|safe }},
|
||||
visible: false,
|
||||
},
|
||||
{% endfor %}
|
||||
],
|
||||
responsive: {
|
||||
rules: [{
|
||||
condition: {
|
||||
maxWidth: 500
|
||||
},
|
||||
chartOptions: {
|
||||
legend: {
|
||||
layout: 'horizontal',
|
||||
align: 'center',
|
||||
verticalAlign: 'bottom'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -1,10 +1,25 @@
|
|||
from django import template
|
||||
from ctfs.models import CTF_flags
|
||||
from events.models import EventPlayer
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def isflagged(user, ctf):
|
||||
flagged = False
|
||||
event_info = ctf.event
|
||||
|
||||
if event_info.team_size == 1:
|
||||
if CTF_flags.objects.filter(user=user, ctf=ctf):
|
||||
flagged = True
|
||||
elif EventPlayer.objects.filter(user=user, event=event_info):
|
||||
player = EventPlayer.objects.get(user=user, event=event_info)
|
||||
solved_list = CTF_flags.objects.filter(ctf=ctf)
|
||||
for s in solved_list:
|
||||
tmp = EventPlayer.objects.get(user=s.user, event=event_info)
|
||||
if tmp.team == player.team:
|
||||
flagged = True
|
||||
|
||||
if flagged:
|
||||
return "success-msg"
|
||||
return ""
|
|
@ -12,4 +12,6 @@ urlpatterns = [
|
|||
path('subscribe/<str:event_slug>', views.subscribe_to_event, name='subscribe_event'),
|
||||
path('create_team/<str:event_slug>', views.create_team, name='create_team'),
|
||||
path('join_team/<str:event_slug>', views.join_team, name='join_team'),
|
||||
path('<str:event_slug>/profile/<str:user_name>', views.profile, name='profile'),
|
||||
path('<str:event_slug>/team/<str:name>', views.team_info, name='team_info'),
|
||||
]
|
||||
|
|
|
@ -2,9 +2,12 @@ from django.shortcuts import render, get_object_or_404, redirect
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.models import timezone
|
||||
from .forms import submit_flag
|
||||
from .models import Event, Scores, EventPlayer, Team
|
||||
from ctfs.models import CTF, CTF_flags
|
||||
from .models import Event, EventPlayer, Team
|
||||
from ctfs.models import CTF, CTF_flags, Category
|
||||
from django.utils.translation import get_language
|
||||
from django.contrib.auth.models import User
|
||||
from accounts.models import UserProfileInfo
|
||||
from django.db.models import Q
|
||||
|
||||
def get_description_by_lang(ctf):
|
||||
lang = get_language()
|
||||
|
@ -35,12 +38,13 @@ def chall_event_info(request, event_slug, chall_slug):
|
|||
wrongflag = False
|
||||
errorform = False
|
||||
notsub = False
|
||||
player = None
|
||||
if request.user.is_authenticated and not request.user.is_staff:
|
||||
userScore = Scores.objects.filter(event=event_info, user=request.user)
|
||||
if not userScore:
|
||||
return redirect('/')
|
||||
player = EventPlayer.objects.filter(event=event_info, user=request.user)
|
||||
if not player:
|
||||
return redirect('events:event_info', event_slug=event_slug)
|
||||
elif not request.user.is_authenticated:
|
||||
return redirect('/')
|
||||
return redirect('accounts:signin')
|
||||
if request.GET.get('EventIsOver'):
|
||||
eventisover = True
|
||||
if request.GET.get('AlreadyFlagged'):
|
||||
|
@ -53,9 +57,13 @@ def chall_event_info(request, event_slug, chall_slug):
|
|||
errorform = True
|
||||
if request.GET.get('NotRegistered'):
|
||||
notsub = True
|
||||
solved_list = CTF_flags.objects.filter(ctf=ctf_info).order_by('flag_date')
|
||||
solved_challs = CTF_flags.objects.filter(ctf=ctf_info).order_by('flag_date')
|
||||
solved_list = []
|
||||
for s in solved_challs:
|
||||
solved_list.append([s.user, s.flag_date, EventPlayer.objects.get(event=event_info, user=s.user).team.name])
|
||||
description = get_description_by_lang(ctf_info)
|
||||
return render(request, 'events/ctf_info.html', { 'ctf' : ctf_info, 'event':event_info, 'solved_list': solved_list, 'description': description, 'eventisover': eventisover, 'alreadyflag': alreadyflag, 'congrat': congrat, 'wrongflag': wrongflag, 'errorform': errorform, 'notsub': notsub})
|
||||
return render(request, 'events/ctf_info.html', { 'ctf' : ctf_info, 'event':event_info, 'solved_list': solved_list, 'description': description, 'eventisover': eventisover, 'alreadyflag': alreadyflag,
|
||||
'congrat': congrat, 'wrongflag': wrongflag, 'errorform': errorform, 'notsub': notsub})
|
||||
|
||||
def event(request, event_slug):
|
||||
event_info = get_object_or_404(Event, slug=event_slug)
|
||||
|
@ -70,14 +78,13 @@ def event(request, event_slug):
|
|||
if request.GET.get('SubscriptionIsOver'):
|
||||
subisover = True
|
||||
if request.user.is_authenticated:
|
||||
userScore = Scores.objects.filter(event=event_info, user=request.user)
|
||||
player = EventPlayer.objects.filter(event=event_info, user=request.user)
|
||||
if userScore or player:
|
||||
if player:
|
||||
IsRegistered = True
|
||||
if event_info.password:
|
||||
if request.user.is_authenticated:
|
||||
if request.user.is_staff is False:
|
||||
if not userScore and not player:
|
||||
if not player:
|
||||
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': True, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered})
|
||||
else:
|
||||
return render(request, 'events/event_pwd.html', {'event' : event_info, 'logged': False, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered})
|
||||
|
@ -88,13 +95,17 @@ def event(request, event_slug):
|
|||
if timezone.now() >= event_info.start_date:
|
||||
begun = True
|
||||
challenges = CTF.objects.filter(event=event_info).order_by('category', 'points')
|
||||
solved_list = Scores.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'user__username')
|
||||
if event_info.team_size == 1:
|
||||
solved_list = EventPlayer.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'user__username')
|
||||
else:
|
||||
solved_list = Team.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'name')
|
||||
return render(request, 'events/event_info.html', {'event' : event_info, 'IsRegistered': IsRegistered, 'ctfs': challenges, 'solved_list':solved_list, 'ended': ended, 'begun': begun, 'wrongpwd': wrongpwd, 'alreadyregistered': alreadyregistered, 'subisover': subisover})
|
||||
|
||||
@login_required
|
||||
def submit_event_flag(request, event_slug, chall_slug):
|
||||
ev = get_object_or_404(Event, slug=event_slug)
|
||||
response = redirect('events:event_chall_info', event_slug=event_slug, chall_slug=chall_slug)
|
||||
|
||||
if timezone.now() >= ev.end_date:
|
||||
response['Location'] += '?EventIsOver=1'
|
||||
return response
|
||||
|
@ -104,24 +115,36 @@ def submit_event_flag(request, event_slug, chall_slug):
|
|||
if not ctf_info:
|
||||
response['Location'] += '?ChallengeNotFound=1'
|
||||
return response
|
||||
|
||||
flagged = False
|
||||
if CTF_flags.objects.filter(user=request.user, ctf=ctf_info):
|
||||
player = EventPlayer.objects.get(user=request.user, event=ev)
|
||||
|
||||
if player:
|
||||
if ev.team_size == 1 and CTF_flags.objects.filter(user=request.user, ctf=ctf_info):
|
||||
flagged = True
|
||||
else:
|
||||
solved_list = CTF_flags.objects.filter(ctf=ctf_info)
|
||||
for s in solved_list:
|
||||
tmp = EventPlayer.objects.get(user=s.user, event=ev)
|
||||
if tmp.team == player.team:
|
||||
flagged = True
|
||||
if flagged == True:
|
||||
response['Location'] += '?AlreadyFlagged=1'
|
||||
return response
|
||||
try:
|
||||
score = Scores.objects.get(user=request.user, event=ev)
|
||||
except:
|
||||
score = None
|
||||
if score:
|
||||
|
||||
form = submit_flag(data=request.POST)
|
||||
if flagged == False and form.is_valid():
|
||||
|
||||
if form.is_valid():
|
||||
if ctf_info.flag == request.POST.get('flag'):
|
||||
new = CTF_flags(user = request.user, ctf = ctf_info, flag_date = timezone.now())
|
||||
new.save()
|
||||
score.last_submission_date = timezone.now()
|
||||
score.score += ctf_info.points
|
||||
score.save()
|
||||
player.last_submission_date = timezone.now()
|
||||
player.score += ctf_info.points
|
||||
player.save()
|
||||
if player.team:
|
||||
player.team.last_submission_date = timezone.now()
|
||||
player.team.score += ctf_info.points
|
||||
player.team.save()
|
||||
response['Location'] += '?Congrat=1'
|
||||
return response
|
||||
else:
|
||||
|
@ -150,16 +173,16 @@ def submit_pwd(request, event_slug):
|
|||
response['Location'] += '?WrongPassword=1'
|
||||
return response
|
||||
|
||||
if Scores.objects.filter(user=request.user, event=ev).exists() or EventPlayer.objects.filter(user=request.user, event=ev).exists():
|
||||
if EventPlayer.objects.filter(user=request.user, event=ev).exists() or EventPlayer.objects.filter(user=request.user, event=ev).exists():
|
||||
response['Location'] += '?AlreadyRegistered=1'
|
||||
return response
|
||||
else:
|
||||
new = EventPlayer(user=request.user, event=ev)
|
||||
# new = Scores(user=request.user, event=ev, score=0)
|
||||
new.save()
|
||||
# return redirect('events:event_info', event_slug=event_slug)
|
||||
if event_info.team_size > 1:
|
||||
return render(request, 'events/create_team.html', {'event' : event_info, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False})
|
||||
# return redirect('events:create_team', event_slug=event_slug)
|
||||
return redirect('events:event_info', event_slug=event_slug)
|
||||
|
||||
|
||||
@login_required
|
||||
def subscribe_to_event(request, event_slug):
|
||||
|
@ -173,12 +196,14 @@ def subscribe_to_event(request, event_slug):
|
|||
if timezone.now() >= ev.end_date:
|
||||
response['Location'] += '?SubscriptionIsOver=1'
|
||||
return response
|
||||
if Scores.objects.filter(user=request.user, event=ev).exists():
|
||||
if EventPlayer.objects.filter(user=request.user, event=ev).exists():
|
||||
response['Location'] += '?AlreadyRegistered=1'
|
||||
return response
|
||||
else:
|
||||
new = Scores(user=request.user, event=ev, score=0)
|
||||
new = EventPlayer(user=request.user, event=ev, score=0)
|
||||
new.save()
|
||||
if ev.team_size > 1:
|
||||
return render(request, 'events/create_team.html', {'event' : ev, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False})
|
||||
return redirect('events:event_info', event_slug=event_slug)
|
||||
|
||||
@login_required
|
||||
|
@ -206,10 +231,99 @@ def join_team(request, event_slug):
|
|||
team = None
|
||||
if team is None:
|
||||
return render(request, 'events/create_team.html', {'event' : ev, 'logged': True, 'wrongpwd': True, 'registered' : True, 'notexist' : True})
|
||||
else:
|
||||
members = EventPlayer.objects.filter(team=team)
|
||||
if request.POST.get('password') != team.password:
|
||||
return render(request, 'events/create_team.html', {'event' : ev, 'logged': True, 'wrongpwd': True, 'registered' : True, 'notexist' : False})
|
||||
if members.count() >= ev.team_size:
|
||||
return render(request, 'events/create_team.html', {'event' : ev, 'logged': True, 'wrongpwd': False, 'registered' : True, 'notexist' : False, 'max' : True})
|
||||
else:
|
||||
player = EventPlayer.objects.get(user=request.user, event=ev)
|
||||
player.team = team
|
||||
player.save()
|
||||
return redirect('events:event_info', event_slug=event_slug)
|
||||
|
||||
@login_required
|
||||
def profile(request, user_name, event_slug):
|
||||
catsDatas = []
|
||||
|
||||
event_info = get_object_or_404(Event, slug=event_slug)
|
||||
user_obj = get_object_or_404(User, username=user_name)
|
||||
player = EventPlayer.objects.get(user=user_obj, event=event_info)
|
||||
all_players = list(EventPlayer.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'user__username'))
|
||||
rank = all_players.index(get_object_or_404(EventPlayer, user=user_obj, event=event_info)) + 1
|
||||
cats = Category.objects.all()
|
||||
pointDatas = {}
|
||||
|
||||
for cat in cats:
|
||||
# prepare categories
|
||||
solved_count = CTF_flags.objects.filter(user=user_obj, ctf__event=event_info , ctf__category__name=cat.name).count()
|
||||
max_count = CTF.objects.filter(category__name=cat.name, event=event_info).count()
|
||||
# get datas
|
||||
somme = 0
|
||||
solved = CTF_flags.objects.filter(user=user_obj, ctf__category__name=cat.name, ctf__event=event_info).order_by('flag_date')
|
||||
pointDatas[cat.name] = []
|
||||
pointDatas[cat.name].append([user_obj.date_joined.timestamp() * 1000, 0])
|
||||
percent = (solved_count / max_count) * 100
|
||||
catsDatas.append([cat.name, solved_count, max_count, '{:.0f}'.format(percent)])
|
||||
for flag in solved:
|
||||
somme += flag.ctf.points
|
||||
pointDatas[cat.name].append([flag.flag_date.timestamp() * 1000, somme])
|
||||
|
||||
solves = CTF_flags.objects.filter(user=user_obj, ctf__event=event_info).order_by('-flag_date')
|
||||
solved = []
|
||||
somme = 0
|
||||
solved.append([user_obj.date_joined.timestamp() * 1000, 0])
|
||||
for s in solves.reverse():
|
||||
somme += s.ctf.points
|
||||
solved.append([s.flag_date.timestamp() * 1000,somme])
|
||||
|
||||
return render(request,'accounts/profile.html', {'user':user_obj, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas, 'rank': rank, 'score' : somme})
|
||||
|
||||
@login_required
|
||||
def team_info(request, name, event_slug):
|
||||
event_info = get_object_or_404(Event, slug=event_slug)
|
||||
team = Team.objects.get(name=name, event=event_info)
|
||||
|
||||
catsDatas = []
|
||||
|
||||
players = EventPlayer.objects.filter(team=team, event=event_info)
|
||||
users = [p.user for p in players]
|
||||
all_teams = list(Team.objects.filter(event=event_info).order_by('-score', 'last_submission_date', 'name'))
|
||||
rank = all_teams.index(get_object_or_404(Team, id=team.id, event=event_info)) + 1
|
||||
cats = Category.objects.all()
|
||||
pointDatas = {}
|
||||
|
||||
for cat in cats:
|
||||
# prepare categories
|
||||
solved_count = 0
|
||||
solved = []
|
||||
max_count = CTF.objects.filter(category__name=cat.name, event=event_info).count()
|
||||
somme = 0
|
||||
pointDatas[cat.name] = [[event_info.start_date.timestamp()*1000, 0]]
|
||||
for user_obj in users:
|
||||
# get datas
|
||||
solved_count += CTF_flags.objects.filter(user=user_obj, ctf__event=event_info , ctf__category__name=cat.name).count()
|
||||
solved += CTF_flags.objects.filter(user=user_obj, ctf__category__name=cat.name, ctf__event=event_info).order_by('flag_date')
|
||||
# pointDatas[cat.name].append([user_obj.date_joined.timestamp() * 1000, 0])
|
||||
percent = (solved_count / max_count) * 100
|
||||
catsDatas.append([cat.name, solved_count, max_count, '{:.0f}'.format(percent)])
|
||||
for flag in solved:
|
||||
somme += flag.ctf.points
|
||||
pointDatas[cat.name].append([flag.flag_date.timestamp() * 1000, somme])
|
||||
|
||||
query = Q()
|
||||
for user_obj in users:
|
||||
query |= Q(user=user_obj)
|
||||
query &= Q(ctf__event=event_info)
|
||||
|
||||
solves = CTF_flags.objects.filter(query).order_by('-flag_date')
|
||||
solved = []
|
||||
somme = 0
|
||||
solved.append([event_info.start_date.timestamp() * 1000, 0])
|
||||
for s in solves.reverse():
|
||||
somme += s.ctf.points
|
||||
solved.append([s.flag_date.timestamp() * 1000,somme])
|
||||
|
||||
return render(request,'events/team.html', {'users':users, 'solves':solves,'solved':solved,'catsDatas': catsDatas, 'pointDatas': pointDatas,
|
||||
'rank': rank, 'team':team, 'score':somme, 'event':event_info})
|
Loading…
Reference in New Issue