-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rozwijanie scenariusza Czat (poziom rozszerzony)
- Loading branch information
Showing
18 changed files
with
444 additions
and
30 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- czat/czat/templates/czat/index.html --> | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Witaj w aplikacji Czat!</h1> | ||
|
||
{% if messages %} | ||
<ul> | ||
{% for komunikat in messages %} | ||
<li>{{ komunikat|capfirst }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if user.is_authenticated %} | ||
<p>Jesteś zalogowany jako {{ user.username }}.</p> | ||
<p><a href="{% url 'wyloguj' %}">Wyloguj się</a></p> | ||
{% else %} | ||
<p><a href="{% url 'loguj' %}">Zaloguj się</a></p> | ||
<p><a href="{% url 'rejestruj' %}">Zarejestruj się</a></p> | ||
{% endif %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- czat/czat/templates/czat/index.html --> | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Witaj w aplikacji Czat!</h1> | ||
|
||
{% if messages %} | ||
<ul> | ||
{% for komunikat in messages %} | ||
<li>{{ komunikat|capfirst }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if user.is_authenticated %} | ||
<p>Jesteś zalogowany jako {{ user.username }}.</p> | ||
<p><a href="{% url 'wiadomosci' %}">Wiadomosci</a></p> | ||
<p><a href="{% url 'wyloguj' %}">Wyloguj się</a></p> | ||
{% else %} | ||
<p><a href="{% url 'loguj' %}">Zaloguj się</a></p> | ||
<p><a href="{% url 'rejestruj' %}">Zarejestruj się</a></p> | ||
{% endif %} | ||
</body> | ||
</html> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# czat/czat/admin.py | ||
|
||
from django.contrib import admin | ||
from czat.models import Wiadomosc # importujemy nasz model | ||
|
||
# rejestrujemy model Wiadomosc w panelu administracyjnym | ||
admin.site.register(Wiadomosc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# czat/czat/models.py | ||
|
||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
class Wiadomosc(models.Model): | ||
"""Klasa reprezentująca wiadomość w systemie""" | ||
tekst = models.CharField(u'wiadomość', max_length=250) | ||
data_pub = models.DateTimeField(u'data publikacji') | ||
autor = models.ForeignKey(User) | ||
|
||
class Meta: # ustawienia dodatkowe | ||
verbose_name = u'wiadomość' # nazwa obiektu w języku polskim | ||
verbose_name_plural = u'wiadomości' # nazwa obiektów w l.m. | ||
ordering = ['data_pub'] # domyślne porządkowanie danych | ||
|
||
def __unicode__(self): | ||
return self.tekst # "autoprezentacja" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Django settings for czat project. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.6/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.6/ref/settings/ | ||
""" | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
import os | ||
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'd3qrzpt#6s&8s6p@i^s^vtfd^pbltt51dfu!x@@116&@kqbq$!' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
TEMPLATE_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', | ||
'czat', #rejestrujemy aplikację czat w projekcie | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'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 = 'czat.urls' | ||
|
||
WSGI_APPLICATION = 'czat.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.6/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'pl' | ||
|
||
TIME_ZONE = 'Europe/Warsaw' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.6/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
from django.core.urlresolvers import reverse_lazy | ||
LOGIN_REDIRECT_URL = reverse_lazy('index') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- czat/czat/templates/czat/index.html --> | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Witaj w aplikacji Czat!</h1> | ||
|
||
{% if messages %} | ||
<ul> | ||
{% for komunikat in messages %} | ||
<li>{{ komunikat|capfirst }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if user.is_authenticated %} | ||
<p>Jesteś zalogowany jako {{ user.username }}.</p> | ||
<p><a href="{% url 'wiadomosci' %}">Wiadomosci</a></p> | ||
<p><a href="{% url 'wyloguj' %}">Wyloguj się</a></p> | ||
{% else %} | ||
<p><a href="{% url 'loguj' %}">Zaloguj się</a></p> | ||
<p><a href="{% url 'rejestruj' %}">Zarejestruj się</a></p> | ||
{% endif %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
<body> | ||
<h1>Logowanie użytkownika</h1> | ||
{% if user.is_authenticated %} | ||
<p>Jesteś już zalogowany jako {{ user.username }}. | ||
<br /><a href="/">Strona główna</a></p> | ||
{% else %} | ||
<form method="POST"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type="submit">Zaloguj</button> | ||
</form> | ||
{% endif %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
<body> | ||
<h1>Rejestracja użytkownika</h1> | ||
{% if user.is_authenticated %} | ||
<p>Jesteś już zarejestrowany jako {{ user.username }}. | ||
<br /><a href="/">Strona główna</a></p> | ||
{% else %} | ||
<form method="POST"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type="submit">Zarejestruj</button> | ||
</form> | ||
{% endif %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- czat/czat/templates/czat/wiadomosci.html --> | ||
<html> | ||
<body> | ||
<h1>Wiadomości</h1> | ||
|
||
{% if messages %} | ||
<ul> | ||
{% for komunikat in messages %} | ||
<li>{{ komunikat|capfirst }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
<h2>Dodaj wiadomość</h2> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
<input type="text" name="tekst" /> | ||
<button type="submit">Zapisz</button> | ||
</form> | ||
|
||
<h2>Lista wiadomości:</h2> | ||
<ol> | ||
{% for wiadomosc in wiadomosci %} | ||
<li> | ||
<strong>{{ wiadomosc.autor.username }}</strong> ({{ wiadomosc.data_pub }}): | ||
<br /> {{ wiadomosc.tekst }} | ||
</li> | ||
{% endfor %} | ||
</ol> | ||
|
||
<p><a href="{% url 'index' %}">Strona główna</a></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# czat/czat/urls.py | ||
|
||
from django.conf.urls import patterns, include, url | ||
from django.contrib import admin | ||
from czat import views # importujemy zdefiniowane w pliku views.py widoki | ||
|
||
admin.autodiscover() # potrzebne tylko w Django 1.6 | ||
|
||
from django.views.generic.edit import CreateView | ||
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm | ||
from django.core.urlresolvers import reverse_lazy | ||
|
||
urlpatterns = patterns('', | ||
# Examples: | ||
# url(r'^$', 'czat.views.home', name='home'), | ||
# url(r'^blog/', include('blog.urls')), | ||
|
||
# główny adres (/) o nazwie index łączymy z widokiem index | ||
url(r'^$', views.index, name='index'), | ||
#url(r'^rejestruj/', views.rejestruj, name='rejestruj'), | ||
#url(r'^loguj/', views.loguj, name='loguj'), | ||
#url(r'^wyloguj/', views.wyloguj, name='wyloguj'), | ||
url(r'^rejestruj/', CreateView.as_view( | ||
template_name='czat/rejestruj.html', | ||
form_class=UserCreationForm, | ||
success_url='/'), name='rejestruj'), | ||
url(r'^loguj/', 'django.contrib.auth.views.login', | ||
{'template_name': 'czat/loguj.html'}, | ||
name='loguj'), | ||
url(r'^wyloguj/', 'django.contrib.auth.views.logout', | ||
{'next_page': reverse_lazy('index')}, | ||
name='wyloguj'), | ||
url(r'^wiadomosci/', views.wiadomosci, name='wiadomosci'), | ||
|
||
url(r'^admin/', include(admin.site.urls)), | ||
) |
Oops, something went wrong.