Skip to content

Commit

Permalink
Added dashbaord
Browse files Browse the repository at this point in the history
  • Loading branch information
nilandev committed Jan 10, 2024
1 parent 500b5b5 commit 5a8b1ce
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 123 deletions.
34 changes: 22 additions & 12 deletions bloggy/forms/edit_profile_form.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django import forms
from django.forms import ClearableFileInput

from django.forms import ClearableFileInput, ModelForm, inlineformset_factory
from bloggy.models import User


Expand All @@ -11,18 +10,20 @@ class NonClearableFileInput(ClearableFileInput):
class EditProfileForm(forms.ModelForm):
class Meta:
model = User
help_texts={
"bio": "This will be displayed publicly on your profile. Keep it short and crisp."
help_texts = {
"bio": "This will be displayed publicly on your profile. Keep it short and crisp.",
'receive_news_updates': "News about product and feature updates",
'receive_new_content': "Get notified when new content is added"
}

labels = {
'receive_news_updates': "News and updates",
'receive_new_content': "New tutorials & courses"
}

fields = [
'profile_photo',
'name',
'website',
'twitter',
'linkedin',
'youtube',
'github',
'bio'
'profile_photo', 'name', 'website', 'twitter', 'linkedin', 'youtube', 'github', 'bio',
'receive_news_updates', 'receive_new_content'
]

widgets = {
Expand Down Expand Up @@ -64,4 +65,13 @@ class Meta:
'rows': 5,
'placeholder': 'Your github'
}),

'receive_news_updates': forms.CheckboxInput(attrs={
'class': 'form-check-input',
}),

'receive_new_content': forms.CheckboxInput(attrs={
'class': 'form-check-input',
}),

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2024-01-10 14:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bloggy', '0007_alter_post_difficulty_alter_post_post_type_and_more'),
]

operations = [
migrations.AddField(
model_name='user',
name='receive_new_content',
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name='user',
name='receive_news_updates',
field=models.BooleanField(default=True),
),
]
2 changes: 2 additions & 0 deletions bloggy/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class User(AbstractBaseUser, ResizeImageMixin, PermissionsMixin):
youtube = models.CharField(max_length=100, null=True, blank=True)
github = models.CharField(max_length=100, null=True, blank=True)
bio = models.TextField(max_length=250, null=True, blank=True)
receive_news_updates = models.BooleanField(default=True)
receive_new_content = models.BooleanField(default=True)

class Meta:
db_table = "bloggy_user"
Expand Down
Binary file modified bloggy/templates/.DS_Store
Binary file not shown.
10 changes: 7 additions & 3 deletions bloggy/templates/pages/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ <h1 class="h2 my-3">{{ userProfile.username }}</h1>
<div class="py-3 pb-md-5">
<h1 class="h2 py-3 px-2">My articles(so far)</h1>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-2 g-3 mb-3">
{% for post in posts %}
<div class="col">{% include "partials/post_list_item.html" with post=post cssClass="" %}</div>
{% endfor %}
{% if posts|length <= 0 %}
<p class="lead my-3 text-muted">Currently, there are no published posts.</p>
{% else %}
{% for post in posts %}
<div class="col">{% include "partials/post_list_item.html" with post=post cssClass="" %}</div>
{% endfor %}
{% endif %}
</div>
{% include 'partials/paging.html' with posts=posts %}

Expand Down
32 changes: 15 additions & 17 deletions bloggy/templates/partials/article_row_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,39 @@
<div class="d-flex align-items-center">
<div class="flex-grow-1">
<div class="hero article-meta-container mb-2" style="font-size: 0.75rem">
<small class="d-inline-block mb-1 text-muted text-uppercase">Updated on {{ article.updated_date|date:"M j, Y" }}</small>

{% if article.publish_status == 'DRAFT' %}
<span class="ms-3 badge-meta-pill {{ article.publish_status | lower }}">{{ article.publish_status | capfirst }}</span>
<small class="d-inline-block mb-1 text-muted text-uppercase">Updated
on {{ post.updated_date|date:"M j, Y" }}</small>
{% if post.publish_status == 'DRAFT' %}
<span class="ms-3 badge-meta-pill {{ post.publish_status | lower }}">{{ post.publish_status | capfirst }}</span>
{% endif %}
<span class="ms-3 badge-meta-pill {{ article.post_type| lower }}">{{ article.post_type | capfirst }}</span>


<span class="ms-3 badge-meta-pill {{ post.post_type| lower }}">{{ post.post_type | capfirst }}</span>
</div>
<h3 class="h3 fw-500 mb-2">
<a href="{% url 'post_single' slug=article.slug %}"
class="text-decoration-none link-dark">{{ article.title }}</a>
<h3 class="h4 fw-500 mb-2">
<a href="{% url 'post_single' slug=post.slug %}"
class="text-decoration-none link-dark">{{ post.title }}</a>
</h3>


{% if article.author.username == user.username %}
{% if post.author.username == user.username %}
<small class="me-3 text-muted text-uppercase" style="font-size:0.75rem">
<i class="fa-solid fa-signal"></i>&nbsp;
{% get_hit_count for article %} views
{% get_hit_count for post %} views
</small>


<small class="me-3 text-muted text-uppercase" style="font-size:0.75rem">
<i class="fa-regular fa-comment"></i>
{{ article.get_comments_count }} comments
{{ post.get_comments_count }} comments
</small>
<a class="btn btn-sm btn-xs btn-light me-3" href="{{ article.get_admin_url }}"><i class="fa-regular fa-pen-to-square"></i> Edit</a>
<a class="btn btn-sm btn-xs btn-outline-primary me-3" href="{{ post.get_admin_url }}"><i
class="fa-regular fa-pen-to-square"></i> Edit</a>
{% endif %}

</div>

<div class="flex-shrink-0 ms-3">
{% if article.thumbnail %}
{% if post.thumbnail %}
<div class="archive-media-object" style="max-width: 100px">
<img loading="lazy" src="{{ article.thumbnail.url }}" alt="{{ article.title }}" height="auto">
<img loading="lazy" src="{{ post.thumbnail.url }}" alt="{{ post.title }}" height="auto">
</div>
{% endif %}
</div>
Expand Down
15 changes: 11 additions & 4 deletions bloggy/templates/partials/dashboard_menu.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
{% load static %}
{% load custom_widgets %}
<div class="card card-bordered card-shadowd p-4">
<div class="card card-bordered card-shadowdd p-4 mb-3">
<a href="{% url 'index' %}" class="pb-3 text-decoration-none link-dark link-offset-2 fw-600">Home</a>
<hr class="m-0 opacity-25">
<a href="{% url 'profile.account' %}" class="py-3 text-decoration-none link-dark link-offset-2 fw-600">Account</a>
<hr class="m-0 opacity-25">

<a href="{% url 'user_profile' username=user.username %}"
class="py-3 text-decoration-none link-dark link-offset-2 fw-600">Your profile</a>
<a href="{% url 'profile.dashboard' %}" class="py-3 text-decoration-none link-dark link-offset-2 fw-600">
Dashboard</a>
<hr class="m-0 opacity-25">

{% if user.is_staff %}
<a href="{% url 'user_profile' username=user.username %}"
class="py-3 text-decoration-none link-dark link-offset-2 fw-600">Your profile<i
class="fa-solid fa-arrow-up-right-from-square float-lg-end ms-3"></i></a>
<hr class="m-0 opacity-25">
{% endif %}

{% if user.is_superuser %}
<a href="{% url 'admin:index' %}" class="py-3 text-decoration-none link-dark link-offset-2 fw-600">
Dashboard</a>
Admin panel<i class="fa-solid fa-arrow-up-right-from-square float-lg-end ms-3"></i></a>
<hr class="m-0 opacity-25">
{% endif %}

Expand Down
68 changes: 45 additions & 23 deletions bloggy/templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,35 @@
<hr>

<ul class="navbar-nav flex-shrink-0">
<li class="nav-item">
<a class="nav-link py-3">{% if user.name %}Hello, {{ request.user.name }}{% else %}
My Account{% endif %}</a>
<li class="nav-item">
<a class="nav-link py-3">{% if user.name %}Hello,
{{ request.user.name }}{% else %}
My Account{% endif %}</a>
</li>

<li class="nav-item">
<a class="nav-link py-3" href="{% url 'profile.edit_profile' %}">Edit
profile</a>
<a href="{% url 'profile.account' %}" class="nav-link py-3">Account</a>
</li>
{# <li class="nav-item">#}
{# <a class="nav-link py-3" href="{% url 'profile.bookmarks' %}">Bookmarks</a>#}
{# </li>#}

<li class="nav-item">
<a href="{% url 'profile.dashboard' %}" class="nav-link py-3">Dashboard</a>
</li>

{% if user.is_staff %}
<li class="nav-item">
<a class="nav-link py-3"
href="{% url 'user_profile' username=user.username %}">Your profile<i
class="fa-solid fa-arrow-up-right-from-square float-lg-end ms-3"></i></a>
</li>
{% endif %}

{% if user.is_superuser %}
<li class="nav-item">
<a class="nav-link py-3" href="{% url 'admin:index' %}">Dashboard</a>
<a class="nav-link py-3" href="{% url 'admin:index' %}">Admin panel<i
class="fa-solid fa-arrow-up-right-from-square float-lg-end ms-3"></i></a>
</li>
{% endif %}

<hr>
<li class="nav-item">
<a class="nav-link text-danger py-3"
Expand Down Expand Up @@ -111,32 +121,44 @@

<div class="dropdown custom-dropdown">
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
{# <p class="menu-heading font-xs pt-2">#}
<li class="nav-item">
<a class="dropdown-item"><span class="menu-heading">{% if user.name %}<span class="me-2">👋</span>Hello, {{ user.name }}{% else %}My Account{% endif %}</span></a>
<li class="nav-item">
<a class="dropdown-item"><span class="menu-heading">
<span class="me-2">👋</span>Hello, {{ user.name }}</span>
</a>
</li>

{% if user.is_superuser %}
<li class="nav-item">
<a class="dropdown-item" href="{% url 'profile.account' %}"><i
class="fa-solid fa-user me-2"></i>My Account</a>
</li>

<li class="nav-item">
<a class="dropdown-item" href="{% url 'profile.dashboard' %}"><i
class="fa-solid fa-gauge me-2"></i>Dashboard</a>
</li>

{% if user.is_staff %}
<li class="nav-item">
<a class="dropdown-item" href="{% url 'index' %}"><i class="fa-solid fa-house me-2"></i>Home</a>
<a class="dropdown-item"
href="{% url 'user_profile' username=user.username %}"><i
class="fa-solid fa-arrow-up-right-from-square me-2"></i>Your Profile</a>
</li>
{% endif %}

<li class="nav-item">
<a class="dropdown-item" href="{% url 'profile.account' %}"><i class="fa-solid fa-user me-2"></i>My Account</a>
</li>

<li class="nav-item">
<a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#feedbackModal"><i class="fa-solid fa-comments me-2"></i>Give Feedback</a>
<a class="dropdown-item" href="#" data-bs-toggle="modal"
data-bs-target="#feedbackModal"><i class="fa-solid fa-comments me-2"></i>Give
Feedback</a>
</li>


{# <a class="dropdown-item" href="{% url 'profile.edit_profile' %}">Edit profile</a>#}
{# <a class="dropdown-item" href="{% url 'profile.bookmarks' %}">Bookmarks</a>#}
{% if user.is_superuser %}
<a class="dropdown-item" href="{% url 'admin:index' %}"><i class="fa-solid fa-gauge me-2"></i>Dashboard</a>
<li class="nav-item">
<a class="dropdown-item" href="{% url 'admin:index' %}"><i
class="fa-solid fa-gauge me-2"></i>Admin Panel</a>
</li>
{% endif %}
<hr>

<a class="dropdown-item text-danger"
href="{% url 'logout' %}?next={{ request.path }}">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
Expand Down
31 changes: 23 additions & 8 deletions bloggy/templates/profile/account_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

<div class="container mt-5">
<div class="row">
<div class="col-lg-3">
{% include 'partials/dashboard_menu.html' %}
<div class="col-12 col-lg-3 col-xl-3">
{% include 'partials/dashboard_menu.html' with user=user %}
</div>

<div class="col-lg-7">
<div class="col-12 col-lg-9 col-xl-7">
<div class="card p-lg-5 p-3 card-bordered card-shadowd">
<h1 class="h2">Account details</h1>
<p>Manage your account settings such as username, password, and personal information.</p>
Expand Down Expand Up @@ -64,8 +64,7 @@ <h4 class="h4 mb-0">Joined on</h4>

</div>
<div class="mb-3">
<a href="{% url 'profile.account.change_password' %}" class="btn border-2 btn-outline-primary"
target="_blank">Change password</a>
<a href="{% url 'profile.account.change_password' %}" class="btn border-2 btn-outline-primary">Change password</a>
</div>

<div class="d-flex justify-content-between mt-5">
Expand All @@ -81,9 +80,9 @@ <h3 class="h3 mb-4"><span class="">Personal</span> information</h3>
<div class="col-12">
<h4 class="h4 mb-0">Profile photo</h4>
<img src="{{ user.get_avatar }}" alt=""
class="img-fluid rounded-circled mt-2 mb-3" id="profile_photo_preview"
height="100px"
width="100px">
class="img-fluid rounded-circled mt-2 mb-3" id="profile_photo_preview"
height="100px"
width="100px">
</div>

<div class="col-12 col-lg-6">
Expand Down Expand Up @@ -116,6 +115,22 @@ <h4 class="h4 mb-0">Bio</h4>
<p class="text-muted">{% if user.bio %}{{ user.bio }}{% else %}-{% endif %}</p>
</div>
</div>


<h2 class="h3 mt-4 mb-2">Notification settings</h2>
<div class="custom-form">
<div class="col-md-12 my-2">
<input type="checkbox" name="receive_news_updates" class="form-check-input" id="id_receive_news_updates" {% if user.receive_news_updates %}checked{% endif %} style="pointer-events: none;">
<label class="form-check-label px-2" for="id_receive_news_updatesd">News and updates</label>
<span id="emailHelp" class="helptext ms-4 text-muted">News about product and feature updates</span>
</div>

<div class="col-md-12 mt-3">
<input type="checkbox" name="receive_new_content" class="form-check-input" id="id_receive_new_content" {% if user.receive_new_content %}checked{% endif %} style="pointer-events: none;">
<label class="form-check-label px-2" for="id_receive_new_contentd">New tutorials&amp; courses</label>
<span id="emailHelp" class="helptext ms-4 text-muted">Get notified when new content is added</span>
</div>
</div>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions bloggy/templates/profile/change_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@

<div class="container mt-5">
<div class="row">
<div class="col-lg-3">
<div class="col-12 col-lg-3 col-xl-3">
{% include 'partials/dashboard_menu.html' with user=user %}
</div>

<div class="col-lg-7">
<div class="col-12 col-lg-9 col-xl-7">
<div class="card p-lg-5 p-3 card-bordered card-shadowd">
<h1 class="h2">Change Password</h1>
<h1 class="h2">Change password</h1>
<form method="post" action="" class="col-12 col-lg-9 custom-form">
{% csrf_token %}
{{ form.as_p }}
<div class="form-group mt-4">
<button type="submit" class="btn btn-primary">Change Password</button>
<button type="submit" class="btn btn-primary">Change password</button>
</div>
</form>
</div>
Expand Down
Loading

0 comments on commit 5a8b1ce

Please sign in to comment.