support articles
This commit is contained in:
51
models.py
51
models.py
@@ -537,4 +537,53 @@ class Instance(db.Model):
|
||||
updated_at = db.Column(db.DateTime, nullable=False, server_default=db.text('CURRENT_TIMESTAMP'), onupdate=db.text('CURRENT_TIMESTAMP'))
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Instance {self.name}>'
|
||||
return f'<Instance {self.name}>'
|
||||
|
||||
class HelpArticle(db.Model):
|
||||
__tablename__ = 'help_articles'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
title = db.Column(db.String(200), nullable=False)
|
||||
category = db.Column(db.String(50), nullable=False) # getting-started, user-management, file-management, communication, security, administration
|
||||
body = db.Column(db.Text, nullable=False) # Rich text content
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
created_by = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False)
|
||||
is_published = db.Column(db.Boolean, default=True)
|
||||
order_index = db.Column(db.Integer, default=0) # For ordering articles within categories
|
||||
|
||||
# Relationships
|
||||
creator = db.relationship('User', backref=db.backref('created_help_articles', cascade='all, delete-orphan'), foreign_keys=[created_by])
|
||||
|
||||
def __repr__(self):
|
||||
return f'<HelpArticle {self.title} ({self.category})>'
|
||||
|
||||
@classmethod
|
||||
def get_categories(cls):
|
||||
"""Get all available categories with their display names"""
|
||||
return {
|
||||
'getting-started': 'Getting Started',
|
||||
'user-management': 'User Management',
|
||||
'file-management': 'File Management',
|
||||
'communication': 'Communication',
|
||||
'security': 'Security & Privacy',
|
||||
'administration': 'Administration'
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_articles_by_category(cls, category, published_only=True):
|
||||
"""Get articles for a specific category"""
|
||||
query = cls.query.filter_by(category=category)
|
||||
if published_only:
|
||||
query = query.filter_by(is_published=True)
|
||||
return query.order_by(cls.order_index.asc(), cls.created_at.desc()).all()
|
||||
|
||||
@classmethod
|
||||
def get_all_published(cls):
|
||||
"""Get all published articles grouped by category"""
|
||||
articles = cls.query.filter_by(is_published=True).order_by(cls.order_index.asc(), cls.created_at.desc()).all()
|
||||
grouped = {}
|
||||
for article in articles:
|
||||
if article.category not in grouped:
|
||||
grouped[article.category] = []
|
||||
grouped[article.category].append(article)
|
||||
return grouped
|
||||
Reference in New Issue
Block a user