Skeleton for app
This commit is contained in:
parent
81b1ad443c
commit
cc371244ef
|
@ -0,0 +1,4 @@
|
|||
env/
|
||||
__pycache__
|
||||
db.sqlite3
|
||||
ras/frontend/node_modules
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'api'
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 4.1.1 on 2022-09-05 13:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Books',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('name', models.TextField(max_length=255)),
|
||||
('author', models.TextField(max_length=255)),
|
||||
('genre', models.TextField(max_length=100)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -0,0 +1,25 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
class Books(models.Model):
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
name = models.TextField(
|
||||
max_length=255,
|
||||
null=False,
|
||||
blank=False
|
||||
)
|
||||
|
||||
author = models.TextField(
|
||||
max_length=255,
|
||||
null=False,
|
||||
blank=False
|
||||
)
|
||||
|
||||
genre = models.TextField(
|
||||
max_length=100,
|
||||
null=False,
|
||||
blank=False
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Books
|
||||
|
||||
class BooksSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Books
|
||||
fields = ('id', 'name', 'author', 'genre')
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import path
|
||||
from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('books', api_all_books),
|
||||
path('books/<int:_id>', api_get_book),
|
||||
]
|
|
@ -0,0 +1,26 @@
|
|||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
from .models import Books
|
||||
|
||||
from .serializers import BooksSerializer
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def api_all_books(request):
|
||||
all_books = Books.objects.all()
|
||||
if all_books:
|
||||
serializer = BooksSerializer(all_books, many=True)
|
||||
return Response(serializer.data)
|
||||
else:
|
||||
return Response({"Message": 'Books Not Found'})
|
||||
|
||||
@api_view(['GET'])
|
||||
def api_get_book(request, _id):
|
||||
|
||||
obj = Books.objects.filter(id = _id)[0]
|
||||
if obj:
|
||||
serializer = BooksSerializer(obj)
|
||||
return Response(serializer.data)
|
||||
else:
|
||||
return Response({"Message": 'Book Not Found'})
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class FrontendConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'frontend'
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"targets": {
|
||||
"node": "10"
|
||||
}
|
||||
}
|
||||
],
|
||||
"@babel/preset-react"
|
||||
],
|
||||
"plugins": ["@babel/plugin-proposal-class-properties"]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "frontend",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "webpack --mode development --watch",
|
||||
"build": "webpack --mode production"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.13",
|
||||
"@babel/preset-env": "^7.18.10",
|
||||
"@babel/preset-react": "^7.18.6",
|
||||
"babel-loader": "^8.2.5",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"webpack": "^5.74.0",
|
||||
"webpack-cli": "^4.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
||||
"@emotion/react": "^11.10.4",
|
||||
"@emotion/styled": "^11.10.4",
|
||||
"@material-ui/icons": "^4.11.3",
|
||||
"@mui/material": "^5.10.3",
|
||||
"react-router-dom": "^6.3.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import React, { Component } from "react"
|
||||
import {render} from "react-dom"
|
||||
|
||||
export default class App extends Component{
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render(){
|
||||
return <p>Soon here comes the Reading Analytics System!</p>
|
||||
}
|
||||
}
|
||||
|
||||
const appDiv = document.getElementById("app");
|
||||
render(<App />, appDiv);
|
|
@ -0,0 +1 @@
|
|||
import App from "./App";
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,31 @@
|
|||
/*!********************!*\
|
||||
!*** ./src/App.js ***!
|
||||
\********************/
|
||||
|
||||
/*!**********************!*\
|
||||
!*** ./src/index.js ***!
|
||||
\**********************/
|
||||
|
||||
/*!*************************************!*\
|
||||
!*** ./node_modules/react/index.js ***!
|
||||
\*************************************/
|
||||
|
||||
/*!*****************************************!*\
|
||||
!*** ./node_modules/react-dom/index.js ***!
|
||||
\*****************************************/
|
||||
|
||||
/*!*****************************************!*\
|
||||
!*** ./node_modules/scheduler/index.js ***!
|
||||
\*****************************************/
|
||||
|
||||
/*!*****************************************************!*\
|
||||
!*** ./node_modules/react/cjs/react.development.js ***!
|
||||
\*****************************************************/
|
||||
|
||||
/*!*************************************************************!*\
|
||||
!*** ./node_modules/react-dom/cjs/react-dom.development.js ***!
|
||||
\*************************************************************/
|
||||
|
||||
/*!*************************************************************!*\
|
||||
!*** ./node_modules/scheduler/cjs/scheduler.development.js ***!
|
||||
\*************************************************************/
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,31 @@
|
|||
/*!********************!*\
|
||||
!*** ./src/App.js ***!
|
||||
\********************/
|
||||
|
||||
/*!**********************!*\
|
||||
!*** ./src/index.js ***!
|
||||
\**********************/
|
||||
|
||||
/*!*************************************!*\
|
||||
!*** ./node_modules/react/index.js ***!
|
||||
\*************************************/
|
||||
|
||||
/*!*****************************************!*\
|
||||
!*** ./node_modules/react-dom/index.js ***!
|
||||
\*****************************************/
|
||||
|
||||
/*!*****************************************!*\
|
||||
!*** ./node_modules/scheduler/index.js ***!
|
||||
\*****************************************/
|
||||
|
||||
/*!*****************************************************!*\
|
||||
!*** ./node_modules/react/cjs/react.development.js ***!
|
||||
\*****************************************************/
|
||||
|
||||
/*!*************************************************************!*\
|
||||
!*** ./node_modules/react-dom/cjs/react-dom.development.js ***!
|
||||
\*************************************************************/
|
||||
|
||||
/*!*************************************************************!*\
|
||||
!*** ./node_modules/scheduler/cjs/scheduler.development.js ***!
|
||||
\*************************************************************/
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Reading Analytics System</title>
|
||||
{% load static %}
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/>
|
||||
<link rel="stylesheet" type="text/css" href="{% static "css/index.css" %}"/>
|
||||
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
|
||||
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
|
||||
crossorigin=""/>
|
||||
|
||||
<!-- Make sure you put this AFTER Leaflet's CSS -->
|
||||
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
|
||||
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
|
||||
crossorigin=""></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="app"></div>
|
||||
</div>
|
||||
|
||||
<script src="{% static "frontend/main.js" %}"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,6 @@
|
|||
from django.urls import path
|
||||
from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('', index),
|
||||
]
|
|
@ -0,0 +1,4 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
def index(request, *args, **kwargs):
|
||||
return render(request,'index.html')
|
|
@ -0,0 +1,40 @@
|
|||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
|
||||
module.exports = {
|
||||
entry: "./src/index.js",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "./static/js"),
|
||||
filename: "[name].js",
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: "babel-loader",
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [ 'style-loader', 'css-loader' ]
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpe?g|gif)$/i,
|
||||
use: [ 'file-loader' ]
|
||||
}
|
||||
],
|
||||
},
|
||||
optimization: {
|
||||
minimize: true,
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
"process.env": {
|
||||
// This has effect on the react lib size
|
||||
NODE_ENV: JSON.stringify("development"),
|
||||
},
|
||||
}),
|
||||
],
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ras.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,3 @@
|
|||
import pymysql
|
||||
|
||||
pymysql.install_as_MySQLdb()
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
ASGI config for ras project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ras.settings')
|
||||
|
||||
application = get_asgi_application()
|
|
@ -0,0 +1,138 @@
|
|||
"""
|
||||
Django settings for ras project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.1.1.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.1/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.1/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-qfe0=yednzq!rghf1qx6rniiq5$3sbye^%pypj263!y=9ee_rc'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'frontend.apps.FrontendConfig',
|
||||
'api.apps.ApiConfig',
|
||||
'rest_framework',
|
||||
'corsheaders',
|
||||
]
|
||||
|
||||
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',
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
]
|
||||
|
||||
CORS_ORIGIN_ALLOW_ALL = False
|
||||
CORS_ORIGIN_WHITELIST = (
|
||||
'http://localhost:8000',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'ras.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'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 = 'ras.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'reading-analytics-system',
|
||||
'USER': 'root',
|
||||
'PASSWORD': '',
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '3306',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.1/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/4.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.1/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
@ -0,0 +1,23 @@
|
|||
"""ras URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.1/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
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/', include('api.urls')),
|
||||
path('', include('frontend.urls')),
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for ras 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/4.1/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ras.settings')
|
||||
|
||||
application = get_wsgi_application()
|
Loading…
Reference in New Issue