Esempio n. 1
0

class SimpleIndigenousLandKMLSerializer(CachedSerializerMixin,
                                        serializers.ModelSerializer):

    geometry = serializers.SerializerMethodField()

    class Meta:
        model = IndigenousLand
        fields = ['name', 'geometry']

    def get_geometry(self, obj):
        return obj.geometry.kml


cache_registry.register(SimpleIndigenousLandKMLSerializer)


class ProjectSerializer(serializers.ModelSerializer):

    indigenous_lands = SimpleIndigenousLandSerializer(many=True)

    class Meta:
        model = Project
        fields = [
            'id',
            'name',
            'description',
            'start_date',
            'end_date',
            'files',
Esempio n. 2
0
        model = CompanyMeetingColor


class CompanyDefaultMessageSerializer(CachedSerializerMixin,
                                      serializers.ModelSerializer):
    class Meta:
        model = CompanyDefaultMessage


class UserPreferenceSerializer(CachedSerializerMixin,
                               serializers.ModelSerializer):
    class Meta:
        model = UserPreference


cache_registry.register(UserSerializer)
cache_registry.register(RoadshowSerializer)
cache_registry.register(RoadshowCitySerializer)
cache_registry.register(RoadshowDateSerializer)
cache_registry.register(RoadshowMeetingSerializer)
cache_registry.register(RoadshowFlightSerializer)
cache_registry.register(RoadshowHotelSerializer)
cache_registry.register(RoadshowRentalSerializer)
cache_registry.register(RoadshowExpenseSerializer)
cache_registry.register(ExpenseDocumentSerializer)
cache_registry.register(RoadshowDinnerSerializer)
cache_registry.register(CategorySerializer)
cache_registry.register(MeetingSummarySerializer)
cache_registry.register(MeetingDocumentSerializer)
cache_registry.register(CompanyMeetingColorSerializer)
cache_registry.register(CompanyDefaultMessageSerializer)
        ]


class TaskFacetSerializerV1(HaystackFacetSerializer):
    """
    A facet view to use facets on the API.
    """

    # Setting this to True will serialize the
    # queryset into an `objects` list. This
    # is useful if you need to display the faceted
    # results. Defaults to False.
    serialize_objects = True

    class Meta:
        index_classes = [Task]
        fields = [
            "created_at",
            "is_deleted",
            "status",
            "kind",
            "type",
        ]

        field_options = {}


# Cache configuration
cache_registry.register(TaskSerializerV1)
cache_registry.register(TaskSearchSerializerV1)
    class Meta:
        index_classes = [BovespaCompany]
        fields = [
            "created_at",
            "updated_at",
            "situation",
            "company_type",
            "granted_date",
            "canceled_date",
            "ccvm",
            "cnpj",
        ]


# Cache configuration
cache_registry.register(BovespaCompanySerializerV1)
cache_registry.register(BovespaCompanySearchSerializerV1)


class BovespaCompanyFileSerializerV1(dse_serializers.CassandraModelSerializer, BaseCachedSerializerMixin):
    """
    Represents a Business Object API View with support for JSON, list, and map
    fields.
    """

    class Meta:
        model = BovespaCompanyFile
        fields = (
            "ccvm",
            "doc_type",
            "fiscal_date",
Esempio n. 5
0
            'velocidade',
            'latitude_l',
            'latitude',
            'longitude',
            'ligado',
            'data_desli',
            'motivo_des',
            'mi_style',
            'mi_prinx',
            'geom',
            'emme_gid',
            'mdc_gid',
        ]


cache_registry.register(BaseRadaresSerializer)


class ContagensSerializer(CachedSerializerMixin, serializers.ModelSerializer):

    # acuracia = serializers.Ser

    class Meta:
        model = Contagens
        fields = [
            'data_e_hora', 'localidade', 'tipo', 'contagem', 'autuacoes',
            'placas', 'acuracia', 'autuacoes_por_placas'
        ]


cache_registry.register(ContagensSerializer)
Esempio n. 6
0
from rest_framework import serializers

#cache
from rest_framework_cache.serializers import CachedSerializerMixin
from rest_framework_cache.registry import cache_registry

#models
from apps.common.models import Example


class PagesSerializer(CachedSerializerMixin):  #serializers.ModelSerializer,
    class Meta:
        model = Example
        fields = ('id', 'simple')


cache_registry.register(PagesSerializer)
    class Meta:
        index_classes = [CompanyIndex]
        fields = ["foundation_date", "country_code", "stock_symbol",
                  "founders", "specialties", "last_round"]

        field_options = {
            "country_code": {},
            "stock_symbol": {},
            "founders": {},
            "specialties": {},
            "foundation_date": {
                "start_date": datetime.now() - timedelta(days=50 * 365),
                "end_date": datetime.now(),
                "gap_by": "month",
                "gap_amount": 6
            },
            "last_round": {
                "start_date": datetime.now() - timedelta(days=10 * 365),
                "end_date": datetime.now(),
                "gap_by": "month",
                "gap_amount": 3
            }
        }


# Cache configuration
cache_registry.register(CompanySerializerV1)
cache_registry.register(CompanySearchSerializerV1)
cache_registry.register(CompanyGEOSearchSerializerV1)
Esempio n. 8
0
"""Area serializer class to make JSON REST API"""

from rest_framework import serializers
from rest_framework_cache.serializers import CachedSerializerMixin
from rest_framework_cache.registry import cache_registry

from .models import Area


class AreaSerializer(CachedSerializerMixin):
    # SlugRelatedField is to display name of provider instead of it id
    provider = serializers.SlugRelatedField(read_only=True, slug_field='name')

    class Meta:
        model = Area
        fields = ("name", "price", "provider", "poly")


cache_registry.register(AreaSerializer)
Esempio n. 9
0
    class Meta:
        model = NetContentUOM
        fields = ('id', 'abbr', 'code')


class ProductWeightUOMSerializer(CachedModelSerializer):
    """
    Serializes product_weight_uom
    """
    def to_representation(self, instance):
        representation = super().to_representation(instance)
        representation['uom'] = instance.uom
        return representation

    class Meta:
        model = WeightUOM
        fields = ('id', 'abbr', 'code')


# cache config
# cache_registry.register(ProductSerializer)
cache_registry.register(ProductAttributeSerializer)
cache_registry.register(ProductTemplateSerializer)
cache_registry.register(ProductLanguageSerializer)
cache_registry.register(ProductCountryOfOriginSerializer)
cache_registry.register(ProductTargetMarketSerializer)
cache_registry.register(ProductDimensionUOMSerializer)
cache_registry.register(ProductNetContentUOMSerializer)
cache_registry.register(ProductWeightUOMSerializer)
Esempio n. 10
0
        fields = ('name', 'slug', 'parent_slug', 'parent', 'is_leaf_node')

    @classmethod
    def get_parent_slug(cls, obj):
        return obj.parent.slug if obj.parent else 'category'

    @classmethod
    def get_parent(cls, obj):
        return obj.parent.name if obj.parent else _('All rubrics')


class CategorySerializer(LightCategorySerializer):

    count = serializers.SerializerMethodField()

    class Meta:
        model = Category
        fields = LightCategorySerializer.Meta.fields + ('count',)

    def get_count(self, obj):
        min_price = self.context['request'].query_params.get('min_price')
        max_price = self.context['request'].query_params.get('max_price')
        return get_tree_ads_count(
            obj,
            Q(price__gte=min_price) if min_price else Q(),
            Q(price__lte=max_price) if min_price else Q()
        )


cache_registry.register(CategorySerializer)
Esempio n. 11
0
#cache
from rest_framework_cache.serializers import CachedSerializerMixin
from rest_framework_cache.registry import cache_registry
from rest_framework import serializers

#models
from apps.common.models import Intro, About, Service1, Service2, Service3, FeedBack, Example, FeedBack


class PagesSerializer(CachedSerializerMixin):
    class Meta:
        model = Example
        fields = ('id', 'simple')

cache_registry.register(PagesSerializer)


class IntroSerializer(CachedSerializerMixin):
    class Meta:
        model = Intro
        fields = ('header', 'sub_header')


class AboutSerializer(CachedSerializerMixin):
    class Meta:
        model = About
        fields = ('about', )


class Service1Serializer(CachedSerializerMixin):
Esempio n. 12
0
    class Meta:
        model = Ad
        fields = ('slug', 'subject', 'message', 'category', 'location',
                  'price', 'image', 'created', 'is_vip')

    @classmethod
    def get_image(cls, obj):
        image_instance = obj.images.first()
        if image_instance:
            return image_instance.image.url


class AdDetailSerializer(serializers.ModelSerializer):

    category = CategorySerializer(read_only=True)
    user = UserProfileSerializer(read_only=True)
    images = serializers.SerializerMethodField()

    class Meta:
        model = Ad
        fields = ('subject', 'slug', 'phone', 'message', 'category',
                  'location', 'user', 'price', 'images', 'created')

    @classmethod
    def get_images(cls, obj):
        return [ad_image.image.url for ad_image in obj.images.all()]


cache_registry.register(AdListSerializer)
 def setUp(self):
     cache_registry.register(TestSerializer)
Esempio n. 14
0
            'inn', 'rnn', 'roleperson', 'roleperson_id'
        ]
        depth = 1


class CompanySerializer(serializers.ModelSerializer):
    faunders = serializers.SerializerMethodField()
    #city = serializers.CharField(source='City.name_ru', read_only=True)
    city_id = serializers.IntegerField(write_only=True)

    def get_faunders(self, instance):
        names = []
        persons = Person2Company.objects.filter(company=instance)

        for p in persons:
            person = p.person
            names.append({'name': person.full_name_ru, 'id': person.id})
        return names

    class Meta:
        model = Company
        fields = [
            'name_ru', 'name_kz', 'city', 'city_id', 'faunders', 'bin', 'id'
        ]
        depth = 1


cache_registry.register(RoleSerializer)
cache_registry.register(CitySerializer)
cache_registry.register(PersonSerializer)
cache_registry.register(CompanySerializer)
Esempio n. 15
0
"""Provider serializer class to make JSON REST API"""

from rest_framework import serializers
from rest_framework_cache.serializers import CachedSerializerMixin
from rest_framework_cache.registry import cache_registry

from .models import Provider


class ProviderSerializer(CachedSerializerMixin):
    class Meta:
        model = Provider
        fields = ("name", "email", "phone_number", "language", "currency")


cache_registry.register(ProviderSerializer)
Esempio n. 16
0
 def setUp(self):
     cache_registry.register(TestSerializer)