Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
A
Aspava
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
Aspava
Commits
3c979907
Kaydet (Commit)
3c979907
authored
May 04, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Post class and rendering
üst
981ab284
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
75 additions
and
12 deletions
+75
-12
settings.py
aspava/settings.py
+3
-0
admin.py
social/admin.py
+2
-1
0001_initial.py
social/migrations/0001_initial.py
+6
-1
models.py
social/models.py
+10
-0
home.html
social/templates/home.html
+11
-7
post.html
social/templates/repr/post.html
+7
-0
__init__.py
social/templatetags/__init__.py
+0
-0
renderer.py
social/templatetags/renderer.py
+9
-0
views.py
social/views.py
+27
-3
No files found.
aspava/settings.py
Dosyayı görüntüle @
3c979907
...
@@ -124,3 +124,6 @@ STATIC_URL = '/static/'
...
@@ -124,3 +124,6 @@ STATIC_URL = '/static/'
LOGIN_REDIRECT_URL
=
'/'
LOGIN_REDIRECT_URL
=
'/'
LOGOUT_REDIRECT_URL
=
'/'
LOGOUT_REDIRECT_URL
=
'/'
AUTH_USER_MODEL
=
'social.SocialUser'
AUTH_USER_MODEL
=
'social.SocialUser'
# Extra Settings
MAX_POST_LENGTH
=
144
*
2
social/admin.py
Dosyayı görüntüle @
3c979907
...
@@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model
...
@@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model
from
django.contrib.auth.admin
import
UserAdmin
from
django.contrib.auth.admin
import
UserAdmin
from
social.forms
import
SocialUserCreationForm
,
SocialUserChangeForm
from
social.forms
import
SocialUserCreationForm
,
SocialUserChangeForm
from
social.models
import
SocialUser
from
social.models
import
SocialUser
,
Post
class
SocialUserAdmin
(
UserAdmin
):
class
SocialUserAdmin
(
UserAdmin
):
add_form
=
SocialUserCreationForm
add_form
=
SocialUserCreationForm
...
@@ -12,3 +12,4 @@ class SocialUserAdmin(UserAdmin):
...
@@ -12,3 +12,4 @@ class SocialUserAdmin(UserAdmin):
list_display
=
[
'email'
,
'username'
,]
list_display
=
[
'email'
,
'username'
,]
admin
.
site
.
register
(
SocialUser
,
SocialUserAdmin
)
admin
.
site
.
register
(
SocialUser
,
SocialUserAdmin
)
admin
.
site
.
register
(
Post
)
social/migrations/0001_initial.py
Dosyayı görüntüle @
3c979907
# Generated by Django 2.2.1 on 2019-05-04 15:
09
# Generated by Django 2.2.1 on 2019-05-04 15:
47
from
django.conf
import
settings
from
django.conf
import
settings
import
django.contrib.auth.models
import
django.contrib.auth.models
...
@@ -47,7 +47,12 @@ class Migration(migrations.Migration):
...
@@ -47,7 +47,12 @@ class Migration(migrations.Migration):
name
=
'Post'
,
name
=
'Post'
,
fields
=
[
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'text'
,
models
.
TextField
(
max_length
=
288
)),
(
'pub_date'
,
models
.
TimeField
(
auto_now
=
True
)),
(
'author'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
settings
.
AUTH_USER_MODEL
)),
(
'author'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
settings
.
AUTH_USER_MODEL
)),
],
],
options
=
{
'ordering'
:
[
'pub_date'
],
},
),
),
]
]
social/models.py
Dosyayı görüntüle @
3c979907
...
@@ -6,7 +6,17 @@ class SocialUser(AbstractUser):
...
@@ -6,7 +6,17 @@ class SocialUser(AbstractUser):
pass
pass
class
Post
(
models
.
Model
):
class
Post
(
models
.
Model
):
class
Meta
:
ordering
=
[
'pub_date'
]
author
=
models
.
ForeignKey
(
author
=
models
.
ForeignKey
(
settings
.
AUTH_USER_MODEL
,
settings
.
AUTH_USER_MODEL
,
on_delete
=
models
.
CASCADE
,
on_delete
=
models
.
CASCADE
,
)
)
text
=
models
.
TextField
(
max_length
=
settings
.
MAX_POST_LENGTH
)
pub_date
=
models
.
TimeField
(
auto_now
=
True
)
def
__str__
(
self
):
return
f
"{self.author}#{self.id}"
social/templates/home.html
Dosyayı görüntüle @
3c979907
...
@@ -3,11 +3,15 @@
...
@@ -3,11 +3,15 @@
{% block title %}Home{% endblock %}
{% block title %}Home{% endblock %}
{% block content %}
{% block content %}
{% if user.is_authenticated %}
{% if user.is_authenticated %}
Hi {{ user.username }}!
Hi {{ user.username }}!
<p><a
href=
"{% url 'logout' %}"
>
logout
</a></p>
<p><a
href=
"{% url 'logout' %}"
>
logout
</a></p>
{% else %}
{% load renderer %}
<p>
You are not logged in
</p>
{% for item in feed %}
<a
href=
"{% url 'login' %}"
>
login
</a>
{% as_html item %}
{% endif %}
{% endfor %}
{% else %}
<p>
You are not logged in
</p>
<a
href=
"{% url 'login' %}"
>
login
</a>
{% endif %}
{% endblock %}
{% endblock %}
social/templates/repr/post.html
0 → 100644
Dosyayı görüntüle @
3c979907
<div>
<fieldset>
<legend>
{{ item.author }}
</legend>
<p>
{{ item.text }}
</p><br>
-- wrote this at {{ item.pub_date }};
</fieldset>
</div>
social/templatetags/__init__.py
0 → 100644
Dosyayı görüntüle @
3c979907
social/templatetags/renderer.py
0 → 100644
Dosyayı görüntüle @
3c979907
from
django
import
template
from
django.template.loader
import
render_to_string
register
=
template
.
Library
()
@register.simple_tag
def
as_html
(
item
):
result
=
render_to_string
(
f
"repr/{item.__class__.__name__.lower()}.html"
,
{
'item'
:
item
})
return
result
social/views.py
Dosyayı görüntüle @
3c979907
from
django.contrib.auth.forms
import
UserCreationForm
from
django.contrib.auth.forms
import
UserCreationForm
from
django.urls
import
reverse_lazy
from
django.urls
import
reverse_lazy
from
django.views.generic
import
CreateView
from
django.views.generic
import
CreateView
,
ListView
from
django.views.generic.base
import
TemplateView
from
django.views.generic.base
import
TemplateView
from
social.models
import
Post
from
operator
import
or_
from
functools
import
wraps
,
reduce
class
Home
(
TemplateView
):
def
ret_or_super
(
func
):
template_name
=
'home.html'
def
wrapper
(
*
args
,
**
kwargs
):
try
:
res
=
func
(
*
args
,
**
kwargs
)
except
:
self
=
args
[
0
]
res
=
getattr
(
super
(
self
.
__class__
,
self
),
func
.
__name__
)(
*
args
,
**
kwargs
)
return
res
return
wrapper
class
ExtendedListView
(
ListView
):
@ret_or_super
def
get_queryset
(
self
):
queryset
=
reduce
(
or_
,
map
(
lambda
model
:
model
.
_default_manager
.
all
(),
self
.
models
))
return
queryset
class
Home
(
ExtendedListView
):
models
=
Post
,
template_name
=
'home.html'
context_object_name
=
'feed'
class
Register
(
CreateView
):
class
Register
(
CreateView
):
form_class
=
UserCreationForm
form_class
=
UserCreationForm
success_url
=
reverse_lazy
(
'login'
)
success_url
=
reverse_lazy
(
'login'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment