Skip to content

Commit e3db657

Browse files
authored
Merge pull request #611 from liangliangyy/dev
datetime->timezone
2 parents 888c0cf + f37e128 commit e3db657

File tree

10 files changed

+43
-81
lines changed

10 files changed

+43
-81
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
# For most projects, this workflow file will not need changing; you simply need
2-
# to commit it to your repository.
3-
#
4-
# You may wish to alter this file to override the set of languages analyzed,
5-
# or to provide custom queries or build logic.
6-
#
7-
# ******** NOTE ********
8-
# We have attempted to detect the languages in your repository. Please check
9-
# the `language` matrix defined below to confirm you have the correct set of
10-
# supported CodeQL languages.
11-
#
121
name: "CodeQL"
132

143
on:
154
push:
16-
branches:
5+
branches:
176
- master
187
- dev
198
paths-ignore:
@@ -23,7 +12,6 @@ on:
2312
- '**/*.yml'
2413
- '**/*.txt'
2514
pull_request:
26-
# The branches below must be a subset of the branches above
2715
branches:
2816
- master
2917
- dev
@@ -34,54 +22,26 @@ on:
3422
- '**/*.yml'
3523
- '**/*.txt'
3624
schedule:
37-
- cron: '33 6 * * 0'
25+
- cron: '30 1 * * 0'
26+
3827

3928
jobs:
40-
analyze:
41-
name: Analyze
29+
CodeQL-Build:
4230
runs-on: ubuntu-latest
4331
permissions:
32+
security-events: write
4433
actions: read
4534
contents: read
46-
security-events: write
47-
48-
strategy:
49-
fail-fast: false
50-
matrix:
51-
language: [ 'python' ]
52-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
53-
# Learn more:
54-
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
5535

5636
steps:
5737
- name: Checkout repository
58-
uses: actions/checkout@v2
38+
uses: actions/checkout@v3
5939

60-
# Initializes the CodeQL tools for scanning.
6140
- name: Initialize CodeQL
62-
uses: github/codeql-action/init@v1
63-
with:
64-
languages: ${{ matrix.language }}
65-
# If you wish to specify custom queries, you can do so here or in a config file.
66-
# By default, queries listed here will override any specified in a config file.
67-
# Prefix the list here with "+" to use these queries and those in the config file.
68-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
41+
uses: github/codeql-action/init@v2
6942

70-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
71-
# If this step fails, then you should remove it and run the build manually (see below)
7243
- name: Autobuild
73-
uses: github/codeql-action/autobuild@v1
74-
75-
# ℹ️ Command-line programs to run using the OS shell.
76-
# 📚 https://git.io/JvXDl
77-
78-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
79-
# and modify them (or add more) to build your code if your project
80-
# uses a compiled language
81-
82-
#- run: |
83-
# make bootstrap
84-
# make release
44+
uses: github/codeql-action/autobuild@v2
8545

8646
- name: Perform CodeQL Analysis
87-
uses: github/codeql-action/analyze@v1
47+
uses: github/codeql-action/analyze@v2

.github/workflows/django.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ jobs:
4242
mysql user: root
4343
mysql password: root
4444

45-
- uses: actions/checkout@v2
45+
- uses: actions/checkout@v3
4646
- name: Set up Python ${{ matrix.python-version }}
47-
uses: actions/setup-python@v1
47+
uses: actions/setup-python@v4
4848
with:
4949
python-version: ${{ matrix.python-version }}
50+
cache: 'pip'
5051
- name: Install Dependencies
5152
run: |
5253
python -m pip install --upgrade pip
@@ -93,11 +94,12 @@ jobs:
9394
stack-version: '7.12.1'
9495
plugins: 'https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip'
9596

96-
- uses: actions/checkout@v2
97+
- uses: actions/checkout@v3
9798
- name: Set up Python ${{ matrix.python-version }}
98-
uses: actions/setup-python@v1
99+
uses: actions/setup-python@v4
99100
with:
100101
python-version: ${{ matrix.python-version }}
102+
cache: 'pip'
101103
- name: Install Dependencies
102104
run: |
103105
python -m pip install --upgrade pip
@@ -122,12 +124,12 @@ jobs:
122124
- name: Checkout
123125
uses: actions/checkout@v2
124126
- name: Set up QEMU
125-
uses: docker/setup-qemu-action@v1
127+
uses: docker/setup-qemu-action@v2
126128
- name: Set up Docker Buildx
127-
uses: docker/setup-buildx-action@v1
129+
uses: docker/setup-buildx-action@v2
128130

129131
- name: Build and push
130-
uses: docker/build-push-action@v2
132+
uses: docker/build-push-action@v3
131133
with:
132134
context: .
133135
push: false

.github/workflows/docker.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ jobs:
2222
run: |
2323
echo "DOCKER_TAG=latest" >> $GITHUB_ENV
2424
- name: Checkout
25-
uses: actions/checkout@v2
25+
uses: actions/checkout@v3
2626
- name: Set up QEMU
27-
uses: docker/setup-qemu-action@v1
27+
uses: docker/setup-qemu-action@v2
2828
- name: Set up Docker Buildx
29-
uses: docker/setup-buildx-action@v1
29+
uses: docker/setup-buildx-action@v2
3030

3131
- name: Login to DockerHub
32-
uses: docker/login-action@v1
32+
uses: docker/login-action@v2
3333
with:
3434
username: ${{ secrets.DOCKERHUB_USERNAME }}
3535
password: ${{ secrets.DOCKERHUB_TOKEN }}
3636
- name: Build and push
37-
uses: docker/build-push-action@v2
37+
uses: docker/build-push-action@v3
3838
with:
3939
context: .
4040
push: true

.github/workflows/publish-release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v3
1313

1414
- name: Docker meta
1515
id: meta
1616
uses: docker/metadata-action@v3
1717
with:
1818
images: name/app
1919
- name: Set up QEMU
20-
uses: docker/setup-qemu-action@v1
20+
uses: docker/setup-qemu-action@v2
2121
- name: Set up Docker Buildx
22-
uses: docker/setup-buildx-action@v1
22+
uses: docker/setup-buildx-action@v2
2323
- name: Login to DockerHub
24-
uses: docker/login-action@v1
24+
uses: docker/login-action@v2
2525
with:
2626
username: ${{ secrets.DOCKERHUB_USERNAME }}
2727
password: ${{ secrets.DOCKERHUB_TOKEN }}
2828
- name: Build and push
29-
uses: docker/build-push-action@v2
29+
uses: docker/build-push-action@v3
3030
with:
3131
context: .
3232
push: true

blog/context_processors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
2-
from datetime import datetime
2+
3+
from django.utils import timezone
34

45
from djangoblog.utils import cache, get_blog_setting
56
from .models import Category, Article
@@ -33,6 +34,6 @@ def seo_processor(requests):
3334
'ANALYTICS_CODE': setting.analyticscode,
3435
"BEIAN_CODE_GONGAN": setting.gongan_beiancode,
3536
"SHOW_GONGAN_CODE": setting.show_gongan_code,
36-
"CURRENT_YEAR": datetime.now().year}
37+
"CURRENT_YEAR": timezone.now().year}
3738
cache.set(key, value, 60 * 60 * 10)
3839
return value

blog/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import datetime
21
import logging
32
import os
43
import uuid
@@ -8,6 +7,7 @@
87
from django.http import HttpResponse, HttpResponseForbidden
98
from django.shortcuts import get_object_or_404
109
from django.shortcuts import render
10+
from django.utils import timezone
1111
from django.views.decorators.csrf import csrf_exempt
1212
from django.views.generic.detail import DetailView
1313
from django.views.generic.list import ListView
@@ -309,7 +309,7 @@ def fileupload(request):
309309
return HttpResponseForbidden()
310310
response = []
311311
for filename in request.FILES:
312-
timestr = datetime.datetime.now().strftime('%Y/%m/%d')
312+
timestr = timezone.now().strftime('%Y/%m/%d')
313313
imgextensions = ['jpg', 'png', 'jpeg', 'bmp']
314314
fname = u''.join(str(filename))
315315
isimage = len([i for i in imgextensions if fname.find(i) >= 0]) > 0

comments/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Comment(models.Model):
2929
'是否显示', default=True, blank=False, null=False)
3030

3131
class Meta:
32-
ordering = ['id']
32+
ordering = ['-id']
3333
verbose_name = "评论"
3434
verbose_name_plural = verbose_name
3535
get_latest_by = 'id'

djangoblog/feeds.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from datetime import datetime
2-
31
from django.contrib.auth import get_user_model
42
from django.contrib.syndication.views import Feed
3+
from django.utils import timezone
54
from django.utils.feedgenerator import Rss201rev2Feed
65

7-
from djangoblog.utils import CommonMarkdown
86
from blog.models import Article
7+
from djangoblog.utils import CommonMarkdown
98

109

1110
class DjangoBlogFeed(Feed):
@@ -31,7 +30,7 @@ def item_description(self, item):
3130
return CommonMarkdown.get_markdown(item.body)
3231

3332
def feed_copyright(self):
34-
now = datetime.now()
33+
now = timezone.now()
3534
return "Copyright© {year} 且听风吟".format(year=now.year)
3635

3736
def item_link(self, item):

oauth/views.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import datetime
21
import logging
32
# Create your views here.
43
from urllib.parse import urlparse
@@ -13,6 +12,7 @@
1312
from django.shortcuts import get_object_or_404
1413
from django.shortcuts import render
1514
from django.urls import reverse
15+
from django.utils import timezone
1616
from django.views.generic import FormView
1717

1818
from djangoblog.blog_signals import oauth_user_login_signal
@@ -73,8 +73,7 @@ def authorize(request):
7373
user = manager.get_oauth_userinfo()
7474
if user:
7575
if not user.nikename or not user.nikename.strip():
76-
import datetime
77-
user.nikename = "djangoblog" + datetime.datetime.now().strftime('%y%m%d%I%M%S')
76+
user.nikename = "djangoblog" + timezone.now().strftime('%y%m%d%I%M%S')
7877
try:
7978
temp = OAuthUser.objects.get(type=type, openid=user.openid)
8079
temp.picture = user.picture
@@ -102,7 +101,7 @@ def authorize(request):
102101
except ObjectDoesNotExist:
103102
author.username = user.nikename
104103
else:
105-
author.username = "djangoblog" + datetime.datetime.now().strftime('%y%m%d%I%M%S')
104+
author.username = "djangoblog" + timezone.now().strftime('%y%m%d%I%M%S')
106105
author.source = 'authorize'
107106
author.save()
108107

@@ -141,7 +140,7 @@ def emailconfirm(request, id, sign):
141140
if result[1]:
142141
author.source = 'emailconfirm'
143142
author.username = oauthuser.nikename.strip() if oauthuser.nikename.strip(
144-
) else "djangoblog" + datetime.datetime.now().strftime('%y%m%d%I%M%S')
143+
) else "djangoblog" + timezone.now().strftime('%y%m%d%I%M%S')
145144
author.save()
146145
oauthuser.author = author
147146
oauthuser.save()

owntracks/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.http import HttpResponse
1111
from django.http import JsonResponse
1212
from django.shortcuts import render
13+
from django.utils import timezone
1314
from django.views.decorators.csrf import csrf_exempt
1415

1516
from .models import OwnTrackLog
@@ -45,7 +46,7 @@ def manage_owntrack_log(request):
4546
@login_required
4647
def show_maps(request):
4748
if request.user.is_superuser:
48-
defaultdate = str(datetime.datetime.now().date())
49+
defaultdate = str(timezone.now().date())
4950
date = request.GET.get('date', defaultdate)
5051
context = {
5152
'date': date

0 commit comments

Comments
 (0)