Skip to content

Commit

Permalink
Merge branch 'bugfix/sonarlint'
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoleoncio committed Sep 25, 2024
1 parent e8f0174 commit 05d4df2
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 257 deletions.
6 changes: 3 additions & 3 deletions contests/handlers/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_list_articles(self, contest):
'gpllimit': 'max',
}
response = requests.get(contest.api_endpoint, params=list_api_params).json()
if not 'query' in response:
if 'query' not in response:
return list_

list_.extend(response['query']['pages'])
Expand All @@ -107,7 +107,7 @@ def get_category_articles(self, contest):
"gcmlimit": "max",
}
response = requests.get(contest.api_endpoint, params=categorymembers_api_params).json()
if not 'query' in response:
if 'query' not in response:
return list_

list_.extend(response['query']['pages'])
Expand All @@ -132,7 +132,7 @@ def get_deletion_pages(self, contest):
'cmprop': 'title',
}
response = requests.get(contest.api_endpoint, params=deletion_api_params).json()
if not 'query' in response:
if 'query' not in response:
return list_

list_.extend(response['query']['categorymembers'])
Expand Down
2 changes: 1 addition & 1 deletion contests/handlers/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def count_articles(self, contest):
'format': 'json'
}
response = requests.get(contest.api_endpoint, params=api_params).json()
if not 'query' in response:
if 'query' not in response:
return list_

list_.extend(response['query']['pages'])
Expand Down
11 changes: 5 additions & 6 deletions contests/handlers/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ def __init__(self, contest):
def execute(self, request):
evaluator = self.get_current_evaluator(request)

if request.method == 'POST':
if evaluator.user_status == 'G':
if request.POST.get('new'):
self.add_new_evaluator(request.POST.get('new'))
if request.method == 'POST' and evaluator.user_status == 'G':
if request.POST.get('new'):
self.add_new_evaluator(request.POST.get('new'))

if request.POST.get('user'):
self.update_evaluator_status(request)
if request.POST.get('user'):
self.update_evaluator_status(request)

return {
'contest': self.contest,
Expand Down
10 changes: 5 additions & 5 deletions contests/handlers/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def __init__(self, contest):
self.counter = CounterHandler(contest=self.contest)
self.start_day = self.contest.start_time.strftime("%Y-%m-%d")

def execute(self, request):
def execute(self):
if self.is_contest_not_started():
return self._response_with_empty_graph()

end_day, finished = self.get_end_day_and_status()
end_day = self.get_end_day()
days, last_day = self.prepare_days_range(end_day)
all_points = self.collect_points_for_days(days + [last_day])
best_users = self.get_top_users(all_points, last_day)
Expand All @@ -33,11 +33,11 @@ def execute(self, request):
def is_contest_not_started(self):
return now().date() < self.contest.start_time.date()

def get_end_day_and_status(self):
def get_end_day(self):
if now().date() > self.contest.end_time.date():
end_day = (self.contest.end_time + timedelta(days=1)).strftime("%Y-%m-%d")
return end_day, True
return now().strftime("%Y-%m-%d"), False
return end_day
return now().strftime("%Y-%m-%d")

def prepare_days_range(self, end_day):
days = self.generate_date_range(self.start_day, end_day)
Expand Down
140 changes: 74 additions & 66 deletions contests/handlers/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,77 +10,85 @@ def __init__(self, contest):
self.contest = contest

def execute(self, request):
contest = self.contest
edit = None
diff = None
content = None
author = None
comment = None
evaluation = None
allowed = False
history_qualifications = None
history_evaluations = None

if Evaluator.objects.get(
contest=contest,
profile=request.user.profile
).user_status == 'G' or edit.last_evaluation.evaluator.profile == request.user.profile:
allowed = True

if request.method == 'POST' and request.POST.get('diff'):
diff = request.POST.get('diff')
edit = Edit.objects.get(contest=contest, diff=diff)
edit = self.get_edit(diff)

if not edit:
return {'contest': self.contest, 'diff': diff, 'content': None}

allowed = self.is_allowed(request, edit)
content, author, comment = self.get_comparison_data(diff)
history_qualifications = self.get_history_qualifications(edit)
history_evaluations = self.get_history_evaluations(edit)

evaluation = None
if request.POST.get('obs'):
evaluation = self.create_evaluation(request, edit, allowed)

compare_params = {
'action': 'compare',
'prop': 'title|diff|comment|user|ids',
'format': 'json',
'fromrev': diff,
'torelative': 'prev',
return {
'contest': self.contest,
'edit': edit,
'diff': diff,
'evaluation': evaluation,
'allowed': allowed,
'content': content,
'author': author,
'comment': comment,
'history_qualifications': history_qualifications,
'history_evaluations': history_evaluations,
}
compare = requests.get(contest.api_endpoint, params=compare_params).json().get('compare', {})
else:
return {'contest': self.contest, 'edit': None}

content = compare.get('*', '')
author = compare.get('touser', '')
comment = compare.get('tocomment', '')
def get_edit(self, diff):
try:
return Edit.objects.get(contest=self.contest, diff=diff)
except Edit.DoesNotExist:
return False

history_qualifications = Qualification.objects.filter(
contest=contest,
diff=edit
).select_related('evaluator__profile').order_by('-when')
def is_allowed(self, request, edit):
evaluator = Evaluator.objects.get(contest=self.contest, profile=request.user.profile)
return evaluator.user_status == 'G' or edit.last_evaluation.evaluator.profile == request.user.profile

history_evaluations = Evaluation.objects.filter(
contest=contest,
diff=edit
).select_related('evaluator__profile').order_by('-when')

if request.POST.get('obs'):
if allowed:
evaluation = Evaluation.objects.create(
contest=contest,
evaluator=Evaluator.objects.get(contest=contest, profile=request.user.profile),
diff=edit,
valid_edit=True if request.POST.get('valid') == '1' else False,
pictures=request.POST.get('pic') if request.POST.get('pic').isnumeric() else 0,
real_bytes=request.POST.get('overwrite') or Edit.objects.get(contest=contest, diff=diff).orig_bytes,
status=1,
obs=request.POST.get('obs'),
)
edit.last_evaluation = evaluation
edit.save()
else:
raise PermissionDenied("You are not allowed to perform this action.")

return_dict = {
'contest': contest,
'edit': edit,
'diff': diff,
'evaluation': evaluation,
'allowed': allowed,
'content': content,
'author': author,
'comment': comment,
'history_qualifications': history_qualifications,
'history_evaluations': history_evaluations,
def get_comparison_data(self, diff):
compare_params = {
'action': 'compare',
'prop': 'title|diff|comment|user|ids',
'format': 'json',
'fromrev': diff,
'torelative': 'prev',
}
return return_dict
compare = requests.get(self.contest.api_endpoint, params=compare_params).json().get('compare', {})
return compare.get('*', ''), compare.get('touser', ''), compare.get('tocomment', '')

def get_history_qualifications(self, edit):
return Qualification.objects.filter(
contest=self.contest,
diff=edit
).select_related('evaluator__profile').order_by('-when')

def get_history_evaluations(self, edit):
return Evaluation.objects.filter(
contest=self.contest,
diff=edit
).select_related('evaluator__profile').order_by('-when')

def create_evaluation(self, request, edit, allowed):
if allowed:
evaluation = Evaluation.objects.create(
contest=self.contest,
evaluator=Evaluator.objects.get(contest=self.contest, profile=request.user.profile),
diff=edit,
valid_edit=True if request.POST.get('valid') == '1' else False,
pictures=request.POST.get('pic') if request.POST.get('pic').isnumeric() else 0,
real_bytes=request.POST.get('overwrite') or edit.orig_bytes,
status=1,
obs=request.POST.get('obs'),
)
edit.last_evaluation = evaluation
edit.save()
return True
else:
raise PermissionDenied("You are not allowed to perform this action.")

4 changes: 1 addition & 3 deletions contests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class Evaluation(models.Model):
when = models.DateTimeField(auto_now_add=True)
obs = models.TextField(blank=True, null=True)

def __str__(self):
return (f"{self.contest.name_id} - {self.diff.diff} - {self.evaluator.profile.username} - {self.status} - {self.when}")

def __str__(self):
name = self.evaluator.profile.username if self.evaluator else 'None'
return (f"{self.contest.name_id} - {self.diff.diff} - {name} - {self.status} - {self.when}")
5 changes: 4 additions & 1 deletion contests/templates/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
</style>
{% endif %}
<link rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/font-awesome/6.2.0/css/all.css">
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<script
src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/Chart.js/3.9.1/chart.min.js"
integrity="sha384-9MhbyIRcBVQiiC7FSd7T38oJNj2Zh+EfxS7/vjhBi4OOT78NlHSnzM31EZRWR1LZ"
crossorigin="anonymous"></script>
</head>
<body>
<div class="w3-{{ contest.theme }} w3-large w3-bar">
Expand Down
25 changes: 20 additions & 5 deletions contests/templates/edits.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@
<link rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables/1.10.21/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-buttons-dt/2.3.6/buttons.dataTables.min.css" />
<link rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-responsive-dt/2.4.1/responsive.dataTables.min.css" />
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net/2.1.1/jquery.dataTables.min.js"></script>
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-responsive/2.4.1/dataTables.responsive.min.js"></script>
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-buttons/2.3.6/js/dataTables.buttons.min.js"></script>
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-buttons/2.3.6/js/buttons.colVis.min.js"></script>
<script
src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/jquery/3.7.0/jquery.min.js"
integrity="sha384-NXgwF8Kv9SSAr+jemKKcbvQsz+teULH/a5UNJvZc6kP47hZgl62M1vGnw6gHQhb1"
crossorigin="anonymous"></script>
<script
src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net/2.1.1/jquery.dataTables.min.js"
integrity="sha384-FL5V3MGBdvjK1/lXuDlPXHHDAjM6lXTKHQH1rBXPSF63sIN2p6/49GfrqXI9N/t7"
crossorigin="anonymous"></script>
<script
src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-responsive/2.4.1/dataTables.responsive.min.js"
integrity="sha384-iQC83CKNYyann9W2gqpKB/p3aitJrLa4MIcxGclC61mNprEqXuheYiCE7JSJnRO9"
crossorigin="anonymous"></script>
<script
src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-buttons/2.3.6/js/dataTables.buttons.min.js"
integrity="sha384-jbU1hH+4p38WsOp+7JWEb6ztIpXa7u9npGVDNGEj4w9AUujc3X2E4aTDZ+xo1PgU"
crossorigin="anonymous"></script>
<script
src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/datatables.net-buttons/2.3.6/js/buttons.colVis.min.js"
integrity="sha384-h/SRPFzc2+BE+XfOqlAqiHb43fnY8jzXhQ0fI1JBfgrjbxUokMr9To2eLbSWEt1g"
crossorigin="anonymous"></script>
<style>
.loader {
border: 16px solid #f3f3f3;
Expand Down
Loading

0 comments on commit 05d4df2

Please sign in to comment.