-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from UtsavBhamra/blog
Migrated blogs from old site to new Django app (Envision project)
- Loading branch information
Showing
70 changed files
with
8,609 additions
and
232 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions
37
corpus/accounts/management/commands/load_json_data_exec.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
37 changes: 37 additions & 0 deletions
37
corpus/accounts/management/commands/load_json_data_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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") |
20 changes: 13 additions & 7 deletions
20
corpus/accounts/migrations/0006_alter_executivemember_date_joined.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
), | ||
] |
1 change: 0 additions & 1 deletion
1
corpus/accounts/migrations/0007_alter_executivemember_date_joined.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import json | ||
import re | ||
import os | ||
|
||
# Get the directory of the script file | ||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Define the input and output JSON file paths | ||
INPUT_FILE = os.path.join(SCRIPT_DIR, "blog_data_cpy2.json") | ||
OUTPUT_FILE = os.path.join(SCRIPT_DIR, "blog_data_cpy3.json") | ||
|
||
# Regex pattern to match {% static 'path' %} | ||
STATIC_PATTERN = r"{%\s*static\s*'([^']+)'?\s*%}" | ||
REPLACEMENT = r"media\1" | ||
|
||
def replace_static_in_json(input_file, output_file): | ||
with open(input_file, "r", encoding="utf-8") as f: | ||
data = json.load(f) | ||
|
||
# Process each entry in the JSON file | ||
for entry in data: | ||
if "text" in entry: | ||
# Replace static tags in the "text" field | ||
entry["text"] = re.sub(STATIC_PATTERN, REPLACEMENT, entry["text"]) | ||
|
||
# Save the updated data back to a new file | ||
with open(output_file, "w", encoding="utf-8") as f: | ||
json.dump(data, f, indent=4, ensure_ascii=False) | ||
|
||
print(f"Updated JSON saved to {output_file}") | ||
|
||
# Run the function | ||
replace_static_in_json(INPUT_FILE, OUTPUT_FILE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")), | ||
], | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
corpus/blog/migrations/0002_alter_post_author_github_alter_post_layout.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
), | ||
] |
Oops, something went wrong.