Ejemplo n.º 1
0
    def reset(self, request):
        """
        Reset all the measures back to the defaults (as provided by BuildingSync)
        ---
        parameters: {}
        type:
            organization_id:
                required: true
                type: integer
                paramType: query
            status:
                required: true
                type: string
                description: Either success or error
            measures:
                required: true
                type: list
                description: list of measures
        """
        organization_id = request.query_params.get('organization_id', None)
        if not organization_id:
            return JsonResponse(
                {
                    'status': 'error',
                    'message': 'organization_id not provided'
                },
                status=status.HTTP_400_BAD_REQUEST)

        Measure.populate_measures(organization_id)
        data = dict(measures=list(
            Measure.objects.filter(
                organization_id=organization_id).order_by('id').values()))

        data['status'] = 'success'
        return JsonResponse(data)
Ejemplo n.º 2
0
    def save(self, *args, **kwargs):
        """Perform checks before saving."""
        # There can only be one.
        if self.parent_org is not None and self.parent_org.parent_org is not None:
            raise TooManyNestedOrgs

        super(Organization, self).save(*args, **kwargs)

        # Create a default cycle for the organization if there isn't one already
        from seed.models import Cycle
        Cycle.get_or_create_default(self)
        from seed.models import Measure
        Measure.populate_measures(self.id)
Ejemplo n.º 3
0
    def reset(self, request):
        """
        Reset all the measures back to the defaults (as provided by BuildingSync)
        """
        organization_id = request.query_params.get('organization_id', None)
        if not organization_id:
            return JsonResponse(
                {
                    'status': 'error',
                    'message': 'organization_id not provided'
                },
                status=status.HTTP_400_BAD_REQUEST)

        Measure.populate_measures(organization_id)
        data = dict(measures=list(
            Measure.objects.filter(
                organization_id=organization_id).order_by('id').values()))

        data['status'] = 'success'
        return JsonResponse(data)