Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#163463708 Add article image uploading #45

Merged
merged 1 commit into from
Jan 25, 2019

Conversation

GransonO
Copy link
Contributor

@GransonO GransonO commented Jan 24, 2019

What does this PR do?

Add a view function for uploading the articles images to cloudinary

Description of Task to be completed?

Any image added to the article editor should be automatically uploaded and the return data should be in a particular format

Any background context you want to provide?

Cloudinary is an image and media files storage cloud service that allows for posting of images whose URLs can then be used to display them anywhere

What are the relevant pivotal tracker stories?

#163463708

Screenshots (if appropriate)

Questions:

Checklist:

  • My code follows the style guidelines of this project
  • At least 2 people have reviewed my PR
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My PR has one commit.


except Exception as error:
print("The error is : {}".format(error))
return Response({'error': 'I cant do that !!! '},status.HTTP_400_BAD_REQUEST)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)
missing whitespace after ','

},status.HTTP_200_OK)
else:
return Response({'error': 'Could not get file from posted data'},status.HTTP_404_NOT_FOUND)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace

'link': result['secure_url'],
},status.HTTP_200_OK)
else:
return Response({'error': 'Could not get file from posted data'},status.HTTP_404_NOT_FOUND)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (107 > 79 characters)
missing whitespace after ','

return Response({
'success': 'file posted',
'link': result['secure_url'],
},status.HTTP_200_OK)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ','

cloudinary.config(
cloud_name = os.getenv('CLOUD_NAME'),
api_key = os.getenv('API_KEY'),
api_secret = os.getenv('API_SECRET')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line missing indentation or outdented
trailing whitespace
unexpected spaces around keyword / parameter equals

if request.method == 'POST' and request.FILES['image_file']:
myfile = request.FILES['image_file']

cloudinary.config(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

try:
if request.method == 'POST' and request.FILES['image_file']:
myfile = request.FILES['image_file']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace


class ImageUpload(APIView):
serializer_class = ArticleSerializer
"""Upload image to cloudinary"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

@@ -197,3 +203,28 @@ def delete(self, request, slug, **kwargs):
logger.debug("Error is : ".format(what_now))
return Response({"message": "Could not find that article"},
status.HTTP_404_NOT_FOUND)

class ImageUpload(APIView):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

@@ -2,10 +2,16 @@
import random
import readtime
import uuid
import json

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'json' imported but unused

@GransonO GransonO force-pushed the fix-article_image_upload-163463708 branch from 4062056 to 9e435f0 Compare January 24, 2019 20:03

except Exception as error:
print("The error is : {}".format(error))
return Response({'error': 'I cant do that !!! '}, status.HTTP_400_BAD_REQUEST)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (90 > 79 characters)

if request.method == 'POST' and request.FILES['image_file']:
myfile = request.FILES['image_file']
cloudinary.config(
cloud_name=os.getenv('CLOUD_NAME'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line missing indentation or outdented

@GransonO GransonO force-pushed the fix-article_image_upload-163463708 branch from 9e435f0 to 1e742c6 Compare January 24, 2019 20:06
}, status.HTTP_200_OK)
else:
return Response({'error': 'Could not get file from posted data'},
status.HTTP_404_NOT_FOUND)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

'link': result['secure_url'],
}, status.HTTP_200_OK)
else:
return Response({'error': 'Could not get file from posted data'},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

@GransonO GransonO force-pushed the fix-article_image_upload-163463708 branch from 1e742c6 to 2971054 Compare January 24, 2019 20:08
except Exception as error:
print("The error is : {}".format(error))
return Response({'error': 'I cant do that !!! '},
status.HTTP_400_BAD_REQUEST)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

@GransonO GransonO force-pushed the fix-article_image_upload-163463708 branch from 2971054 to 465c97d Compare January 24, 2019 20:10
- uploads image when user add it to the editor
- show upload progress
- parse and return image data as required by editor
[Finishes #163463708]
@GransonO GransonO force-pushed the fix-article_image_upload-163463708 branch from 465c97d to 8ad33bf Compare January 25, 2019 07:16
@@ -2,10 +2,15 @@
import random
import readtime
import uuid
import os

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'os' imported but unused

@brayovsky brayovsky merged commit 878ee7d into develop Jan 25, 2019
@brayovsky brayovsky deleted the fix-article_image_upload-163463708 branch January 25, 2019 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants