Commit 17f94d67 authored by bence92's avatar bence92
Browse files

everything

parents
### Python template
# 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
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Created by .ignore support plugin (hsz.mobi)
db.sqlite3
*.jpg
.idea/
\ No newline at end of file
"""
Django settings for entries project.
Generated by 'django-admin startproject' using Django 1.9.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/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/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9k+#vz^lx&8u(y$08jbebyk1f(4d_7o5=xhcy5nw7n%@*+!yx+'
# 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',
'pityu'
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'entries.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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 = 'entries.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/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/1.9/ref/settings/#auth-password-validators
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
LOGIN_URL = '/login/'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
from django.conf.urls import url, include
from django.contrib import admin
from pityu.urls import url_patterns
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'),
url(r'^', include(url_patterns)),
]
"""
WSGI config for entries 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/1.9/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "entries.settings")
application = get_wsgi_application()
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "entries.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
from django.contrib import admin
from .models import Entry
class EntryAdmin(admin.ModelAdmin):
pass
admin.site.register(Entry, EntryAdmin)
from django.apps import AppConfig
class PityuConfig(AppConfig):
name = 'pityu'
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-04-06 17:37
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Entry',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=60)),
('description', models.TextField(blank=True)),
('url', models.URLField(blank=True)),
('logo', models.ImageField(blank=True, upload_to='')),
('added_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
from django.db import models
from django.contrib.auth.models import User
class Entry(models.Model):
title = models.CharField(max_length=60)
description = models.TextField(blank=True)
url = models.URLField(blank=True)
logo = models.ImageField(blank=True)
added_by = models.ForeignKey(User)
def __str__(self):
return self.title
# -*- encoding: utf-8 -*-
from django.conf.urls import url
from .views import home, EntryCreateView
url_patterns = [
url(r'^$', home, name='home'),
url(r'^create/$', EntryCreateView.as_view(), name='create_entry'),
]
from django.shortcuts import render
from django.core.urlresolvers import reverse_lazy
from django.views.generic import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from .models import Entry
def home(request):
entries = Entry.objects.all()
context = {
'valami': 'Szaki',
'entries': entries
}
return render(request, 'index.html', context)
class EntryCreateView(LoginRequiredMixin, CreateView):
model = Entry
fields = ('title', 'description', 'url', 'logo')
template_name = 'create_entry.html'
success_url = reverse_lazy('home')
def form_valid(self, form):
form.instance.added_by = self.request.user
return super(EntryCreateView, self).form_valid(form)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{% block css %}
{% endblock %}
<title>{% block title %}Awsome entries{% endblock %}</title>
</head>
<body>
<h1>Awsome entries!</h1>
{% if user.is_authenticated %}
<p>Hello, {{ user }}!</p>
{% endif %}
<a href="{% url 'home' %}">Home</a>
{% if user.is_authenticated %}
<a href="{% url 'create_entry' %}">New entry</a>
<a href="{% url 'logout' %}">Logout</a>
{% else %}
<a href="{% url 'login' %}">Login</a>
{% endif %}
<hr>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit">
</form>
{% endblock %}
{% extends 'base.html' %}
{% block title %}
Barni
{% endblock %}
{% block css %}
<style>
.entry{
margin: 15px;
padding: 5px;
border: solid 1px black;
}
</style>
{% endblock %}
{% block content %}
{% for entry in entries %}
<div class="entry">
<h3>{{ entry.title }}</h3>
<p>{{ entry.description }}</p>
<a href="{{ entry.url }}">Click!!</a>
</div>
{% empty %}
No entries.
{% endfor %}
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<form action="{% url 'login' %}?next={{ next }}" method="post">
{% csrf_token %}
{{ form }}
<input type="hidden" value="{{ next }}">
<input type="submit">
</form>
</body>
</html>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment