Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Flask Configuration
FLASK_ENV=development
SECRET_KEY=your-secret-key-here
DEBUG=True

# Database
DATABASE_URL=postgresql://username:password@localhost/bloghub_db

# Email Configuration
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=your-email-password

# External Services
STRIPE_SECRET_KEY=sk_test_your_stripe_key
STRIPE_PUBLIC_KEY=pk_test_your_stripe_key
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key

# Monitoring
SENTRY_DSN=your-sentry-dsn

# Application Settings
PORT=5000
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
venv/
env/
ENV/
.venv

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store

# Testing
.pytest_cache/
.coverage
htmlcov/
*.cover

# Database
*.db
*.sqlite
*.sqlite3

# Logs
*.log
logs/

# Environment variables
.env
.env.local

# Uploads
app/static/uploads/*
!app/static/uploads/.gitkeep

# Backups
backups/
*.sql
*.gz

# OS
Thumbs.db
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM python:3.11-slim

LABEL maintainer="[email protected]"
LABEL description="BlogHub CMS Application"

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
postgresql-client \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create necessary directories
RUN mkdir -p /app/app/static/uploads /app/logs

# Expose port
EXPOSE 5000

# Set environment variables
ENV FLASK_APP=app.py
ENV PYTHONUNBUFFERED=1

# Run the application
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "app:create_app()"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 BlogHub Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include requirements.txt
include LICENSE
include README.md
recursive-include app/templates *
recursive-include app/static *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.PHONY: help install test lint format run docker-build docker-up clean

help:
@echo "BlogHub - Make commands"
@echo ""
@echo "install Install dependencies"
@echo "test Run tests"
@echo "lint Run linters"
@echo "format Format code"
@echo "run Run development server"
@echo "docker-build Build Docker image"
@echo "docker-up Start Docker containers"
@echo "clean Clean up temporary files"

install:
pip install -r requirements.txt

test:
pytest tests/ -v

test-cov:
pytest tests/ -v --cov=app --cov-report=html --cov-report=term

lint:
flake8 app/ tests/
mypy app/ --ignore-missing-imports

format:
black app/ tests/

run:
python app.py

docker-build:
docker build -t bloghub:latest .

docker-up:
docker-compose up -d

docker-down:
docker-compose down

migrate:
sqlite3 bloghub.db < migrations/001_initial_schema.sql

clean:
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
find . -type d -name "*.egg-info" -exec rm -rf {} +
rm -rf .pytest_cache
rm -rf htmlcov
rm -rf dist
rm -rf build
rm -f .coverage
48 changes: 48 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
BlogHub - A Simple CMS Platform
Main application entry point
"""
import os
from flask import Flask
from app.routes import posts, auth, admin, api
from app.utils.database import init_db
from config import Config

def create_app(config_class=Config):
"""
Application factory pattern for creating Flask app instances.

Args:
config_class: Configuration class to use

Returns:
Flask application instance
"""
app = Flask(__name__)
app.config.from_object(config_class)

# Initialize database
init_db(app)

# Register blueprints
app.register_blueprint(posts.bp)
app.register_blueprint(auth.bp)
app.register_blueprint(admin.bp)
app.register_blueprint(api.bp)

# Error handlers
@app.errorhandler(404)
def not_found(error):
return {"error": "Not found"}, 404

@app.errorhandler(500)
def internal_error(error):
return {"error": "Internal server error"}, 500

return app

if __name__ == '__main__':
app = create_app()
# Get port from environment or use default
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=app.config['DEBUG'])
4 changes: 4 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
BlogHub application package.
"""
__version__ = '1.2.0'
8 changes: 8 additions & 0 deletions app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Database models for BlogHub.
"""
from .user import User
from .post import Post
from .comment import Comment

__all__ = ['User', 'Post', 'Comment']
46 changes: 46 additions & 0 deletions app/models/comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Comment model for blog posts.
"""
from datetime import datetime

class Comment:
"""
Comment model for user comments on blog posts.

Attributes:
id: Unique comment identifier
post_id: ID of the post this comment belongs to
user_id: ID of the user who created the comment
content: Comment text
created_at: Comment creation timestamp
is_approved: Moderation status
"""

def __init__(self, post_id, user_id, content):
self.post_id = post_id
self.user_id = user_id
self.content = content
self.created_at = datetime.utcnow()
self.is_approved = True # Auto-approve for now

def approve(self):
"""Approve the comment for display."""
self.is_approved = True

def to_dict(self):
"""
Convert comment to dictionary.

Returns:
dict: Comment data
"""
return {
'post_id': self.post_id,
'user_id': self.user_id,
'content': self.content,
'created_at': self.created_at.isoformat(),
'is_approved': self.is_approved
}

def __repr__(self):
return f'<Comment on post {self.post_id}>'
Loading
Loading