-
Notifications
You must be signed in to change notification settings - Fork 981
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
implement uploads for sponsor logos in admin #9792
Conversation
warnings.warn( | ||
"LocalSponsorLogoStorage is intended only for use in development, you " | ||
"should not use it in production due to the lack of safe guards " | ||
"for safely locating files on disk.", | ||
InsecureStorageWarning, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice touch here!
fp.write(request.POST["color_logo"].file.read()) | ||
extension = os.path.splitext(request.POST["white_logo"].filename)[-1] | ||
filename = f"{sponsor.id}-color-logo{extension}" | ||
form.color_logo_url.data = storage.store(filename, fp.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! By updating color/white_logo_url
we won't have to change anything were the logo is being displayed 👍
request.session.flash("Sponsor updated", queue="success") | ||
return HTTPSeeOther(location=request.current_route_path()) | ||
if request.method == "POST": | ||
_handle_images(request, form) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should only be called if the form is valid?
redirect_url = request.route_url("admin.sponsor.list") | ||
return HTTPSeeOther(location=redirect_url) | ||
if request.method == "POST": | ||
_handle_images(request, form) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
form won't validate if the white_logo is being uploaded and we don't have a url yet :/
other option is to fingerprint each upload, which is fine, I think I'll will address in #9794 also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(note fingerprinting will effectively mean that we'll "collect" a bunch of old logos in the bucket over time... which is probably OK?)
if request.POST.get("white_logo") not in [None, b""]: | ||
with tempfile.NamedTemporaryFile() as fp: | ||
fp.write(request.POST["white_logo"].file.read()) | ||
storage = request.find_service(ISponsorLogoStorage) | ||
extension = os.path.splitext(request.POST["white_logo"].filename)[-1] | ||
filename = f"{sponsor_name}-white-logo{extension}" | ||
form.white_logo_url.data = storage.store(filename, fp.name) | ||
if request.POST.get("color_logo") not in [None, b""]: | ||
with tempfile.NamedTemporaryFile() as fp: | ||
storage = request.find_service(ISponsorLogoStorage) | ||
fp.write(request.POST["color_logo"].file.read()) | ||
extension = os.path.splitext(request.POST["color_logo"].filename)[-1] | ||
filename = f"{sponsor_name}-color-logo{extension}" | ||
form.color_logo_url.data = storage.store(filename, fp.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we could benefit from some de-duplication here. Maybe storage.store
needs an interface for storing a data blob instead of a filename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will address in #9794
* chore: replace deprecated scalar method SQLAlchemy 1.4.x deprecated the `.as_scalar()` method and replaced it with `.scalar_subquery()` and issued a `SADeprecationWarning`. Refs: https://docs.sqlalchemy.org/en/14/changelog/changelog_14.html#change-f413ff8c13a1fb7d766bfa16dfcdfbf1 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: ignore InsecureStorageWarning When another class was added, it wasn't excluded from the warnings report. Refs: #9792 Original ignore: #4360 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: ignore CIText warnings in test output The updated SQLAlchemy library now emits 2,000+ warnings for CIText(). I've opened an issue on the responsible repo. Refs: mahmoudimus/sqlalchemy-citext#25 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: filter out known legacy behavior in test The test case knowingly creates invalid versions, and the code handles them by performing some extra validation, and throws the error. Suppress the warnings for creating `LegacyVersion`. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: filter out SAWarning for invalidation The collections used in the test case are intentionally being modified. Signed-off-by: Mike Fiedler <miketheman@gmail.com> Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
* implement uploads for sponsor logos in admin * correct the interface * fix _most_ of the tests * process sponsor image uploads in create and edit views * repair all existing tests * linting * test new services
* chore: replace deprecated scalar method SQLAlchemy 1.4.x deprecated the `.as_scalar()` method and replaced it with `.scalar_subquery()` and issued a `SADeprecationWarning`. Refs: https://docs.sqlalchemy.org/en/14/changelog/changelog_14.html#change-f413ff8c13a1fb7d766bfa16dfcdfbf1 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: ignore InsecureStorageWarning When another class was added, it wasn't excluded from the warnings report. Refs: pypi#9792 Original ignore: pypi#4360 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: ignore CIText warnings in test output The updated SQLAlchemy library now emits 2,000+ warnings for CIText(). I've opened an issue on the responsible repo. Refs: mahmoudimus/sqlalchemy-citext#25 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: filter out known legacy behavior in test The test case knowingly creates invalid versions, and the code handles them by performing some extra validation, and throws the error. Suppress the warnings for creating `LegacyVersion`. Signed-off-by: Mike Fiedler <miketheman@gmail.com> * test: filter out SAWarning for invalidation The collections used in the test case are intentionally being modified. Signed-off-by: Mike Fiedler <miketheman@gmail.com> Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
No description provided.