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

Posting functionality

üst c49d49c8
purima @ c60678ba
Subproject commit b0a1904f280c0faf20dd6de5efb0ef35235b2b4a Subproject commit c60678baf7b1cf3d16af0002ced05ee1b9763e08
...@@ -2,7 +2,7 @@ from django import forms ...@@ -2,7 +2,7 @@ from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm 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 social.models import SocialUser from social.models import Post
class SocialUserCreationForm(UserCreationForm): class SocialUserCreationForm(UserCreationForm):
...@@ -14,3 +14,8 @@ class SocialUserChangeForm(UserChangeForm): ...@@ -14,3 +14,8 @@ class SocialUserChangeForm(UserChangeForm):
class Meta: class Meta:
model = get_user_model() model = get_user_model()
fields = ("username", "email", "avatar") fields = ("username", "email", "avatar")
class PostCreationForm(forms.ModelForm):
class Meta:
model = Post
fields = ("text",)
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</li> </li>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#">Post</a> <a class="nav-link" href="{% url 'post' %}">Post</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Logout</a> <a class="nav-link" href="{% url 'logout' %}">Logout</a>
......
{% extends 'base.html' %}
{% block title %}Post{% endblock %}
{% block content %}
{% load bootstrap4 %}
<h2>Post to feed</h2>
<form action="{% url 'post' %}" method="post" class="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Post</button>
{% endbuttons %}
</form>
{% endblock %}
...@@ -5,11 +5,12 @@ from typing import Optional, Sequence ...@@ -5,11 +5,12 @@ 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 PatternManager, IncludeFilter
from social.views import Home, Profile, Register from social.views import Home, Profile, Register, Post
class SocialPatterns(PatternManager): class SocialPatterns(PatternManager):
home = "", Home home = "", Home
post = "post/", Post
profile = "people/<slug>/", Profile profile = "people/<slug>/", Profile
register = "accounts/register/", Register register = "accounts/register/", Register
......
from itertools import chain
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
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, DetailView, ListView from django.views.generic import CreateView, DetailView, ListView
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from purima.views import ExtendedListView
from social.models import Link, Post, Snippet from social.models import Link, Post, Snippet
from social.forms import SocialUserCreationForm from social.forms import PostCreationForm, SocialUserCreationForm
class ExtendedListView(ListView):
def get_queryset(self):
return chain.from_iterable(
map(lambda model: model._default_manager.all(), self.models)
)
class Home(ExtendedListView): class Home(ExtendedListView):
models = Post, Snippet, Link models = Post, Snippet, Link
...@@ -32,7 +24,15 @@ class Register(CreateView): ...@@ -32,7 +24,15 @@ class Register(CreateView):
success_url = reverse_lazy("login") success_url = reverse_lazy("login")
template_name = "registration/register.html" template_name = "registration/register.html"
class Post(CreateView):
form_class = PostCreationForm
success_url = reverse_lazy("home")
template_name = "forms/post.html"
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
class Profile(DetailView): class Profile(DetailView):
model = get_user_model() model = get_user_model()
slug_field = "username" slug_field = "username"
......
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