Skip to content

Commit

Permalink
Merge pull request #524 from liangliangyy/dev
Browse files Browse the repository at this point in the history
代码结构调整及缓存优化
  • Loading branch information
liangliangyy authored Nov 17, 2021
2 parents 62285aa + 6284fff commit 6e6b161
Show file tree
Hide file tree
Showing 86 changed files with 402 additions and 1,015 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ venv/
migrations/
!migrations/__init__.py
collectedstatic/
DjangoBlog/whoosh_index/
djangoblog/whoosh_index/
uploads/
settings_production.py
*.md
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ venv/
migrations/
!migrations/__init__.py
collectedstatic/
DjangoBlog/whoosh_index/
djangoblog/whoosh_index/
google93fd32dbd906620a.html
baidu_verify_FlHL7cUyC9.html
BingSiteAuth.xml
cb9339dbe2ff86a5aa169d28dba5f615.txt
werobot_session
werobot_session.*
django.jpg
uploads/
settings_production.py
Expand Down
56 changes: 0 additions & 56 deletions DjangoBlog/urls.py

This file was deleted.

6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3
ENV PYTHONUNBUFFERED 1
WORKDIR /code/DjangoBlog/
WORKDIR /code/djangoblog/
RUN apt-get install default-libmysqlclient-dev -y && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ADD requirements.txt requirements.txt
Expand All @@ -10,5 +10,5 @@ RUN pip install --upgrade pip && \
pip cache purge

ADD . .
RUN chmod +x /code/DjangoBlog/bin/docker_start.sh
ENTRYPOINT ["/code/DjangoBlog/bin/docker_start.sh"]
RUN chmod +x /code/djangoblog/bin/docker_start.sh
ENTRYPOINT ["/code/djangoblog/bin/docker_start.sh"]
8 changes: 4 additions & 4 deletions accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.contrib.auth.forms import UserChangeForm
from django.contrib.auth.forms import UsernameField
from django.utils.translation import gettext_lazy as _

# Register your models here.
from .models import BlogUser
from django.utils.translation import gettext, gettext_lazy as _
from django.contrib.auth.forms import UsernameField


class BlogUserCreationForm(forms.ModelForm):
Expand Down
16 changes: 1 addition & 15 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: [email protected]
@site: https://www.lylinux.net/
@software: PyCharm
@file: forms.py
@time: 2016/11/20 下午3:16
"""
from django import forms
from django.contrib.auth import get_user_model, password_validation
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
Expand Down Expand Up @@ -108,7 +94,7 @@ def clean_new_password2(self):
def clean_email(self):
user_email = self.cleaned_data.get("email")
if not BlogUser.objects.filter(
email=user_email
email=user_email
).exists():
# todo 这里的报错提示可以判断一个邮箱是不是注册过,如果不想暴露可以修改
raise ValidationError("未找到邮箱对应的用户")
Expand Down
5 changes: 3 additions & 2 deletions accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.urls import reverse
from DjangoBlog.utils import get_current_site
from django.utils.timezone import now

from djangoblog.utils import get_current_site


# Create your models here.

Expand Down
14 changes: 0 additions & 14 deletions accounts/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: [email protected]
@site: https://www.lylinux.net/
@software: PyCharm
@file: __init__.py
@time: 2016/11/2 下午9:15
"""
4 changes: 2 additions & 2 deletions accounts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse
from django.utils import timezone

from DjangoBlog.utils import *
from djangoblog.utils import *
from accounts.models import BlogUser
from blog.models import Article, Category
from . import utils
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_validate_register(self):
user.is_superuser = True
user.is_staff = True
user.save()
delete_sidebar_cache(user.username)
delete_sidebar_cache()
category = Category()
category.name = "categoryaaa"
category.created_time = timezone.now()
Expand Down
17 changes: 1 addition & 16 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: [email protected]
@site: https://www.lylinux.net/
@software: PyCharm
@file: urls.py
@time: 2016/11/20 下午3:52
"""

from django.conf.urls import url
from django.urls import path

from .forms import LoginForm
from . import views
from .forms import LoginForm

app_name = "accounts"

Expand Down
15 changes: 0 additions & 15 deletions accounts/user_login_backend.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: [email protected]
@site: https://www.lylinux.net/
@software: PyCharm
@file: user_login_backend.py
@time: 2017/2/17 下午8:45
"""
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

Expand Down
2 changes: 1 addition & 1 deletion accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.core.cache import cache

from DjangoBlog.utils import send_email
from djangoblog.utils import send_email

_code_ttl = timedelta(minutes=5)

Expand Down
9 changes: 3 additions & 6 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic import FormView, RedirectView

from DjangoBlog.utils import send_email, get_sha256, get_current_site, generate_code
from djangoblog.utils import send_email, get_sha256, get_current_site, generate_code, delete_sidebar_cache
from . import utils
from .forms import RegisterForm, LoginForm, ForgetPasswordForm, ForgetPasswordCodeForm
from .models import BlogUser
Expand Down Expand Up @@ -84,9 +84,8 @@ def dispatch(self, request, *args, **kwargs):
return super(LogoutView, self).dispatch(request, *args, **kwargs)

def get(self, request, *args, **kwargs):
from DjangoBlog.utils import cache
cache.clear()
logout(request)
delete_sidebar_cache()
return super(LogoutView, self).get(request, *args, **kwargs)


Expand Down Expand Up @@ -116,9 +115,7 @@ def form_valid(self, form):
form = AuthenticationForm(data=self.request.POST, request=self.request)

if form.is_valid():
from DjangoBlog.utils import cache
if cache and cache is not None:
cache.clear()
delete_sidebar_cache()
logger.info(self.redirect_field_name)

auth.login(self.request, form.get_user())
Expand Down
32 changes: 0 additions & 32 deletions bin/django_start.sh

This file was deleted.

4 changes: 2 additions & 2 deletions bin/docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ DJANGODIR=/code/DjangoBlog # Django project directory
USER=root # the user to run as
GROUP=root # the group to run as
NUM_WORKERS=1 # how many worker processes should Gunicorn spawn
#DJANGO_SETTINGS_MODULE=DjangoBlog.settings # which settings file should Django use
DJANGO_WSGI_MODULE=DjangoBlog.wsgi # WSGI module name
#DJANGO_SETTINGS_MODULE=djangoblog.settings # which settings file should Django use
DJANGO_WSGI_MODULE=djangoblog.wsgi # WSGI module name


echo "Starting $NAME as `whoami`"
Expand Down
11 changes: 6 additions & 5 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.contrib import admin
# Register your models here.
from .models import Article, Category, Tag, Links, SideBar, BlogSettings
from django import forms
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _

# Register your models here.
from .models import Article


class ArticleListFilter(admin.SimpleListFilter):
Expand Down Expand Up @@ -101,7 +102,7 @@ def get_view_on_site_url(self, obj=None):
url = obj.get_full_url()
return url
else:
from DjangoBlog.utils import get_current_site
from djangoblog.utils import get_current_site
site = get_current_site().domain
return site

Expand Down
22 changes: 4 additions & 18 deletions blog/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: [email protected]
@site: https://www.lylinux.net/
@software: PyCharm
@file: context_processors.py
@time: 2016/11/6 下午4:23
"""
from .models import Category, Article, Tag, BlogSettings
from DjangoBlog.utils import cache, get_blog_setting

from datetime import datetime
import logging
from datetime import datetime

from djangoblog.utils import cache, get_blog_setting
from .models import Category, Article

logger = logging.getLogger(__name__)

Expand Down
21 changes: 5 additions & 16 deletions blog/documents.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
#!/usr/bin/env python
# encoding: utf-8
"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: [email protected]
@site: https://www.lylinux.net/
@software: PyCharm
@file: documents.py
@time: 2019-04-05 13:05
"""
import elasticsearch.client
from elasticsearch_dsl.connections import connections
import time
from blog.models import Article
from elasticsearch_dsl import Document, InnerDoc, Date, Integer, Long, Text, Object, GeoPoint, Keyword, Boolean

import elasticsearch.client
from django.conf import settings
from elasticsearch_dsl import Document, InnerDoc, Date, Integer, Long, Text, Object, GeoPoint, Keyword, Boolean
from elasticsearch_dsl.connections import connections

from blog.models import Article

ELASTICSEARCH_ENABLED = hasattr(settings, 'ELASTICSEARCH_DSL')

Expand Down
Loading

0 comments on commit 6e6b161

Please sign in to comment.