Skip to content

Commit

Permalink
resolving some merge comflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
krrish-sehgal committed Nov 5, 2024
2 parents b197a79 + dd3f630 commit 7842e66
Show file tree
Hide file tree
Showing 18 changed files with 543 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
DATABASE_URL=postgres://user:password@localhost:5432/dbname

#Sentry DSN
SENTRY_DSN=https://[email protected]/0
SENTRY_DSN=https://[email protected]/0
Empty file added blog/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin

from .models import Post


@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ("title", "author", "created_at", "image")
prepopulated_fields = {"slug": ("title",)}
6 changes: 6 additions & 0 deletions 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"
42 changes: 42 additions & 0 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 5.0.8 on 2024-10-30 15:57

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="Post",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=200)),
("slug", models.SlugField(unique=True)),
("content", models.TextField()),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"author",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
17 changes: 17 additions & 0 deletions blog/migrations/0002_alter_post_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.8 on 2024-10-30 18:52

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("blog", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="post",
name="slug",
field=models.SlugField(blank=True, unique=True),
),
]
19 changes: 19 additions & 0 deletions blog/migrations/0003_post_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.8 on 2024-10-31 08:48

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("blog", "0002_alter_post_slug"),
]

operations = [
migrations.AddField(
model_name="post",
name="image",
field=models.ImageField(default=django.utils.timezone.now, upload_to=""),
preserve_default=False,
),
]
Empty file added blog/migrations/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse


class Post(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True, blank=True)
author = models.ForeignKey(User, on_delete=models.CASCADE)
content = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
image = models.ImageField()

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse("post_detail", kwargs={"slug": self.slug})
65 changes: 65 additions & 0 deletions blog/templates/blog/post_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{% extends "base.html" %}

{% block content %}
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}

.confirm-buttons {
display: flex;
gap: 10px;
justify-content: center;
margin-top: 20px;
}

.delete-button {
padding: 10px 20px;
border: none;
border-radius: 5px;
color: #fff;
font-weight: bold;
background-color: #dc3545;
text-decoration: none;
cursor: pointer;
}

.delete-button:hover {
background-color: #c82333;
}

.cancel-button {
padding: 10px 20px;
border: none;
border-radius: 5px;
color: #fff;
font-weight: bold;
background-color: #007bff;
text-decoration: none;
cursor: pointer;
}

.cancel-button:hover {
background-color: #0056b3;
}

.post_content {
text-align: center;
margin: 0;
}
</style>

{% include "includes/sidenav.html" %}
<h1>Confirm Delete</h1>
<p class="post_content">Are you sure you want to delete the post "{{ post.title }}"?</p>
<form method="post" class="confirm-buttons">
{% csrf_token %}
<button type="submit" class="delete-button">Delete</button>
<a href="{% url 'post_detail' slug=post.slug %}" class="cancel-button">Cancel</a>
</form>
{% endblock content %}
108 changes: 108 additions & 0 deletions blog/templates/blog/post_details.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{% extends "base.html" %}

{% block content %}
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}

.post-article {
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 800px;
margin: 0 auto;
}

.post-title {
font-size: 2.5em;
color: #333;
margin-bottom: 10px;
text-align: center;
}

.post-meta {
font-size: 1em;
color: #666;
text-align: center;
margin-bottom: 20px;
}

.post-content {
line-height: 1.6;
color: #444;
}

.b-update {
display: inline-block;
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
color: #fff;
background-color: #007bff;
text-decoration: none;
font-weight: bold;
text-align: center;
}

.b-update:hover {
background-color: #0056b3;
}

.b-delete {
display: inline-block;
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
color: #fff;
background-color: #dc3545;
text-decoration: none;
font-weight: bold;
text-align: center;
}

.b-delete:hover {
background-color: #c82333;
}

.btn-div {
text-align: center;
margin-top: 20px;
}

.post-image img {
width: 100%;
height: auto;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}
</style>

{% include "includes/sidenav.html" %}
<article class="post-article">
<h1 class="post-title">{{ post.title }}</h1>
<p class="post-meta">By {{ post.author }} on {{ post.created_at }}</p>
<div class="post-content">
{{ post.content|safe }}
</div>
{% if post.image %}
<div class="post-image">
<img height="200" width="100%" src="{{ post.image.url }}" alt="{{ post.title }}">
</div>
{% endif %}

{% if request.user == post.author %}
<div class="btn-div">
<a href="{% url 'post_update' slug=post.slug %}" class="b-update">Update Post</a>
<a href="{% url 'post_delete' slug=post.slug %}" class="b-delete">Delete Post</a>
</div>
{% endif %}
</article>
{% endblock content %}
87 changes: 87 additions & 0 deletions blog/templates/blog/post_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{% extends "base.html" %}

{% block content %}
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}

#form-title {
text-align: center;
color: #333;
margin-bottom: 20px;
font-size: 2em; /* Adjusted font size for better visibility */
}

.form-container {
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 600px;
margin: 0 auto;
}

.form-container button {
background-color: #007bff;
color: black;
border: none;
border-radius: 5px;
padding: 10px 15px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}

.form-container button:hover {
background-color: #0056b3;
}

.form-field {
margin-bottom: 15px;
}
</style>

{% include "includes/sidenav.html" %}
<h1 id="form-title">{% if form.instance.pk %}Edit{% else %}New{% endif %} Post</h1>

<div class="form-container">
<form method="post" enctype="multipart/form-data" novalidate>
{% csrf_token %}
<div class="form-field">
{{ form.title.label }}<br>
{{ form.title }}<br>
{% for error in form.title.errors %}
<div>{{ error }}</div>
{% endfor %}
</div>

<div class="form-field">
{{ form.content.label }}<br>
{{ form.content }}<br>
{% for error in form.content.errors %}
<div>{{ error }}</div>
{% endfor %}
</div>

<div class="form-field">
{{ form.image.label }}<br>
{{ form.image }}<br>
{% for error in form.image.errors %}
<div>{{ error }}</div>
{% endfor %}
</div>

<button type="submit">Save</button>
</form>
</div>

<link rel="stylesheet" href="https://unpkg.com/easymde/dist/easymde.min.css">
<script src="https://unpkg.com/easymde/dist/easymde.min.js"></script>
<script>
var easyMDE = new EasyMDE({ element: document.getElementById('id_content') });
</script>
{% endblock content %}
Loading

0 comments on commit 7842e66

Please sign in to comment.