Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyack committed Nov 27, 2019
1 parent 564432d commit acc386d
Show file tree
Hide file tree
Showing 873 changed files with 194,617 additions and 15 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
*.pyc
cache/*
filebase/*
postbase/*
*db.sqlite3
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ If you do like static pages, my [previous blog](https://zhyack.github.io/posts/2

Let's just do it.

# Getting Start
# Getting Started

## The Environment

These have been tested on ubuntu 14.04, 16.04, 18.04.

1. Get Python3: [official install](https://www.python.org/downloads/), `apt-get install`, or [Anaconda](https://www.anaconda.com/distribution/#download-section)
2. Install pip: [download](https://bootstrap.pypa.io/get-pip.py) and `python3 get-pip.py`
3. Install django: `pip3 install django==2.0.2`
4. Use Apache2 to deploy the site:
4. Modify the config file `blogOurBlog/config.json`:
* Change the hosts according to your domain.
* A complicated `secret_key` is suggested to replace the original one.
* It's suggessted to turn close the debugging mode by set `show_debug_info` to `false`.
5. Use Apache2 to deploy the site:
* `apt-get install apache2 apache2-dev python3-dev libapache2-mod-wsgi-py3`
* Add this to the end of `/etc/apache2/envvars`
```
Expand All @@ -53,28 +59,32 @@ Let's just do it.
```
* Add this to the begining of `/etc/apache2/apache2.conf`
```
Alias /static/ path-to-your-site/static/
<Directory path-to-your-site/static>
Alias /static/ path-to-blogOurBlog/static/
<Directory path-to-blogOurBlog/static>
Require all granted
</Directory>
WSGIScriptAlias / path-to-your-site/mysite/mysite/wsgi.py
WSGIPythonPath path-to-your-site/mysite/
<Directory path-to-your-site/mysite/mysite/>
WSGIScriptAlias / path-to-blogOurBlog/mysite/mysite/wsgi.py
WSGIPythonPath path-to-blogOurBlog/mysite/
<Directory path-to-blogOurBlog/mysite/mysite/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
```
* `chmod -R 777 path-to-your-site/`
* `chmod -R 777 path-to-blogOurBlog/`
* `service apache2 restart`
5. Or just expose the site on port 80 (or any other port):
6. Or just expose the site on port 80 (or any other port):
```
$ screen
$ cd path-to-your-site/mysite/
$ cd path-to-blogOurBlog/mysite/
$ python3 manage.py runserver 80
```
7. Use the browser to test whether you launched the site.
8. The original admin account is :
* username: creator
* password: blogOurBlog
* It's the only account that can access the admin panel. **Remember to change the password.**

6. Use the browser to test whether you launched the site.

## What Are The Files For

Expand Down
2 changes: 2 additions & 0 deletions cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosts": [
"zhyack.cn",
"*.zhyack.cn"
],
"index_title": "blogOurBlog",
"secret_key": "tpegey53)+-817alfam_v3gv+^l!%h_w*i#yc1+e3jhbz5ns-&",
"show_debug_info": true,
"owner_id": "creator"
}
Binary file added db.sqlite3
Binary file not shown.
2 changes: 2 additions & 0 deletions filebase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions postbase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/migrations/*
Empty file added src/core/__init__.py
Empty file.
140 changes: 140 additions & 0 deletions src/core/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
Django settings for core project.
Generated by 'django-admin startproject' using Django 2.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""



import os
import json

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

myconfig = {'hosts':[], 'index_title':'blogOurBlog', 'secret_key':'tpegey53)+-817alfam_v3gv+^l!%h_w*i#yc1+e3jhbz5ns-&', 'show_debug_info':False, 'owner_id':'creator'}

CONFIG_PATH = os.path.join(os.path.dirname(BASE_DIR), 'config.json')
if os.path.exists(CONFIG_PATH):
myconfig = json.load(open(CONFIG_PATH, 'r'))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = myconfig['secret_key']

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = myconfig['show_debug_info']

ALLOWED_HOSTS = myconfig['hosts']+['localhost', '127.0.0.1', '[::1]']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users',
'files',
'posts',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'core.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(BASE_DIR), 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'core.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(os.path.dirname(BASE_DIR), 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

STATICFILES_DIRS = [
os.path.join(os.path.dirname(BASE_DIR), "static/"),
]

AUTH_USER_MODEL = 'users.User'
LOGOUT_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = '/'
47 changes: 47 additions & 0 deletions src/core/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""core URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from main import views as mviews
from editor import views as eviews
from files import views as fviews
from posts import views as pviews

urlpatterns = [
path('admin/', admin.site.urls),
path('users/', include('users.urls')),
path('users/', include('django.contrib.auth.urls')),
path('', mviews.index, name='index'),
path('home/', mviews.home, name='home'),
path('upnav/', mviews.refreshNav, name='nav'),
path('uptagednav/', mviews.refreshtagedNav, name='tagednav'),
path('upsearchnav/<path:cont>', mviews.refreshsearchNav, name='searcgnav'),
path('upfile/', fviews.uploadPage, name='uploadpage'),
path('download/<path:fp>', fviews.downFiles, name='download'),
path('upload/', fviews.upload, name='upload'),
path('files/<path:fp>/', fviews.viewFiles, name='viewfiles'),
path('removefile/<path:fp>/', fviews.removeFile, name='removefile'),
path('updatefile/<path:fp>/', fviews.updateFile, name='updatefile'),
path('setpost/', pviews.setPost, name='setpost'),
path('updatepost/<path:fp>/', pviews.updatePost, name='updatepost'),
path('removepost/<path:fp>/', pviews.removePost, name='removepost'),
path('validpost/', pviews.validPost, name='validpost'),
path('savecache/', pviews.saveCache, name='savecache'),
path('posts/', include('posts.urls')),
path('preview/<path:route>', mviews.preview, name='preview'),
path('preview_table/<path:route>', mviews.preview_table, name='preview_table'),
path('edit/', include('editor.urls')),
]
16 changes: 16 additions & 0 deletions src/core/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for core project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

application = get_wsgi_application()
Empty file added src/editor/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions src/editor/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 src/editor/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class EditorConfig(AppConfig):
name = 'editor'
3 changes: 3 additions & 0 deletions src/editor/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 src/editor/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.
7 changes: 7 additions & 0 deletions src/editor/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path
from . import views

app_name = 'editor'
urlpatterns = [
path('<path:fp>/', views.mainpage, name='editor'),
]
16 changes: 16 additions & 0 deletions src/editor/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.shortcuts import render
from posts.views import getPosts, getCachedPosts
from django.http import JsonResponse, HttpResponseNotFound, HttpResponseForbidden, HttpResponse
# Create your views here.

def mainpage(request, fp):
# judge whether the user and file are right.
answer = getPosts(request, fp)
pcache = getCachedPosts(request, fp)
answer['post_cache']=pcache
if answer['success'] == 0:
return HttpResponseForbidden()
elif answer['success'] == 1:
return HttpResponseNotFound()
else:
return render(request, 'editor/editor.html', context=answer)
Empty file added src/files/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions src/files/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import myFile
# Register your models here.

admin.site.register(myFile)
5 changes: 5 additions & 0 deletions src/files/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class FilesConfig(AppConfig):
name = 'files'
12 changes: 12 additions & 0 deletions src/files/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django import forms

class UploadForm(forms.Form):
fviewers = forms.CharField(max_length=200)
ufile = forms.FileField(required=False, widget=forms.ClearableFileInput(attrs={'multiple': True}))
fname = forms.CharField(max_length=200, required=False)
ftags = forms.CharField(max_length=200)
ffeature = forms.CharField(max_length=20)
foverlap = forms.BooleanField(required=False)
fpass = forms.CharField(max_length=100, required=False)
frank = forms.IntegerField()
ftrace = forms.IntegerField()

0 comments on commit acc386d

Please sign in to comment.