Пример #1
0
def endpoint(request):
    """Endpoint.

    :param django.http.HttpRequest request:
    :return django.http.HttpResponse:
    """
    logger.debug("POST: {0}\nFILES: {1}".format(request.POST, request.FILES))

    for field_name, imf in request.FILES.items():
        handle_uploaded_file('foo', "{0}".format(uuid.uuid4()))

    return HttpResponse("POST: {0}\nFILES: {1}".format(request.POST,
                                                       request.FILES))
Пример #2
0
def endpoint(request):
    """
    Endpoint.

    :param django.http.HttpRequest request:
    :param string template_name:
    :return django.http.HttpResponse:
    """
    logger.debug("POST: {0}\nFILES: {1}".format(request.POST, request.FILES))

    for field_name, imf in request.FILES.items():
        handle_uploaded_file('foo', "{0}".format(uuid.uuid4()))

    return HttpResponse("POST: {0}\nFILES: {1}".format(request.POST, request.FILES))
Пример #3
0
    def submit_plugin_form_data(self, form_entry, request, form):
        """Submit plugin form data/process file upload.

        Handling the posted data for file plugin when form is submitted.
        This method affects the original form and that's why it returns it.

        :param fobi.models.FormEntry form_entry: Instance
            of ``fobi.models.FormEntry``.
        :param django.http.HttpRequest request:
        :param django.forms.Form form:
        """
        # Get the file path
        file_path = form.cleaned_data.get(self.data.name, None)
        if file_path:
            # Handle the upload
            saved_file = handle_uploaded_file(FILES_UPLOAD_DIR, file_path)
            # Overwrite ``cleaned_data`` of the ``form`` with path to moved
            # file.
            file_relative_url = saved_file.replace(os.path.sep, '/')
            form.cleaned_data[self.data.name] = "{0}{1}".format(
                settings.MEDIA_URL,
                file_relative_url
            )

        # It's critically important to return the ``form`` with updated
        # ``cleaned_data``
        return form
Пример #4
0
 def save_plugin_data(self, request=None):
     """
     Saving the plugin data and moving the file.
     """
     file_path = self.cleaned_data.get('file', None)
     if file_path:
         saved_image = handle_uploaded_file(IMAGES_UPLOAD_DIR, file_path)
         self.cleaned_data['file'] = saved_image
Пример #5
0
 def save_plugin_data(self, request=None):
     """
     Saving the plugin data and moving the file.
     """
     file_path = self.cleaned_data.get('file', None)
     if file_path:
         saved_image = handle_uploaded_file(IMAGES_UPLOAD_DIR, file_path)
         self.cleaned_data['file'] = saved_image
Пример #6
0
 def prepare_plugin_form_data(self, cleaned_data):
     # Get the file path
     file_path = cleaned_data.get(self.data.name, None)
     if file_path:
         # Handle the upload
         saved_file = handle_uploaded_file(FILES_UPLOAD_DIR, file_path)
         # Overwrite ``cleaned_data`` of the ``form`` with path to moved
         # file.
         file_relative_url = saved_file.replace(os.path.sep, '/')
         cleaned_data[self.data.name] = "{0}{1}".format(
             settings.MEDIA_URL,
             file_relative_url
         )
         # It's critically important to return the ``form`` with updated
         # ``cleaned_data``
         return cleaned_data
Пример #7
0
    def prepare_plugin_form_data(self, cleaned_data):
        """Prepare plugin form data.

        :param cleaned_data:
        :return:
        """
        # Get the file path
        file_path = cleaned_data.get(self.data.name, None)
        if file_path:
            # Handle the upload
            saved_file = handle_uploaded_file(FILES_UPLOAD_DIR, file_path)
            # Overwrite ``cleaned_data`` of the ``form`` with path to moved
            # file.
            file_relative_url = saved_file.replace(os.path.sep, '/')
            cleaned_data[self.data.name] = "{0}{1}".format(
                settings.MEDIA_URL,
                file_relative_url
            )
            # It's critically important to return the ``form`` with updated
            # ``cleaned_data``
            return cleaned_data
Пример #8
0
    def submit_plugin_form_data(self, form_entry, request, form):
        """
        Submit plugin form data/process file upload. Handling the posted data for file
        plugin when form is submitted. This method affects the original form and that's
        why it returns it.

        :param fobi.models.FormEntry form_entry: Instance of ``fobi.models.FormEntry``.
        :param django.http.HttpRequest request:
        :param django.forms.Form form:
        """
        # Get the file path
        file_path = form.cleaned_data.get(self.data.name, None)
        if file_path:
            # Handle the upload
            saved_file = handle_uploaded_file(FILES_UPLOAD_DIR, file_path)
            # Overwrite ``cleaned_data`` of the ``form`` with path to moved file.
            file_relative_url = saved_file.replace(os.path.sep, "/")
            form.cleaned_data[self.data.name] = "{0}{1}".format(settings.MEDIA_URL, file_relative_url)

        # It's critically important to return the ``form`` with updated ``cleaned_data``
        return form