Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions geonode/documents/enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@
"xls": "text",
"xlsx": "text",
"xml": "text",
"bm": "image",
"bmp": "image",
"dwg": "archive",
"dxf": "archive",
"fif": "image",
"gif": "image",
"jpg": "image",
"jpe": "image",
"jpeg": "image",
"png": "image",
"tif": "archive",
"tiff": "archive",
"tif": "image",
"tiff": "image",
"pbm": "archive",
"odp": "presentation",
"ppt": "presentation",
Comment on lines 32 to 45
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While refactoring DOCUMENT_TYPE_MAP, several image formats like bm, bmp, and jpe were removed. This appears to be a regression, as it will prevent EXIF metadata extraction for these file types since the logic now relies on doc.is_image. This also introduces an inconsistency with DOCUMENT_MIMETYPE_MAP, where these extensions are still defined.

I suggest adding these image types back to ensure continued support. The change to correctly classify tif and tiff as image is correct and has been preserved in the suggestion.

    "xls": "text",
    "xlsx": "text",
    "xml": "text",
    "bm": "image",
    "bmp": "image",
    "dwg": "archive",
    "dxf": "archive",
    "fif": "image",
    "gif": "image",
    "jpg": "image",
    "jpe": "image",
    "jpeg": "image",
    "png": "image",
    "tif": "image",
    "tiff": "image",
    "pbm": "archive",
    "odp": "presentation",
    "ppt": "presentation"

Copy link
Contributor Author

@sijandh35 sijandh35 Dec 19, 2025

Choose a reason for hiding this comment

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

Now DOCUMENT_MIMETYPE_MAP also has been updated(by removing: bm, bmp , fif and jpe type) to make it consistent with DOCUMENT_TYPE_MAP.

Expand Down Expand Up @@ -89,13 +85,9 @@
"xls": "application/excel",
"xlsx": "application/vnd.ms-excel",
"xml": "application/xml",
"bm": "image/bmp",
"bmp": "image/bmp",
"dwg": "image/vnd.dwg",
"dxf": "image/vnd.dwg",
"fif": "image/fif",
"gif": "image/gif",
"jpe": "image/jpeg",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"png": "image/png",
Expand Down
22 changes: 15 additions & 7 deletions geonode/documents/exif/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#
#########################################################################

import os
import logging

from slugify import slugify
Expand Down Expand Up @@ -70,13 +69,14 @@ def exif_extract_metadata_doc(doc):
return None

file_path = doc.files[0]
_, ext = os.path.splitext(os.path.basename(file_path))

if ext[1:] in {"jpg", "jpeg", "png"}:
if doc.is_image:
from PIL import Image, ExifTags

img = Image.open(file_path)
exif_data = {ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS}
exif = img.getexif()
# Main EXIF tags
exif_data = {ExifTags.TAGS[k]: v for k, v in exif.items() if k in ExifTags.TAGS}

model = None
date = None
Expand All @@ -86,6 +86,12 @@ def exif_extract_metadata_doc(doc):
lon = None
abstract = None

# Get Exif IFD for DateTimeOriginal etc.
exif_ifd = exif.get_ifd(ExifTags.IFD.Exif)
if exif_ifd:
exif_ifd_data = {ExifTags.TAGS.get(k, k): v for k, v in exif_ifd.items()}
exif_data.update(exif_ifd_data)

if "DateTime" in exif_data:
date = exif_data["DateTime"]
elif "DateTimeOriginal" in exif_data:
Expand All @@ -107,11 +113,13 @@ def exif_extract_metadata_doc(doc):
model = exif_data.get("Model", None)
keywords.append(slugify(model))

if "GPSInfo" in exif_data:
# Get GPS IFD for GPS data
gps_ifd = exif.get_ifd(ExifTags.IFD.GPSInfo)
if gps_ifd:
gpsinfo = {}
for key in exif_data["GPSInfo"].keys():
for key in gps_ifd.keys():
decode = ExifTags.GPSTAGS.get(key, key)
gpsinfo[decode] = exif_data["GPSInfo"][key]
gpsinfo[decode] = gps_ifd[key]
if "GPSLatitude" in gpsinfo and "GPSLongitude" in gpsinfo:
lat = convertExifLocationToDecimalDegrees(gpsinfo["GPSLatitude"], gpsinfo.get("GPSLatitudeRef", "N"))
lon = convertExifLocationToDecimalDegrees(gpsinfo["GPSLongitude"], gpsinfo.get("GPSLongitudeRef", "E"))
Expand Down
4 changes: 2 additions & 2 deletions geonode/documents/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def test_document_mimetypes_rendering(self):
# Make sure we won't have template rendering issues
self.assertTrue("dwg" in ARCHIVETYPES)
self.assertTrue("dxf" in ARCHIVETYPES)
self.assertTrue("tif" in ARCHIVETYPES)
self.assertTrue("tiff" in ARCHIVETYPES)
self.assertTrue("tif" in IMGTYPES)
self.assertTrue("tiff" in IMGTYPES)
self.assertTrue("pbm" in ARCHIVETYPES)

@patch("geonode.documents.tasks.create_document_thumbnail")
Expand Down
Loading