Skip to content

아티클 큐레이션 기능 #16

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

Merged
merged 6 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY=sk-proj-xxxxx
GEMINI_API_KEY=asdasd
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
- ./pythonkr_backend:/app/pythonkr_backend
ports:
- "8080:8080"
env_file:
- .env
depends_on:
- db
environment:
Expand All @@ -23,4 +25,4 @@ services:
POSTGRES_PASSWORD: pktesting

volumes:
postgres_data:
postgres_data:
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"beautifulsoup4>=4.13.3",
"django>=5.1.7",
"gunicorn>=23.0.0",
"httpx>=0.28.1",
"llm>=0.24.2",
"llm-gemini>=0.18.1",
"lxml>=5.3.2",
"markdown>=3.7",
"psycopg[binary]>=3.2.5",
"readtime>=3.0.0",
"requests>=2.32.3",
"tiktoken>=0.9.0",
"wagtail>=6.4.1",
"wagtail-bakery>=0.8.0",
]
Expand Down
Empty file.
88 changes: 88 additions & 0 deletions pythonkr_backend/curation/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from django.contrib import admin, messages
from .models import Article, Category # Or combine imports


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'slug')
search_fields = ('name',)
prepopulated_fields = {'slug': ('name',)} # Auto-populate slug from name


@admin.action(description="Fetch content, summarize, and translate selected articles")
def summarize_selected_articles(modeladmin, request, queryset):
success_count = 0
errors = []

for article in queryset:
result = article.fetch_and_summarize()
if result.startswith("Error"):
errors.append(f"{article.url}: {result}")
else:
success_count += 1

if success_count > 0:
modeladmin.message_user(
request,
f"Successfully processed {success_count} article(s) (fetch, summarize, translate).",
messages.SUCCESS
)

if errors:
error_message = "Errors encountered:\n" + "\n".join(errors)
modeladmin.message_user(request, error_message, messages.WARNING)




@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
list_display = ('url', 'title', 'display_categories', 'summary_preview', 'summary_ko_preview', 'reading_time_minutes', 'updated_at', 'created_at')
list_filter = ('categories', 'created_at', 'updated_at')
search_fields = ('url', 'title', 'summary', 'summary_ko', 'categories__name')
readonly_fields = ('created_at', 'updated_at', 'summary', 'summary_ko', 'reading_time_minutes')
actions = [summarize_selected_articles]
filter_horizontal = ('categories',)

fieldsets = (
('Article Information', {
'fields': ('url', 'title', 'categories')
}),
('Generated Content', {
'fields': ('summary', 'summary_ko', 'reading_time_minutes'),
'classes': ('collapse',)
}),
('Metadata', {
'fields': ('created_at', 'updated_at'),
'classes': ('collapse',)
}),
)

@admin.display(description='Categories')
def display_categories(self, obj):
"""Displays categories as a comma-separated string in the list view."""
if obj.categories.exists():
return ", ".join([category.name for category in obj.categories.all()])
return '-' # Or None, or empty string

def get_readonly_fields(self, request, obj=None):
# Make 'categories' always read-only as it's set by the LLM
readonly = list(super().get_readonly_fields(request, obj))
if 'categories' not in readonly:
readonly.append('categories')
return readonly

@admin.display(description='Summary Preview')
def summary_preview(self, obj):
if obj.summary:
preview = obj.summary[:100]
return f"{preview}..." if len(obj.summary) > 100 else preview
return "No summary available"

@admin.display(description='Korean Summary Preview')
def summary_ko_preview(self, obj):
if obj.summary_ko:
if obj.summary_ko.startswith("Translation Error"): return obj.summary_ko
preview = obj.summary_ko[:50]
return f"{preview}..." if len(obj.summary_ko) > 50 else preview
return "No Korean summary"
6 changes: 6 additions & 0 deletions pythonkr_backend/curation/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CurationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'curation'
25 changes: 25 additions & 0 deletions pythonkr_backend/curation/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.2 on 2025-04-20 05:42

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Article',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField(help_text='The unique URL of the article.', max_length=2048, unique=True)),
('title', models.CharField(blank=True, help_text='Article title (can be fetched automatically or entered manually).', max_length=512)),
('summary', models.TextField(blank=True, help_text='AI-generated summary of the article.')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2 on 2025-04-20 06:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('curation', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='article',
name='reading_time_minutes',
field=models.PositiveIntegerField(blank=True, help_text='Estimated reading time in minutes.', null=True),
),
]
18 changes: 18 additions & 0 deletions pythonkr_backend/curation/migrations/0003_article_summary_ko.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2 on 2025-04-20 06:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('curation', '0002_article_reading_time_minutes'),
]

operations = [
migrations.AddField(
model_name='article',
name='summary_ko',
field=models.TextField(blank=True, help_text='Korean translation of the summary (via OpenAI).'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2 on 2025-04-20 06:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('curation', '0003_article_summary_ko'),
]

operations = [
migrations.AlterField(
model_name='article',
name='reading_time_minutes',
field=models.PositiveIntegerField(blank=True, help_text='Estimated reading time in minutes (based on full article content).', null=True),
),
]
25 changes: 25 additions & 0 deletions pythonkr_backend/curation/migrations/0005_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.2 on 2025-04-20 07:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('curation', '0004_alter_article_reading_time_minutes'),
]

operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text="The name of the category (e.g., 'Web Development', 'LLM').", max_length=100, unique=True)),
('slug', models.SlugField(blank=True, help_text='A URL-friendly slug for the category.', max_length=100, unique=True)),
],
options={
'verbose_name_plural': 'Categories',
'ordering': ['name'],
},
),
]
18 changes: 18 additions & 0 deletions pythonkr_backend/curation/migrations/0006_article_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2 on 2025-04-20 07:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('curation', '0005_category'),
]

operations = [
migrations.AddField(
model_name='article',
name='categories',
field=models.ManyToManyField(blank=True, help_text='Select one or more categories for this article.', related_name='articles', to='curation.category'),
),
]
Empty file.
Loading