add defaults templates
This commit is contained in:
Binary file not shown.
BIN
__pycache__/create_default_templates.cpython-313.pyc
Normal file
BIN
__pycache__/create_default_templates.cpython-313.pyc
Normal file
Binary file not shown.
5
app.py
5
app.py
@@ -13,6 +13,7 @@ from tasks import cleanup_trash
|
||||
import click
|
||||
from utils import timeago
|
||||
from extensions import db, login_manager, csrf
|
||||
from utils.email_templates import create_default_templates
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
@@ -85,6 +86,10 @@ def create_app():
|
||||
# Register custom filters
|
||||
app.jinja_env.filters['timeago'] = timeago
|
||||
|
||||
# Create default email templates if they don't exist
|
||||
with app.app_context():
|
||||
create_default_templates()
|
||||
|
||||
return app
|
||||
|
||||
app = create_app()
|
||||
|
||||
@@ -15,6 +15,7 @@ def init_app(app: Flask):
|
||||
from .rooms import rooms_bp as rooms_routes
|
||||
from .conversations import conversations_bp as conversations_routes
|
||||
from .admin import admin as admin_routes
|
||||
from .email_templates import email_templates as email_templates_routes
|
||||
|
||||
# Initialize routes
|
||||
init_main_routes(main_bp)
|
||||
@@ -33,6 +34,7 @@ def init_app(app: Flask):
|
||||
app.register_blueprint(contacts_routes)
|
||||
app.register_blueprint(conversations_routes)
|
||||
app.register_blueprint(admin_routes)
|
||||
app.register_blueprint(email_templates_routes)
|
||||
|
||||
@app.route('/rooms/<int:room_id>/trash')
|
||||
@login_required
|
||||
|
||||
Binary file not shown.
BIN
routes/__pycache__/email_templates.cpython-313.pyc
Normal file
BIN
routes/__pycache__/email_templates.cpython-313.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -651,9 +651,7 @@ def init_routes(main_bp):
|
||||
users = {user.id: user for user in User.query.filter(User.id.in_(user_ids)).all()}
|
||||
|
||||
# Get email templates for the email templates tab
|
||||
email_templates = []
|
||||
if active_tab == 'email_templates':
|
||||
email_templates = EmailTemplate.query.filter_by(is_active=True).all()
|
||||
email_templates = EmailTemplate.query.filter_by(is_active=True).all()
|
||||
|
||||
if request.method == 'GET':
|
||||
company_form.company_name.data = site_settings.company_name
|
||||
|
||||
@@ -4,6 +4,18 @@ from .event_logger import log_event, get_user_events, get_room_events, get_recen
|
||||
from .notification import create_notification, get_user_notifications, mark_notification_read, mark_all_notifications_read, get_unread_count, delete_notification, delete_old_notifications
|
||||
from .path_utils import clean_path, secure_file_path
|
||||
from .time_utils import timeago, format_datetime, parse_datetime
|
||||
from functools import wraps
|
||||
from flask import flash, redirect, url_for
|
||||
from flask_login import current_user
|
||||
|
||||
def admin_required(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if not current_user.is_authenticated or not current_user.is_admin:
|
||||
flash('You do not have permission to access this page.', 'error')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
__all__ = [
|
||||
'user_has_permission',
|
||||
|
||||
Binary file not shown.
BIN
utils/__pycache__/email_templates.cpython-313.pyc
Normal file
BIN
utils/__pycache__/email_templates.cpython-313.pyc
Normal file
Binary file not shown.
139
utils/email_templates.py
Normal file
139
utils/email_templates.py
Normal file
@@ -0,0 +1,139 @@
|
||||
from models import EmailTemplate, User, db
|
||||
|
||||
def create_default_templates():
|
||||
"""Create default email templates if they don't exist."""
|
||||
# Get the first admin user to be the creator
|
||||
admin = User.query.filter_by(is_admin=True).first()
|
||||
if not admin:
|
||||
print("No admin user found. Please create an admin user first.")
|
||||
return
|
||||
|
||||
# Define default templates for each notification type
|
||||
default_templates = [
|
||||
{
|
||||
'name': 'Account Created',
|
||||
'subject': 'Welcome to DocuPulse!',
|
||||
'body': '''
|
||||
<h2>Welcome to DocuPulse!</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>Your account has been successfully created. You can now log in and start using DocuPulse.</p>
|
||||
<p>If you have any questions, please don't hesitate to contact our support team.</p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Password Reset',
|
||||
'subject': 'Password Reset Request',
|
||||
'body': '''
|
||||
<h2>Password Reset Request</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>We received a request to reset your password. Click the link below to set a new password:</p>
|
||||
<p><a href="{{ reset_link }}">Reset Password</a></p>
|
||||
<p>If you didn't request this, please ignore this email or contact support if you have concerns.</p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Account Deleted',
|
||||
'subject': 'Your DocuPulse Account Has Been Deleted',
|
||||
'body': '''
|
||||
<h2>Account Deletion Confirmation</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>Your DocuPulse account has been successfully deleted as requested.</p>
|
||||
<p>We're sorry to see you go. If you change your mind, you can create a new account at any time.</p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Account Updated',
|
||||
'subject': 'Your DocuPulse Account Has Been Updated',
|
||||
'body': '''
|
||||
<h2>Account Update Confirmation</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>Your DocuPulse account has been successfully updated.</p>
|
||||
<p>If you didn't make these changes, please contact our support team immediately.</p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Room Invite',
|
||||
'subject': 'You\'ve Been Invited to a Room',
|
||||
'body': '''
|
||||
<h2>Room Invitation</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>{{ sender.username }} has invited you to join the room "{{ room_name }}".</p>
|
||||
<p>Click the link below to view the room:</p>
|
||||
<p><a href="{{ room_link }}">View Room</a></p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Room Invite Removed',
|
||||
'subject': 'Room Invitation Removed',
|
||||
'body': '''
|
||||
<h2>Room Invitation Removed</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>Your invitation to the room "{{ room_name }}" has been removed.</p>
|
||||
<p>If you believe this is an error, please contact the room administrator.</p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Conversation Invite',
|
||||
'subject': 'You\'ve Been Invited to a Conversation',
|
||||
'body': '''
|
||||
<h2>Conversation Invitation</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>{{ sender.username }} has invited you to join a conversation.</p>
|
||||
<p>Click the link below to view the conversation:</p>
|
||||
<p><a href="{{ conversation_link }}">View Conversation</a></p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Conversation Invite Removed',
|
||||
'subject': 'Conversation Invitation Removed',
|
||||
'body': '''
|
||||
<h2>Conversation Invitation Removed</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>Your invitation to the conversation has been removed.</p>
|
||||
<p>If you believe this is an error, please contact the conversation administrator.</p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
},
|
||||
{
|
||||
'name': 'Conversation Message',
|
||||
'subject': 'New Message in Conversation',
|
||||
'body': '''
|
||||
<h2>New Message</h2>
|
||||
<p>Dear {{ user.username }},</p>
|
||||
<p>{{ sender.username }} has sent a new message in your conversation.</p>
|
||||
<p>Click the link below to view the message:</p>
|
||||
<p><a href="{{ message_link }}">View Message</a></p>
|
||||
<p>Best regards,<br>The DocuPulse Team</p>
|
||||
'''
|
||||
}
|
||||
]
|
||||
|
||||
# Create templates if they don't exist
|
||||
for template_data in default_templates:
|
||||
existing_template = EmailTemplate.query.filter_by(name=template_data['name']).first()
|
||||
if not existing_template:
|
||||
template = EmailTemplate(
|
||||
name=template_data['name'],
|
||||
subject=template_data['subject'],
|
||||
body=template_data['body'],
|
||||
created_by=admin.id,
|
||||
is_active=True
|
||||
)
|
||||
db.session.add(template)
|
||||
print(f"Created template: {template_data['name']}")
|
||||
else:
|
||||
print(f"Template already exists: {template_data['name']}")
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
print("All default templates have been created successfully!")
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
print(f"Error creating templates: {str(e)}")
|
||||
Reference in New Issue
Block a user