Skip to content

Commit

Permalink
Zjednotena konvencia nazyvania metod pre SerializerMethodFieldov (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe authored Apr 13, 2024
1 parent 4407282 commit fc10eec
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Meta:
class CompetitionSerializer(serializers.ModelSerializer):
competition_type = CompetitionTypeSerializer(many=False, read_only=True)
upcoming_or_current_event = serializers.SerializerMethodField(
'get_upcoming_or_current')
'get_upcoming_or_current_event')
history_events = serializers.SerializerMethodField('get_history_events')

class Meta:
Expand All @@ -103,7 +103,7 @@ class Meta:
'sites'
]

def get_upcoming_or_current(self, obj):
def get_upcoming_or_current_event(self, obj):
try:
return EventSerializer(obj.event_set.upcoming_or_current()).data
except models.Event.DoesNotExist:
Expand Down Expand Up @@ -151,7 +151,7 @@ class Meta:
read_only_fields = ['series', 'submitted', 'num_comments']

submitted = serializers.SerializerMethodField(
'submitted_solution')
'get_submitted')
num_comments = serializers.SerializerMethodField(
'get_num_comments')
# correction = ProblemCorrectionSerializer(many=False,)
Expand All @@ -161,7 +161,7 @@ def get_num_comments(self, obj):
user = self.context['request'].user if 'request' in self.context else AnonymousUser
return len(list(obj.get_comments(user)))

def submitted_solution(self, obj):
def get_submitted(self, obj):
if 'request' in self.context:
if (
self.context['request'].user.is_anonymous or
Expand All @@ -188,12 +188,12 @@ class Meta:
fields = '__all__'

posted_by_name = serializers.SerializerMethodField('get_posted_by_name')
edit_allowed = serializers.SerializerMethodField('can_edit')
edit_allowed = serializers.SerializerMethodField('get_edit_allowed')

def get_posted_by_name(self, obj: models.Comment):
return obj.posted_by.get_full_name()

def can_edit(self, obj: models.Comment):
def get_edit_allowed(self, obj: models.Comment):
if 'request' in self.context:
return obj.can_user_modify(self.context['request'].user)
return None
Expand Down Expand Up @@ -237,9 +237,9 @@ class ProblemWithSolutionsSerializer(serializers.ModelSerializer):
correction = ProblemCorrectionSerializer(many=False)
series = SeriesSerializer()

histogram = serializers.SerializerMethodField('get_series_histogram')
histogram = serializers.SerializerMethodField('get_histogram')
total_solutions = serializers.SerializerMethodField(
'get_series_num_solutions')
'get_total_solutions')
tex_header = serializers.SerializerMethodField('get_tex_header')

class Meta:
Expand Down Expand Up @@ -275,19 +275,19 @@ def get_tex_header(self, obj: Problem) -> str:
corrected_suffix = ''
best_solutions = None
best_solution_suffix = 'a'
num_solutions = self.get_series_num_solutions(obj)
histogram = self.get_series_histogram(obj)
num_solutions = self.get_total_solutions(obj)
histogram = self.get_histogram(obj)
return f'\\vzorak{{{corrected_suffix}}}'\
f'{{{self.format_list_of_names(corrected_by)}}}'\
f'{{{num_solutions}}}'\
f'{{{best_solution_suffix}}}'\
f'{{{self.format_list_of_names(best_solutions)}}}'\
f'{{{self.format_histogram(histogram)}}}'

def get_series_histogram(self, obj):
def get_histogram(self, obj):
return models.Problem.get_stats(obj).get('histogram')

def get_series_num_solutions(self, obj):
def get_total_solutions(self, obj):
return models.Problem.get_stats(obj).get('num_solutions')


Expand Down

0 comments on commit fc10eec

Please sign in to comment.