Skip to content

Commit

Permalink
admin can clone newsletter (#1938)
Browse files Browse the repository at this point in the history
* admin can clone newsletter

- remove unique constraint on newsletter subject
- admin can clone newsletter

* update coupon image

---------

Co-authored-by: Son NK <son@simplelogin.io>
  • Loading branch information
nguyenkims and Son NK authored Nov 7, 2023
1 parent a097e33 commit 75dd3cf
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/admin_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,26 @@ def send_newsletter_to_address(self, newsletter_ids):
else:
flash(error_msg, "error")

@action(
"clone_newsletter",
"Clone this newsletter",
)
def clone_newsletter(self, newsletter_ids):
if len(newsletter_ids) != 1:
flash("you can only select 1 newsletter", "error")
return

newsletter_id = newsletter_ids[0]
newsletter: Newsletter = Newsletter.get(newsletter_id)
new_newsletter = Newsletter.create(
subject=newsletter.subject,
html=newsletter.html,
plain_text=newsletter.plain_text,
commit=True,
)

flash(f"Newsletter {new_newsletter.subject} has been cloned", "success")


class NewsletterUserAdmin(SLModelView):
column_searchable_list = ["id"]
Expand Down
2 changes: 1 addition & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@ def is_active(self):

class Newsletter(Base, ModelMixin):
__tablename__ = "newsletter"
subject = sa.Column(sa.String(), nullable=False, unique=True, index=True)
subject = sa.Column(sa.String(), nullable=False, index=True)

html = sa.Column(sa.Text)
plain_text = sa.Column(sa.Text)
Expand Down
31 changes: 31 additions & 0 deletions migrations/versions/2023_110714_4bc54632d9aa_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""empty message
Revision ID: 4bc54632d9aa
Revises: 46ecb648a47e
Create Date: 2023-11-07 14:02:17.610226
"""
import sqlalchemy_utils
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '4bc54632d9aa'
down_revision = '46ecb648a47e'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('ix_newsletter_subject', table_name='newsletter')
op.create_index(op.f('ix_newsletter_subject'), 'newsletter', ['subject'], unique=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_newsletter_subject'), table_name='newsletter')
op.create_index('ix_newsletter_subject', 'newsletter', ['subject'], unique=True)
# ### end Alembic commands ###
Binary file modified static/images/coupon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 75dd3cf

Please sign in to comment.