Commit 70528e69 authored by Barnabás Czémán's avatar Barnabás Czémán
Browse files

Refactoring & Design

parent 2e106e8a
......@@ -108,7 +108,8 @@ LOGIN_URL = '/login/'
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'bower_components')
os.path.join(BASE_DIR, 'bower_components'),
os.path.join(BASE_DIR, 'static')
]
STATIC_URL = '/static/'
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib import admin, auth
from web.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'^login/$', auth.views.login, name='login'),
url(r'^logout/$', auth.views.logout, name='logout'),
url(r'^', include(url_patterns)),
]
html
background-image: url('../images/body-bg.gif')
......@@ -7,37 +7,61 @@
{% endblock %}
<title>{% block title %}Awsome entries{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'uikit/css/uikit.almost-flat.min.css' %}"/>
<link rel="stylesheet" type="text/css" href="{% static 'uikit/css/uikit.gradient.min.css' %}"/>
<link rel="stylesheet" type="text/css" href="{% static 'css/base.css' %}">
</head>
<body>
<div class="uk-width-small-5-6 uk-width-medium-1-2 uk-width-large-1-2 uk-container-center">
<nav class="uk-navbar uk-margin-top uk-margin-bottom">
<a href="{% url 'home' %}" class="uk-navbar-brand uk-hidden-small">Free Entries</a>
<ul class="uk-navbar-nav uk-hidden-small">
<li><a href="{% url 'home' %}">Home</a></li>
<nav class="uk-navbar">
<ul class="uk-navbar-nav">
<li><a href="{% url 'home' %}" class="uk-navbar-brand">Free Entries</a>
<li><a href="{% url 'home' %}">Home</a></li>
{% if user.is_authenticated %}
<li><a href="{% url 'create_entry' %}">New entry</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'login' %}">Login</a></li>
{% endif %}
</ul>
{% if user.is_authenticated %}
<li><a href="{% url 'create_entry' %}">New entry</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'login' %}">Login</a></li>
{% endif %}
</ul>
</nav>
<ul class="uk-navbar-nav uk-hidden-medium uk-hidden-large">
<li><a href="#main-offcanvas" data-uk-offcanvas><i class="uk-icon-bars"></i> Menu</a></li>
</ul>
</nav>
{% if user.is_authenticated %}
<div class="uk-alert uk-alert-success"><p>Hello, {{ user }}!</p></div>
<div id="main-offcanvas" class="uk-offcanvas">
<div class="uk-offcanvas-bar">
<ul class="uk-nav uk-nav-offcanvas" data-uk-nav>
<li><a href="{% url 'home' %}">Home</a></li>
{% endif %}
{% if user.is_authenticated %}
<li><a href="{% url 'create_entry' %}">New entry</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'login' %}">Login</a></li>
{% endif %}
</ul>
</div>
{% block content %}
</div>
{% endblock %}
{% if user.is_authenticated %}
<div class="uk-alert uk-alert-success" data-uk-alert>
<a href="" class="uk-alert-close uk-close"></a>
<p>Hello, {{ user }}!</p>
</div>
{% endif %}
{% block content %}
{% endblock %}
</div>
<script src="{% static 'jquery/dist/jquery.min.js' %}" />
<script src="{% static 'uikit/js/ukit.min.js' %}" />
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'uikit/js/uikit.min.js' %}"></script>
</body>
</html>
{% extends 'base.html' %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
<div class="uk-panel uk-panel-box">
<form class="uk-form" action="" method="post">
{% csrf_token %}
{% for paragraph in form %}
<div class="uk-form-row uk-form-stacked">
<label class="uk-form-label" for="">{{ paragraph.label }}</label>
<div class="uk-form-controls">{{ paragraph }}</div>
</div>
{% endfor %}
<input class="uk-button uk-button-primary uk-margin-top uk-align-right" type="submit">
{{ form.as_p }}
<input type="submit">
</form>
</form>
</div>
{% endblock %}
{% extends 'base.html' %}
{% block title %}
Barni
Free Entries
{% endblock %}
{% block content %}
{% for entry in entries %}
<div class="uk-panel uk-panel-box uk-margin">
<h3 class="uk-panel-title">{{ entry.title }}</h3>
<p>{{ entry.description }}</p>
<a href="{{ entry.url }}">Click!!</a>
</div>
<div class="uk-panel uk-panel-box uk-margin-bottom">
<h3 class="uk-panel-title">{{ entry.title }}</h3>
<p>{{ entry.description }}</p>
<a href="{{ entry.url }}">Click!!</a>
</div>
{% empty %}
No entries.
{% endfor %}
......
<!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
{% extends 'base.html'%}
{% block title %}
Login
{% endblock %}
{% block content%}
<div class="uk-panel uk-panel-box">
<form class="uk-form" action="{% url 'login' %}?next={{ next }}" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="hidden" value="{{ next }}">
<button class="uk-button uk-button-primary" type="submit">Login</button>
</form>
<div>
{% endblock %}
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 WebConfig(AppConfig):
name = 'web'
# -*- 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)
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