Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
IfatNeumann committed Jul 9, 2021
0 parents commit fae381e
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 0 deletions.
Empty file added encyclopedia/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions encyclopedia/admin.py
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions encyclopedia/apps.py
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class EncyclopediaConfig(AppConfig):
name = 'encyclopedia'
Empty file.
3 changes: 3 additions & 0 deletions encyclopedia/models.py
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
38 changes: 38 additions & 0 deletions encyclopedia/static/encyclopedia/styles.css
@@ -0,0 +1,38 @@
body {
margin: 0;
background-color: white;
}

code {
white-space: pre;
}

h1 {
margin-top: 0px;
padding-top: 20px;
}

textarea {
height: 90vh;
width: 80%;
}

.main {
padding: 10px;
}

.search {
width: 100%;
font-size: 15px;
line-height: 15px;
}

.sidebar {
background-color: #f0f0f0;
height: 100vh;
padding: 20px;
}

.sidebar h2 {
margin-top: 5px;
}
16 changes: 16 additions & 0 deletions encyclopedia/templates/encyclopedia/index.html
@@ -0,0 +1,16 @@
{% extends "encyclopedia/layout.html" %}

{% block title %}
Encyclopedia
{% endblock %}

{% block body %}
<h1>All Pages</h1>

<ul>
{% for entry in entries %}
<li>{{ entry }}</li>
{% endfor %}
</ul>

{% endblock %}
37 changes: 37 additions & 0 deletions encyclopedia/templates/encyclopedia/layout.html
@@ -0,0 +1,37 @@
{% load static %}

<!DOCTYPE html>

<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="{% static 'encyclopedia/styles.css' %}" rel="stylesheet">
</head>
<body>
<div class="row">
<div class="sidebar col-lg-2 col-md-3">
<h2>Wiki</h2>
<form>
<input class="search" type="text" name="q" placeholder="Search Encyclopedia">
</form>
<div>
<a href="{% url 'index' %}">Home</a>
</div>
<div>
Create New Page
</div>
<div>
Random Page
</div>
{% block nav %}
{% endblock %}
</div>
<div class="main col-lg-10 col-md-9">
{% block body %}
{% endblock %}
</div>
</div>

</body>
</html>
3 changes: 3 additions & 0 deletions encyclopedia/tests.py
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions encyclopedia/urls.py
@@ -0,0 +1,7 @@
from django.urls import path

from . import views

urlpatterns = [
path("", views.index, name="index")
]
37 changes: 37 additions & 0 deletions encyclopedia/util.py
@@ -0,0 +1,37 @@
import re

from django.core.files.base import ContentFile
from django.core.files.storage import default_storage


def list_entries():
"""
Returns a list of all names of encyclopedia entries.
"""
_, filenames = default_storage.listdir("entries")
return list(sorted(re.sub(r"\.md$", "", filename)
for filename in filenames if filename.endswith(".md")))


def save_entry(title, content):
"""
Saves an encyclopedia entry, given its title and Markdown
content. If an existing entry with the same title already exists,
it is replaced.
"""
filename = f"entries/{title}.md"
if default_storage.exists(filename):
default_storage.delete(filename)
default_storage.save(filename, ContentFile(content))


def get_entry(title):
"""
Retrieves an encyclopedia entry by its title. If no such
entry exists, the function returns None.
"""
try:
f = default_storage.open(f"entries/{title}.md")
return f.read().decode("utf-8")
except FileNotFoundError:
return None
10 changes: 10 additions & 0 deletions encyclopedia/views.py
@@ -0,0 +1,10 @@
from django.shortcuts import render

from . import util


def index(request):
return render(request, "encyclopedia/index.html", {
"entries": util.list_entries()
})

3 changes: 3 additions & 0 deletions entries/CSS.md
@@ -0,0 +1,3 @@
# CSS

CSS is a language that can be used to add style to an [HTML](/wiki/HTML) page.
3 changes: 3 additions & 0 deletions entries/Django.md
@@ -0,0 +1,3 @@
# Django

Django is a web framework written using [Python](/wiki/Python) that allows for the design of web applications that generate [HTML](/wiki/HTML) dynamically.
7 changes: 7 additions & 0 deletions entries/Git.md
@@ -0,0 +1,7 @@
# Git

Git is a version control tool that can be used to keep track of versions of a software project.

## GitHub

GitHub is an online service for hosting git repositories.
11 changes: 11 additions & 0 deletions entries/HTML.md
@@ -0,0 +1,11 @@
# HTML

HTML is a markup language that can be used to define the structure of a web page. HTML elements include

* headings
* paragraphs
* lists
* links
* and more!

The most recent major version of HTML is HTML5.
3 changes: 3 additions & 0 deletions entries/Python.md
@@ -0,0 +1,3 @@
# Python

Python is a programming language that can be used both for writing **command-line scripts** or building **web applications**.
21 changes: 21 additions & 0 deletions manage.py
@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wiki.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()
Empty file added wiki/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions wiki/asgi.py
@@ -0,0 +1,16 @@
"""
ASGI config for wiki 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.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wiki.settings')

application = get_asgi_application()
121 changes: 121 additions & 0 deletions wiki/settings.py
@@ -0,0 +1,121 @@
"""
Django settings for wiki project.
Generated by 'django-admin startproject' using Django 3.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%710m*zic)#0u((qugw#1@e^ty!c)9j04956v@ly(_86n$rg)h'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'encyclopedia',
'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 = 'wiki.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 = 'wiki.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.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/3.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/3.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/3.0/howto/static-files/

STATIC_URL = '/static/'
22 changes: 22 additions & 0 deletions wiki/urls.py
@@ -0,0 +1,22 @@
"""wiki URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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('admin/', admin.site.urls),
path('', include("encyclopedia.urls"))
]

0 comments on commit fae381e

Please sign in to comment.