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
360d6b48
Kaydet (Commit)
360d6b48
authored
May 08, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
style
üst
dbaf6bbc
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
86 additions
and
65 deletions
+86
-65
admin.py
social/admin.py
+0
-1
forms.py
social/forms.py
+14
-9
0005_auto_20190506_0252.py
social/migrations/0005_auto_20190506_0252.py
+3
-9
0006_auto_20190507_1848.py
social/migrations/0006_auto_20190507_1848.py
+10
-8
models.py
social/models.py
+4
-1
renderer.py
social/templatetags/renderer.py
+7
-4
urls.py
social/urls.py
+7
-6
__init__.py
social/views/__init__.py
+3
-3
auth.py
social/views/auth.py
+5
-3
__init__.py
social/views/crud/__init__.py
+1
-1
create.py
social/views/crud/create.py
+10
-5
delete.py
social/views/crud/delete.py
+12
-8
update.py
social/views/crud/update.py
+10
-7
No files found.
social/admin.py
Dosyayı görüntüle @
360d6b48
...
...
@@ -4,7 +4,6 @@ from django.contrib.auth.admin import UserAdmin
from
social.forms
import
SocialUserChangeForm
,
SocialUserCreationForm
from
social.models
import
Link
,
Post
,
Snippet
,
SocialUser
from
django.contrib.auth
import
get_user_model
class
SocialUserAdmin
(
UserAdmin
):
...
...
social/forms.py
Dosyayı görüntüle @
360d6b48
from
captcha.fields
import
CaptchaField
from
django
import
forms
from
django.contrib.auth.forms
import
UserChangeForm
,
UserCreationForm
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.forms
import
UserChangeForm
,
UserCreationForm
from
django_ace
import
AceWidget
from
captcha.fields
import
CaptchaField
from
social.models
import
Post
,
Link
,
Snippet
from
social.models
import
Link
,
Post
,
Snippet
class
SocialUserCreationForm
(
UserCreationForm
):
captcha
=
CaptchaField
()
class
Meta
:
model
=
get_user_model
()
fields
=
(
"username"
,
"email"
)
class
SocialUserChangeForm
(
UserChangeForm
):
captcha
=
CaptchaField
()
class
Meta
:
model
=
get_user_model
()
fields
=
(
"username"
,
"email"
)
class
SharedForm
(
forms
.
ModelForm
):
captcha
=
CaptchaField
()
class
CreatePostForm
(
SharedForm
):
class
Meta
:
model
=
Post
fields
=
(
"text"
,)
class
CreateSnippetForm
(
SharedForm
):
class
Meta
:
model
=
Snippet
fields
=
(
"text"
,)
widgets
=
{
"text"
:
AceWidget
(
mode
=
'python'
,
theme
=
'monokai'
),
}
widgets
=
{
"text"
:
AceWidget
(
mode
=
"python"
,
theme
=
"monokai"
)}
class
CreateLinkForm
(
SharedForm
):
class
Meta
:
model
=
Link
...
...
social/migrations/0005_auto_20190506_0252.py
Dosyayı görüntüle @
360d6b48
...
...
@@ -5,19 +5,13 @@ from django.db import migrations, models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'social'
,
'0004_link'
),
]
dependencies
=
[(
"social"
,
"0004_link"
)]
operations
=
[
migrations
.
AddField
(
model_name
=
'socialuser'
,
name
=
'desc'
,
field
=
models
.
TextField
(
blank
=
True
),
model_name
=
"socialuser"
,
name
=
"desc"
,
field
=
models
.
TextField
(
blank
=
True
)
),
migrations
.
AlterField
(
model_name
=
'socialuser'
,
name
=
'avatar'
,
field
=
models
.
URLField
(
blank
=
True
),
model_name
=
"socialuser"
,
name
=
"avatar"
,
field
=
models
.
URLField
(
blank
=
True
)
),
]
social/migrations/0006_auto_20190507_1848.py
Dosyayı görüntüle @
360d6b48
# Generated by Django 2.2.1 on 2019-05-07 18:48
from
django.db
import
migrations
,
models
import
social.models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'social'
,
'0005_auto_20190506_0252'
),
]
dependencies
=
[(
"social"
,
"0005_auto_20190506_0252"
)]
operations
=
[
migrations
.
AlterField
(
model_name
=
'socialuser'
,
name
=
'avatar'
,
model_name
=
"socialuser"
,
name
=
"avatar"
,
field
=
models
.
URLField
(
blank
=
True
,
default
=
social
.
models
.
get_avatar
),
),
migrations
.
AlterField
(
model_name
=
'socialuser'
,
name
=
'desc'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
'Apparently, this user prefers to keep an air of mystery about them.'
),
model_name
=
"socialuser"
,
name
=
"desc"
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
"Apparently, this user prefers to keep an air of mystery about them."
,
),
),
]
social/models.py
Dosyayı görüntüle @
360d6b48
from
pathlib
import
Path
from
random
import
randint
from
django.conf
import
settings
from
django.contrib.auth.models
import
AbstractUser
from
django.db
import
models
def
get_avatar
():
return
settings
.
STATIC_URL
/
Path
(
settings
.
AVATAR_BASE
.
format
(
randint
(
1
,
4
)))
class
SocialUser
(
AbstractUser
):
avatar
=
models
.
URLField
(
blank
=
True
,
default
=
get_avatar
)
desc
=
models
.
TextField
(
blank
=
True
,
default
=
settings
.
DESC
)
...
...
social/templatetags/renderer.py
Dosyayı görüntüle @
360d6b48
from
urllib.parse
import
urlparse
from
django
import
template
from
django.urls
import
reverse
from
django.template.loader
import
render_to_string
from
django.urls
import
reverse
from
purima.utils.get_preview
import
_get_preview
,
construct_preview
register
=
template
.
Library
()
...
...
@@ -10,7 +11,8 @@ register = template.Library()
def
_get_class
(
item
):
return
item
.
__class__
.
__name__
.
lower
()
@register.filter
def
get_class
(
item
):
return
_get_class
(
item
)
...
...
@@ -30,10 +32,11 @@ def get_preview(url):
preview
=
_get_preview
(
url
)
except
:
_url
=
urlparse
(
url
)
preview
=
construct_preview
(
url
,
{
'title'
:
_url
.
netloc
})
preview
=
construct_preview
(
url
,
{
"title"
:
_url
.
netloc
})
return
preview
@register.simple_tag
def
get_opt
(
opt
,
item
):
return
reverse
(
f
"{opt}_{_get_class(item)}"
,
args
=
(
item
.
id
,))
social/urls.py
Dosyayı görüntüle @
360d6b48
...
...
@@ -3,8 +3,8 @@ from dataclasses import dataclass
from
typing
import
Optional
,
Sequence
from
django.urls
import
include
,
path
from
purima.urls
import
PatternManager
,
IncludeFilter
from
purima.urls
import
IncludeFilter
,
PatternManager
from
social.views
import
*
...
...
@@ -12,26 +12,27 @@ class SocialPatterns(PatternManager):
home
=
""
,
Home
profile
=
"people/<slug>/"
,
Profile
register
=
"accounts/register/"
,
Register
includes
=
{
"accounts/"
:
IncludeFilter
(
"django.contrib.auth.urls"
,
whitelist
=
(
"login"
,
"logout"
)
),
"captcha/"
:
"captcha.urls"
"captcha/"
:
"captcha.urls"
,
}
class
SocialPostPatterns
(
PatternManager
):
create_post
=
"post/create"
,
CreatePost
update_post
=
"post/update/<int:pk>"
,
UpdatePost
delete_post
=
"post/delete/<int:pk>"
,
DeletePost
create_link
=
"link/create"
,
CreateLink
update_link
=
"link/update/<int:pk>"
,
UpdateLink
delete_link
=
"link/delete/<int:pk>"
,
DeleteLink
create_snippet
=
"snippet/create"
,
CreateSnippet
update_snippet
=
"snippet/update/<int:pk>"
,
UpdateSnippet
delete_snippet
=
"snippet/delete/<int:pk>"
,
DeleteSnippet
urlpatterns
=
SocialPatterns
()
+
SocialPostPatterns
()
urlpatterns
=
SocialPatterns
()
+
SocialPostPatterns
()
social/views/__init__.py
Dosyayı görüntüle @
360d6b48
from
social.views.crud
import
*
from
social.views.auth
import
*
from
purima.views
import
ExtendedListView
from
social.models
import
Link
,
Post
,
Snippet
from
social.views.auth
import
*
from
social.views.crud
import
*
class
Home
(
ExtendedListView
):
models
=
Post
,
Snippet
,
Link
...
...
social/views/auth.py
Dosyayı görüntüle @
360d6b48
from
django.views.generic
import
CreateView
,
DetailView
from
django.urls
import
reverse_lazy
from
django.contrib.auth
import
get_user_model
from
django.urls
import
reverse_lazy
from
django.views.generic
import
CreateView
,
DetailView
from
social
import
forms
__all__
=
[
'Register'
,
'Profile'
]
__all__
=
[
"Register"
,
"Profile"
]
class
Register
(
CreateView
):
form_class
=
forms
.
SocialUserCreationForm
success_url
=
reverse_lazy
(
"login"
)
template_name
=
"registration/register.html"
class
Profile
(
DetailView
):
model
=
get_user_model
()
slug_field
=
"username"
...
...
social/views/crud/__init__.py
Dosyayı görüntüle @
360d6b48
from
social.views.crud.create
import
*
from
social.views.crud.update
import
*
from
social.views.crud.delete
import
*
from
social.views.crud.update
import
*
social/views/crud/create.py
Dosyayı görüntüle @
360d6b48
from
django.urls
import
reverse_lazy
from
django.views.generic
import
CreateView
from
social
import
forms
__all__
=
[
'CreatePost'
,
'CreateLink'
,
'CreateSnippet'
]
__all__
=
[
"CreatePost"
,
"CreateLink"
,
"CreateSnippet"
]
class
SharableCreate
(
CreateView
):
def
__init_subclass__
(
cls
):
simple_name
=
cls
.
__name__
.
replace
(
'Create'
,
''
)
.
lower
()
simple_name
=
cls
.
__name__
.
replace
(
"Create"
,
""
)
.
lower
()
cls
.
form_class
=
getattr
(
forms
,
f
"{cls.__name__}Form"
)
cls
.
success_url
=
reverse_lazy
(
"home"
)
cls
.
template_name
=
f
"forms/create/{simple_name}.html"
super
()
.
__init_subclass__
()
def
form_valid
(
self
,
form
):
form
.
instance
.
author
=
self
.
request
.
user
return
super
()
.
form_valid
(
form
)
class
CreatePost
(
SharableCreate
):
pass
class
CreateLink
(
SharableCreate
):
pass
class
CreateSnippet
(
SharableCreate
):
pass
social/views/crud/delete.py
Dosyayı görüntüle @
360d6b48
from
django.http
import
HttpResponse
from
django.urls
import
reverse_lazy
from
django.views.generic
import
DeleteView
from
django.http
import
HttpResponse
from
social
import
models
__all__
=
[
'DeletePost'
,
'DeleteLink'
,
'DeleteSnippet'
]
__all__
=
[
"DeletePost"
,
"DeleteLink"
,
"DeleteSnippet"
]
class
SharableDelete
(
DeleteView
):
def
__init_subclass__
(
cls
):
simple_name
=
cls
.
__name__
.
replace
(
'Delete'
,
''
)
.
lower
()
simple_name
=
cls
.
__name__
.
replace
(
"Delete"
,
""
)
.
lower
()
cls
.
model
=
getattr
(
models
,
f
"{simple_name.title()}"
)
cls
.
success_url
=
reverse_lazy
(
"home"
)
cls
.
template_name
=
f
"forms/delete/{simple_name}.html"
super
()
.
__init_subclass__
()
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
if
self
.
get_object
()
.
author
==
request
.
user
:
return
super
()
.
delete
(
request
,
*
args
,
**
kwargs
)
else
:
return
HttpResponse
(
'Unauthorized'
,
status
=
401
)
return
HttpResponse
(
"Unauthorized"
,
status
=
401
)
class
DeletePost
(
SharableDelete
):
pass
class
DeleteLink
(
SharableDelete
):
pass
class
DeleteSnippet
(
SharableDelete
):
pass
social/views/crud/update.py
Dosyayı görüntüle @
360d6b48
from
django.http
import
HttpResponse
from
django.urls
import
reverse_lazy
from
django.views.generic
import
UpdateView
from
django.http
import
HttpResponse
from
social
import
forms
,
models
from
social
import
models
,
forms
__all__
=
[
"UpdatePost"
,
"UpdateLink"
,
"UpdateSnippet"
]
__all__
=
[
'UpdatePost'
,
'UpdateLink'
,
'UpdateSnippet'
]
class
SharableUpdate
(
UpdateView
):
def
__init_subclass__
(
cls
):
simple_name
=
cls
.
__name__
.
replace
(
'Update'
,
''
)
.
lower
()
simple_name
=
cls
.
__name__
.
replace
(
"Update"
,
""
)
.
lower
()
cls
.
model
=
getattr
(
models
,
f
"{simple_name.title()}"
)
cls
.
success_url
=
reverse_lazy
(
"home"
)
cls
.
template_name
=
f
"forms/update/{simple_name}.html"
...
...
@@ -21,13 +21,16 @@ class SharableUpdate(UpdateView):
if
self
.
get_object
()
.
author
==
self
.
request
.
user
:
return
super
()
.
form_valid
(
*
args
,
**
kwargs
)
else
:
return
HttpResponse
(
'Unauthorized'
,
status
=
401
)
return
HttpResponse
(
"Unauthorized"
,
status
=
401
)
class
UpdatePost
(
SharableUpdate
):
pass
class
UpdateLink
(
SharableUpdate
):
pass
class
UpdateSnippet
(
SharableUpdate
):
pass
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