Ejemplo n.º 1
0
    def retrieve(self, request, pk):
        """
        Get taxlot details
        ---
        parameters:
            - name: pk
              description: The primary key of the TaxLotView
              required: true
              paramType: path
            - name: organization_id
              description: The organization_id for this user's organization
              required: true
              paramType: query
        """
        result = self._get_taxlot_view(pk)
        if result.get('status', None) != 'error':
            taxlot_view = result.pop('taxlot_view')
            result.update(TaxLotViewSerializer(taxlot_view).data)
            # remove TaxLotView id from result
            result.pop('id')

            result['state'] = TaxLotStateSerializer(taxlot_view.state).data
            result['properties'] = self._get_properties(taxlot_view.pk)
            result['history'], master = self.get_history(taxlot_view)
            result = update_result_with_master(result, master)
            return JsonResponse(result, status=status.HTTP_200_OK)
        else:
            return JsonResponse(result, status=status.HTTP_404_NOT_FOUND)
Ejemplo n.º 2
0
 def _get_taxlots(self, pk):
     lot_view_pks = TaxLotProperty.objects.filter(property_view_id=pk).values_list(
         'taxlot_view_id', flat=True)
     lot_views = TaxLotView.objects.filter(pk__in=lot_view_pks).select_related('cycle', 'state')
     lots = []
     for lot in lot_views:
         lots.append(TaxLotViewSerializer(lot).data)
     return lots
Ejemplo n.º 3
0
    def get_taxlots(self, obj):
        """Get associated taxlots"""
        lot_view_pks = TaxLotProperty.objects.filter(
            property_view_id=obj.id).values_list('taxlot_view_id', flat=True)

        lot_views = TaxLotView.objects.filter(
            pk__in=lot_view_pks).select_related('cycle', 'state')
        return [TaxLotViewSerializer(lot).data
                for lot in lot_views] if lot_views else None
Ejemplo n.º 4
0
    def retrieve(self, request, pk):
        """
        Get taxlot details
        """
        result = self._get_taxlot_view(pk)
        if result.get('status', None) != 'error':
            taxlot_view = result.pop('taxlot_view')
            result.update(TaxLotViewSerializer(taxlot_view).data)
            # remove TaxLotView id from result
            result.pop('id')

            result['state'] = TaxLotStateSerializer(taxlot_view.state).data
            result['properties'] = self._get_properties(taxlot_view.pk)
            result['history'], master = self.get_history(taxlot_view)
            result = update_result_with_master(result, master)
            return JsonResponse(result, status=status.HTTP_200_OK)
        else:
            return JsonResponse(result, status=status.HTTP_404_NOT_FOUND)
Ejemplo n.º 5
0
 def retrieve(self, request, pk):
     """
     Get property details
     ---
     parameters:
         - name: cycle_id
           description: The cycle id for filtering the taxlot view
           required: true
           paramType: query
         - name: organization_id
           description: The organization_id for this user's organization
           required: true
           paramType: query
     """
     cycle_pk = request.query_params.get('cycle_id', None)
     if not cycle_pk:
         return JsonResponse({
             'status':
             'error',
             'message':
             'Must pass in cycle_id as query parameter'
         })
     result = self._get_taxlot_view(pk, cycle_pk)
     if result.get('status', None) != 'error':
         taxlot_view = result.pop('taxlot_view')
         result.update(TaxLotViewSerializer(taxlot_view).data)
         # remove TaxLotView id from result
         result.pop('id')
         result['state'] = TaxLotStateSerializer(taxlot_view.state).data
         result['properties'] = self._get_properties(taxlot_view.pk)
         result['history'], master = self.get_history(taxlot_view)
         result = update_result_with_master(result, master)
         status_code = status.HTTP_200_OK
     else:
         status_code = status.HTTP_404_NOT_FOUND
     return JsonResponse(result, status=status_code)
Ejemplo n.º 6
0
    def retrieve(self, request, pk):
        """
        Retrieves details about a project.

        :GET: Expects organization_id in query string.
        ---
        parameter_strategy: replace
        parameters:
            - name: organization_id
              description: The organization_id for this user's organization
              required: true
              paramType: query
            - name: project slug or pk
              description: The project slug identifier or primary key for this project
              required: true
              paramType: path

        Returns::

            {
             'id': project's primary key,
             'name': project's name,
             'slug': project's identifier,
             'status': 'active',
             'number_of_buildings': Count of buildings associated with project
             'last_modified': Timestamp when project last changed
             'last_modified_by': {
                'first_name': first name of user that made last change,
                'last_name': last name,
                'email': email address,
                },
             'is_compliance': True if project is a compliance project,
             'compliance_type': Description of compliance type,
             'deadline_date': Timestamp of when compliance is due,
             'end_date': Timestamp of end of project
             'property_count': number of property views associated with project,
             'taxlot_count':  number of taxlot views associated with project,
             'property_views': [list of serialized property views associated with the project...],
             'taxlot_views': [list of serialized taxlot views associated with the project...],
            }

        """

        error = None
        status_code = status.HTTP_200_OK
        key = self.get_key(pk)
        project = self.get_project(key, pk)
        cycle = request.query_params.get('cycle', None)
        if not project:
            error, status_code = self.get_error(
                'not found', key=key, val=pk
            )
            result = {'status': 'error', 'message': error}
        else:
            project = project[0]
            property_views = project.property_views.all()
            taxlot_views = project.taxlot_views.all()
            if cycle:
                property_views = property_views.filter(
                    cycle_id=cycle
                )
                taxlot_views = taxlot_views.filter(
                    cycle_id=cycle
                )
            project_data = ProjectSerializer(project).data
            project_data['property_views'] = [
                PropertyViewSerializer(property_view).data
                for property_view in property_views
            ]
            project_data['taxlot_views'] = [
                TaxLotViewSerializer(taxlot_view).data
                for taxlot_view in taxlot_views
            ]
            result = {
                'status': 'success',
                'project': project_data,
            }
        return Response(result, status=status_code)