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
710ed9f5
Kaydet (Commit)
710ed9f5
authored
May 07, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Delete operation for all sharables
üst
1bf26eaf
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
130 additions
and
12 deletions
+130
-12
forms.py
social/forms.py
+4
-7
link.html
social/templates/forms/delete/link.html
+22
-0
post.html
social/templates/forms/delete/post.html
+22
-0
snippet.html
social/templates/forms/delete/snippet.html
+26
-0
home.html
social/templates/home.html
+3
-0
renderer.py
social/templatetags/renderer.py
+9
-1
urls.py
social/urls.py
+8
-3
create.py
social/views/crud/create.py
+4
-1
delete.py
social/views/crud/delete.py
+32
-0
No files found.
social/forms.py
Dosyayı görüntüle @
710ed9f5
...
...
@@ -19,17 +19,15 @@ class SocialUserChangeForm(UserChangeForm):
model
=
get_user_model
()
fields
=
(
"username"
,
"email"
)
class
Create
SharedForm
(
forms
.
ModelForm
):
class
SharedForm
(
forms
.
ModelForm
):
captcha
=
CaptchaField
()
class
CreatePostForm
(
CreateSharedForm
):
captcha
=
CaptchaField
()
class
CreatePostForm
(
SharedForm
):
class
Meta
:
model
=
Post
fields
=
(
"text"
,)
class
CreateSnippetForm
(
CreateSharedForm
):
captcha
=
CaptchaField
()
class
CreateSnippetForm
(
SharedForm
):
class
Meta
:
model
=
Snippet
fields
=
(
"text"
,)
...
...
@@ -37,8 +35,7 @@ class CreateSnippetForm(CreateSharedForm):
"text"
:
AceWidget
(
mode
=
'python'
,
theme
=
'monokai'
),
}
class
CreateLinkForm
(
CreateSharedForm
):
captcha
=
CaptchaField
()
class
CreateLinkForm
(
SharedForm
):
class
Meta
:
model
=
Link
fields
=
(
"url"
,)
social/templates/forms/delete/link.html
0 → 100644
Dosyayı görüntüle @
710ed9f5
{% extends 'base.html' %}
{% block title %}Delete link{% endblock %}
{% block content %}
{% load bootstrap4 %}
{% load renderer %}
<h2>
Delete Link
</h2>
<div
class=
"container-fluid __{{ item | get_class }}"
>
<fieldset
class=
"border p-2"
>
{% as_html object %}
<small
class=
"text-muted"
>
{{ object.pub_date }}
</small>
</fieldset>
</div>
<form
method=
"post"
class=
"form"
>
{% csrf_token %}
{% buttons %}
<button
type=
"submit"
class=
"btn btn-primary"
value=
"Confirm"
>
Delete Link
</button>
{% endbuttons %}
</form>
{% endblock %}
social/templates/forms/delete/post.html
0 → 100644
Dosyayı görüntüle @
710ed9f5
{% extends 'base.html' %}
{% block title %}Delete post{% endblock %}
{% block content %}
{% load bootstrap4 %}
{% load renderer %}
<h2>
Delete Post
</h2>
<div
class=
"container-fluid __{{ item | get_class }}"
>
<fieldset
class=
"border p-2"
>
{% as_html object %}
<small
class=
"text-muted"
>
{{ object.pub_date }}
</small>
</fieldset>
</div>
<form
method=
"post"
class=
"form"
>
{% csrf_token %}
{% buttons %}
<button
type=
"submit"
class=
"btn btn-primary"
value=
"Confirm"
>
Delete Post
</button>
{% endbuttons %}
</form>
{% endblock %}
social/templates/forms/delete/snippet.html
0 → 100644
Dosyayı görüntüle @
710ed9f5
{% extends 'base.html' %}
{% block title %}Delete snippet{% endblock %}
{% block content %}
{% load bootstrap4 %}
{% load renderer %}
<h2>
Delete Snippet
</h2>
<div
class=
"container-fluid __{{ item | get_class }}"
>
<fieldset
class=
"border p-2"
>
{% as_html object %}
<small
class=
"text-muted"
>
{{ object.pub_date }}
</small>
</fieldset>
</div>
<form
method=
"post"
class=
"form"
>
{% csrf_token %}
{% buttons %}
<button
type=
"submit"
class=
"btn btn-primary"
value=
"Confirm"
>
Delete Snippet
</button>
{% endbuttons %}
</form>
{% endblock %}
{% block js %}
<script
src=
"//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"
></script>
<script>
hljs
.
initHighlightingOnLoad
();
</script>
{% endblock %}
social/templates/home.html
Dosyayı görüntüle @
710ed9f5
...
...
@@ -13,6 +13,9 @@
<legend
class=
"w-auto"
><a
href=
"{% url 'profile' item.author %}"
>
{{ item.author }}
</a></legend>
{% as_html item %}
<small
class=
"text-muted"
>
{{ item.pub_date }}
</small>
{% if item.author == request.user %}
<small
class=
"text-muted"
><a
href=
"{% get_delete item %}"
>
delete
</a></small>
{% endif %}
</fieldset>
</div>
{% endfor %}
...
...
social/templatetags/renderer.py
Dosyayı görüntüle @
710ed9f5
from
urllib.parse
import
urlparse
from
django
import
template
from
django.urls
import
reverse
from
django.template.loader
import
render_to_string
from
purima.utils.get_preview
import
_get_preview
,
construct_preview
register
=
template
.
Library
()
def
_get_class
(
item
):
return
item
.
__class__
.
__name__
.
lower
()
@register.filter
def
get_class
(
item
):
return
item
.
__class__
.
__name__
.
lower
(
)
return
_get_class
(
item
)
@register.simple_tag
...
...
@@ -29,3 +33,7 @@ def get_preview(url):
preview
=
construct_preview
(
url
,
{
'title'
:
_url
.
netloc
})
return
preview
@register.simple_tag
def
get_delete
(
item
):
return
reverse
(
f
"delete_{_get_class(item)}"
,
args
=
(
item
.
id
,))
social/urls.py
Dosyayı görüntüle @
710ed9f5
...
...
@@ -21,9 +21,14 @@ class SocialPatterns(PatternManager):
}
class
SocialPostPatterns
(
PatternManager
):
create_post
=
"create/post"
,
CreatePost
create_link
=
"create/link"
,
CreateLink
create_snippet
=
"create/snippet"
,
CreateSnippet
create_post
=
"post/create"
,
CreatePost
delete_post
=
"post/delete/<int:pk>"
,
DeletePost
create_link
=
"link/create"
,
CreateLink
delete_link
=
"link/delete/<int:pk>"
,
DeleteLink
create_snippet
=
"snippet/create"
,
CreateSnippet
delete_snippet
=
"snippet/delete/<int:pk>"
,
DeleteSnippet
urlpatterns
=
SocialPatterns
()
+
SocialPostPatterns
()
social/views/crud/create.py
Dosyayı görüntüle @
710ed9f5
...
...
@@ -6,9 +6,12 @@ __all__ = ['CreatePost', 'CreateLink', 'CreateSnippet']
class
SharableCreate
(
CreateView
):
def
__init_subclass__
(
cls
):
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/{cls.__name__.replace('Create', '').lower()}.html"
cls
.
template_name
=
f
"forms/create/{simple_name}.html"
super
()
.
__init_subclass__
()
def
form_valid
(
self
,
form
):
...
...
social/views/crud/delete.py
Dosyayı görüntüle @
710ed9f5
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'
]
class
SharableDelete
(
DeleteView
):
def
__init_subclass__
(
cls
):
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
)
class
DeletePost
(
SharableDelete
):
pass
class
DeleteLink
(
SharableDelete
):
pass
class
DeleteSnippet
(
SharableDelete
):
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