Skip to content

Commit

Permalink
Heroku config
Browse files Browse the repository at this point in the history
  • Loading branch information
yaozeliangtest committed Apr 16, 2020
1 parent 5ded974 commit 447c8c8
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 30 deletions.
2 changes: 1 addition & 1 deletion article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ArticlePost(models.Model):

avatar = ProcessedImageField(
upload_to='article/%Y%m%d',
processors=[ResizeToFit(width=350)],
processors=[ResizeToFit(width=400)],
format='JPEG',
options={'quality': 100},
)
Expand Down
14 changes: 14 additions & 0 deletions comment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from .forms import CommentForm
from . models import Comment

from notifications.signals import notify
from django.contrib.auth.models import User

# 文章评论
@login_required(login_url='/userprofile/login/')
def post_comment(request, article_id):
Expand All @@ -19,6 +22,17 @@ def post_comment(request, article_id):
new_comment.article = article
new_comment.user = request.user
new_comment.save()

# 新增代码,给管理员发送通知
if not request.user.is_superuser:
notify.send(
request.user,
recipient=User.objects.filter(is_superuser=1),
verb='回复了你',
target=article,
action_object=new_comment,
)

return redirect(article)
else:
return HttpResponse("表单内容有误,请重新填写。")
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
Binary file added media/article/20200415/landscape-4036789_1280.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions my_blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand All @@ -44,17 +44,18 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'password_reset',
'notifications',


'notice',

]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # new!
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down Expand Up @@ -130,9 +131,10 @@

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') # new
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

CRISPY_TEMPLATE_PACK = 'bootstrap4'

Expand Down
1 change: 1 addition & 0 deletions my_blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
path('password-reset/', include('password_reset.urls')),
path('comment/', include('comment.urls')),
path('inbox/notifications/', include(notifications.urls, namespace='notifications')),
path('notice/', include('notice.urls')),
]


Expand Down
Empty file added notice/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions notice/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions notice/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class NoticeConfig(AppConfig):
name = 'notice'
Empty file added notice/migrations/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions notice/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions notice/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
11 changes: 11 additions & 0 deletions notice/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path
from . import views

app_name = 'notice'

urlpatterns = [
# 通知列表
path('list/', views.CommentNoticeListView.as_view(), name='list'),
# 更新通知状态
path('update/', views.CommentNoticeUpdateView.as_view(), name='update'),
]
39 changes: 39 additions & 0 deletions notice/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# Create your views here.
from django.shortcuts import render, redirect
from django.views import View
from django.views.generic import ListView,DetailView,DeleteView
from django.views.generic.edit import CreateView,UpdateView
from django.contrib.auth.mixins import LoginRequiredMixin
from article.models import ArticlePost


class CommentNoticeListView(LoginRequiredMixin, ListView):
"""通知列表"""
# 上下文的名称
context_object_name = 'notices'
# 模板位置
template_name = 'notice/list.html'
# 登录重定向
login_url = '/userprofile/login/'

# 未读通知的查询集
def get_queryset(self):
return self.request.user.notifications.unread()


class CommentNoticeUpdateView(View):
"""更新通知状态"""
# 处理 get 请求
def get(self, request):
# 获取未读消息
notice_id = request.GET.get('notice_id')
# 更新单条通知
if notice_id:
article = ArticlePost.objects.get(id=request.GET.get('article_id'))
request.user.notifications.get(id=notice_id).mark_as_read()
return redirect(article)
# 更新全部通知
else:
request.user.notifications.mark_all_as_read()
return redirect('notice:list')
114 changes: 92 additions & 22 deletions templates/article/list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% extends "base.html" %} {% load static %}
{% extends "base.html" %}

{% load static %}

{% block title %}
首页
Expand All @@ -9,6 +11,8 @@

<!-- 定义放置文章标题的div容器 -->
<div class="container">
<div class="row">
<main class="col-md-8 mr-auto">
<br />
<nav aria-label="breadcrumb">
<ol class="breadcrumb" style="background-color: white; padding: 0 0 0 2px; font-size: 1.2em">
Expand Down Expand Up @@ -39,8 +43,7 @@
</nav>

<!-- 新增,搜索栏 -->
<div class="row">
<div class="col-md-8">

<form class="form-inline">
<label class="sr-only">content</label>
<input
Expand All @@ -54,8 +57,7 @@
<button type="submit" class="btn btn-warning">Search</button>
</form>
<br>
</div>
</div>


<!-- 新增,搜索提示语 -->
{% if search %}
Expand Down Expand Up @@ -85,10 +87,10 @@ <h4>暂无<span style="color: red;">"{{ search }}"</span>有关的文章。</h4>
{% endif %}

<!-- 栏目 -->
<div class="col">
<div class="col-9">

<!-- 标题 -->
<h4>
<h5>
<b>
<a
href="{% url 'article:article_detail' article.id %}"
Expand All @@ -97,38 +99,37 @@ <h4>
{{ article.title }}
</a>
</b>
</h4>
</h5>
<!-- 摘要 -->

<p style="color: gray;" >
{{ article.body|slice:'100' }}...
{{ article.body|slice:'50' }}...
</p>

<h5>
<p>
{% if article.category %}
<span>
<a
role="button"
href="{% url 'article:article_list' %}?category={{ article.category.id }}"
class="btn btn-sm mb-2
{% if article.category.name == 'Html' %} btn-success btn-sm
{% elif article.category.name == 'Java' %} btn-danger btn-sm
{% elif article.category.name == 'Python' %} btn-info btn-sm
{% endif %}"
><i class="fas fa-code"></i> &nbsp;{{ article.category }}&nbsp;</a>
class="btn btn-sm mb-1 btn-success"><i class="fas fa-code-branch"></i>&nbsp;{{ article.category }}&nbsp;</a>
{% endif %}
</span>

<!-- Tags -->
<span>
{% for tag in article.tags.all %}
{% for tag in article.tags.all %}
<span>
<a
href="{% url 'article:article_list' %}?tag={{ tag }}"
class="badge badge-pill badge-light"
class="badge badge-secondary"
>
{{ tag }}
</a>
{% endfor %}
</span>
</h5>
{% empty %}
{% endfor %}

</p>

<p >
<span>
Expand All @@ -151,7 +152,6 @@ <h5>
</p>
</div>
<hr style="width: 100%;"/>

{% endfor %}

</div>
Expand Down Expand Up @@ -202,5 +202,75 @@ <h5>
</span>
</div>
</div>

</main>

<aside class="col-md-4 mt-md-5">



<div class="row notification">
<div class="card col-10 ml-md-2 mb-3">
<div class="card-body">
<p class="card-text"><i class="fas fa-bullhorn"></i> 修改海量bug中</p>
</div>
</div>
</div>



<div class="row contanct">
<div class="card col-10 ml-md-2 mb-3">
<div class="card-body pb-0">
<h5 class="card-title">About Me
<a href="https://www.linkedin.com/in/zeliang-yao-359183114/">
<i class="fab fa-linkedin"></i></a>

<a href="https://github.com/yaozeliang/">
<i class="fab fa-github" style="color: lightslategrey"></i></a>
</h5>
<p class="card-text mb-0"> Python爱好者, 玻尿酸采购直邮</p>
<p class="card-text mb-0"><span><i class="far fa-envelope "></i></span> [email protected]</p>
<p><span><i class="fab fa-weixin" style="color: yellowgreen"></i></span> alpha94511</p>

</div>
</div>
</div>


<div class="row gallery">
<div class="card col-10 ml-md-2 mb-3">

<div class="card-body ">
<h6 class="card-title">Category <span><i class="fas fa-code-branch"></i></span> </h6>
<p class="card-text">


</p>

</div>
</div>
</div>





</div>






</aside>






</div>

</div>
{% endblock content %}
8 changes: 5 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<!-- 引入bootstrap的css文件 -->
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'md_css/monokai.css' %}">
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"
integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf"
crossorigin="anonymous"
>
Expand All @@ -25,7 +24,10 @@


<div id="wrapper">
{% block content %}{% endblock content %}


{% block content %}
{% endblock content %}
<div id="push"></div>
</div>

Expand Down
16 changes: 16 additions & 0 deletions templates/header.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- 引入notifications的模板标签 -->
{% load notifications_tags %}
{% notifications_unread as unread_count %}

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<!-- 导航栏商标 -->
Expand Down Expand Up @@ -27,9 +31,21 @@
aria-haspopup="true"
aria-expanded="false"
>
{% if unread_count %}
<svg viewBox="0 0 8 8"
width="8px"
height="8px"><circle cx="4"cy="4"r="4"fill="#ff6b6b"></circle></svg>
{% endif %}


{{ user.username }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'notice:list' %}">通知
{% if unread_count %}
<span class="badge badge-danger">{{ unread_count }}</span>
{% endif %}
</a>
<a class="dropdown-item" href='{% url "userprofile:edit" user.id %}'>个人信息</a>
<a class="dropdown-item" href="{% url 'article:article_create' %}"
>写文章</a>
Expand Down
Loading

0 comments on commit 447c8c8

Please sign in to comment.