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

Project published notification view and template #1792

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
25 changes: 25 additions & 0 deletions funnel/models/notification_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'RegistrationCancellationNotification',
'RegistrationConfirmationNotification',
'ProjectStartingNotification',
'ProjectPublishedNotification',
'OrganizationAdminMembershipNotification',
'OrganizationAdminMembershipRevokedNotification',
]
Expand All @@ -57,6 +58,15 @@ def preference_context(self) -> Profile:
return self.document.profile # type: ignore[attr-defined]


class DocumentIsProfile:
"""Mixin class for notifications on the profile."""

@property
def preference_context(self) -> Profile:
"""Return the document as the preference context."""
return self.document # type: ignore[attr-defined]


# --- Account notifications ------------------------------------------------------------


Expand Down Expand Up @@ -153,6 +163,21 @@ class ProjectStartingNotification(
# This is a notification triggered without an actor


class ProjectPublishedNotification(
DocumentIsProfile, Notification[Profile, Project], type='project_published'
):
"""Notification of a newly published project."""

category = notification_categories.participant
title = __("When a project is published")
description = __(
"Notifies all members of a profile when a new project is published"
)

roles = ['project_crew', 'project_participant', 'account_participant']
exclude_actor = False # Send to everyone including the actor


# --- Comment notifications ------------------------------------------------------------


Expand Down
9 changes: 6 additions & 3 deletions funnel/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,17 @@ def __repr__(self) -> str:
message=__("Submissions will be accepted until the optional closing date"),
type='success',
)
def open_cfp(self):
def open_cfp(self) -> bool:
"""Change state to accept submissions."""
first_opened = False
# If closing date is in the past, remove it
if self.cfp_end_at is not None and self.cfp_end_at <= utcnow():
self.cfp_end_at = None
# If opening date is not set, set it
if self.cfp_start_at is None:
self.cfp_start_at = sa.func.utcnow()
first_opened = True
return first_opened

@with_roles(call={'editor'}) # skipcq: PTC-W0049
@cfp_state.transition(
Expand All @@ -494,7 +497,7 @@ def open_cfp(self):
message=__("Submissions will no longer be accepted"),
type='success',
)
def close_cfp(self):
def close_cfp(self) -> None:
"""Change state to not accept submissions."""

@with_roles(call={'editor'})
Expand Down Expand Up @@ -522,7 +525,7 @@ def publish(self) -> bool:
message=__("The project has been withdrawn and is no longer listed"),
type='success',
)
def withdraw(self):
def withdraw(self) -> None:
"""Withdraw a project."""

@property
Expand Down
8 changes: 4 additions & 4 deletions funnel/templates/notifications/layout_email.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@

<center role="article" aria-roledescription="email" lang="en">
<!--[if mso | IE]>
<table class="header-container" align="left" role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #f0f0f0; text-align: left";>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #f0f0f0;">
<tr>
<td>
<![endif]-->
Expand All @@ -356,9 +356,9 @@
1. max-width for all clients except Desktop Windows Outlook, allowing the email to squish on narrow but never go wider than 600px.
2. MSO tags for Desktop Windows Outlook enforce a 600px width.
#}
<div align="left" class="email-container">
<div align="center" class="email-container">
<!--[if mso]>
<table class="header-container" align="left" role="presentation" cellspacing="0" cellpadding="0" border="0" width="600" style="text-align: left">
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="600">
<tr>
<td>
<![endif]-->
Expand Down Expand Up @@ -434,7 +434,7 @@

{# Email content : BEGIN #}
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
{% if view %}
{% if view.hero_image %}
{# Hero image centered : BEGIN #}
{%- if view.hero_image %}
{{ hero_image(view.hero_image, view.email_heading or '') }}
Expand Down
125 changes: 125 additions & 0 deletions funnel/templates/notifications/project_published_email.html.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{%- extends "notifications/layout_email.html.jinja2" -%}
{%- from "notifications/macros_email.html.jinja2" import cta_button, rsvp_footer, pinned_update -%}

{% block stylesheet %}
<style>
a {
text-decoration: none;
font-weight: bold;
color: #1f2d3d;
}
.project-banner__box__image {
position: relative;
transform: translate(0, -8px);
object-fit: cover;
width: 100%;
height: 100%;
}
.mui-list--unstyled {
padding-left: 0;
list-style: none;
}
.mui--align-middle {
vertical-align: middle !important;
}
.fa-icon--right-margin {
margin-right: 8px;
}
.project_time {
margin: 8px 0 8px;
font-size: 16px;
font-weight: 600;
}
.mui--text-light {
color: #4d5763;
}
.button-td,
.button-a {
border-radius: 4px;
background-color: #4d5763;
transition: all 100ms ease-in;
font-family: sans-serif;
font-size: 15px;
line-height: 15px;
text-decoration: none;
}
.button-a {
border: 1px solid #4d5763;
padding: 13px 17px;
color: #ffffff;
display: block;
}
.button-td-primary:hover,
.button-a-primary:hover {
background-color: #1f2d3d !important;
border-color: #1f2d3d !important;
}
.project-banner__profile-details {
display: -webkit-box-flex;
display: -ms-flexbox;
display: flex;
line-height: 30px;
margin-left: 0;
}
.project_title {
line-height: 1.6rem;
margin-top: 0;
}
.project_details {
padding: 0;
}
.profile-details__text {
margin-left: 4px;
}
</style>
{% endblock stylesheet %}
{%- block content -%}

<tr>
<td>
{%- if view.project.bg_image.url %}
<img class="project-banner__box__image" src="{{ view.project.bg_image.resize(700) }}" alt="{{ view.project.title }}"/>
{%- else %}
<img class="project-banner__box__image" src="{{ url_for('static', filename='img/default-banner.png') }}" alt="{{ view.project.title }}"/>
{% endif %}
</td>
</tr>
<tr>
<td class="project_details" align="left">
<div class="project-banner__profile-details">
{%- if view.project.profile.logo_url.url %}
<a href="{{ view.project.profile.url_for() }}">
<img src="{{ view.project.profile.logo_url.resize(30) }}" alt="{{ view.project.profile.title }}"/>
</a>
{% endif %}
<a href="{{ view.project.profile.url_for() }}" class="profile-details__text">{{ view.project.profile.title }}</a>
</div>
</td>
</tr>
<tr width="100%">
<td align="left">
<h2 class="project_title"><a href="{{ view.project.url_for() }}">{{ view.project.title }}</a></h2>
<p class="project_time">{{ view.project.start_at|datetime(format='dd MMM YYYY') }} | {{ view.project.start_at|datetime(format='HH:MM') }}</p>
</td>
</tr>
<tr>
<td>
{{ view.project.description.html }}
</td>
</tr>
<br>

{# Button : BEGIN #}
{{ cta_button(view.project.url_for(_external=true), gettext("Register") )}}
{# Button : END #}

{# {{ pinned_update(view, project) }} #}

<tr>
<td class="line-separator"></td>
</tr>
<tr>
<td class="footer-text">{{ view.reason }}</td>
</tr>

{%- endblock content -%}
1 change: 1 addition & 0 deletions funnel/views/notifications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
comment_notification,
organization_membership_notification,
project_crew_notification,
project_published_notification,
project_starting_notification,
proposal_notification,
rsvp_notification,
Expand Down
70 changes: 70 additions & 0 deletions funnel/views/notifications/project_published_notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Project published notification."""

from __future__ import annotations

from flask import render_template

from baseframe import _, __

from ...models import Project, ProjectPublishedNotification
from ...transports.sms import SmsTemplate
from ..helpers import shortlink
from ..notification import RenderNotification
from .mixins import TemplateVarMixin


class ProjectPublishedTemplate(TemplateVarMixin, SmsTemplate):
"""DLT registered template for Project published."""

registered_template = (
"{#var#}, whose event you previously registered for, has just announced"
" {#var#}. Details here: {#var#}\n\nhttps://bye.li to stop -Hasgeek"
)
template = (
"{profile}, whose event you previously registered for, has just announced"
" {project}. Details here: {url}\n\nhttps://bye.li to stop -Hasgeek"
)
plaintext_template = "{profile} has published a new project: {url}"
Copy link
Member

Choose a reason for hiding this comment

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

This needs to have {project} to be sufficiently verbose.


url: str
profile: str


@ProjectPublishedNotification.renderer
class RenderProjectPublishedNotification(RenderNotification):
"""Notify account followers when a new project is published."""

project: Project
aliases = {'document': 'profile', 'fragment': 'project'}
emoji_prefix = "📰 "
reason = __(
"You are receiving this because you have registered for this or related"
" projects"
)

@property
def actor(self):
return self.project.user

def web(self):
return render_template('notifications/update_new_web.html.jinja2', view=self)

def email_subject(self):
return self.emoji_prefix + _("{update} ({project})").format(
update=self.project.title, project=self.project.joined_title
)

def email_content(self):
return render_template(
'notifications/project_published_email.html.jinja2', view=self
)

def sms(self) -> ProjectPublishedTemplate:
return ProjectPublishedTemplate(
profile=self.project.profile,
project=self.project,
url=shortlink(
self.update.url_for(_external=True, **self.tracking_tags('sms')),
shorter=True,
),
)
17 changes: 13 additions & 4 deletions funnel/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
from json import JSONDecodeError
from types import SimpleNamespace
from typing import Optional

from flask import Response, abort, current_app, flash, render_template, request
from flask_babel import format_number
Expand Down Expand Up @@ -41,6 +42,7 @@
RSVP_STATUS,
Profile,
Project,
ProjectPublishedNotification,
RegistrationCancellationNotification,
RegistrationConfirmationNotification,
Rsvp,
Expand Down Expand Up @@ -563,15 +565,22 @@ def edit_boxoffice_data(self) -> ReturnView:
def transition(self) -> ReturnView:
"""Change project's state."""
transition_form = ProjectTransitionForm(obj=self.obj)
if (
transition_form.validate_on_submit()
): # check if the provided transition is valid
# Check if the provided transition is valid
if transition_form.validate_on_submit():
transition = getattr(
self.obj.current_access(), transition_form.transition.data
)
transition() # call the transition
first_time_flag: Optional[bool] = transition() # call the transition
db.session.commit()
flash(transition.data['message'], 'success')
if transition_form.transition.data == 'publish' and first_time_flag:
dispatch_notification(
ProjectPublishedNotification(
document=self.obj.profile, fragment=self.obj
)
)
# If there's a future notification for CFP open, it can be dispatched here
# elif transition_form.transition.data == 'open_cfp' and first_time_flag:
else:
flash(_("Invalid transition for this project"), 'error')
abort(403)
Expand Down