Skip to content

Commit ad7f5a5

Browse files
Modified the project code.
1 parent dfc37e3 commit ad7f5a5

26 files changed

+11
-148
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

accounts/forms.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class SignUpForm(UserCreationForm):
77
email = forms.CharField(max_length=254, required=True, widget=forms.EmailInput())
8-
98
class Meta:
109
model = User
1110
fields = ('username', 'email', 'password1', 'password2')

accounts/views.py

-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ def signup(request):
2020
else:
2121
#form = UserCreationForm()
2222
form = SignUpForm()
23-
2423
return render(request, 'signup.html', {'form':form})
2524

2625
#CBV -for my account
27-
2826
@method_decorator(login_required, name='dispatch')
2927
class UserUpdateView(UpdateView):
3028
model = User
Binary file not shown.

myFirstDjangoProject/urls.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
from django.contrib.auth import views as auth_views
2222
from django.urls import path
2323

24-
25-
2624
#https://docs.djangoproject.com/en/4.0/topics/http/urls/
25+
2726
urlpatterns = [
2827
path('', views.home, name='home'),#default home page path
2928
path('home/', views.home, name='home'),
@@ -36,12 +35,12 @@
3635
re_path(r'^logout/$',auth_views.LogoutView.as_view(),name='logout'),
3736

3837
re_path(r'^reset/$',
39-
auth_views.PasswordResetView.as_view(
40-
template_name='password_reset.html',
41-
email_template_name='password_reset_email.html',
42-
subject_template_name='password_reset_subject.txt'
43-
),
44-
name='password_reset'),
38+
auth_views.PasswordResetView.as_view(
39+
template_name='password_reset.html',
40+
email_template_name='password_reset_email.html',
41+
subject_template_name='password_reset_subject.txt'
42+
),
43+
name='password_reset'),
4544

4645
re_path(r'^reset/done/$',
4746
auth_views.PasswordResetDoneView.as_view(template_name='password_reset_done.html'),
@@ -72,6 +71,7 @@
7271

7372
#FBV url board_topic
7473
#re_path(r'^board_topic/(?P<pk>\d+)/$', views.board_topic, name='board_topic'),
74+
7575
#CBV-url board_topic
7676
re_path(r'^board_topic/(?P<pk>\d+)/$', views.TopicListView.as_view(),
7777
name='board_topic'),
@@ -90,7 +90,6 @@
9090
re_path(r'^board_topic/(?P<pk>\d+)/topics/(?P<topic_pk>\d+)/$',
9191
views.PostListView.as_view(), name='topic_posts'),
9292

93-
9493
re_path(r'^board_topic/(?P<pk>\d+)/topics/(?P<topic_pk>\d+)/reply/$',
9594
views.reply_topic, name='reply_topic'),
9695

@@ -99,5 +98,4 @@
9998
name='edit_post'),
10099

101100
path('admin/', admin.site.urls),
102-
103101
]

static/img/moroccan-flower-dark.png

-72.8 KB
Binary file not shown.

templates/base.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
2121
<div class="container">
2222
<a class="navbar-brand" href="{% url 'home' %}">Web Chat Boards</a>
23-
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mainMenu" aria-controls="mainMenu" aria-expanded="false" aria-label="Toggle navigation">
24-
<span class="navbar-toggler-icon"></span>
25-
</button>
23+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mainMenu" aria-controls="mainMenu" aria-expanded="false" aria-label="Toggle navigation">
24+
<span class="navbar-toggler-icon"></span>
25+
</button>
2626
<div class="collapse navbar-collapse" id="mainMenu">
2727
{% if user.is_authenticated %}
2828
<ul class="navbar-nav ms-auto">

templates/chat_board_topics.html

-90
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
{% block breadcrumb %}
1010
<li class="breadcrumb-item"><a href="{% url 'home' %}">Web Chat Boards</a></li>
1111
<li class="breadcrumb-item active">{{ chat_board.name }}</li>
12-
1312
{% endblock %}
1413

1514
{% block content %}
16-
1715
<div class="mb-4">
1816
<a href="{% url 'new_board_topic' chat_board.pk %}" class="btn btn-primary">New topic</a>
1917
</div>
@@ -51,97 +49,9 @@
5149
<td>{{ topic.views }}</td>
5250
<td>{{ topic.lastUpdate|naturaltime }}</td>
5351
</tr>
54-
55-
5652
{% endfor %}
5753
</tbody>
5854
</table>
59-
6055
{% include 'includes/pagination.html' %}
6156

62-
<!--below code for CBV-->
63-
<!--{% if is_paginated %}
64-
<nav aria-label="Topics pagination" class="mb-4">
65-
<ul class="pagination">
66-
{% if page_obj.has_previous %}
67-
<li class="page-item">
68-
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a>
69-
</li>
70-
{% else %}
71-
<li class="page-item disabled">
72-
<span class="page-link">Previous</span>
73-
</li>
74-
{% endif %}
75-
76-
{% for page_num in paginator.page_range %}
77-
{% if page_obj.number == page_num %}
78-
<li class="page-item active">
79-
<span class="page-link">
80-
{{ page_num }}
81-
<span class="sr-only">(current)</span>
82-
</span>
83-
</li>
84-
{% else %}
85-
<li class="page-item">
86-
<a class="page-link" href="?page={{ page_num }}">{{ page_num }}</a>
87-
</li>
88-
{% endif %}
89-
{% endfor %}
90-
91-
{% if page_obj.has_next %}
92-
<li class="page-item">
93-
<a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a>
94-
</li>
95-
{% else %}
96-
<li class="page-item disabled">
97-
<span class="page-link">Next</span>
98-
</li>
99-
{% endif %}
100-
</ul>
101-
</nav>
102-
{% endif %}-->
103-
104-
105-
<!--below code for FBV-->
106-
<!--{% if topics.has_other_pages %}
107-
<nav aria-label="Topics pagination" class="mb-4">
108-
<ul class="pagination">
109-
{% if topics.has_previous %}
110-
<li class="page-item">
111-
<a class="page-link" href="?page={{ topics.previous_page_number }}">Previous</a>
112-
</li>
113-
{% else %}
114-
<li class="page-item disabled">
115-
<span class="page-link">Previous</span>
116-
</li>
117-
{% endif %}
118-
119-
{% for page_num in topics.paginator.page_range %}
120-
{% if topics.number == page_num %}
121-
<li class="page-item active">
122-
<span class="page-link">
123-
{{ page_num }}
124-
<span class="sr-only">(current)</span>
125-
</span>
126-
</li>
127-
{% else %}
128-
<li class="page-item">
129-
<a class="page-link" href="?page={{ page_num }}">{{ page_num }}</a>
130-
</li>
131-
{% endif %}
132-
{% endfor %}
133-
134-
{% if topics.has_next %}
135-
<li class="page-item">
136-
<a class="page-link" href="?page={{ topics.next_page_number }}">Next</a>
137-
</li>
138-
{% else %}
139-
<li class="page-item disabled">
140-
<span class="page-link">Next</span>
141-
</li>
142-
{% endif %}
143-
</ul>
144-
</nav>
145-
{% endif %}-->
146-
14757
{% endblock %}

templates/edit_post.html

-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
{% block title %}Edit post{% endblock %}
66

7-
87
{% block stylesheet %}
98
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
109
{% endblock %}
@@ -16,22 +15,18 @@
1615
</script>
1716
{% endblock %}
1817

19-
2018
{% block breadcrumb %}
2119
<li class="breadcrumb-item"><a href="{% url 'home' %}">Web Chat Boards</a></li>
2220
<li class="breadcrumb-item"><a href="{% url 'board_topic' post.topic.boardName.pk %}">{{ post.topic.boardName.name }}</a></li>
2321
<li class="breadcrumb-item"><a href="{% url 'topic_posts' post.topic.boardName.pk post.topic.pk %}">{{ post.topic.subject }}</a></li>
2422
<li class="breadcrumb-item active">Edit</li>
25-
2623
{% endblock %}
2724

2825
{% block content %}
29-
3026
<form method="post" class="md-4" novalidate>
3127
{% csrf_token %}
3228
{% include 'includes/form.html' %}
3329
<button type="submit" class="btn btn-success">Save changes</button>
3430
<a href="{% url 'topic_posts' post.topic.boardName.pk post.topic.pk %}" class ="btn btn-outline-secondary" role="button">Cancel</a>
3531
</form>
36-
3732
{% endblock %}

templates/includes/form.html

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{% load form_tags widget_tweaks %}
32

43
{% if form.non_field_errors %}

templates/login.html

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<h3 class="card-title">Log in</h3>
1111
<form method = "post" novalidate>
1212
{% csrf_token %}
13-
<!--{{ form.as_p}}-->
1413
<input type="hidden" name="next" value="{{ next }}">
1514
{% include 'includes/form.html' %}
1615
<button type="submit" class="btn btn-primary btn-block">Log in</button>
@@ -28,5 +27,4 @@ <h3 class="card-title">Log in</h3>
2827
</div>
2928
</div>
3029
</div>
31-
3230
{% endblock %}

templates/new_board_topic.html

-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
{% endblock %}
1414

1515
{% block content %}
16-
1716
<form method="post" novalidate>
1817
{% csrf_token %}
19-
2018
{% include 'includes/form.html' %}
21-
2219
<button type="submit" class="btn btn-success">Post</button>
2320
</form>
24-
2521
{% endblock %}

templates/password_change_done.html

-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
<div class="alert alert-success" role="alert">
1212
<strong>Success!!</strong>Ypur password has been changed.
1313
</div>
14-
1514
<a href="{% url 'home' %}" class="btn btn-secondary">Return to home page</a>
1615
{% endblock %}

templates/password_reset.html

-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ <h3 class="card-title">Reset your password</h3>
1313
{% csrf_token %}
1414
{% include 'includes/form.html' %}
1515
<button type="submit" class="btn btn-primary btn-block">Send password reset email</button>
16-
1716
</form>
18-
1917
</div>
20-
2118
</div>
22-
2319
</div>
2420
</div>
25-
2621
{% endblock %}

templates/password_reset_done.html

-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ <h3 class="card-title">Reset your password</h3>
1111
<p>Check your email for a link to reset your password.
1212
If it does not appear your inbox wait a few minutes, and check your spam folder.</p>
1313
<a href="{% url 'login' %}" class="btn btn-secondary btn-block">Return to log in</a>
14-
1514
</div>
16-
1715
</div>
18-
1916
</div>
2017
</div>
21-
2218
{% endblock %}

templates/reply_topic.html

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{% extends 'base.html' %}
2-
32
{% load static %}
43
{% load humanize %}
54
{% block title %}Post a reply{% endblock %}
65

7-
86
{% block stylesheet %}
97
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
108
{% endblock %}
@@ -16,7 +14,6 @@
1614
</script>
1715
{% endblock %}
1816

19-
2017
{% block breadcrumb %}
2118
<li class="breadcrumb-item"><a href="{% url 'home' %}">Web Chat Boards</a></li>
2219
<li class="breadcrumb-item"><a href="{% url 'board_topic' topic.boardName.pk %}">{{ topic.boardName.name }}</a></li>
@@ -25,7 +22,6 @@
2522
{% endblock %}
2623

2724
{% block content %}
28-
2925
<form method="post" class="mb-4" novalidate>
3026
{% csrf_token %}
3127
{% include 'includes/form.html' %}
@@ -47,5 +43,4 @@
4743
</div>
4844
</div>
4945
{% endfor %}
50-
5146
{% endblock %}

templates/topic_posts.html

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{% extends 'base.html'%}
2-
32
{% load static %}
43
{% load humanize %}
54
{% block title %} {{ topic.subject }} {% endblock %}
65

7-
86
{% block stylesheet %}
97
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
108
{% endblock %}
@@ -23,12 +21,9 @@
2321
{% endblock %}
2422

2523
{% block content %}
26-
2724
<div class="mb-4">
2825
<a href="{% url 'reply_topic' topic.boardName.pk topic.pk %}" class="btn btn-primary" role="button">Reply</a>
2926
</div>
30-
31-
3227
{% for post in posts %}
3328
<div id="{{ post.pk }}" class="card {% if forloop.last %}mb-4{% else %}mb-2{% endif %} {% if forloop.first %} border-dark{% endif %}">
3429
{% if forloop.first %}
@@ -64,9 +59,7 @@
6459
</div>
6560
</div>
6661
{% endfor %}
67-
6862
{% include 'includes/pagination.html' %}
69-
7063
{% endblock %}
7164

7265
<!--https://www.iconfinder.com/search/icons?q=avatar&price=free&license=2-->
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

webchat/forms.py

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from .models import ChatTopic
44
from .models import Post
55

6-
7-
86
class NewChatTopicForm(forms.ModelForm):
97
message = forms.CharField(
108
widget = forms.Textarea(
@@ -18,7 +16,6 @@ class Meta:
1816
model = ChatTopic
1917
fields = ['subject', 'message']
2018

21-
2219
class PostForm(forms.ModelForm):
2320
class Meta:
2421
model = Post

webchat/models.py

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def get_page_range(self):
5050
def get_last_five_posts(self):
5151
return self.posts.order_by('createdAt')[:5]
5252

53-
54-
5553
class Post(models.Model):
5654
message = models.TextField(max_length = 5000)
5755
topic = models.ForeignKey(ChatTopic, related_name = 'posts',on_delete=models.CASCADE)
Binary file not shown.

0 commit comments

Comments
 (0)