Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pridaný verbose_name do serializerov #362

Merged
merged 1 commit into from
Apr 13, 2024
Merged
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: 9 additions & 4 deletions competition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ def registered_profiles(self):
return Profile.objects.filter(eventregistration_set__event=self.pk)

def __str__(self):
if self.semester:
try:
return str(self.semester)

return f'{self.competition.name}, {self.year}. ročník - {self.season_code}'
except Event.semester.RelatedObjectDoesNotExist:
name_components = [f'{self.competition.name}, {self.year}. ročník']
if self.season_code != 2:
name_components.append(self.season)
if self.additional_name:
name_components.append(self.additional_name)
return ' - '.join(name_components)

@property
def is_active(self):
Expand Down Expand Up @@ -725,7 +730,7 @@ def generate_name(self, forced=False):
self.save()

def __str__(self):
return self.name
return f'{self.event} - {self.name}'

def can_user_modify(self, user):
return self.event.can_user_modify(user)
Expand Down
22 changes: 20 additions & 2 deletions competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ class Meta:

@ts_interface(context='competition')
class PublicationSerializer(serializers.ModelSerializer):
verbose_name = serializers.SerializerMethodField('get_verbose_name')

class Meta:
model = models.Publication
fields = '__all__'

def get_verbose_name(self, obj):
return str(obj)


@ts_interface(context='competition')
class RegistrationLinkSerializer(serializers.ModelSerializer):
Expand All @@ -50,6 +55,7 @@ class Meta:

@ts_interface(context='competition')
class EventSerializer(ModelWithParticipationSerializer):
verbose_name = serializers.SerializerMethodField('get_verbose_name')
publication_set = PublicationSerializer(many=True, read_only=True)
registration_link = RegistrationLinkSerializer(
many=False,
Expand All @@ -74,6 +80,9 @@ def create(self, validated_data):
**validated_data,
)

def get_verbose_name(self, obj):
return str(obj)


@ts_interface(context='competition')
class CompetitionTypeSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -154,6 +163,7 @@ class Meta:
'get_submitted')
num_comments = serializers.SerializerMethodField(
'get_num_comments')
verbose_name = serializers.SerializerMethodField('get_verbose_name')
# correction = ProblemCorrectionSerializer(many=False,)

def get_num_comments(self, obj):
Expand All @@ -180,6 +190,9 @@ def get_submitted(self, obj):
return SolutionSerializer(solution).data
return None

def get_verbose_name(self, obj):
return str(obj)


@ts_interface(context='competition')
class CommentSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -300,14 +313,16 @@ class SeriesWithProblemsSerializer(ModelWithParticipationSerializer):
can_submit = serializers.SerializerMethodField('get_can_submit')
can_resubmit = serializers.SerializerMethodField('get_can_resubmit')
complete = serializers.SerializerMethodField('get_complete')
verbose_name = serializers.SerializerMethodField('get_verbose_name')

class Meta:
model = models.Series
exclude = ['sum_method', 'frozen_results']
include = ['complete', 'problems', 'can_submit', 'can_resubmit']
include = ['complete', 'problems', 'can_submit',
'can_resubmit', 'verbose_name']
read_only_fields = [
'complete',
'can_submit', 'can_resubmit']
'can_submit', 'can_resubmit', 'verbose_name']

def get_can_submit(self, obj):
return obj.can_submit
Expand All @@ -321,6 +336,9 @@ def get_can_resubmit(self, obj):
def get_event(self, obj):
return obj.semester

def get_verbose_name(self, obj):
return str(obj)


@ts_interface(context='competition')
class SemesterSerializer(serializers.ModelSerializer):
Expand Down
Loading