Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM alpine
FROM python:3

ADD entrypoint.sh /entrypoint.sh
ADD requirements.txt requirements.txt

RUN \
chmod +x /entrypoint.sh && \
apk add --update --no-cache python py-pip gettext && \
pip install --upgrade pip && \
pip install Django>=1.9 gunicorn && \
rm -rf /var/cache/apk/*
apt-get update && \
apt-get install -y --no-install-recommends gettext && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN pip install -r requirements.txt

ENTRYPOINT ["/entrypoint.sh"]
6 changes: 3 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!bin/sh
#!bin/bash
cd /ipt_connect

if [ "$DEV" == "true" ]; then
if [ "$DEV" = "true" ]; then
python manage.py runserver 0.0.0.0:8000
exit 1
fi

gunicorn --workers=${WORKERS} --bind=unix:/ipt_connect/ipt_connect.sock ipt_connect.wsgi
gunicorn --workers=${WORKERS} --bind=unix:/ipt_connect/ipt_connect.sock ipt_connect.wsgi
4 changes: 2 additions & 2 deletions ipt_connect/IPTdev/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.contrib import admin
from solo.admin import SingletonModelAdmin

from model_SupplementaryMaterial import *
from models import *
from .model_SupplementaryMaterial import *
from .models import *

# from config.models import SiteConfiguration

Expand Down
4 changes: 2 additions & 2 deletions ipt_connect/IPTdev/cache_per_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def apply_cache(request, *args, **kwargs):
# No caching for authorized users:
# they have to see the results of their edits immideately!

can_cache = request.user.is_anonymous() and request.method == 'GET'
can_cache = request.user.is_anonymous and request.method == 'GET'

# Gera a chave do cache
if prefix:
Expand All @@ -47,7 +47,7 @@ def apply_cache(request, *args, **kwargs):
response = None

if not response:
print 'Not in cache: %s' % (CACHE_KEY)
print('Not in cache: %s' % (CACHE_KEY))
response = function(request, *args, **kwargs)
if can_cache:
cache.set(CACHE_KEY, response, ttl)
Expand Down
6 changes: 3 additions & 3 deletions ipt_connect/IPTdev/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django import forms
from django.http import JsonResponse
from django.utils.encoding import smart_unicode
from django.utils.encoding import smart_str

from models import Participant
from .models import Participant


# class RegisterForm(forms.ModelForm):
Expand Down Expand Up @@ -31,7 +31,7 @@ def member_for_team(request):
if request.GET and "team_id" in request.GET:
objs = Participant.objects.filter(team=request.GET["team_id"])
for o in objs:
res.append({"id": o.id, "name": smart_unicode(o)})
res.append({"id": o.id, "name": smart_str(o)})

# return HttpResponse(json.dumps(res), content_type="application/json")
return JsonResponse({"res": res})
2 changes: 1 addition & 1 deletion ipt_connect/IPTdev/func_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def ipt_mean(vec):
# There was an unsuccessful attempt to refactor it.
# The code should be refactored and tested.

nhigh = nreject / 2
nhigh = nreject // 2
nlow = nreject - nhigh

if nhigh == 0:
Expand Down
6 changes: 3 additions & 3 deletions ipt_connect/IPTdev/model_SupplementaryMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from django.db import models

import models as ipt_connect_models
from . import models as ipt_connect_models


class SupplementaryMaterial(models.Model):
team = models.ForeignKey(ipt_connect_models.Team, null=True)
problem = models.ForeignKey(ipt_connect_models.Problem)
team = models.ForeignKey(ipt_connect_models.Team, null=True, on_delete=models.CASCADE)
problem = models.ForeignKey(ipt_connect_models.Problem, on_delete=models.CASCADE)
name = models.CharField(max_length=500)
link = models.CharField(max_length=5000)
67 changes: 33 additions & 34 deletions ipt_connect/IPTdev/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding: utf8
import os
import time
from string import replace
from uuid import uuid4

from django.contrib.auth.models import User
Expand All @@ -16,9 +15,9 @@
from django.utils.encoding import iri_to_uri
from solo.models import SingletonModel

import func_mean as means
import parameters as params
from func_bonus import distribute_bonus_points
from . import func_mean as means
from . import parameters as params
from .func_bonus import distribute_bonus_points

# Useful static variables
selective_fights = [i + 1 for i in range(params.npf)]
Expand Down Expand Up @@ -120,7 +119,7 @@ class Participant(models.Model):
passport_number = models.CharField(blank=True, max_length=50)
birthdate = models.DateField(default='1900-01-31', verbose_name='Birthdate')
# photo = models.ImageField(upload_to=UploadToPathAndRename(params.instance_name+'/id_photo'),help_text="Please use a clear ID photo. This will be used for badges and transportation cards.", null=True)
team = models.ForeignKey('Team', null=True, verbose_name='Team')
team = models.ForeignKey('Team', null=True, verbose_name='Team', on_delete=models.CASCADE)
role = models.CharField(
max_length=20,
choices=ROLE_CHOICES,
Expand Down Expand Up @@ -166,7 +165,7 @@ def fullname(self):
"""
return self.name + ' ' + self.surname

def __unicode__(self):
def __str__(self):
"""
:return: return the full name of the participant
"""
Expand Down Expand Up @@ -252,7 +251,7 @@ class Problem(models.Model):
mean_score_of_opponents = models.FloatField(default=0.0, editable=False)
mean_score_of_reviewers = models.FloatField(default=0.0, editable=False)

def __unicode__(self):
def __str__(self):
return self.name

def status(self, verbose=True, meangradesonly=False):
Expand Down Expand Up @@ -392,7 +391,7 @@ class Team(models.Model):
nrounds_as_opp = models.IntegerField(default=0, editable=False)
nrounds_as_rev = models.IntegerField(default=0, editable=False)

def __unicode__(self):
def __str__(self):

return self.name

Expand Down Expand Up @@ -601,7 +600,7 @@ class Room(models.Model):
name = models.CharField(max_length=50)
link = models.CharField(max_length=2083, blank=True, default='')

def __unicode__(self):
def __str__(self):
return self.name

@property
Expand All @@ -625,7 +624,7 @@ def fullname(self):
"""
return self.name + ' ' + self.surname

def __unicode__(self):
def __str__(self):
return self.fullname()

email = models.EmailField(
Expand All @@ -639,7 +638,7 @@ def __unicode__(self):
verbose_name='Affiliation to display',
help_text='Will be used for export (badges and web).',
)
team = models.ForeignKey('Team', null=True, blank=True)
team = models.ForeignKey('Team', null=True, blank=True, on_delete=models.CASCADE)
# TODO: unhardcode PF number!
pf1 = models.BooleanField(default=False, verbose_name='PF 1')
pf2 = models.BooleanField(default=False, verbose_name='PF 2')
Expand All @@ -666,29 +665,29 @@ class Round(models.Model):
),
default=None,
)
room = models.ForeignKey(Room)
room = models.ForeignKey(Room, on_delete=models.CASCADE)
reporter_team = models.ForeignKey(
Team, related_name='reporterteam', blank=True, null=True
Team, related_name='reporterteam', blank=True, null=True, on_delete=models.CASCADE
)
opponent_team = models.ForeignKey(
Team, related_name='opponentteam', blank=True, null=True
Team, related_name='opponentteam', blank=True, null=True, on_delete=models.CASCADE
)
reviewer_team = models.ForeignKey(
Team, related_name='reviewerteam', blank=True, null=True
Team, related_name='reviewerteam', blank=True, null=True, on_delete=models.CASCADE
)
reporter = models.ForeignKey(
Participant, related_name='reporter_name_1', blank=True, null=True
Participant, related_name='reporter_name_1', blank=True, null=True, on_delete=models.CASCADE
)
reporter_2 = models.ForeignKey(
Participant, related_name='reporter_name_2', blank=True, null=True
Participant, related_name='reporter_name_2', blank=True, null=True, on_delete=models.CASCADE
)
opponent = models.ForeignKey(
Participant, related_name='opponent_name', blank=True, null=True
Participant, related_name='opponent_name', blank=True, null=True, on_delete=models.CASCADE
)
reviewer = models.ForeignKey(
Participant, related_name='reviewer_name', blank=True, null=True
Participant, related_name='reviewer_name', blank=True, null=True, on_delete=models.CASCADE
)
problem_presented = models.ForeignKey(Problem, blank=True, null=True)
problem_presented = models.ForeignKey(Problem, blank=True, null=True, on_delete=models.CASCADE)
submitted_date = models.DateTimeField(default=timezone.now, blank=True, null=True)

score_reporter = models.FloatField(default=0.0, editable=False)
Expand All @@ -705,7 +704,7 @@ class Round(models.Model):
default=0.0, editable=params.manual_bonus_points
)

def __unicode__(self):
def __str__(self):
try:
fight_name = params.fights['names'][self.pf_number - 1]
except:
Expand Down Expand Up @@ -844,16 +843,16 @@ class Meta:


class JuryGrade(models.Model):
round = models.ForeignKey(Round, null=True)
jury = models.ForeignKey(Jury)
round = models.ForeignKey(Round, null=True, on_delete=models.CASCADE)
jury = models.ForeignKey(Jury, on_delete=models.CASCADE)

grade_reporter = models.IntegerField(choices=grade_choices, default=None)

grade_opponent = models.IntegerField(choices=grade_choices, default=None)

grade_reviewer = models.IntegerField(choices=grade_choices, default=None)

def __unicode__(self):
def __str__(self):
return "Grade of %s" % self.jury.name

def info(self):
Expand Down Expand Up @@ -881,36 +880,36 @@ def info(self):


class TacticalRejection(models.Model):
round = models.ForeignKey(Round, null=True)
problem = models.ForeignKey(Problem)
round = models.ForeignKey(Round, null=True, on_delete=models.CASCADE)
problem = models.ForeignKey(Problem, on_delete=models.CASCADE)
extra_free = models.BooleanField(
default=False,
verbose_name='Extra free rejection',
editable=params.enable_extra_free_tactical_rejections,
)

def __unicode__(self):
def __str__(self):
return "Problem rejected : %s" % self.problem.pk


class EternalRejection(models.Model):
round = models.ForeignKey(Round, null=True)
problem = models.ForeignKey(Problem)
round = models.ForeignKey(Round, null=True, on_delete=models.CASCADE)
problem = models.ForeignKey(Problem, on_delete=models.CASCADE)
extra_free = models.BooleanField(
default=False,
verbose_name='Extra free rejection',
editable=params.enable_extra_free_eternal_rejections,
)

def __unicode__(self):
def __str__(self):
return "Problem rejected : %s" % self.problem.pk


class AprioriRejection(models.Model):
team = models.ForeignKey(Team, null=True)
problem = models.ForeignKey(Problem)
team = models.ForeignKey(Team, null=True, on_delete=models.CASCADE)
problem = models.ForeignKey(Problem, on_delete=models.CASCADE)

def __unicode__(self):
def __str__(self):
# TODO: also print the Team
return "Problem rejected : %s" % self.problem.pk

Expand Down Expand Up @@ -962,7 +961,7 @@ class SiteConfiguration(SingletonModel):
image_URL = models.URLField(default="http://i.imgur.com/QH8aoXL.gif")
image_repeat_count = models.IntegerField(default=6)

def __unicode__(self):
def __str__(self):
return u"Site Configuration"

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion ipt_connect/IPTdev/parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from get_script_dir import get_script_dir
from .get_script_dir import get_script_dir

# Here we get the name of the folder in which THIS FILE is located.
# It is probably NOT the current working directory.
Expand Down
20 changes: 10 additions & 10 deletions ipt_connect/IPTdev/tactics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from views import *
from .views import *


def build_tactics_for_two_teams(reporter_team, opponent_team, current_round=None):
Expand Down Expand Up @@ -51,38 +51,38 @@ def build_tactics_for_two_teams(reporter_team, opponent_team, current_round=None
# Will be filled later
# TODO: is it possible to cast a lambda here?
),
'apriori_rejected_by_reporter': map(
'apriori_rejected_by_reporter': list(map(
lambda rejection: None,
list(apri_rej.filter(team=reporter_team)),
),
'eternally_rejected_by_reporter': map(
)),
'eternally_rejected_by_reporter': list(map(
lambda rejection: rejection.round,
list(eter_rej.filter(round__reporter_team=reporter_team)),
),
)),
'reported_by_reporter': list(atrounds.filter(reporter_team=reporter_team)),
'opposed_by_opponent': list(atrounds.filter(opponent_team=opponent_team)),
'reported_by_opponent': list(atrounds.filter(reporter_team=opponent_team)),
# These categories are not forbidden, but are valuable knowledge
# If the opponent tried to challenge for a problem and received a rejection,
# it is likely that the opponent will try to challenge for the same problem again.
# This knowledge is obviously valuable for the reporter ;-)
'tried_by_opponent': map(
'tried_by_opponent': list(map(
lambda rejection: rejection.round,
list(tact_rej.filter(round__opponent_team=opponent_team))
+ list(eter_rej.filter(round__opponent_team=opponent_team)),
),
)),
# The same thing for reviewing
'reviewed_by_opponent': list(atrounds.filter(reviewer_team=opponent_team)),
# reporter's oppositions...
'opposed_by_reporter': list(atrounds.filter(opponent_team=reporter_team)),
# ... and for reporter's reviews - no idea what for
'reviewed_by_reporter': list(atrounds.filter(reviewer_team=reporter_team)),
# Crazyness must go on!
'tried_by_reporter': map(
'tried_by_reporter': list(map(
lambda rejection: rejection.round,
list(tact_rej.filter(round__opponent_team=reporter_team))
+ list(eter_rej.filter(round__opponent_team=reporter_team)),
),
)),
}

for round in previous_rounds:
Expand Down Expand Up @@ -197,7 +197,7 @@ class TacticsForm(forms.Form):
try:
# This fails if no teams are registered (which is essentially for a new tournament)
all_teams = Team.objects.all()
team_choices = map(lambda team: (team.pk, team), all_teams)
team_choices = [(team.pk, team) for team in all_teams]
reporter_team = forms.ChoiceField(label='Reporter team', choices=team_choices)
opponent_team = forms.ChoiceField(label='Opponent team', choices=team_choices)
except:
Expand Down
2 changes: 1 addition & 1 deletion ipt_connect/IPTdev/templates/IPTdev/bebacksoon.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends params.instance_name|add:'/head.html' %}
{% load staticfiles %}
{% load static %}
{% load i18n %}
{% load solo_tags %}

Expand Down
2 changes: 1 addition & 1 deletion ipt_connect/IPTdev/templates/IPTdev/head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n %}
{% load staticfiles %}
{% load static %}

<html lang="en">
<head>
Expand Down
Loading