Skip to content
Draft
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
2 changes: 1 addition & 1 deletion udata/commands/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"permissions",
],
"resource": ["latest", "preview_url", "last_modified"],
"organization": ["class", "page", "uri", "logo_thumbnail", "permissions"],
"organization": ["class", "page", "uri", "logo_thumbnail", "banner_thumbnail", "permissions"],
"reuse": [
"datasets",
"image_thumbnail",
Expand Down
26 changes: 26 additions & 0 deletions udata/core/organization/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,32 @@ def put(self, org):
return {"image": org.logo}


@ns.route("/<org:org>/banner/", endpoint="organization_banner")
@api.doc(**common_doc)
class BannerAPI(API):
@api.secure
@api.doc("organization_banner")
@api.expect(image_parser)
@api.marshal_with(uploaded_image_fields)
def post(self, org):
"""Upload a new banner"""
org.permissions["edit"].test()
parse_uploaded_image(org.banner)
org.save()
return {"image": org.banner}

@api.secure
@api.doc("resize_organization_banner")
@api.expect(image_parser)
@api.marshal_with(uploaded_image_fields)
def put(self, org):
"""Set the banner BBox"""
org.permissions["edit"].test()
parse_uploaded_image(org.banner)
org.save()
return {"image": org.banner}


dataset_parser = DatasetApiParser()


Expand Down
27 changes: 26 additions & 1 deletion udata/core/organization/api_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
from udata.auth.helpers import current_user_is_admin_or_self
from udata.core.badges.models import Badge

from .constants import BIGGEST_LOGO_SIZE, DEFAULT_ROLE, MEMBERSHIP_STATUS, ORG_ROLES, REQUEST_TYPES
from .constants import (
BIGGEST_BANNER_SIZE,
BIGGEST_LOGO_SIZE,
DEFAULT_ROLE,
MEMBERSHIP_STATUS,
ORG_ROLES,
REQUEST_TYPES,
)

generic_reference_fields = api.model(
"GenericReference",
Expand Down Expand Up @@ -51,6 +58,15 @@
description="The organization logo thumbnail URL. This is the square "
"({0}x{0}) and cropped version.".format(BIGGEST_LOGO_SIZE),
),
"banner": fields.ImageField(original=True, description="The organization banner URL"),
"banner_thumbnail": fields.ImageField(
attribute="banner",
size=BIGGEST_BANNER_SIZE,
description="The organization banner thumbnail URL ({0}px wide).".format(
BIGGEST_BANNER_SIZE
),
),
"banner_color": fields.String(description="The organization banner color (hex)"),
"badges": fields.List(
fields.Nested(Badge.__read_fields__),
description="The organization badges",
Expand Down Expand Up @@ -234,6 +250,15 @@ def member_email_with_visibility_check(email):
description="The organization logo thumbnail URL. This is the square "
"({0}x{0}) and cropped version.".format(BIGGEST_LOGO_SIZE),
),
"banner": fields.ImageField(original=True, description="The organization banner URL"),
"banner_thumbnail": fields.ImageField(
attribute="banner",
size=BIGGEST_BANNER_SIZE,
description="The organization banner thumbnail URL ({0}px wide).".format(
BIGGEST_BANNER_SIZE
),
),
"banner_color": fields.String(description="The organization banner color (hex)"),
"members": fields.List(
fields.Nested(member_fields, description="The organization members")
),
Expand Down
4 changes: 4 additions & 0 deletions udata/core/organization/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
LOGO_SIZES = [100, 60, 25]
BIGGEST_LOGO_SIZE = LOGO_SIZES[0]

BANNER_MAX_SIZE = 2000
BANNER_SIZES = [1400, 400]
BIGGEST_BANNER_SIZE = BANNER_SIZES[0]

PUBLIC_SERVICE = "public-service"
CERTIFIED = "certified"
ASSOCIATION = "association"
Expand Down
4 changes: 3 additions & 1 deletion udata/core/organization/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from udata.forms import Form, ModelForm, fields, validators
from udata.i18n import lazy_gettext as _

from .constants import DESCRIPTION_SIZE_LIMIT, LOGO_SIZES, ORG_ROLES, TITLE_SIZE_LIMIT
from .constants import BANNER_SIZES, DESCRIPTION_SIZE_LIMIT, LOGO_SIZES, ORG_ROLES, TITLE_SIZE_LIMIT
from .models import Member, MembershipRequest, Organization

__all__ = (
Expand Down Expand Up @@ -54,6 +54,8 @@ class OrganizationForm(ModelForm):
)
url = fields.URLField(_("Website"), description=_("The organization website URL"))
logo = fields.ImageField(_("Logo"), sizes=LOGO_SIZES)
banner = fields.ImageField(_("Banner"), sizes=BANNER_SIZES)
banner_color = fields.StringField(_("Banner color"))
business_number_id = fields.StringField(
_("Business id"), [org_bid_check], description=_("Business identification number")
)
Expand Down
16 changes: 16 additions & 0 deletions udata/core/organization/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
from .constants import (
ASSIGNABLE_OBJECT_TYPES,
ASSOCIATION,
BANNER_MAX_SIZE,
BANNER_SIZES,
BIGGEST_BANNER_SIZE,
BIGGEST_LOGO_SIZE,
CERTIFIED,
COMPANY,
Expand Down Expand Up @@ -198,6 +201,19 @@ class Organization(
"size": BIGGEST_LOGO_SIZE,
},
)
banner = field(
ImageField(
fs=avatars,
basename=default_image_basename,
max_size=BANNER_MAX_SIZE,
thumbnails=BANNER_SIZES,
),
show_as_ref=True,
thumbnail_info={
"size": BIGGEST_BANNER_SIZE,
},
)
banner_color = field(StringField(max_length=7))
business_number_id = field(StringField(max_length=ORG_BID_SIZE_LIMIT))

members = field(ListField(EmbeddedDocumentField(Member)))
Expand Down