fix: adding bookmark throws a 404
This commit is contained in:
parent
4000658b2f
commit
f56df5e235
BIN
ai/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
ai/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
ai/__pycache__/local_ai_api.cpython-311.pyc
Normal file
BIN
ai/__pycache__/local_ai_api.cpython-311.pyc
Normal file
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from .celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
||||
Binary file not shown.
BIN
config/__pycache__/celery.cpython-311.pyc
Normal file
BIN
config/__pycache__/celery.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
20
config/celery.py
Normal file
20
config/celery.py
Normal file
@ -0,0 +1,20 @@
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
app = Celery('config')
|
||||
|
||||
# Using a string here means the worker doesn't have to serialize
|
||||
# the configuration object to child processes.
|
||||
# - namespace='CELERY' means all celery-related configuration keys
|
||||
# should have a `CELERY_` prefix.
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
# Load task modules from all registered Django app configs.
|
||||
app.autodiscover_tasks()
|
||||
|
||||
@app.task(bind=True, ignore_result=True)
|
||||
def debug_task(self):
|
||||
print(f'Request: {self.request!r}')
|
||||
@ -55,6 +55,9 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'taggit',
|
||||
'django_filters',
|
||||
'core',
|
||||
]
|
||||
|
||||
@ -180,3 +183,33 @@ if EMAIL_USE_SSL:
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
# DRF Settings
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
],
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
'rest_framework.authentication.BasicAuthentication',
|
||||
],
|
||||
'DEFAULT_FILTER_BACKENDS': (
|
||||
'django_filters.rest_framework.DjangoFilterBackend',
|
||||
),
|
||||
}
|
||||
|
||||
# Celery Settings
|
||||
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL', 'redis://localhost:6379/0')
|
||||
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', 'redis://localhost:6379/0')
|
||||
CELERY_ACCEPT_CONTENT = ['json']
|
||||
CELERY_TASK_SERIALIZER = 'json'
|
||||
CELERY_RESULT_SERIALIZER = 'json'
|
||||
CELERY_TIMEZONE = TIME_ZONE
|
||||
|
||||
# Run tasks synchronously in development (no Redis required)
|
||||
CELERY_TASK_ALWAYS_EAGER = True
|
||||
CELERY_TASK_EAGER_PROPAGATES = True
|
||||
|
||||
# Login/Logout Redirects
|
||||
LOGIN_REDIRECT_URL = 'home'
|
||||
LOGOUT_REDIRECT_URL = 'home'
|
||||
@ -1,29 +1,10 @@
|
||||
"""
|
||||
URL configuration for config project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/5.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.urls import path, include
|
||||
from django.contrib.auth import views as auth_views
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("", include("core.urls")),
|
||||
path('admin/', admin.site.urls),
|
||||
path('accounts/login/', auth_views.LoginView.as_view(), name='login'),
|
||||
path('accounts/logout/', auth_views.LogoutView.as_view(), name='logout'),
|
||||
path('', include('core.urls')),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static("/assets/", document_root=settings.BASE_DIR / "assets")
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
||||
Binary file not shown.
BIN
core/__pycache__/api_views.cpython-311.pyc
Normal file
BIN
core/__pycache__/api_views.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
core/__pycache__/serializers.cpython-311.pyc
Normal file
BIN
core/__pycache__/serializers.cpython-311.pyc
Normal file
Binary file not shown.
BIN
core/__pycache__/tasks.cpython-311.pyc
Normal file
BIN
core/__pycache__/tasks.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,30 @@
|
||||
from django.contrib import admin
|
||||
from .models import Team, TeamMembership, Bookmark, BookmarkShare, Extraction, Summary
|
||||
|
||||
# Register your models here.
|
||||
class TeamMembershipInline(admin.TabularInline):
|
||||
model = TeamMembership
|
||||
extra = 1
|
||||
|
||||
@admin.register(Team)
|
||||
class TeamAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'created_at', 'updated_at')
|
||||
inlines = [TeamMembershipInline]
|
||||
|
||||
@admin.register(Bookmark)
|
||||
class BookmarkAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', 'url', 'user', 'is_favorite', 'created_at')
|
||||
list_filter = ('is_favorite', 'created_at', 'user')
|
||||
search_fields = ('title', 'url', 'notes')
|
||||
|
||||
@admin.register(BookmarkShare)
|
||||
class BookmarkShareAdmin(admin.ModelAdmin):
|
||||
list_display = ('bookmark', 'team', 'shared_by', 'shared_at')
|
||||
list_filter = ('team', 'shared_at')
|
||||
|
||||
@admin.register(Extraction)
|
||||
class ExtractionAdmin(admin.ModelAdmin):
|
||||
list_display = ('bookmark', 'extracted_at')
|
||||
|
||||
@admin.register(Summary)
|
||||
class SummaryAdmin(admin.ModelAdmin):
|
||||
list_display = ('bookmark', 'generated_at')
|
||||
32
core/api_views.py
Normal file
32
core/api_views.py
Normal file
@ -0,0 +1,32 @@
|
||||
from rest_framework import viewsets, permissions, filters
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from core.models import Bookmark, Team
|
||||
from core.serializers import BookmarkSerializer, BookmarkDetailSerializer, TeamSerializer
|
||||
from core.tasks import process_bookmark
|
||||
|
||||
class BookmarkViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
filter_backends = [DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter]
|
||||
filterset_fields = ['is_favorite']
|
||||
search_fields = ['title', 'url', 'notes', 'extraction__content_text']
|
||||
ordering_fields = ['created_at', 'updated_at', 'title']
|
||||
ordering = ['-created_at']
|
||||
|
||||
def get_queryset(self):
|
||||
return Bookmark.objects.filter(user=self.request.user).select_related('extraction')
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.action == 'retrieve':
|
||||
return BookmarkDetailSerializer
|
||||
return BookmarkSerializer
|
||||
|
||||
def perform_create(self, serializer):
|
||||
bookmark = serializer.save()
|
||||
process_bookmark.delay(bookmark.id)
|
||||
|
||||
class TeamViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
serializer_class = TeamSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return self.request.user.teams.all()
|
||||
94
core/migrations/0001_initial.py
Normal file
94
core/migrations/0001_initial.py
Normal file
@ -0,0 +1,94 @@
|
||||
# Generated by Django 5.2.7 on 2026-02-04 16:55
|
||||
|
||||
import django.db.models.deletion
|
||||
import taggit.managers
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('taggit', '0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Team',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('description', models.TextField(blank=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Bookmark',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('url', models.URLField(max_length=1000)),
|
||||
('title', models.CharField(blank=True, max_length=255)),
|
||||
('notes', models.TextField(blank=True)),
|
||||
('is_favorite', models.BooleanField(default=False)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('tags', taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bookmarks', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Extraction',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('content_html', models.TextField(blank=True)),
|
||||
('content_text', models.TextField(blank=True)),
|
||||
('metadata', models.JSONField(blank=True, default=dict)),
|
||||
('extracted_at', models.DateTimeField(auto_now_add=True)),
|
||||
('bookmark', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='extraction', to='core.bookmark')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Summary',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('content', models.TextField()),
|
||||
('generated_at', models.DateTimeField(auto_now_add=True)),
|
||||
('bookmark', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='summary', to='core.bookmark')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TeamMembership',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('role', models.CharField(choices=[('OWNER', 'Owner'), ('ADMIN', 'Admin'), ('MEMBER', 'Member')], default='MEMBER', max_length=10)),
|
||||
('joined_at', models.DateTimeField(auto_now_add=True)),
|
||||
('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.team')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'unique_together': {('user', 'team')},
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='team',
|
||||
name='members',
|
||||
field=models.ManyToManyField(related_name='teams', through='core.TeamMembership', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='BookmarkShare',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('shared_at', models.DateTimeField(auto_now_add=True)),
|
||||
('bookmark', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shares', to='core.bookmark')),
|
||||
('shared_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shared_bookmarks', to='core.team')),
|
||||
],
|
||||
options={
|
||||
'unique_together': {('bookmark', 'team')},
|
||||
},
|
||||
),
|
||||
]
|
||||
BIN
core/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
core/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
@ -1,3 +1,68 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
# Create your models here.
|
||||
class Team(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
description = models.TextField(blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
members = models.ManyToManyField(User, through='TeamMembership', related_name='teams')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class TeamMembership(models.Model):
|
||||
ROLE_CHOICES = [
|
||||
('OWNER', 'Owner'),
|
||||
('ADMIN', 'Admin'),
|
||||
('MEMBER', 'Member'),
|
||||
]
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
team = models.ForeignKey(Team, on_delete=models.CASCADE)
|
||||
role = models.CharField(max_length=10, choices=ROLE_CHOICES, default='MEMBER')
|
||||
joined_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('user', 'team')
|
||||
|
||||
class Bookmark(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='bookmarks')
|
||||
url = models.URLField(max_length=1000)
|
||||
title = models.CharField(max_length=255, blank=True)
|
||||
notes = models.TextField(blank=True)
|
||||
is_favorite = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
tags = TaggableManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.title or self.url
|
||||
|
||||
class BookmarkShare(models.Model):
|
||||
bookmark = models.ForeignKey(Bookmark, on_delete=models.CASCADE, related_name='shares')
|
||||
team = models.ForeignKey(Team, on_delete=models.CASCADE, related_name='shared_bookmarks')
|
||||
shared_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
shared_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('bookmark', 'team')
|
||||
|
||||
class Extraction(models.Model):
|
||||
bookmark = models.OneToOneField(Bookmark, on_delete=models.CASCADE, related_name='extraction')
|
||||
content_html = models.TextField(blank=True)
|
||||
content_text = models.TextField(blank=True)
|
||||
metadata = models.JSONField(default=dict, blank=True)
|
||||
extracted_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"Extraction for {self.bookmark}"
|
||||
|
||||
class Summary(models.Model):
|
||||
bookmark = models.OneToOneField(Bookmark, on_delete=models.CASCADE, related_name='summary')
|
||||
content = models.TextField()
|
||||
generated_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"Summary for {self.bookmark}"
|
||||
|
||||
40
core/serializers.py
Normal file
40
core/serializers.py
Normal file
@ -0,0 +1,40 @@
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth.models import User
|
||||
from core.models import Bookmark, Team, TeamMembership, BookmarkShare, Extraction, Summary
|
||||
from taggit.serializers import TagListSerializerField, TaggitSerializer
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['id', 'username', 'email']
|
||||
|
||||
class TeamSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Team
|
||||
fields = ['id', 'name', 'description', 'created_at']
|
||||
|
||||
class BookmarkSerializer(TaggitSerializer, serializers.ModelSerializer):
|
||||
tags = TagListSerializerField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = Bookmark
|
||||
fields = ['id', 'url', 'title', 'notes', 'is_favorite', 'tags', 'created_at', 'updated_at']
|
||||
read_only_fields = ['id', 'created_at', 'updated_at']
|
||||
|
||||
def create(self, validated_data):
|
||||
user = self.context['request'].user
|
||||
tags = validated_data.pop('tags', [])
|
||||
bookmark = Bookmark.objects.create(user=user, **validated_data)
|
||||
bookmark.tags.set(tags)
|
||||
return bookmark
|
||||
|
||||
class ExtractionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Extraction
|
||||
fields = ['content_text', 'extracted_at']
|
||||
|
||||
class BookmarkDetailSerializer(BookmarkSerializer):
|
||||
extraction = ExtractionSerializer(read_only=True)
|
||||
|
||||
class Meta(BookmarkSerializer.Meta):
|
||||
fields = BookmarkSerializer.Meta.fields + ['extraction']
|
||||
91
core/tasks.py
Normal file
91
core/tasks.py
Normal file
@ -0,0 +1,91 @@
|
||||
import httpx
|
||||
from celery import shared_task
|
||||
from django.utils import timezone
|
||||
from core.models import Bookmark, Extraction, Summary
|
||||
from ai.local_ai_api import LocalAIApi
|
||||
from bs4 import BeautifulSoup
|
||||
import html2text
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@shared_task(bind=True, max_retries=3)
|
||||
def process_bookmark(self, bookmark_id):
|
||||
try:
|
||||
bookmark = Bookmark.objects.get(id=bookmark_id)
|
||||
except Bookmark.DoesNotExist:
|
||||
return
|
||||
|
||||
try:
|
||||
with httpx.Client(follow_redirects=True, timeout=30.0) as client:
|
||||
response = client.get(bookmark.url)
|
||||
response.raise_for_status()
|
||||
html_content = response.text
|
||||
except Exception as exc:
|
||||
logger.error(f"Error fetching bookmark {bookmark_id}: {exc}")
|
||||
raise self.retry(exc=exc, countdown=60)
|
||||
|
||||
soup = BeautifulSoup(html_content, 'html.parser')
|
||||
|
||||
# Simple title extraction if not already set
|
||||
if not bookmark.title:
|
||||
title_tag = soup.find('title')
|
||||
if title_tag:
|
||||
bookmark.title = title_tag.string.strip()[:255]
|
||||
bookmark.save()
|
||||
|
||||
# Readability extraction
|
||||
h = html2text.HTML2Text()
|
||||
h.ignore_links = False
|
||||
h.ignore_images = True
|
||||
text_content = h.handle(html_content)
|
||||
|
||||
extraction, created = Extraction.objects.update_or_create(
|
||||
bookmark=bookmark,
|
||||
defaults={
|
||||
'content_html': html_content,
|
||||
'content_text': text_content,
|
||||
'metadata': {
|
||||
'status_code': response.status_code,
|
||||
'content_type': response.headers.get('content-type'),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
# AI Summary generation
|
||||
generate_summary.delay(bookmark_id)
|
||||
|
||||
return f"Processed bookmark {bookmark_id}"
|
||||
|
||||
@shared_task
|
||||
def generate_summary(bookmark_id):
|
||||
try:
|
||||
bookmark = Bookmark.objects.get(id=bookmark_id)
|
||||
extraction = bookmark.extraction
|
||||
except (Bookmark.DoesNotExist, Extraction.DoesNotExist):
|
||||
return
|
||||
|
||||
if not extraction.content_text:
|
||||
return
|
||||
|
||||
# Prepare prompt for AI
|
||||
prompt = f"Summarize the following content from the webpage '{bookmark.title or bookmark.url}' in 2-3 concise sentences. Focus on the main points for a researcher.\n\nContent:\n{extraction.content_text[:4000]}"
|
||||
|
||||
response = LocalAIApi.create_response({
|
||||
"input": [
|
||||
{"role": "system", "content": "You are a helpful assistant that summarizes web content for researchers and knowledge workers. Be concise and professional."},
|
||||
{"role": "user", "content": prompt},
|
||||
],
|
||||
})
|
||||
|
||||
if response.get("success"):
|
||||
summary_text = LocalAIApi.extract_text(response)
|
||||
if summary_text:
|
||||
Summary.objects.update_or_create(
|
||||
bookmark=bookmark,
|
||||
defaults={'content': summary_text}
|
||||
)
|
||||
return f"Generated summary for bookmark {bookmark_id}"
|
||||
|
||||
logger.error(f"Failed to generate summary for bookmark {bookmark_id}: {response.get('error')}")
|
||||
return f"Failed to generate summary for bookmark {bookmark_id}"
|
||||
@ -1,25 +1,169 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{% block title %}Knowledge Base{% endblock %}</title>
|
||||
{% if project_description %}
|
||||
<meta name="description" content="{{ project_description }}">
|
||||
<meta property="og:description" content="{{ project_description }}">
|
||||
<meta property="twitter:description" content="{{ project_description }}">
|
||||
{% endif %}
|
||||
{% if project_image_url %}
|
||||
<meta property="og:image" content="{{ project_image_url }}">
|
||||
<meta property="twitter:image" content="{{ project_image_url }}">
|
||||
{% endif %}
|
||||
{% load static %}
|
||||
<link rel="stylesheet" href="{% static 'css/custom.css' %}?v={{ deployment_timestamp }}">
|
||||
{% block head %}{% endblock %}
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Knowledge Base{% endblock %}</title>
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- Bootstrap & Icons -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--primary-accent: #3b82f6;
|
||||
--secondary-accent: #10b981;
|
||||
--bg-light: #f3f4f6;
|
||||
--card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--bg-light);
|
||||
font-family: 'Inter', sans-serif;
|
||||
color: #1f2937;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
background: rgba(255, 255, 255, 0.8) !important;
|
||||
backdrop-filter: blur(10px);
|
||||
border-bottom: 1px solid rgba(0,0,0,0.05);
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: 700;
|
||||
color: #111827 !important;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: #4b5563 !important;
|
||||
font-weight: 500;
|
||||
padding: 0.5rem 1rem !important;
|
||||
border-radius: 0.5rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
background: rgba(0,0,0,0.05);
|
||||
color: #111827 !important;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--primary-accent);
|
||||
border: none;
|
||||
font-weight: 600;
|
||||
padding: 0.625rem 1.25rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #2563eb;
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
|
||||
}
|
||||
|
||||
.card {
|
||||
border: none;
|
||||
border-radius: 1rem;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.breadcrumb-item a {
|
||||
text-decoration: none;
|
||||
color: var(--primary-accent);
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Glassmorphism effect */
|
||||
.glass {
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.page-link {
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
.page-item.active .page-link {
|
||||
background-color: var(--primary-accent);
|
||||
border-color: var(--primary-accent);
|
||||
}
|
||||
</style>
|
||||
{% block extra_css %}{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
<nav class="navbar navbar-expand-lg sticky-top mb-5">
|
||||
<div class="container">
|
||||
<a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
|
||||
<div class="bg-primary text-white rounded-3 p-1 me-2 d-flex align-items-center justify-content-center" style="width: 32px; height: 32px;">
|
||||
<i class="bi bi-bookmark-star-fill fs-5"></i>
|
||||
</div>
|
||||
<span>KnoBase</span>
|
||||
</a>
|
||||
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto align-items-center">
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'home' %}">My Library</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'team-list' %}">Teams</a>
|
||||
</li>
|
||||
<li class="nav-item ms-lg-3">
|
||||
<a class="btn btn-primary rounded-pill px-4" href="{% url 'bookmark-add' %}">
|
||||
<i class="bi bi-plus-lg me-1"></i> Add
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown ms-lg-3">
|
||||
<a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
|
||||
<div class="bg-secondary text-white rounded-circle d-flex align-items-center justify-content-center me-2" style="width: 32px; height: 32px;">
|
||||
{{ user.username|first|upper }}
|
||||
</div>
|
||||
{{ user.username }}
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end shadow border-0 mt-2">
|
||||
<li><a class="dropdown-item" href="/admin/">Admin Panel</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<form method="post" action="{% url 'logout' %}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="dropdown-item text-danger">Logout</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'login' %}">Login</a>
|
||||
</li>
|
||||
<li class="nav-item ms-lg-3">
|
||||
<a class="btn btn-primary rounded-pill px-4" href="{% url 'login' %}">Get Started</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container pb-5">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
{% block extra_js %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
147
core/templates/core/bookmark_detail.html
Normal file
147
core/templates/core/bookmark_detail.html
Normal file
@ -0,0 +1,147 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ bookmark.title|default:bookmark.url }} - Knowledge Base{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{% url 'home' %}">My Bookmarks</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Details</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="card p-4 mb-4">
|
||||
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||
<h1 class="h2">{{ bookmark.title|default:bookmark.url }}</h1>
|
||||
{% if bookmark.user == request.user %}
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-secondary btn-sm" type="button" data-bs-toggle="dropdown">
|
||||
<i class="bi bi-three-dots"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="{% url 'bookmark-edit' bookmark.pk %}">Edit</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<form action="{% url 'bookmark-delete' bookmark.pk %}" method="post" onsubmit="return confirm('Are you sure?');">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="dropdown-item text-danger">Delete</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<p class="text-muted mb-4">
|
||||
<i class="bi bi-link-45deg"></i> <a href="{{ bookmark.url }}" target="_blank" class="text-break">{{ bookmark.url }}</a>
|
||||
</p>
|
||||
|
||||
{% if bookmark.notes %}
|
||||
<div class="mb-4">
|
||||
<h5 class="text-uppercase small fw-bold text-muted mb-2">My Notes</h5>
|
||||
<div class="p-3 bg-light rounded border-start border-4 border-primary">
|
||||
{{ bookmark.notes|linebreaks }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if bookmark.summary %}
|
||||
<div class="mb-4">
|
||||
<h5 class="text-uppercase small fw-bold text-muted mb-2">AI Summary</h5>
|
||||
<div class="p-3 border rounded shadow-sm bg-white">
|
||||
{{ bookmark.summary.content }}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-light border text-center small py-3">
|
||||
<div class="spinner-border spinner-border-sm text-primary me-2" role="status"></div>
|
||||
AI Summary is being generated...
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="mt-4">
|
||||
{% for tag in bookmark.tags.all %}
|
||||
<span class="badge bg-light text-dark border p-2 me-1">#{{ tag.name }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if bookmark.extraction %}
|
||||
<div class="card p-4">
|
||||
<h5 class="text-uppercase small fw-bold text-muted mb-3">Extracted Text Content</h5>
|
||||
<div class="extraction-content text-muted small" style="max-height: 500px; overflow-y: auto;">
|
||||
{{ bookmark.extraction.content_text|linebreaks }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{% if bookmark.user == request.user %}
|
||||
<div class="card p-4 mb-4">
|
||||
<h5 class="h6 mb-3">Share with Teams</h5>
|
||||
<div class="list-group list-group-flush">
|
||||
{% for team in user.teams.all %}
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center px-0">
|
||||
<div>
|
||||
<div class="fw-bold">{{ team.name }}</div>
|
||||
<div class="small text-muted">{{ team.members.count }} members</div>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-primary share-toggle"
|
||||
data-url="{% url 'bookmark-share-toggle' bookmark.pk team.pk %}"
|
||||
data-team-id="{{ team.pk }}">
|
||||
{% with shared=False %}
|
||||
{% for share in bookmark.shares.all %}
|
||||
{% if share.team == team %}{% with shared=True %}Shared{% endwith %}{% endif %}
|
||||
{% endfor %}
|
||||
{% if not shared %}Share{% endif %}
|
||||
{% endwith %}
|
||||
</button>
|
||||
</div>
|
||||
{% empty %}
|
||||
<p class="small text-muted mb-0">You are not a member of any teams. <a href="{% url 'team-list' %}">Explore teams</a>.</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card p-4">
|
||||
<h5 class="h6 mb-3">Information</h5>
|
||||
<ul class="list-unstyled small mb-0">
|
||||
<li class="mb-2"><span class="text-muted">Saved on:</span> {{ bookmark.created_at|date:"F d, Y H:i" }}</li>
|
||||
<li class="mb-2"><span class="text-muted">Last updated:</span> {{ bookmark.updated_at|date:"F d, Y H:i" }}</li>
|
||||
<li><span class="text-muted">Saved by:</span> {{ bookmark.user.username }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
document.querySelectorAll('.share-toggle').forEach(button => {
|
||||
button.addEventListener('click', async function() {
|
||||
const url = this.getAttribute('data-url');
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRFToken': '{{ csrf_token }}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
const data = await response.json();
|
||||
if (data.shared) {
|
||||
this.textContent = 'Shared';
|
||||
this.classList.remove('btn-outline-primary');
|
||||
this.classList.add('btn-primary');
|
||||
} else {
|
||||
this.textContent = 'Share';
|
||||
this.classList.remove('btn-primary');
|
||||
this.classList.add('btn-outline-primary');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
54
core/templates/core/bookmark_form.html
Normal file
54
core/templates/core/bookmark_form.html
Normal file
@ -0,0 +1,54 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{% if object %}Edit{% else %}Add{% endif %} Bookmark - Knowledge Base{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card p-4">
|
||||
<h2 class="mb-4">{% if object %}Edit{% else %}Add New{% endif %} Bookmark</h2>
|
||||
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="id_url" class="form-label">URL</label>
|
||||
<input type="url" name="url" class="form-control form-control-lg" id="id_url" placeholder="https://example.com" value="{{ form.url.value|default:'' }}" required>
|
||||
{% if form.url.errors %}<div class="text-danger small mt-1">{{ form.url.errors }}</div>{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="id_title" class="form-label">Title (Optional)</label>
|
||||
<input type="text" name="title" class="form-control" id="id_title" placeholder="Leave blank to auto-extract" value="{{ form.title.value|default:'' }}">
|
||||
<div class="form-text">We'll try to fetch the title automatically if you leave this blank.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="id_notes" class="form-label">Notes</label>
|
||||
<textarea name="notes" class="form-control" id="id_notes" rows="3">{{ form.notes.value|default:'' }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="tags_input" class="form-label">Tags</label>
|
||||
<input type="text" name="tags_input" class="form-control" id="tags_input" placeholder="research, ai, deep-learning" value="{% for tag in object.tags.all %}{{ tag.name }}{% if not forloop.last %}, {% endif %}{% endfor %}">
|
||||
<div class="form-text">Comma-separated tags.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" name="is_favorite" id="id_is_favorite" {% if form.is_favorite.value %}checked{% endif %}>
|
||||
<label class="form-check-label" for="id_is_favorite">Mark as Favorite</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<a href="{% url 'home' %}" class="btn btn-link text-muted">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary px-5 py-2 rounded-pill">
|
||||
{% if object %}Update{% else %}Save{% endif %} Bookmark
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -1,145 +1,151 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ project_name }}{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><path d='M-10 10L110 10M10 -10L10 110' stroke-width='1' stroke='rgba(255,255,255,0.05)'/></svg>");
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
@keyframes bg-pan {
|
||||
0% {
|
||||
background-position: 0% 0%;
|
||||
}
|
||||
|
||||
100% {
|
||||
background-position: 100% 100%;
|
||||
}
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2.5rem 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: clamp(2.2rem, 3vw + 1.2rem, 3.2rem);
|
||||
font-weight: 700;
|
||||
margin: 0 0 1.2rem;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
opacity: 0.92;
|
||||
}
|
||||
|
||||
.loader {
|
||||
margin: 1.5rem auto;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border: 4px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.runtime code {
|
||||
background: rgba(0, 0, 0, 0.25);
|
||||
padding: 0.15rem 0.45rem;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
border: 0;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 0.85rem;
|
||||
opacity: 0.75;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
{% block title %}My Bookmarks - Knowledge Base{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your app…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
<div class="row">
|
||||
<!-- Sidebar -->
|
||||
<div class="col-md-3">
|
||||
<div class="card p-3 mb-4 shadow-sm border-0 bg-white rounded-3">
|
||||
<h5 class="h6 text-uppercase fw-bold text-muted mb-3">Filter by Tag</h5>
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
<a href="{% url 'home' %}" class="badge {% if not request.GET.tag %}bg-primary{% else %}bg-light text-dark border{% endif %} text-decoration-none p-2">All</a>
|
||||
{% for tag in all_tags %}
|
||||
<a href="?tag={{ tag.name }}{% if request.GET.q %}&q={{ request.GET.q }}{% endif %}"
|
||||
class="badge {% if request.GET.tag == tag.name %}bg-primary{% else %}bg-light text-dark border{% endif %} text-decoration-none p-2">
|
||||
#{{ tag.name }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-3 mb-4 shadow-sm border-0 bg-white rounded-3">
|
||||
<h5 class="h6 text-uppercase fw-bold text-muted mb-3">My Teams</h5>
|
||||
<div class="list-group list-group-flush small">
|
||||
{% for team in teams %}
|
||||
<a href="{% url 'team-detail' team.pk %}" class="list-group-item list-group-item-action border-0 px-0 d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-people me-2"></i>{{ team.name }}</span>
|
||||
</a>
|
||||
{% empty %}
|
||||
<p class="text-muted small mb-0">No teams yet. <a href="{% url 'team-list' %}">Explore</a></p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="hint">AppWizzy AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will refresh automatically as the plan is implemented.</p>
|
||||
<p class="runtime">
|
||||
Runtime: Django <code>{{ django_version }}</code> · Python <code>{{ python_version }}</code>
|
||||
— UTC <code>{{ current_time|date:"Y-m-d H:i:s" }}</code>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: {{ current_time|date:"Y-m-d H:i:s" }} (UTC)
|
||||
</footer>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="col-md-9">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h3 mb-0">{% if request.GET.tag %}Tag: #{{ request.GET.tag }}{% else %}My Bookmarks{% endif %}</h1>
|
||||
<a href="{% url 'bookmark-add' %}" class="btn btn-primary rounded-pill px-4">
|
||||
<i class="bi bi-plus-lg me-1"></i> New Bookmark
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<form method="get" class="mb-4">
|
||||
<div class="input-group input-group-lg shadow-sm">
|
||||
<span class="input-group-text bg-white border-end-0"><i class="bi bi-search text-muted"></i></span>
|
||||
<input type="text" name="q" class="form-control border-start-0 ps-0" placeholder="Search by title, url, notes or content..." value="{{ request.GET.q }}">
|
||||
{% if request.GET.tag %}
|
||||
<input type="hidden" name="tag" value="{{ request.GET.tag }}">
|
||||
{% endif %}
|
||||
<button type="submit" class="btn btn-primary px-4">Search</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="row">
|
||||
{% for bookmark in bookmarks %}
|
||||
<div class="col-md-12 mb-3">
|
||||
<div class="card border-0 shadow-sm hover-elevate">
|
||||
<div class="card-body p-4">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div class="flex-grow-1">
|
||||
<div class="d-flex align-items-center mb-1">
|
||||
<h5 class="card-title mb-0 me-2">
|
||||
<a href="{% url 'bookmark-detail' bookmark.pk %}" class="text-decoration-none text-dark fw-bold">{{ bookmark.title|default:bookmark.url }}</a>
|
||||
</h5>
|
||||
{% if bookmark.is_favorite %}
|
||||
<i class="bi bi-star-fill text-warning" title="Favorite"></i>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p class="text-muted small mb-3 text-break">{{ bookmark.url }}</p>
|
||||
|
||||
{% if bookmark.notes %}
|
||||
<p class="card-text text-secondary mb-3">{{ bookmark.notes|truncatewords:40 }}</p>
|
||||
{% endif %}
|
||||
|
||||
<div class="d-flex flex-wrap gap-1 mt-2">
|
||||
{% for tag in bookmark.tags.all %}
|
||||
<span class="badge bg-light text-muted border-0 small">#{{ tag.name }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end ms-3">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-link text-muted p-0" type="button" data-bs-toggle="dropdown">
|
||||
<i class="bi bi-three-dots-vertical"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li><a class="dropdown-item" href="{% url 'bookmark-detail' bookmark.pk %}">View Details</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'bookmark-edit' bookmark.pk %}">Edit</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<form action="{% url 'bookmark-delete' bookmark.pk %}" method="post" style="display: inline;">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="dropdown-item text-danger" onclick="return confirm('Are you sure?')">Delete</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<span class="text-muted small d-block mt-4">{{ bookmark.created_at|date:"M d" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="col-12 text-center py-5">
|
||||
<div class="card border-0 shadow-sm p-5 bg-white">
|
||||
<div class="display-1 text-light mb-3"><i class="bi bi-bookmark-plus"></i></div>
|
||||
<h3 class="h4">No bookmarks found</h3>
|
||||
<p class="text-muted">Start building your knowledge base by adding your first bookmark.</p>
|
||||
<div class="mt-3">
|
||||
<a href="{% url 'bookmark-add' %}" class="btn btn-primary rounded-pill px-4">Add Bookmark</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if is_paginated %}
|
||||
<nav class="mt-4">
|
||||
<ul class="pagination justify-content-center">
|
||||
{% if page_obj.has_previous %}
|
||||
<li class="page-item"><a class="page-link rounded-circle me-2 border-0 shadow-sm" href="?page={{ page_obj.previous_page_number }}{% if request.GET.q %}&q={{ request.GET.q }}{% endif %}{% if request.GET.tag %}&tag={{ request.GET.tag }}{% endif %}"><i class="bi bi-chevron-left"></i></a></li>
|
||||
{% endif %}
|
||||
|
||||
{% for i in paginator.page_range %}
|
||||
{% if page_obj.number == i %}
|
||||
<li class="page-item active"><span class="page-link rounded-circle me-2 border-0 shadow-sm">{{ i }}</span></li>
|
||||
{% elif i > page_obj.number|add:'-3' and i < page_obj.number|add:'3' %}
|
||||
<li class="page-item"><a class="page-link rounded-circle me-2 border-0 shadow-sm text-dark" href="?page={{ i }}{% if request.GET.q %}&q={{ request.GET.q }}{% endif %}{% if request.GET.tag %}&tag={{ request.GET.tag }}{% endif %}">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if page_obj.has_next %}
|
||||
<li class="page-item"><a class="page-link rounded-circle border-0 shadow-sm" href="?page={{ page_obj.next_page_number }}{% if request.GET.q %}&q={{ request.GET.q }}{% endif %}{% if request.GET.tag %}&tag={{ request.GET.tag }}{% endif %}"><i class="bi bi-chevron-right"></i></a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.hover-elevate:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 10px 20px rgba(0,0,0,0.08) !important;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
56
core/templates/core/team_detail.html
Normal file
56
core/templates/core/team_detail.html
Normal file
@ -0,0 +1,56 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ team.name }} - Team Space{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{% url 'team-list' %}">Teams</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">{{ team.name }}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<h1>{{ team.name }}</h1>
|
||||
<span class="badge bg-primary">{{ team.members.count }} Members</span>
|
||||
</div>
|
||||
<p class="text-muted">{{ team.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="mb-4">Shared Bookmarks</h3>
|
||||
|
||||
<div class="row">
|
||||
{% for bookmark in shared_bookmarks %}
|
||||
<div class="col-md-12 mb-3">
|
||||
<div class="card p-3">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div>
|
||||
<h5 class="card-title mb-1">
|
||||
<a href="{% url 'bookmark-detail' bookmark.pk %}" class="text-decoration-none">{{ bookmark.title|default:bookmark.url }}</a>
|
||||
</h5>
|
||||
<p class="text-muted small mb-2">{{ bookmark.url }}</p>
|
||||
<div class="mt-2">
|
||||
{% for tag in bookmark.tags.all %}
|
||||
<span class="badge bg-light text-dark border">{{ tag.name }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end">
|
||||
<span class="text-muted small d-block mb-1">Shared by {{ bookmark.shares.first.shared_by.username }}</span>
|
||||
<span class="text-muted small">{{ bookmark.shares.first.shared_at|date:"M d, Y" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="col-12 text-center py-5">
|
||||
<div class="alert alert-info">
|
||||
No bookmarks have been shared with this team yet.
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
33
core/templates/core/team_list.html
Normal file
33
core/templates/core/team_list.html
Normal file
@ -0,0 +1,33 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}My Teams - Knowledge Base{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
<h1>My Teams</h1>
|
||||
<p class="text-muted">Collaborate with your colleagues by sharing bookmarks in shared team spaces.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
{% for team in teams %}
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card h-100 p-4">
|
||||
<h5 class="card-title">{{ team.name }}</h5>
|
||||
<p class="card-text text-muted">{{ team.description|truncatewords:20 }}</p>
|
||||
<div class="mt-auto">
|
||||
<a href="{% url 'team-detail' team.pk %}" class="btn btn-outline-primary w-100">View Team Bookmarks</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="col-12 text-center py-5">
|
||||
<div class="card p-5 bg-light">
|
||||
<h3>No teams yet</h3>
|
||||
<p>You aren't a member of any teams yet. Teams allow you to share knowledge with others.</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
46
core/templates/registration/login.html
Normal file
46
core/templates/registration/login.html
Normal file
@ -0,0 +1,46 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Login - Knowledge Base{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-4">
|
||||
<div class="card p-4">
|
||||
<h2 class="text-center mb-4">Login</h2>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
<div class="mb-3">
|
||||
<label for="{{ field.id_for_label }}" class="form-label">{{ field.label }}</label>
|
||||
{{ field }}
|
||||
{% if field.errors %}
|
||||
<div class="text-danger small">{{ field.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<style>
|
||||
input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 0.375rem 0.75rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
color: #212529;
|
||||
background-color: #fff;
|
||||
background-clip: padding-box;
|
||||
border: 1px solid #ced4da;
|
||||
appearance: none;
|
||||
border-radius: 0.375rem;
|
||||
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
27
core/urls.py
27
core/urls.py
@ -1,7 +1,26 @@
|
||||
from django.urls import path
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from core.api_views import BookmarkViewSet, TeamViewSet
|
||||
from core.views import (
|
||||
BookmarkListView, BookmarkCreateView, BookmarkDetailView,
|
||||
BookmarkUpdateView, BookmarkDeleteView,
|
||||
TeamListView, TeamDetailView, BookmarkShareToggleView
|
||||
)
|
||||
|
||||
from .views import home
|
||||
router = DefaultRouter()
|
||||
router.register(r'bookmarks', BookmarkViewSet, basename='api-bookmark')
|
||||
router.register(r'teams', TeamViewSet, basename='api-team')
|
||||
|
||||
urlpatterns = [
|
||||
path("", home, name="home"),
|
||||
]
|
||||
path("", BookmarkListView.as_view(), name="home"),
|
||||
path("bookmark/add/", BookmarkCreateView.as_view(), name="bookmark-add"),
|
||||
path("bookmark/<int:pk>/", BookmarkDetailView.as_view(), name="bookmark-detail"),
|
||||
path("bookmark/<int:pk>/edit/", BookmarkUpdateView.as_view(), name="bookmark-edit"),
|
||||
path("bookmark/<int:pk>/delete/", BookmarkDeleteView.as_view(), name="bookmark-delete"),
|
||||
path("bookmark/<int:pk>/share/<int:team_id>/", BookmarkShareToggleView.as_view(), name="bookmark-share-toggle"),
|
||||
|
||||
path("teams/", TeamListView.as_view(), name="team-list"),
|
||||
path("teams/<int:pk>/", TeamDetailView.as_view(), name="team-detail"),
|
||||
|
||||
path("api/", include(router.urls)),
|
||||
]
|
||||
150
core/views.py
150
core/views.py
@ -1,25 +1,133 @@
|
||||
import os
|
||||
import platform
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.views import View
|
||||
from django.views.generic import ListView, CreateView, DetailView, UpdateView, DeleteView
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.urls import reverse_lazy
|
||||
from django.db.models import Q
|
||||
from django.http import JsonResponse
|
||||
from .models import Bookmark, Team, Extraction, BookmarkShare
|
||||
from .tasks import process_bookmark
|
||||
|
||||
from django import get_version as django_version
|
||||
from django.shortcuts import render
|
||||
from django.utils import timezone
|
||||
class BookmarkListView(LoginRequiredMixin, ListView):
|
||||
model = Bookmark
|
||||
template_name = 'core/index.html'
|
||||
context_object_name = 'bookmarks'
|
||||
paginate_by = 20
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Bookmark.objects.filter(user=self.request.user).order_by('-created_at')
|
||||
|
||||
# Search filter
|
||||
query = self.request.GET.get('q')
|
||||
if query:
|
||||
queryset = queryset.filter(
|
||||
Q(title__icontains=query) |
|
||||
Q(url__icontains=query) |
|
||||
Q(notes__icontains=query) |
|
||||
Q(extraction__content_text__icontains=query)
|
||||
).distinct()
|
||||
|
||||
# Tag filter
|
||||
tag = self.request.GET.get('tag')
|
||||
if tag:
|
||||
queryset = queryset.filter(tags__name__in=[tag])
|
||||
|
||||
return queryset
|
||||
|
||||
def home(request):
|
||||
"""Render the landing screen with loader and environment details."""
|
||||
host_name = request.get_host().lower()
|
||||
agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic"
|
||||
now = timezone.now()
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
# Add all tags used by the user for a sidebar or filter list
|
||||
from taggit.models import Tag
|
||||
context['all_tags'] = Tag.objects.filter(bookmark__user=self.request.user).distinct()
|
||||
context['teams'] = self.request.user.teams.all()
|
||||
return context
|
||||
|
||||
context = {
|
||||
"project_name": "New Style",
|
||||
"agent_brand": agent_brand,
|
||||
"django_version": django_version(),
|
||||
"python_version": platform.python_version(),
|
||||
"current_time": now,
|
||||
"host_name": host_name,
|
||||
"project_description": os.getenv("PROJECT_DESCRIPTION", ""),
|
||||
"project_image_url": os.getenv("PROJECT_IMAGE_URL", ""),
|
||||
}
|
||||
return render(request, "core/index.html", context)
|
||||
class BookmarkCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Bookmark
|
||||
fields = ['url', 'title', 'notes', 'is_favorite']
|
||||
template_name = 'core/bookmark_form.html'
|
||||
success_url = reverse_lazy('home')
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.user = self.request.user
|
||||
response = super().form_valid(form)
|
||||
# Handle tags if provided in a separate field or as a comma-separated string
|
||||
# For simplicity, we'll assume the model's TaggableManager handles it if added to fields,
|
||||
# but here we might need to handle it manually if we use a custom field.
|
||||
# Let's add 'tags' to fields in the actual form.
|
||||
tags = self.request.POST.get('tags_input')
|
||||
if tags:
|
||||
form.instance.tags.add(*[t.strip() for t in tags.split(',')])
|
||||
|
||||
process_bookmark.delay(self.object.id)
|
||||
return response
|
||||
|
||||
class BookmarkUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Bookmark
|
||||
fields = ['url', 'title', 'notes', 'is_favorite']
|
||||
template_name = 'core/bookmark_form.html'
|
||||
success_url = reverse_lazy('home')
|
||||
|
||||
def get_queryset(self):
|
||||
return Bookmark.objects.filter(user=self.request.user)
|
||||
|
||||
class BookmarkDeleteView(LoginRequiredMixin, DeleteView):
|
||||
model = Bookmark
|
||||
success_url = reverse_lazy('home')
|
||||
|
||||
def get_queryset(self):
|
||||
return Bookmark.objects.filter(user=self.request.user)
|
||||
|
||||
class BookmarkDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Bookmark
|
||||
template_name = 'core/bookmark_detail.html'
|
||||
context_object_name = 'bookmark'
|
||||
|
||||
def get_queryset(self):
|
||||
# Allow viewing if it's the user's bookmark OR shared with one of their teams
|
||||
user_teams = self.request.user.teams.all()
|
||||
return Bookmark.objects.filter(
|
||||
Q(user=self.request.user) |
|
||||
Q(shares__team__in=user_teams)
|
||||
).distinct()
|
||||
|
||||
class TeamListView(LoginRequiredMixin, ListView):
|
||||
model = Team
|
||||
template_name = 'core/team_list.html'
|
||||
context_object_name = 'teams'
|
||||
|
||||
def get_queryset(self):
|
||||
return self.request.user.teams.all()
|
||||
|
||||
class TeamDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Team
|
||||
template_name = 'core/team_detail.html'
|
||||
context_object_name = 'team'
|
||||
|
||||
def get_queryset(self):
|
||||
return self.request.user.teams.all()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
# Get bookmarks shared with this team
|
||||
context['shared_bookmarks'] = Bookmark.objects.filter(shares__team=self.object).order_by('-shares__shared_at')
|
||||
return context
|
||||
|
||||
class BookmarkShareToggleView(LoginRequiredMixin, View):
|
||||
def post(self, request, pk, team_id):
|
||||
bookmark = get_object_or_404(Bookmark, pk=pk, user=request.user)
|
||||
team = get_object_or_404(Team, pk=team_id, members=request.user)
|
||||
|
||||
share, created = BookmarkShare.objects.get_or_create(
|
||||
bookmark=bookmark,
|
||||
team=team,
|
||||
defaults={'shared_by': request.user}
|
||||
)
|
||||
|
||||
if not created:
|
||||
share.delete()
|
||||
shared = False
|
||||
else:
|
||||
shared = True
|
||||
|
||||
return JsonResponse({'shared': shared})
|
||||
@ -1,3 +1,11 @@
|
||||
Django==5.2.7
|
||||
mysqlclient==2.2.7
|
||||
python-dotenv==1.1.1
|
||||
djangorestframework==3.15.2
|
||||
beautifulsoup4==4.12.3
|
||||
html2text==2024.2.26
|
||||
httpx==0.27.2
|
||||
django-taggit==6.1.0
|
||||
celery==5.4.0
|
||||
redis==5.0.8
|
||||
django-filter==24.3
|
||||
Loading…
x
Reference in New Issue
Block a user