diff --git a/web/auth_app/urls.py b/web/auth_app/urls.py
index 88eecd10..4246569b 100644
--- a/web/auth_app/urls.py
+++ b/web/auth_app/urls.py
@@ -22,4 +22,5 @@
TemplateAPIView.as_view(template_name='auth_app/verification_sent.html'),
name='verify_email_sent',
),
+ path('auth/google', TemplateAPIView.as_view(template_name='auth_app/googleRedirect.html'), name='google_auth'),
]
diff --git a/web/blog/filters.py b/web/blog/filters.py
index 83a5e7b7..101e1c58 100644
--- a/web/blog/filters.py
+++ b/web/blog/filters.py
@@ -2,10 +2,6 @@
from django_filters import rest_framework as filters
-class CharFilter(filters.BaseInFilter, filters.CharFilter):
- pass
-
-
class ArticleFilter(filters.FilterSet):
search = filters.CharFilter(method='search_filter')
diff --git a/web/blog/migrations/0003_remove_article_tags_alter_articletag_name_and_more.py b/web/blog/migrations/0003_remove_article_tags_alter_articletag_name_and_more.py
new file mode 100644
index 00000000..440f9195
--- /dev/null
+++ b/web/blog/migrations/0003_remove_article_tags_alter_articletag_name_and_more.py
@@ -0,0 +1,30 @@
+# Generated by Django 4.2.11 on 2024-03-24 21:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('blog', '0002_remove_comment_author'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='article',
+ name='tags',
+ ),
+ migrations.AlterField(
+ model_name='articletag',
+ name='name',
+ field=models.CharField(max_length=100, unique=True),
+ ),
+ migrations.AlterField(
+ model_name='articletag',
+ name='slug',
+ field=models.SlugField(allow_unicode=True, max_length=100, unique=True),
+ ),
+ migrations.DeleteModel(
+ name='TaggedArticle',
+ ),
+ ]
diff --git a/web/blog/migrations/0004_article_tags.py b/web/blog/migrations/0004_article_tags.py
new file mode 100644
index 00000000..fff82d57
--- /dev/null
+++ b/web/blog/migrations/0004_article_tags.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.11 on 2024-03-24 21:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('blog', '0003_remove_article_tags_alter_articletag_name_and_more'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='article',
+ name='tags',
+ field=models.ManyToManyField(blank=True, related_name='articles', to='blog.articletag'),
+ ),
+ ]
diff --git a/web/blog/models.py b/web/blog/models.py
index a0aba3c9..9d437eba 100644
--- a/web/blog/models.py
+++ b/web/blog/models.py
@@ -14,19 +14,15 @@
User = get_user_model()
-class ArticleTag(TagBase):
- objects = models.Manager()
+class ArticleTag(models.Model):
+ name = models.CharField(unique=True, max_length=100)
+ slug = models.SlugField(unique=True, max_length=100, allow_unicode=True)
class Meta:
verbose_name = _('Tag')
verbose_name_plural = _('Tags')
-class TaggedArticle(TaggedItemBase):
- content_object = models.ForeignKey('Article', on_delete=models.CASCADE, related_name='tagged_article')
- tag = models.ForeignKey(ArticleTag, related_name='tagged_article', on_delete=models.CASCADE)
-
-
class Category(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, unique=True, allow_unicode=True)
@@ -56,7 +52,7 @@ class Article(models.Model):
status = models.PositiveSmallIntegerField(choices=ArticleStatus.choices, default=ArticleStatus.INACTIVE)
image = models.ImageField(upload_to='articles/', blank=True, default='no-image-available.jpg')
votes = GenericRelation(LikeDislike, related_query_name='articles')
- tags = TaggableManager(through=TaggedArticle, related_name='article_tags', blank=True)
+ tags = models.ManyToManyField(ArticleTag, related_name='articles', blank=True)
objects = models.Manager()
@@ -67,14 +63,6 @@ def short_title(self) -> str:
def __str__(self) -> str:
return '{title} - {author}'.format(title=self.short_title, author=self.author)
- @staticmethod
- def get_slug(title: str) -> str:
- return slugify(title, allow_unicode=True)
-
- def save(self, **kwargs):
- self.slug = self.get_slug(self.title)
- return super().save(**kwargs)
-
def get_absolute_url(self) -> str:
return reverse_lazy('blog:blog-detail', kwargs={'slug': self.slug})
diff --git a/web/blog/static/blog/js/post_create.js b/web/blog/static/blog/js/post_create.js
index e1bb5082..81fa9b12 100644
--- a/web/blog/static/blog/js/post_create.js
+++ b/web/blog/static/blog/js/post_create.js
@@ -1,18 +1,32 @@
$(function () {
+ $('.category-select').select2();
$('#createArticleForm').submit(postCreate);
-
+ getCategories();
});
const error_class_name = "has-error"
+function getCategories() {
+ $.ajax({
+ url: '/api/v1/blog/categories/',
+ type: 'GET',
+ success: getCategoriesHandler,
+ })
+}
+
+function getCategoriesHandler (data) {
+ const selector = $('.category-select')
+ data.forEach((category) => selector.append(new Option(category.name, category.id)))
+}
+
function postCreate(event) {
event.preventDefault()
let form = $(this)
- let data = new FormData(form[0]);
+ const formData = new FormData(form[0]);
$.ajax({
url: '/api/v1/blog/articles/new/',
type: form.attr('method'),
- data: data,
+ data: formData,
contentType: false,
processData: false,
success: function (data) {
diff --git a/web/blog/templates/blog/includes/sidebar_blocks/popular_tags.html b/web/blog/templates/blog/includes/sidebar_blocks/popular_tags.html
index 2149b274..1bcf7c8f 100644
--- a/web/blog/templates/blog/includes/sidebar_blocks/popular_tags.html
+++ b/web/blog/templates/blog/includes/sidebar_blocks/popular_tags.html
@@ -1,5 +1,3 @@
-{% load blog %}
-
Popular Tags:
diff --git a/web/blog/templates/blog/post_create.html b/web/blog/templates/blog/post_create.html
index 8b60be05..6214cdf9 100644
--- a/web/blog/templates/blog/post_create.html
+++ b/web/blog/templates/blog/post_create.html
@@ -1,26 +1,27 @@
{% extends "blog/base.html" %}
-{% load static main %}
+{% load static %}
{% block title %}New Post{% endblock title %}
{% block head %}
-
+
+
{% endblock head %}
{% block container %}
Create a new post
-