Skip to content
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

Migrated blogs from old site to new django app (Envision project) #163

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ db.sqlite3
db.sqlite3-journal
media
backend/static
corpus/blog/blog_data.json
corpus/blog/authors_data.json

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
Expand Down
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions corpus/accounts/management/commands/load_json_data_exec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json

from accounts.models import ExecutiveMember
from accounts.models import User
from config.models import SIG
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = "to migrate authors from the json file to the ExecutiveMember model"

def add_arguments(self, parser):
parser.add_argument("json_file", type=str, help="Path to the json file")

def handle(self, *args, **kwargs):
json_file = kwargs["json_file"]

with open(json_file, "r") as file:
data = json.load(file)

counter = 0
for item in data.values():
edu_email = "noemail" + str(counter) + "@nitk.edu.in"
roll_number = "111GG" + str(counter)
reg_number = "1111" + str(counter)
model_sig = SIG.objects.all()[0]
user_model_obj = User.objects.get(email=item["email"])
new_user = ExecutiveMember(
sig=model_sig,
user=user_model_obj,
edu_email=edu_email,
roll_number=roll_number,
reg_number=reg_number,
)
new_user.save()
counter = counter + 1
print(f"user number {counter} with email created")
36 changes: 36 additions & 0 deletions corpus/accounts/management/commands/load_json_data_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json

from accounts.models import User
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = "to migrate authors from the json file to the User model"

def add_arguments(self, parser):
parser.add_argument("json_file", type=str, help="Path to the json file")

def handle(self, *args, **kwargs):
json_file = kwargs["json_file"]

with open(json_file, "r") as file:
data = json.load(file)

counter = 0
for item in data.values():
phone_num = counter + 9999999000
new_user = User(
email=item["email"],
phone_no=phone_num,
gender="N",
)
new_user.save()
# name_arr = item['name'].split()
# first_name = name_arr[0]
# last_name = name_arr[-1]
# user = User.objects.get(email=item['email'])
# user.first_name = first_name
# user.last_name = last_name
# user.save()
counter = counter + 1
print(f"user number={counter} created")
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Generated by Django 4.2.7 on 2024-06-29 07:27

# Generated by Django 4.2.7 on 2024-07-12 05:54
import datetime
from django.db import migrations, models

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0005_alter_executivemember_date_joined_and_more'),
("accounts", "0005_alter_executivemember_date_joined_and_more"),
]

operations = [
migrations.AlterField(
model_name='executivemember',
name='date_joined',
field=models.DateTimeField(default=datetime.datetime(2024, 6, 29, 7, 27, 12, 372509, tzinfo=datetime.timezone.utc), verbose_name='Date Joined'),
model_name="executivemember",
name="date_joined",
field=models.DateTimeField(
default=datetime.datetime(
2024, 7, 12, 5, 54, 40, 426496, tzinfo=datetime.timezone.utc
),
verbose_name="Date Joined",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.7 on 2024-08-02 07:55
import datetime

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0006_alter_executivemember_date_joined"),
]

operations = [
migrations.AlterField(
model_name="executivemember",
name="date_joined",
field=models.DateTimeField(
default=datetime.datetime(
2024, 8, 2, 7, 52, 20, 210123, tzinfo=datetime.timezone.utc
),
verbose_name="Date Joined",
),
),
]
9 changes: 7 additions & 2 deletions corpus/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
path("signup/", signup, name="accounts_signup"),
path("login/", signin, name="accounts_signin"),
path("logout/", signout, name="accounts_signout"),
path("reset/", PasswordResetView.as_view(html_email_template_name="../templates/registration/password_reset_email.html"),
name="password_reset"),
path(
"reset/",
PasswordResetView.as_view(
html_email_template_name="../templates/registration/password_reset_email.html"
),
name="password_reset",
),
path("reset/done/", PasswordResetDoneView.as_view(), name="password_reset_done"),
path(
"reset/confirm/<uidb64>/<token>/",
Expand Down
Empty file added corpus/blog/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions corpus/blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

from .models import Post
from .models import Tag

admin.site.register(Post)
admin.site.register(Tag)
6 changes: 6 additions & 0 deletions corpus/blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "blog"
Empty file.
Empty file.
51 changes: 51 additions & 0 deletions corpus/blog/management/commands/load_blog_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json
from datetime import datetime

from accounts.models import ExecutiveMember
from blog.models import Post
from blog.models import Tag
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = "to migrate authors from the json file to the User model"

def add_arguments(self, parser):
parser.add_argument("json_file", type=str, help="Path to the json file")

def handle(self, *args, **kwargs):
json_file = kwargs["json_file"]

with open(json_file, "r") as file:
data = json.load(file)

counter = 0
for post in data:
name_arr = post["author_name"].split()
first_name = name_arr[0]
last_name = name_arr[-1]
tags = Tag.objects.filter(tag_name=post["categories"][0])
author = ExecutiveMember.objects.filter(
user__first_name=first_name, user__last_name=last_name
)[0]
layout = post["layout"]
title = post["title"]
slug = post["slug"]
description = post["description"]
author_github = post["github_username"]
text = post["text"]
published_date = datetime.strptime(post["date"], "%Y-%m-%dT%H:%M:%S")
blog_post = Post(
layout=layout,
title=title,
author=author,
slug=slug,
description=description,
author_github=author_github,
text=text,
published_date=published_date,
)
blog_post.save()
blog_post.blog_tag.set(tags)
print(counter)
counter = counter + 1
60 changes: 60 additions & 0 deletions corpus/blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 4.2.7 on 2024-06-29 06:03
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Tag",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"tag_name",
models.CharField(
choices=[
("CompSoc", "CompSoc"),
("Diode", "Diode"),
("Piston", "Piston"),
],
max_length=50,
),
),
],
),
migrations.CreateModel(
name="Post",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("layout", models.CharField(max_length=20)),
("title", models.CharField(max_length=200)),
("description", models.CharField(max_length=300)),
("author_github", models.CharField(max_length=70)),
("text", models.TextField()),
("created_date", models.DateTimeField(auto_now_add=True)),
("published_date", models.DateTimeField(blank=True, null=True)),
("blog_tag", models.ManyToManyField(to="blog.tag")),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2024-06-29 07:02
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("blog", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="post",
name="author_github",
field=models.CharField(blank=True, max_length=70, null=True),
),
migrations.AlterField(
model_name="post",
name="layout",
field=models.CharField(blank=True, max_length=20, null=True),
),
]
25 changes: 25 additions & 0 deletions corpus/blog/migrations/0003_post_author.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.7 on 2024-07-01 05:59
import django.db.models.deletion
from django.conf import settings
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("blog", "0002_alter_post_author_github_alter_post_layout"),
]

operations = [
migrations.AddField(
model_name="post",
name="author",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
]
24 changes: 24 additions & 0 deletions corpus/blog/migrations/0004_alter_post_author.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.7 on 2024-07-12 05:54
import django.db.models.deletion
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0006_alter_executivemember_date_joined"),
("blog", "0003_post_author"),
]

operations = [
migrations.AlterField(
model_name="post",
name="author",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="accounts.executivemember",
),
),
]
18 changes: 18 additions & 0 deletions corpus/blog/migrations/0005_alter_post_published_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-07-12 14:49
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("blog", "0004_alter_post_author"),
]

operations = [
migrations.AlterField(
model_name="post",
name="published_date",
field=models.DateTimeField(),
),
]
18 changes: 18 additions & 0 deletions corpus/blog/migrations/0006_alter_post_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-07-13 06:05
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("blog", "0005_alter_post_published_date"),
]

operations = [
migrations.AlterField(
model_name="post",
name="description",
field=models.CharField(max_length=400),
),
]
Loading
Loading