From a2868bacfa71b88dec9c0ebe9d1a780f6b99564f Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Tue, 1 Jun 2021 00:43:58 -0400 Subject: [PATCH] feat: started site --- .gitignore | 162 +++++++++++++++++++++++++++++++++ Pipfile | 12 +++ Pipfile.lock | 50 ++++++++++ ask/__init__.py | 0 ask/admin.py | 5 + ask/apps.py | 6 ++ ask/forms.py | 9 ++ ask/migrations/0001_initial.py | 22 +++++ ask/migrations/__init__.py | 0 ask/models.py | 9 ++ ask/templates/ask/ask.html | 16 ++++ ask/tests.py | 3 + ask/urls.py | 6 ++ ask/views.py | 23 +++++ config/__init__.py | 0 config/asgi.py | 16 ++++ config/settings.py | 126 +++++++++++++++++++++++++ config/urls.py | 22 +++++ config/wsgi.py | 16 ++++ manage.py | 22 +++++ 20 files changed, 525 insertions(+) create mode 100644 .gitignore create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 ask/__init__.py create mode 100644 ask/admin.py create mode 100644 ask/apps.py create mode 100644 ask/forms.py create mode 100644 ask/migrations/0001_initial.py create mode 100644 ask/migrations/__init__.py create mode 100644 ask/models.py create mode 100644 ask/templates/ask/ask.html create mode 100644 ask/tests.py create mode 100644 ask/urls.py create mode 100644 ask/views.py create mode 100644 config/__init__.py create mode 100644 config/asgi.py create mode 100644 config/settings.py create mode 100644 config/urls.py create mode 100644 config/wsgi.py create mode 100755 manage.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee47d22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,162 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/django +# Edit at https://www.toptal.com/developers/gitignore?templates=django + +### Django ### +*.log +*.pot +*.pyc +__pycache__/ +local_settings.py +db.sqlite3 +db.sqlite3-journal +media + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# 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/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo + +# Django stuff: + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +# .env +.env/ +.venv/ +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# operating system-related files +# file properties cache/storage on macOS +*.DS_Store +# thumbnail cache on Windows +Thumbs.db + +# profiling data +.prof + +# vscode +.vscode/ \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..bf92047 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://pypi.python.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +django = "*" + +[dev-packages] + +[requires] +python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..f84d867 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,50 @@ +{ + "_meta": { + "hash": { + "sha256": "8c5cf3144587137d00ba471c76e169783f31809b5255004d85026b9a09e7c1af" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.8" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.python.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "asgiref": { + "hashes": [ + "sha256:92906c611ce6c967347bbfea733f13d6313901d54dcca88195eaeb52b2a8e8ee", + "sha256:d1216dfbdfb63826470995d31caed36225dcaf34f182e0fa257a4dd9e86f1b78" + ], + "version": "==3.3.4" + }, + "django": { + "hashes": [ + "sha256:13ac78dbfd189532cad8f383a27e58e18b3d33f80009ceb476d7fcbfc5dcebd8", + "sha256:7e0a1393d18c16b503663752a8b6790880c5084412618990ce8a81cc908b4962" + ], + "index": "pypi", + "version": "==3.2.3" + }, + "pytz": { + "hashes": [ + "sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da", + "sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798" + ], + "version": "==2021.1" + }, + "sqlparse": { + "hashes": [ + "sha256:017cde379adbd6a1f15a61873f43e8274179378e95ef3fede90b5aa64d304ed0", + "sha256:0f91fd2e829c44362cbcfab3e9ae12e22badaa8a29ad5ff599f9ec109f0454e8" + ], + "version": "==0.4.1" + } + }, + "develop": {} +} diff --git a/ask/__init__.py b/ask/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ask/admin.py b/ask/admin.py new file mode 100644 index 0000000..a727e63 --- /dev/null +++ b/ask/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import Question + +# Register your models here. +admin.site.register(Question) \ No newline at end of file diff --git a/ask/apps.py b/ask/apps.py new file mode 100644 index 0000000..1436430 --- /dev/null +++ b/ask/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AskConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'ask' diff --git a/ask/forms.py b/ask/forms.py new file mode 100644 index 0000000..4460e8f --- /dev/null +++ b/ask/forms.py @@ -0,0 +1,9 @@ +from django import forms + +from .models import Question + + +class QuestionForm(forms.ModelForm): + class Meta: + model = Question + fields = ['name','question'] \ No newline at end of file diff --git a/ask/migrations/0001_initial.py b/ask/migrations/0001_initial.py new file mode 100644 index 0000000..d454802 --- /dev/null +++ b/ask/migrations/0001_initial.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.3 on 2021-06-01 04:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Question', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField(blank=True, null=True)), + ('question', models.TextField()), + ], + ), + ] diff --git a/ask/migrations/__init__.py b/ask/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ask/models.py b/ask/models.py new file mode 100644 index 0000000..dcd4462 --- /dev/null +++ b/ask/models.py @@ -0,0 +1,9 @@ +from django.db import models + +# Create your models here. +class Question(models.Model): + name = models.TextField(blank=True, null=True) + question = models.TextField(blank=False, null=False) + + def __str__(self): + return self.name + '\'s Question' diff --git a/ask/templates/ask/ask.html b/ask/templates/ask/ask.html new file mode 100644 index 0000000..cb2f33d --- /dev/null +++ b/ask/templates/ask/ask.html @@ -0,0 +1,16 @@ + + + + + + + Ask Zaeem + + +

ask a philospher!!!

+
+ {% csrf_token %} {{ form }} + +
+ + diff --git a/ask/tests.py b/ask/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/ask/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/ask/urls.py b/ask/urls.py new file mode 100644 index 0000000..d044998 --- /dev/null +++ b/ask/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('ask/', views.ask, name='ask'), +] \ No newline at end of file diff --git a/ask/views.py b/ask/views.py new file mode 100644 index 0000000..9f3d9a2 --- /dev/null +++ b/ask/views.py @@ -0,0 +1,23 @@ +from django.shortcuts import render, redirect +from django.contrib import messages + + +from .forms import QuestionForm + +# Create your views here. + +def ask(request): + if request.method == "POST": + form = QuestionForm(request.POST) + + if form.is_valid(): + form.save() + return redirect('ask') + else: + form = QuestionForm() + + context = { + 'form': form, + } + + return render(request, 'ask/ask.html', context) \ No newline at end of file diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..8dad602 --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config 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/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_asgi_application() diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 0000000..33f0e3f --- /dev/null +++ b/config/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 3.2.3. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/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/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-ic4)9d42fd$s7thpal4fco9z!ke(16@zt+ao#0m8gp0&d1x%kx' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'ask', + '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 = 'config.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 = 'config.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/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/3.2/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/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..314ba90 --- /dev/null +++ b/config/urls.py @@ -0,0 +1,22 @@ +"""config URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/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('', include('ask.urls')) +] diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..8915671 --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config 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/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..8e7ac79 --- /dev/null +++ b/manage.py @@ -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', 'config.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()