Skip to content

Commit c379992

Browse files
committed
add categories, remove features
1 parent 4a955a7 commit c379992

File tree

13 files changed

+50
-71
lines changed

13 files changed

+50
-71
lines changed

Test templates/CSS/classic.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
}
3131
.blog-container-1 .blog-post {
3232
flex-direction: column;
33-
text-align: center;
33+
/* text-align: center; */
3434
}
3535

3636
.blog-container-1 .post-image {
3737
text-align: center;
3838
width: 100%;
3939

4040
}
41+
.blog-container-1 .post-image img{
42+
width: 90%;
43+
}
4144
}

Test templates/Javascript/Post Template/home and blog/classic.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bloggit.className = "blog-container-1"
2525
</div>
2626
</div>
2727
<div class="post-image">
28-
<img src="http://127.0.0.1:8000${image}" alt="${title}">
28+
<img src="https://bloggit.pythonanywhere.com${image}" alt="${title}">
2929
</div>
3030
`
3131
bloggit.appendChild(post_container)
@@ -35,6 +35,9 @@ bloggit.className = "blog-container-1"
3535
<h2>${title}</h2>
3636
<p>${strip_tags(body)}</p>
3737
<date>${convert_datetime(parameter.time)}</date>
38+
<div class="read-more">
39+
<a href="${data["individual_page"]}?id=${post_id}">Read More</a>
40+
</div>
3841
</div>
3942
<div class="post-image">
4043

Test templates/Javascript/home_and_blog.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ function strip_tags(param){
9292
return words.slice(0, 30).join(' ');
9393
}
9494

95+
const url_parameters = window.location.search;
9596

96-
fetch(`http://127.0.0.1:8000/posts/api/${api_key}?url=${current_url}&cont_rend=${cont_rend}&header_type=${header_type}`)
97+
const category = new URLSearchParams(url_parameters).get("category");
98+
console.log(category);
99+
100+
fetch(`http://127.0.0.1:8000/posts/api/${api_key}?url=${current_url}&cont_rend=${cont_rend}&header_type=${header_type}&category=${category}`)
97101

98102
.then((response) => {
99103
if (response.status === 200) { // Replace with the expected status code

Test templates/blog.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<title>Blog Page</title>
77
<script>
88
const bloggit_conf = {
9-
"api_key": "7070aa3bfb7a4f6f8266fa44180d4aaf",
9+
"api_key": "e9f51a0a6cc0494cb5525d9e8def7337",
1010
"cont_rend":"classic",
1111
"header": {
1212
"type": "milky-way",
@@ -19,7 +19,12 @@
1919
}
2020
}
2121
</script>
22-
<script src="./Javascript/home_and_blog.js"></script>
22+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
23+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
24+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
25+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
26+
<!-- <script src="./Javascript/home_and_blog.js"></script> -->
27+
<script src = "https://bloggit.pythonanywhere.com/static/Javascript/config.js"></script>
2328
</head>
2429
<body>
2530
<section id="bloggit-header">

api/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class Post(models.Model):
1818

1919
)
2020
time = models.DateTimeField(default = datetime.now())
21-
featured = models.BooleanField(default=False)
21+
# featured = models.BooleanField(default=False)
2222
publish = models.BooleanField(default=False)
23+
categories = models.CharField(default = "", max_length=100)
2324

2425
def save(self, *args, **kwargs):
2526
if not self.custom_id:

api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class PostSerializer(ModelSerializer):
66

77
class Meta:
88
model = Post
9-
fields = ["title", "body", "image", "featured", "publish", "time", "custom_id"]
9+
fields = ["title", "body", "image", "publish", "time", "custom_id", "categories"]
1010

1111
# class GetPostSerializer(ModelSerializer):
1212
# class Meta:

api/views.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,17 @@ def get(self, request:Request, api_key, *args, **kwargs):
6868
# Filter Posts
6969
if user_urls.blog_page in requesting_url_homeblog:
7070
# All Posts
71-
72-
data = Post.objects.filter(creator = user)
71+
category = request.GET.get("category")
72+
73+
if category != "null":
74+
75+
data = Post.objects.filter(creator = user, publish = True, categories = category)
76+
if data.exists():
77+
data = data
78+
else:
79+
data = Post.objects.filter(creator = user, publish = True)
80+
elif category == "null":
81+
data = Post.objects.filter(creator = user, publish = True)
7382

7483
serialized_data = PostSerializer(data = data, many = True)
7584
serialized_data.is_valid()
@@ -98,37 +107,6 @@ def get(self, request:Request, api_key, *args, **kwargs):
98107
response_data, status = status.HTTP_200_OK
99108
)
100109

101-
elif user_urls.home_page in requesting_url_homeblog:
102-
# Only Featured Posts
103-
104-
105-
data = Post.objects.filter(creator = user, featured = True)
106-
serialized_data = PostSerializer(data = data, many = True)
107-
serialized_data.is_valid()
108-
109-
110-
response_data = {
111-
"posts": serialized_data.data,
112-
"individual_page": user_urls.individual_blog_post
113-
}
114-
try:
115-
response_data["script"] = script.script
116-
except: pass
117-
118-
try:
119-
response_data["css_render"] = css_render.css_file
120-
except:pass
121-
122-
try:
123-
response_data["header_type"] = header_type.script
124-
except: pass
125-
126-
try:
127-
response_data["css_header"] = css_header.css_file
128-
except: pass
129-
return Response(
130-
response_data, status = status.HTTP_200_OK
131-
)
132110

133111
elif user_urls.individual_blog_post in requesting_url.split("?id=")[0]:
134112
# The Id in the Post will be gotten and used here

app/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class UserSites(models.Model):
55

66
user = models.ForeignKey(User, on_delete=models.CASCADE)
7-
home_page = models.CharField(max_length = 100, blank=True, null=True)
7+
# home_page = models.CharField(max_length = 100, blank=True, null=True)
88
blog_page = models.CharField(max_length = 100, blank=True, null=True)
99
individual_blog_post = models.CharField(max_length = 100, blank=True, null=True)
1010

app/views.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def post(self, request, **kwargs):
2424
if "submitpost" in request.POST:
2525
title = request.POST["title"]
2626
content = request.POST.get("content", "")
27-
27+
category = request.POST["category"]
2828
if not content.strip() or content is None or content == None or content.strip() is None or content.strip() == '<p><br></p>':
2929
messages.info(request, 'Summernote editor is empty')
3030
return redirect("/dashboard/admin")
@@ -34,17 +34,13 @@ def post(self, request, **kwargs):
3434
else:
3535
publish = False
3636

37-
if "featured" in request.POST:
38-
featured = True
39-
else:
40-
featured = False
4137

4238
create_post = Post.objects.create(
4339
creator = request.user,
4440
title = title,
4541
body= content,
4642
publish = publish,
47-
featured = featured
43+
categories = category
4844
)
4945

5046
if request.FILES:
@@ -81,6 +77,7 @@ def post(self, request, post_id, **kwargs):
8177

8278
post_.title = request.POST["title"]
8379
content = request.POST.get("content", "")
80+
category = request.POST["category"]
8481

8582
if not content.strip() or content is None or content == None or content.strip() is None or content.strip() == '<p><br></p>':
8683
messages.info(request, 'Summernote editor is empty')
@@ -94,13 +91,10 @@ def post(self, request, post_id, **kwargs):
9491
else:
9592
publish = False
9693

97-
if "featured" in request.POST:
98-
featured = True
99-
else:
100-
featured = False
94+
10195

10296
post_.publish = publish
103-
post_.featured = featured
97+
post_.categories = category
10498

10599
if request.FILES:
106100
image = request.FILES["image"]
@@ -157,14 +151,12 @@ def post(self, request, *args, **kwargs):
157151
try:
158152
if request.method == "POST":
159153
if "update-sites" in request.POST:
160-
homePage = request.POST["homePage"]
161154

162155
blogPage = request.POST["blogPage"]
163156
individualPostPage = request.POST["individualPostPage"]
164157

165158
sites = get_object_or_404(UserSites, user = request.user)
166159

167-
sites.home_page = homePage
168160
sites.blog_page = blogPage
169161
sites.individual_blog_post = individualPostPage
170162

db.sqlite3

0 Bytes
Binary file not shown.

templates/admin.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ <h3>Create New Post</h3>
5050
<label for="image">Image:</label>
5151
<input type="file" class="form-control-file" id="image" name="image" accept=".png, .jpg, .jpeg">
5252
</section>
53-
53+
<section class="form-group">
54+
<label for="category">Category:</label>
55+
<input type="text" class="form-control" id="category" name="category" required >
56+
</section>
5457
<section class="form-check">
5558
<input type="checkbox" class="form-check-input" id="publish" name="publish">
5659
<label class="form-check-label" for="publish">Publish</label>
5760
</section>
5861

59-
<section class="form-check">
60-
<input type="checkbox" class="form-check-input" id="featured" name="featured">
61-
<label class="form-check-label" for="featured">Featured</label>
62-
</section>
63-
6462
<button type="submit" class="btn btn-primary" name="submitpost" id="make-post">Create Post</button>
6563
</form>
6664
</section>
@@ -77,7 +75,6 @@ <h2>Manage Posts</h2>
7775
<th>Edit</th>
7876
<th>Delete</th>
7977
<th>Publish</th>
80-
<th>Featured</th>
8178
</tr>
8279
</thead>
8380
<tbody>
@@ -96,7 +93,6 @@ <h2>Manage Posts</h2>
9693

9794
</form>
9895
<td><input type="checkbox" {% if post.publish == True %} checked {% endif %} disabled></td>
99-
<td><input type="checkbox" {% if post.featured == True %} checked {% endif %} disabled></td>
10096
</tr>
10197
{% endfor %}
10298
</tbody>

templates/api.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ <h2>Your API Key</h2>
6060
<h2>Site URLS</h2>
6161
<form id="apiInfoForm" method="post">
6262
{% csrf_token %}
63-
<div class="form-group">
64-
<label for="homePage">Home Page URL:</label>
65-
<input type="text" class="form-control" id="homePage" name = "homePage" placeholder="Enter Home Page URL" value = "{{ user_sites.home_page }}">
66-
</div>
6763
<div class="form-group">
6864
<label for="blogPage">Blog Page URL:</label>
6965
<input type="text" class="form-control" id="blogPage" name = "blogPage" placeholder="Enter Blog Page URL" value = "{{ user_sites.blog_page }}">

templates/edit-post.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<head>
66
<meta charset="UTF-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8-
<title>Admin Page</title>
8+
<title>Edit Post</title>
99
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
1010
<link rel="stylesheet" href="{% static 'CSS/admin.css' %}">
1111
<link rel="shortcut icon" href="{% static 'images/logo.png' %}" type="image/x-icon">
@@ -43,15 +43,16 @@ <h3>Edit Post</h3>
4343
<input type="file" class="form-control-file" id="image" name="image" accept=".png, .jpg, .jpeg" >
4444
</section>
4545

46+
<section class="form-group">
47+
<label for="category">Category:</label>
48+
<input type="text" class="form-control" id="category" name="category" required value = "{{ post.categories }}">
49+
</section>
50+
4651
<section class="form-check">
4752
<input type="checkbox" class="form-check-input" id="publish" name="publish" {% if post.publish == True %} checked {% endif %}>
4853
<label class="form-check-label" for="publish">Publish</label>
4954
</section>
5055

51-
<section class="form-check">
52-
<input type="checkbox" class="form-check-input" id="featured" name="featured" {% if post.featured == True %} checked {% endif %}>
53-
<label class="form-check-label" for="featured">Featured</label>
54-
</section>
5556
<section id="btns">
5657
<button type="submit" class="btn btn-primary" name="submitpost" id="make-post">Edit Post</button>
5758
<button type="submit" class="btn btn-primary" name="deletepost" id="delete-post">Delete Post</button>

0 commit comments

Comments
 (0)