class ProjectsSerializer(serializers.ModelSerializer): branches = BranchSerializer(required=False, many=True) organization = OrganizationSerializer() publicationDate = DateTimeToDateField(source='created_at') detailUrl = serializers.CharField(source='get_absolute_url') contextMenu = serializers.SerializerMethodField( method_name='get_context_menu') def get_context_menu(self, instance): if instance.has_perm(self.context['request'].user): return { 'editUrl': reverse('innov:update', args=[instance.pk]), 'removeUrl': reverse('innov:delete', args=[instance.pk]), 'advertiseUrl': reverse('adv_top:top_form', args=[self.Meta.model.__name__.lower(), instance.pk]), } return None class Meta: model = InnovationProject fields = ('id', 'name', 'cost', 'currency', 'branches', 'organization', 'detailUrl', 'cost', 'currency', 'branches', 'publicationDate', 'contextMenu')
class ResumeSerializer(serializers.ModelSerializer): fullName = serializers.CharField(source='user.profile.full_name') flag = serializers.CharField(source='user.profile.country.flag') date = DateTimeToDateField(source='created_at') detailUrl = serializers.CharField(source='get_absolute_url') contextMenu = serializers.SerializerMethodField( method_name='get_context_menu') def get_context_menu(self, instance): if instance.has_perm(self.context['request'].user): return { 'editUrl': reverse('resume:update', args=[instance.pk]), 'removeUrl': reverse('resume:delete', args=[instance.pk]), 'advertiseUrl': reverse('adv_top:top_form', args=[self.Meta.model.__name__.lower(), instance.pk]), } return None class Meta: model = Resume fields = ('id', 'title', 'date', 'flag', 'fullName', 'detailUrl', 'contextMenu')
class NewsSerializer(serializers.ModelSerializer): organization = OrganizationSerializer() image = serializers.SerializerMethodField() flag = serializers.CharField(source='country.flag') date = DateTimeToDateField(source='created_at') detailUrl = serializers.CharField(source='get_absolute_url') contextMenu = serializers.SerializerMethodField( method_name='get_context_menu') def get_context_menu(self, instance): if instance.has_perm(self.context['request'].user): return { 'editUrl': reverse('news:update', args=[instance.pk]), 'removeUrl': reverse('news:delete', args=[instance.pk]), 'advertiseUrl': reverse('adv_top:top_form', args=[self.Meta.model.__name__.lower(), instance.pk]), } return None def get_image(self, instance): return instance.image.big if instance.image else static( 'b24online/img/news.jpg') class Meta: model = News fields = ('id', 'title', 'content', 'organization', 'date', 'flag', 'image', 'detailUrl', 'contextMenu')
class VideoSerializer(serializers.ModelSerializer): organization = OrganizationSerializer() image = serializers.SerializerMethodField() flag = serializers.CharField(source='country.flag') date = DateTimeToDateField(source='created_at') detailUrl = serializers.CharField(source='get_absolute_url') videoCode = serializers.CharField(source='video_code') contextMenu = serializers.SerializerMethodField( method_name='get_context_menu') def get_context_menu(self, instance): if instance.has_perm(self.context['request'].user): return { 'editUrl': reverse('tv:update', args=[instance.pk]), 'removeUrl': reverse('tv:delete', args=[instance.pk]), } return None def get_image(self, instance): return instance.image.big if instance.image else '//img.youtube.com/vi/%s/0.jpg' % instance.video_code class Meta: model = VideoChannel fields = ('id', 'title', 'content', 'organization', 'date', 'flag', 'image', 'detailUrl', 'contextMenu')
class ProposalsSerializer(serializers.ModelSerializer): organization = OrganizationSerializer() date = DateTimeToDateField(source='created_at') flag = serializers.CharField(source='country.flag') countryName = serializers.CharField(source='country.name') detailUrl = serializers.CharField(source='get_absolute_url') contextMenu = serializers.SerializerMethodField( method_name='get_context_menu') def get_context_menu(self, instance): if instance.has_perm(self.context['request'].user): return { 'editUrl': reverse('proposal:update', args=[instance.pk]), 'removeUrl': reverse('proposal:delete', args=[instance.pk]), 'advertiseUrl': reverse('adv_top:top_form', args=[self.Meta.model.__name__.lower(), instance.pk]), } return None class Meta: model = BusinessProposal fields = ('id', 'title', 'organization', 'date', 'flag', 'countryName', 'detailUrl', 'contextMenu')