Пример #1
0
    def validate(self, data):
        for key, value in data.items():
            if not value:
                data.pop(key)

        if 'category' in data and data['category']:
            data['category'] = self.getCategory(data['category']).id

        if 'end_point' in data and data['end_point']:
            mimetype, status, url = MimeTypeForm().get_mimetype(
                data['end_point'])
            data['impl_type'] = get_impl_type(mimetype, url)
            if not data['impl_type']:
                data['impl_type'] = SourceImplementationChoices.HTML
            data['collect_type'] = CollectTypeChoices.URL
            data['file_name'] = data['end_point']

        # Soportamos file_data porque es muy complejo cambiar el request de file_data a file
        # TODO: Sacar cuando se termine la api v1 y dejar solo 'file'
        file_data = None
        if 'file_data' in data:
            file_data = data.pop('file_data')
        elif 'file' in data:
            file_data = data.pop('file')

        if file_data:
            file_data.name = urllib.unquote(file_data.name)
            data['file_data'] = file_data
            data['impl_type'] = get_impl_type(file_data.content_type,
                                              file_data.name)
            data['collect_type'] = CollectTypeChoices.SELF_PUBLISH

        if ('impl_type' not in data or data['impl_type'] is None
                or data['impl_type']
                not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
            # TODO: mejorar errores
            raise exceptions.ValidationError(
                {'impl_type': 'Tipo de Archivo Invalido'})

        if 'license' in data:
            data['license_url'] = data.pop('license')

        if 'tags' in data and data['tags']:
            data['tags'] = map(lambda x: {'name': x}, data['tags'].split(','))

        data['status'] = StatusChoices.PENDING_REVIEW

        data['language'] = self.context['request'].auth['language']

        return data
Пример #2
0
    def validate(self, data):
        for key, value in data.items():
            if not value:
                data.pop(key)

        if 'category' in data and data['category']:
            data['category'] = self.getCategory(data['category']).id

        if 'end_point' in data and data['end_point']:
            mimetype, status, url = MimeTypeForm().get_mimetype(data['end_point'])
            data['impl_type']  = get_impl_type(mimetype, url)
            if not data['impl_type']:
                data['impl_type'] = SourceImplementationChoices.HTML
            data['collect_type'] = CollectTypeChoices.URL
            data['file_name'] = data['end_point']

        # Soportamos file_data porque es muy complejo cambiar el request de file_data a file
        # TODO: Sacar cuando se termine la api v1 y dejar solo 'file'
        file_data = None
        if 'file_data' in data:
            file_data = data.pop('file_data')
        elif 'file' in data:
            file_data = data.pop('file')

        if file_data:
            file_data.name = urllib.unquote(file_data.name)
            data['file_data'] = file_data
            data['impl_type'] = get_impl_type(file_data.content_type, file_data.name)
            data['collect_type'] = CollectTypeChoices.SELF_PUBLISH

        if ('impl_type' not in data or
            data['impl_type'] is None or 
            data['impl_type'] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
                # TODO: mejorar errores
                raise exceptions.ValidationError({'impl_type': 'Tipo de Archivo Invalido'})

        if 'license' in data:
            data['license_url'] = data.pop('license')

        if 'tags' in data and data['tags']:
            data['tags'] = map(lambda x: {'name':x}, data['tags'].split(','))

        data['status'] = StatusChoices.PENDING_REVIEW

        data['language'] = self.context['request'].auth['language']

        return data
Пример #3
0
 def clean(self):
     cleaned_data = super(URLForm, self).clean()
     if 'end_point' in  cleaned_data.keys() and  cleaned_data['end_point']:
         mimetype, status, url = MimeTypeForm().get_mimetype( cleaned_data['end_point'])
         cleaned_data['impl_type'] = get_impl_type(mimetype, url)
         if cleaned_data['impl_type'] is None:
             cleaned_data['impl_type'] = SourceImplementationChoices.HTML
         if ('impl_type' not in cleaned_data or cleaned_data['impl_type'] is None or
             cleaned_data['impl_type'] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
              raise FileTypeNotValidException(file_type=mimetype,
                 valid_types=SOURCE_EXTENSION_LIST)
     return cleaned_data 
Пример #4
0
 def clean(self):
     cleaned_data = super(URLForm, self).clean()
     if 'end_point' in  cleaned_data.keys() and  cleaned_data['end_point']:
         mimetype, status, url = MimeTypeForm().get_mimetype( cleaned_data['end_point'])
         cleaned_data['impl_type'] = get_impl_type(mimetype, url)
         if cleaned_data['impl_type'] is None:
             cleaned_data['impl_type'] = SourceImplementationChoices.HTML
         if ('impl_type' not in cleaned_data or cleaned_data['impl_type'] is None or
             cleaned_data['impl_type'] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
              raise FileTypeNotValidException(file_type=mimetype,
                 valid_types=SOURCE_EXTENSION_LIST)
     return cleaned_data 
Пример #5
0
 def clean(self):
     cleaned_data = super(FileForm, self).clean()
     if 'file_data' in cleaned_data.keys() and cleaned_data['file_data']:    
         cleaned_data['impl_type'] = get_impl_type(
             cleaned_data['file_data'].content_type, 
             cleaned_data['file_data'].name,
             cleaned_data['impl_type'] if 'impl_type' in cleaned_data else None
         )
         if ('impl_type' not in cleaned_data or cleaned_data['impl_type'] is None or
             cleaned_data['impl_type'] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
             raise FileTypeNotValidException(file_type=cleaned_data['file_data'].content_type,
                 valid_types=SOURCE_EXTENSION_LIST)
     return cleaned_data
Пример #6
0
 def clean(self):
     cleaned_data = super(FileForm, self).clean()
     if 'file_data' in cleaned_data.keys() and cleaned_data['file_data']:    
         cleaned_data['impl_type'] = get_impl_type(
             cleaned_data['file_data'].content_type, 
             cleaned_data['file_data'].name,
             cleaned_data['impl_type'] if 'impl_type' in cleaned_data else None
         )
         if ('impl_type' not in cleaned_data or cleaned_data['impl_type'] is None or
             cleaned_data['impl_type'] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
             raise FileTypeNotValidException(file_type=cleaned_data['file_data'].content_type,
                 valid_types=SOURCE_EXTENSION_LIST)
     return cleaned_data
Пример #7
0
    def validate(self, data):
        for key, value in data.items():
            if not value:
                data.pop(key)

        if "category" in data and data["category"]:
            data["category"] = self.getCategory(data["category"]).id

        if "end_point" in data and data["end_point"]:
            mimetype, status, url = MimeTypeForm().get_mimetype(data["end_point"])
            data["impl_type"] = get_impl_type(mimetype, url)
            if not data["impl_type"]:
                data["impl_type"] = SourceImplementationChoices.HTML
            data["collect_type"] = CollectTypeChoices.URL
            data["file_name"] = data["end_point"]

        if "file" in data:
            file_data = data.pop("file")
            file_data.name = urllib.unquote(file_data.name)
            data["file_data"] = file_data
            data["impl_type"] = get_impl_type(file_data.content_type, file_data.name)
            data["collect_type"] = CollectTypeChoices.SELF_PUBLISH

        if (
            "impl_type" not in data
            or data["impl_type"] is None
            or data["impl_type"] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()
        ):
            # TODO: mejorar errores
            raise exceptions.ValidationError({"impl_type": "Tipo de Archivo Invalido"})

        if "license" in data:
            data["license_url"] = data.pop("license")

        data["status"] = StatusChoices.PENDING_REVIEW

        data["language"] = self.context["request"].auth["language"]

        return data
Пример #8
0
    def validate(self, data):
        for key, value in data.items():
            if not value:
                data.pop(key)

        if 'category' in data and data['category']:
            data['category'] = self.getCategory(data['category']).id

        if 'end_point' in data and data['end_point']:
            mimetype, status, url = MimeTypeForm().get_mimetype(data['end_point'])
            data['impl_type']  = get_impl_type(mimetype, url)
            if not data['impl_type']:
                data['impl_type'] = SourceImplementationChoices.HTML
            data['collect_type'] = CollectTypeChoices.URL
            data['file_name'] = data['end_point']

        if 'file' in data:
            file_data = data.pop('file')
            file_data.name = urllib.unquote(file_data.name)
            data['file_data'] = file_data
            data['impl_type'] = get_impl_type(file_data.content_type, file_data.name)
            data['collect_type'] = CollectTypeChoices.SELF_PUBLISH

        if ('impl_type' not in data or
            data['impl_type'] is None or 
            data['impl_type'] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
                # TODO: mejorar errores
                raise exceptions.ValidationError({'impl_type': 'Tipo de Archivo Invalido'})

        if 'license' in data:
            data['license_url'] = data.pop('license')

        data['status'] = StatusChoices.PENDING_REVIEW

        data['language'] = self.context['request'].auth['language']

        return data
Пример #9
0
    def validate(self, data):
        for key, value in data.items():
            if not value:
                data.pop(key)

        if 'category' in data and data['category']:
            data['category'] = self.getCategory(data['category']).id

        if 'end_point' in data and data['end_point']:
            mimetype, status, url = MimeTypeForm().get_mimetype(data['end_point'])
            data['impl_type']  = get_impl_type(mimetype, url)
            if not data['impl_type']:
                data['impl_type'] = SourceImplementationChoices.HTML
            data['collect_type'] = CollectTypeChoices.URL
            data['file_name'] = data['end_point']

        if 'file' in data:
            file_data = data.pop('file')
            file_data.name = urllib.unquote(file_data.name)
            data['file_data'] = file_data
            data['impl_type'] = get_impl_type(file_data.content_type, file_data.name)
            data['collect_type'] = CollectTypeChoices.SELF_PUBLISH

        if ('impl_type' not in data or
            data['impl_type'] is None or 
            data['impl_type'] not in dict(SOURCE_IMPLEMENTATION_CHOICES).keys()):
                # TODO: mejorar errores
                raise serializers.ValidationError('Tipo de Archivo Invalido')

        if 'license' in data:
            data['license_url'] = data.pop('license')

        data['status'] = StatusChoices.PENDING_REVIEW

        data['language'] = self.context['request'].auth['language']

        return data