Merge pull request #611 from liangliangyy/dev

datetime->timezone
develop
且听风吟 4 years ago committed by GitHub
commit e3db6576f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,19 +1,8 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL" name: "CodeQL"
on: on:
push: push:
branches: branches:
- master - master
- dev - dev
paths-ignore: paths-ignore:
@ -23,7 +12,6 @@ on:
- '**/*.yml' - '**/*.yml'
- '**/*.txt' - '**/*.txt'
pull_request: pull_request:
# The branches below must be a subset of the branches above
branches: branches:
- master - master
- dev - dev
@ -34,54 +22,26 @@ on:
- '**/*.yml' - '**/*.yml'
- '**/*.txt' - '**/*.txt'
schedule: schedule:
- cron: '33 6 * * 0' - cron: '30 1 * * 0'
jobs: jobs:
analyze: CodeQL-Build:
name: Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
security-events: write
actions: read actions: read
contents: read contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# 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
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v2

@ -42,11 +42,12 @@ jobs:
mysql user: root mysql user: root
mysql password: root mysql password: root
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1 uses: actions/setup-python@v4
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install Dependencies - name: Install Dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
@ -93,11 +94,12 @@ jobs:
stack-version: '7.12.1' stack-version: '7.12.1'
plugins: 'https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip' plugins: 'https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip'
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1 uses: actions/setup-python@v4
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install Dependencies - name: Install Dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
@ -122,12 +124,12 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v2
- name: Build and push - name: Build and push
uses: docker/build-push-action@v2 uses: docker/build-push-action@v3
with: with:
context: . context: .
push: false push: false

@ -22,19 +22,19 @@ jobs:
run: | run: |
echo "DOCKER_TAG=latest" >> $GITHUB_ENV echo "DOCKER_TAG=latest" >> $GITHUB_ENV
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v2
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1 uses: docker/login-action@v2
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push - name: Build and push
uses: docker/build-push-action@v2 uses: docker/build-push-action@v3
with: with:
context: . context: .
push: true push: true

@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Docker meta - name: Docker meta
id: meta id: meta
@ -17,16 +17,16 @@ jobs:
with: with:
images: name/app images: name/app
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v2
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1 uses: docker/login-action@v2
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push - name: Build and push
uses: docker/build-push-action@v2 uses: docker/build-push-action@v3
with: with:
context: . context: .
push: true push: true

@ -1,5 +1,6 @@
import logging import logging
from datetime import datetime
from django.utils import timezone
from djangoblog.utils import cache, get_blog_setting from djangoblog.utils import cache, get_blog_setting
from .models import Category, Article from .models import Category, Article
@ -33,6 +34,6 @@ def seo_processor(requests):
'ANALYTICS_CODE': setting.analyticscode, 'ANALYTICS_CODE': setting.analyticscode,
"BEIAN_CODE_GONGAN": setting.gongan_beiancode, "BEIAN_CODE_GONGAN": setting.gongan_beiancode,
"SHOW_GONGAN_CODE": setting.show_gongan_code, "SHOW_GONGAN_CODE": setting.show_gongan_code,
"CURRENT_YEAR": datetime.now().year} "CURRENT_YEAR": timezone.now().year}
cache.set(key, value, 60 * 60 * 10) cache.set(key, value, 60 * 60 * 10)
return value return value

@ -1,4 +1,3 @@
import datetime
import logging import logging
import os import os
import uuid import uuid
@ -8,6 +7,7 @@ from django.core.paginator import Paginator
from django.http import HttpResponse, HttpResponseForbidden from django.http import HttpResponse, HttpResponseForbidden
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.shortcuts import render from django.shortcuts import render
from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
@ -309,7 +309,7 @@ def fileupload(request):
return HttpResponseForbidden() return HttpResponseForbidden()
response = [] response = []
for filename in request.FILES: for filename in request.FILES:
timestr = datetime.datetime.now().strftime('%Y/%m/%d') timestr = timezone.now().strftime('%Y/%m/%d')
imgextensions = ['jpg', 'png', 'jpeg', 'bmp'] imgextensions = ['jpg', 'png', 'jpeg', 'bmp']
fname = u''.join(str(filename)) fname = u''.join(str(filename))
isimage = len([i for i in imgextensions if fname.find(i) >= 0]) > 0 isimage = len([i for i in imgextensions if fname.find(i) >= 0]) > 0

@ -29,7 +29,7 @@ class Comment(models.Model):
'是否显示', default=True, blank=False, null=False) '是否显示', default=True, blank=False, null=False)
class Meta: class Meta:
ordering = ['id'] ordering = ['-id']
verbose_name = "评论" verbose_name = "评论"
verbose_name_plural = verbose_name verbose_name_plural = verbose_name
get_latest_by = 'id' get_latest_by = 'id'

@ -1,11 +1,10 @@
from datetime import datetime
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.syndication.views import Feed from django.contrib.syndication.views import Feed
from django.utils import timezone
from django.utils.feedgenerator import Rss201rev2Feed from django.utils.feedgenerator import Rss201rev2Feed
from djangoblog.utils import CommonMarkdown
from blog.models import Article from blog.models import Article
from djangoblog.utils import CommonMarkdown
class DjangoBlogFeed(Feed): class DjangoBlogFeed(Feed):
@ -31,7 +30,7 @@ class DjangoBlogFeed(Feed):
return CommonMarkdown.get_markdown(item.body) return CommonMarkdown.get_markdown(item.body)
def feed_copyright(self): def feed_copyright(self):
now = datetime.now() now = timezone.now()
return "Copyright© {year} 且听风吟".format(year=now.year) return "Copyright© {year} 且听风吟".format(year=now.year)
def item_link(self, item): def item_link(self, item):

@ -1,4 +1,3 @@
import datetime
import logging import logging
# Create your views here. # Create your views here.
from urllib.parse import urlparse from urllib.parse import urlparse
@ -13,6 +12,7 @@ from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.shortcuts import render from django.shortcuts import render
from django.urls import reverse from django.urls import reverse
from django.utils import timezone
from django.views.generic import FormView from django.views.generic import FormView
from djangoblog.blog_signals import oauth_user_login_signal from djangoblog.blog_signals import oauth_user_login_signal
@ -73,8 +73,7 @@ def authorize(request):
user = manager.get_oauth_userinfo() user = manager.get_oauth_userinfo()
if user: if user:
if not user.nikename or not user.nikename.strip(): if not user.nikename or not user.nikename.strip():
import datetime user.nikename = "djangoblog" + timezone.now().strftime('%y%m%d%I%M%S')
user.nikename = "djangoblog" + datetime.datetime.now().strftime('%y%m%d%I%M%S')
try: try:
temp = OAuthUser.objects.get(type=type, openid=user.openid) temp = OAuthUser.objects.get(type=type, openid=user.openid)
temp.picture = user.picture temp.picture = user.picture
@ -102,7 +101,7 @@ def authorize(request):
except ObjectDoesNotExist: except ObjectDoesNotExist:
author.username = user.nikename author.username = user.nikename
else: else:
author.username = "djangoblog" + datetime.datetime.now().strftime('%y%m%d%I%M%S') author.username = "djangoblog" + timezone.now().strftime('%y%m%d%I%M%S')
author.source = 'authorize' author.source = 'authorize'
author.save() author.save()
@ -141,7 +140,7 @@ def emailconfirm(request, id, sign):
if result[1]: if result[1]:
author.source = 'emailconfirm' author.source = 'emailconfirm'
author.username = oauthuser.nikename.strip() if oauthuser.nikename.strip( author.username = oauthuser.nikename.strip() if oauthuser.nikename.strip(
) else "djangoblog" + datetime.datetime.now().strftime('%y%m%d%I%M%S') ) else "djangoblog" + timezone.now().strftime('%y%m%d%I%M%S')
author.save() author.save()
oauthuser.author = author oauthuser.author = author
oauthuser.save() oauthuser.save()

@ -10,6 +10,7 @@ from django.contrib.auth.decorators import login_required
from django.http import HttpResponse from django.http import HttpResponse
from django.http import JsonResponse from django.http import JsonResponse
from django.shortcuts import render from django.shortcuts import render
from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from .models import OwnTrackLog from .models import OwnTrackLog
@ -45,7 +46,7 @@ def manage_owntrack_log(request):
@login_required @login_required
def show_maps(request): def show_maps(request):
if request.user.is_superuser: if request.user.is_superuser:
defaultdate = str(datetime.datetime.now().date()) defaultdate = str(timezone.now().date())
date = request.GET.get('date', defaultdate) date = request.GET.get('date', defaultdate)
context = { context = {
'date': date 'date': date

Loading…
Cancel
Save