Skip to content

Commit

Permalink
Merge pull request #185 from 2077-Collective/feat/sponsored-articles
Browse files Browse the repository at this point in the history
Feat/sponsored articles
  • Loading branch information
losndu authored Oct 24, 2024
2 parents 84f7d01 + 7900097 commit 836b533
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# 2077 Collective

Content management system written in Python(Django) and React.js
Content management system written in Python(Django) and Sveltekit

## Project Architecture

Expand Down
3 changes: 2 additions & 1 deletion server/apps/research/admin/article_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class ArticleAdmin(admin.ModelAdmin):
form = ArticleForm
fieldsets = [
('Article Details', {'fields': ['title', 'slug', 'authors', 'acknowledgement', 'categories', 'thumb', 'content', 'summary', 'status', 'scheduled_publish_time']}),
('Sponsorship Details', {'fields': ['is_sponsored', 'sponsor_color', 'sponsor_text_color', 'sponsor_padding']}),
]
list_display = ('title', 'display_authors', 'status', 'views', 'display_categories', 'min_read', 'created_at', 'scheduled_publish_time')
search_fields = ('title', 'authors__user__username', 'authors__twitter_username', 'content')
list_per_page = 25
list_filter = ('authors', 'status', 'categories', 'created_at')
list_filter = ('authors', 'status', 'categories', 'created_at', 'is_sponsored')
readonly_fields = ('views',)
list_editable = ('status',)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.8 on 2024-10-23 08:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('research', '0005_article_table_of_contents'),
]

operations = [
migrations.AddField(
model_name='article',
name='is_sponsored',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='article',
name='sponsor_color',
field=models.CharField(default='#FF0420', max_length=7),
),
migrations.AddField(
model_name='article',
name='sponsor_text_color',
field=models.CharField(default='#000000', max_length=7),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.8 on 2024-10-23 10:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('research', '0006_article_is_sponsored_article_sponsor_color_and_more'),
]

operations = [
migrations.AlterField(
model_name='article',
name='sponsor_color',
field=models.CharField(default='#FF0420 !important', max_length=7),
),
migrations.AlterField(
model_name='article',
name='sponsor_text_color',
field=models.CharField(default='#000000 !important', max_length=7),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.8 on 2024-10-23 10:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('research', '0007_alter_article_sponsor_color_and_more'),
]

operations = [
migrations.AlterField(
model_name='article',
name='sponsor_color',
field=models.CharField(default='bg-red-700 !important', max_length=7),
),
migrations.AlterField(
model_name='article',
name='sponsor_text_color',
field=models.CharField(default='#bg-gray-700 !important', max_length=7),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-10-23 10:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('research', '0008_alter_article_sponsor_color_and_more'),
]

operations = [
migrations.AlterField(
model_name='article',
name='sponsor_text_color',
field=models.CharField(default='text-gray-700 !important', max_length=7),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.8 on 2024-10-23 11:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('research', '0009_alter_article_sponsor_text_color'),
]

operations = [
migrations.AddField(
model_name='article',
name='sponsor_padding',
field=models.CharField(default='px-4 py-6', max_length=20),
),
migrations.AlterField(
model_name='article',
name='sponsor_color',
field=models.CharField(default='#FF0420', max_length=7),
),
migrations.AlterField(
model_name='article',
name='sponsor_text_color',
field=models.CharField(default='#000000', max_length=7),
),
]
4 changes: 4 additions & 0 deletions server/apps/research/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class Article(BaseModel):
status = models.CharField(max_length=10, choices=options, default='draft', db_index=True)
scheduled_publish_time = models.DateTimeField(null=True, blank=True, db_index=True)
table_of_contents = models.JSONField(default=list, blank=True)
is_sponsored = models.BooleanField(default=False)
sponsor_color = models.CharField(max_length=7, default="#FF0420")
sponsor_text_color = models.CharField(max_length=7, default="#000000")
sponsor_padding = models.CharField(max_length=20, default="px-4 py-6")

objects = models.Manager()
post_objects = ArticleObjects()
Expand Down
5 changes: 3 additions & 2 deletions server/apps/research/serializers/article_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Meta:
fields = [
'id', 'slug', 'title', 'authors', 'thumb', 'categories', 'summary',
'acknowledgement', 'content', 'min_read', 'status', 'views',
'created_at', 'updated_at', 'scheduled_publish_time', 'table_of_contents'
'created_at', 'updated_at', 'scheduled_publish_time', 'table_of_contents',
'is_sponsored', 'sponsor_color', 'sponsor_text_color', 'sponsor_padding'
]

class ArticleCreateUpdateSerializer(serializers.ModelSerializer):
Expand All @@ -37,7 +38,7 @@ class ArticleCreateUpdateSerializer(serializers.ModelSerializer):

class Meta:
model = Article
fields = ['title', 'slug', 'categories', 'thumb', 'content', 'summary', 'acknowledgement', 'status', 'authors', 'scheduled_publish_time']
fields = ['title', 'slug', 'categories', 'thumb', 'content', 'summary', 'acknowledgement', 'status', 'authors', 'scheduled_publish_time', 'is_sponsored', 'sponsor_color', 'sponsor_text_color', 'sponsor_padding']

def create(self, validated_data: dict) -> Article:
"""Create a new article instance."""
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 836b533

Please sign in to comment.