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

NEW FEATURE: custom model field image prefix, custom filename and less duplication #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sstacha
Copy link

@sstacha sstacha commented Sep 30, 2020

I needed some functionality that I think would be valuable to the base project if you are interested in any of it. The 3 feature changes are pretty simple.

  1. If a developer creates a markdownx field with a new attribute field_image_prefix="somepathstring" that prefix is appended to the path adding the ability for field level image separation.
  2. If a content creator renames the image before dropping they can easily control the filename that is stored
    This now gives developers and content creators 3 levels of customization without any overloading or extending this projects code.
    The existing project level setting prefix MARKDOWNX_MEDIA_PATH + model/field level path prefix + imagename
  3. Last, to prevent the number of duplicates and for easy url generation for existing images content creators can drop an existing image from the media folder location into a markdown field to create a link to an image that already exists.

I attempted to add the functionality with the least amount of changes or impact to existing or new installations.

  • if no attribute is included in the model there is no additional prefix appended and everything works like before
  • if no setting MARKDOWNX_USE_ORIGINAL_IMAGE_NAME = True in settings file the normal uuid always add functionality applies like before

I did not intend the comments to be kept but I thought it would be valuable during review to see why I think I needed each change.

An example of what a model field might look like:

content = MarkdownxField(field_image_prefix='markdownpost/content', help_text=mark_safe(
        'Markdown Reference: <a href="https://commonmark.org/help/">https://commonmark.org/help/</a>'))

An example of what a dropped image me.jpg final path might look like with the following settings:

MARKDOWNX_MEDIA_PATH = datetime.datetime.now().strftime('markdownx/%Y')
MARKDOWNX_USE_ORIGINAL_IMAGE_NAME=True

/media/markdownx/2020/markdownpost/content/me.jpg

This is my first attempt at a pull request so if I did something wrong please let me know

…mes, and easy link generation from existing images
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.

1 participant