Kaydet (Commit) a013b202 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

Sharable snippets and links

üst 92a76242
......@@ -2,7 +2,7 @@ from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib.auth import get_user_model
from social.models import Post
from social.models import Post, Link, Snippet
class SocialUserCreationForm(UserCreationForm):
......@@ -19,3 +19,13 @@ class PostCreationForm(forms.ModelForm):
class Meta:
model = Post
fields = ("text",)
class SnippetCreationForm(forms.ModelForm):
class Meta:
model = Snippet
fields = ("text",)
class LinkCreationForm(forms.ModelForm):
class Meta:
model = Link
fields = ("url",)
......@@ -30,6 +30,12 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'post' %}">Post</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'link' %}">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'snippet' %}">Snippet</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
</li>
......
{% extends 'base.html' %}
{% block title %}Post link{% endblock %}
{% block content %}
{% load bootstrap4 %}
<h2>Post link to feed</h2>
<form action="{% url 'link' %}" method="post" class="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Post link</button>
{% endbuttons %}
</form>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Post snippet{% endblock %}
{% block content %}
{% load bootstrap4 %}
<h2>Post snippet to feed</h2>
<form action="{% url 'snippet' %}" method="post" class="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Post snippet</button>
{% endbuttons %}
</form>
{% endblock %}
......@@ -5,15 +5,17 @@ from typing import Optional, Sequence
from django.urls import include, path
from purima.urls import PatternManager, IncludeFilter
from social.views import Home, Profile, Register, Post
from social.views import Home, Profile, Register, Post, Link, Snippet
class SocialPatterns(PatternManager):
home = "", Home
post = "post/", Post
post = "share/post/", Post
link = "share/link/", Link
snippet = "share/snippet/", Snippet
profile = "people/<slug>/", Profile
register = "accounts/register/", Register
includes = {
"accounts/": IncludeFilter(
"django.contrib.auth.urls", whitelist=("login", "logout")
......
......@@ -5,9 +5,8 @@ from django.views.generic import CreateView, DetailView, ListView
from django.views.generic.base import TemplateView
from purima.views import ExtendedListView
from social import forms
from social.models import Link, Post, Snippet
from social.forms import PostCreationForm, SocialUserCreationForm
class Home(ExtendedListView):
models = Post, Snippet, Link
template_name = "home.html"
......@@ -20,18 +19,30 @@ class Home(ExtendedListView):
class Register(CreateView):
form_class = SocialUserCreationForm
form_class = forms.SocialUserCreationForm
success_url = reverse_lazy("login")
template_name = "registration/register.html"
class Post(CreateView):
form_class = PostCreationForm
success_url = reverse_lazy("home")
template_name = "forms/post.html"
class SharableCreate(CreateView):
def __init_subclass__(cls):
cls.form_class = getattr(forms, f"{cls.__name__}CreationForm")
cls.success_url = reverse_lazy("home")
cls.template_name = f"forms/{cls.__name__.lower()}.html"
super().__init_subclass__()
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
class Post(SharableCreate):
pass
class Link(SharableCreate):
pass
class Snippet(SharableCreate):
pass
class Profile(DetailView):
model = get_user_model()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment