From ba2c6a4616db3697ab2f5229d345c389372c6976 Mon Sep 17 00:00:00 2001 From: Renato Date: Tue, 5 Dec 2017 02:31:13 -0200 Subject: [PATCH] First commit --- .gitattributes | 17 ++++ .gitignore | 144 +++++++++++++++++++++++++++++ README.md | 6 +- notto/manage.py | 15 +++ notto/notto/__init__.py | 0 notto/notto/settings.py | 124 +++++++++++++++++++++++++ notto/notto/urls.py | 22 +++++ notto/notto/wsgi.py | 16 ++++ notto/nottoapp/__init__.py | 0 notto/nottoapp/admin.py | 3 + notto/nottoapp/apps.py | 5 + notto/nottoapp/models.py | 25 +++++ notto/nottoapp/templates/note.html | 48 ++++++++++ notto/nottoapp/tests.py | 3 + notto/nottoapp/urls.py | 8 ++ notto/nottoapp/views.py | 56 +++++++++++ requirements.txt | 3 + 17 files changed, 493 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 notto/manage.py create mode 100644 notto/notto/__init__.py create mode 100644 notto/notto/settings.py create mode 100644 notto/notto/urls.py create mode 100644 notto/notto/wsgi.py create mode 100644 notto/nottoapp/__init__.py create mode 100644 notto/nottoapp/admin.py create mode 100644 notto/nottoapp/apps.py create mode 100644 notto/nottoapp/models.py create mode 100644 notto/nottoapp/templates/note.html create mode 100644 notto/nottoapp/tests.py create mode 100644 notto/nottoapp/urls.py create mode 100644 notto/nottoapp/views.py create mode 100644 requirements.txt diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5db3bb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,144 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask instance folder +instance/ + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +/nottoenv +/.vscode +*.sqlite3 +migrations diff --git a/README.md b/README.md index 6915b84..cc20b8a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# notto -An online notepad based on Django and using QuillJS on the frontend. +1. Clone this repo +2. `python -m venv nottoenv` +3. `pip installl -r requirements.txt` +4. `nottoenvt\Scripts\activate` diff --git a/notto/manage.py b/notto/manage.py new file mode 100644 index 0000000..99ac9dd --- /dev/null +++ b/notto/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "notto.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) diff --git a/notto/notto/__init__.py b/notto/notto/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notto/notto/settings.py b/notto/notto/settings.py new file mode 100644 index 0000000..84f0e17 --- /dev/null +++ b/notto/notto/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for notto project. + +Generated by 'django-admin startproject' using Django 2.0. + +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 + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# 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! +if 'NOTTO_SECRET_KEY' in os.environ: + SECRET_KEY = os.environ['NOTTO_SECRET_KEY'] +else: + SECRET_KEY = 'd6f1&y(dx-2oiilb&17itsjtqt6&@*&q#(wpwmx(=hwyu4$64-' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'nottoapp.apps.NottoappConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'notto.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 = 'notto.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(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 = 'en-us' + +TIME_ZONE = 'UTC' + +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/' diff --git a/notto/notto/urls.py b/notto/notto/urls.py new file mode 100644 index 0000000..56ef910 --- /dev/null +++ b/notto/notto/urls.py @@ -0,0 +1,22 @@ +"""notto 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 include, path + +urlpatterns = [ + path('', include('nottoapp.urls')), + path('admin/', admin.site.urls) +] diff --git a/notto/notto/wsgi.py b/notto/notto/wsgi.py new file mode 100644 index 0000000..4805906 --- /dev/null +++ b/notto/notto/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for notto 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", "notto.settings") + +application = get_wsgi_application() diff --git a/notto/nottoapp/__init__.py b/notto/nottoapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notto/nottoapp/admin.py b/notto/nottoapp/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/notto/nottoapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/notto/nottoapp/apps.py b/notto/nottoapp/apps.py new file mode 100644 index 0000000..7855a90 --- /dev/null +++ b/notto/nottoapp/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NottoappConfig(AppConfig): + name = 'nottoapp' diff --git a/notto/nottoapp/models.py b/notto/nottoapp/models.py new file mode 100644 index 0000000..d775904 --- /dev/null +++ b/notto/nottoapp/models.py @@ -0,0 +1,25 @@ +from django.db import models +from django.contrib.auth.models import User + +class Note(models.Model): + ''' + A note made by a user (logged in or not) + ''' + content = models.TextField() + url_title = models.CharField( + max_length=500 + ) + last_modified_date = models.DateTimeField( + auto_now=True + ) + created_by = models.ForeignKey( + User, + on_delete='CASCADE', + blank=True, + null=True + ) + + def __str__(self): + if self.created_by is not None: + return 'A note by {}.'.format(self.created_by.name) + return 'An annonymous note.' diff --git a/notto/nottoapp/templates/note.html b/notto/nottoapp/templates/note.html new file mode 100644 index 0000000..93f7c6c --- /dev/null +++ b/notto/nottoapp/templates/note.html @@ -0,0 +1,48 @@ + + + + +
+ {% csrf_token %} + +
+ +
+ + + diff --git a/notto/nottoapp/tests.py b/notto/nottoapp/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/notto/nottoapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/notto/nottoapp/urls.py b/notto/nottoapp/urls.py new file mode 100644 index 0000000..7339a28 --- /dev/null +++ b/notto/nottoapp/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), + path('', views.note, name='note') +] diff --git a/notto/nottoapp/views.py b/notto/nottoapp/views.py new file mode 100644 index 0000000..0f71ffa --- /dev/null +++ b/notto/nottoapp/views.py @@ -0,0 +1,56 @@ +# from django.shortcuts import render +from django.shortcuts import render +from django.http import Http404 +from django.views.decorators.csrf import csrf_protect +from .models import Note +import json + +# Create your views here. +def index(request): + ''' + Index + ''' + return 'Hello' + +@csrf_protect +def note(request, note_name): + ''' + A note + ''' + note = None + try: + notes = Note.objects.filter( + url_title=note_name + ) + if not notes: + if request.method == 'GET': + raise Note.DoesNotExist + elif request.method == 'POST': + print(request) + print(request.POST) + note = Note( + content='', + url_title=note_name + ) + note.save() + else: + if request.method == 'GET': + note = notes[0] + elif request.method == 'POST': + note = notes[0] + note.content = request.POST['content'] + print(note.content) + note.save() + except Note.DoesNotExist: + note = Note( + content='', + url_title=note_name + ) + return render( + request, + 'note.html', + { + 'content': note.content, + 'note_url': note.url_title + } + ) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d477793 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +django>=2.0 +pylint==1.7.4 +pylint-django==0.7.2