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