Merge branch 'vis'
This commit is contained in:
commit
3b407f393d
17 changed files with 193 additions and 43 deletions
|
|
@ -35,6 +35,7 @@ INSTALLED_APPS = [
|
|||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django_bootstrap5",
|
||||
"flangr.posts",
|
||||
"flangr.circles",
|
||||
]
|
||||
|
|
@ -114,3 +115,5 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|||
MEDIA_URL = "media/"
|
||||
|
||||
AUTH_USER_MODEL = "auth.User"
|
||||
|
||||
STATICFILES_DIRS = ["flangr/static"]
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ app_name = "circles"
|
|||
urlpatterns = [
|
||||
path("", views.CircleListView.as_view(), name="circle_list"),
|
||||
path("circle/<int:pk>", views.CircleUpdateView.as_view(), name="circle_update"),
|
||||
path("add", views.CircleCreateView.as_view(), name="circle_create"),
|
||||
path("circle/new", views.CircleCreateView.as_view(), name="circle_create"),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class CircleCreateView(LoginRequiredMixin, CreateView):
|
|||
circle = form.save(commit=False)
|
||||
circle.owner = self.request.user
|
||||
circle.save()
|
||||
form.save_m2m()
|
||||
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
|
|
|||
|
|
@ -5,5 +5,11 @@ from . import views
|
|||
app_name = "posts"
|
||||
urlpatterns = [
|
||||
path("post/<int:pk>", views.PostDetailView.as_view(), name="post_detail"),
|
||||
path(
|
||||
"post/<int:pk>/fullscreen",
|
||||
views.PostDetailView.as_view(template_name_suffix="_fullscreen"),
|
||||
name="post_fullscreen",
|
||||
),
|
||||
path("post/new", views.PostCreateView.as_view(), name="post_create"),
|
||||
path("posts", views.PostListView.as_view(), name="post_list"),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from django.http import HttpResponseRedirect
|
|||
from django.urls import reverse
|
||||
from django.views.generic import CreateView
|
||||
from django.views.generic import DetailView
|
||||
from django.views.generic import ListView
|
||||
from django.views.generic.edit import ModelFormMixin
|
||||
|
||||
from .models import Comment
|
||||
|
|
@ -48,5 +49,11 @@ class PostCreateView(LoginRequiredMixin, CreateView):
|
|||
self.object = form.save(commit=False)
|
||||
self.object.user = self.request.user
|
||||
self.object.save()
|
||||
form.save_m2m()
|
||||
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
||||
class PostListView(LoginRequiredMixin, ListView):
|
||||
def get_queryset(self):
|
||||
return Post.objects.filter(circles__members=self.request.user)
|
||||
|
|
|
|||
3
flangr/static/css/base.css
Normal file
3
flangr/static/css/base.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.img-full {
|
||||
object-fit: contain;
|
||||
}
|
||||
|
|
@ -1,6 +1,49 @@
|
|||
{% load django_bootstrap5 %}
|
||||
{% load static %}
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Flangr</title>
|
||||
<link rel="stylesheet" href="{% static 'css/base.css' %}">
|
||||
{% bootstrap_css %}
|
||||
{% block extracss %}{% endblock extracss %}
|
||||
</head>
|
||||
<body>{% block content %}{% endblock content %}</body>
|
||||
<body>
|
||||
{% block nav %}
|
||||
<nav class="navbar navbar-expand-md navbar-light bg-light mb-2">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">Flangr</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'posts:post_list' %}">Posts</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'circles:circle_list' %}">Circles</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
{% if user %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">{{ user.username }}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'login' %}">Login</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
{% endblock nav %}
|
||||
{% bootstrap_messages %}
|
||||
{% block content %}{% endblock content %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,17 @@
|
|||
{% extends "base.html" %}
|
||||
{% load django_bootstrap5 %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Circle {{ object.name }}</h1>
|
||||
<form action="#" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit" value="Post">
|
||||
</form>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Create a new circle</h1>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
{% bootstrap_button button_type="submit" content="OK" %}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,22 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h1>Your Circles</h1>
|
||||
<ul>
|
||||
{% for circle in object_list %}
|
||||
<li><a href="{% url "circles:circle_update" circle.pk %}">{{ circle.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Your Circles</h1>
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Members</th>
|
||||
</tr>
|
||||
{% for circle in object_list %}
|
||||
<tr>
|
||||
<td><a href="{% url "circles:circle_update" circle.pk %}">{{ circle.name }}</a></td>
|
||||
<td>{{ circle.members.all }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,30 @@
|
|||
{% extends "base.html" %}
|
||||
{% load django_bootstrap5 %}
|
||||
|
||||
{% block content %}
|
||||
{% if object.title %}
|
||||
<h1>{{ object.title }}</h1>
|
||||
{% else %}
|
||||
<h1>{{ object.user.username }}</h1>
|
||||
{% endif %}
|
||||
<img width=400 src={{ object.img.url }}/>
|
||||
<h2> Comments</h2>
|
||||
<ul>
|
||||
{% for comment in object.comments.all %}
|
||||
<li>{{ comment.user }} - {{ comment.comment }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit", value="Post">
|
||||
</form>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
{% if object.title %}
|
||||
<h1>{{ object.title }}</h1>
|
||||
{% else %}
|
||||
<h1>{{ object.user.username }}</h1>
|
||||
{% endif %}
|
||||
<a href="{% url 'posts:post_fullscreen' object.pk %}"><img class="img-fluid" src={{ object.img.url }}/></a>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h2> Comments</h2>
|
||||
<ul>
|
||||
{% for comment in object.comments.all %}
|
||||
<li>{{ comment.user }} - {{ comment.comment }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
{% bootstrap_button button_type="submit" content="OK" %}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,19 @@
|
|||
{% extends "base.html" %}
|
||||
{% load django_bootstrap5 %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Upload a new picture</h1>
|
||||
<form enctype="multipart/form-data" action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit" value="Post">
|
||||
</form>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Upload a new picture</h1>
|
||||
<form enctype="multipart/form-data" action="" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
{% bootstrap_button button_type="submit" content="OK" %}
|
||||
<input type="submit" value="Post">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
||||
|
|
|
|||
16
flangr/templates/posts/post_fullscreen.html
Normal file
16
flangr/templates/posts/post_fullscreen.html
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{% extends "base.html" %}
|
||||
{% load django_bootstrap5 %}
|
||||
|
||||
{% block nav %}{% endblock nav %}
|
||||
|
||||
{% block content %}
|
||||
<div class="vh-100 bg-dark d-flex flex-column">
|
||||
<div class="d-flex flex-row m-2 justify-content-between align-items-center">
|
||||
<h3 class="text-light">{{ object.title }}</h1>
|
||||
<a class="btn btn-dark" href="{% url 'posts:post_detail' object.pk %}">X</a>
|
||||
</div>
|
||||
<div class="flex-fill flex-shrink-1">
|
||||
<img class="img-full w-100 h-100" src={{ object.img.url }}/>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
15
flangr/templates/posts/post_list.html
Normal file
15
flangr/templates/posts/post_list.html
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Posts Shared with you</h1>
|
||||
<ul>
|
||||
{% for post in object_list %}
|
||||
<li><a href="{% url "posts:post_detail" post.pk %}">{{ post.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
@ -1,10 +1,19 @@
|
|||
{% extends "base.html" %}
|
||||
{% load django_bootstrap5 %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Login</h1>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit", value="Post">
|
||||
</form>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Login</h1>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
{% bootstrap_button button_type="submit" content="OK" %}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -16,15 +16,20 @@ Including another URLconf
|
|||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from django.urls import include
|
||||
from django.urls import path
|
||||
|
||||
from .posts.views import PostListView
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("accounts/", include("django.contrib.auth.urls")),
|
||||
path("posts/", include("flangr.posts.urls")),
|
||||
path("circles/", include("flangr.circles.urls")),
|
||||
path("", PostListView.as_view(), name="home"),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
pillow
|
||||
django
|
||||
coverage
|
||||
django-bootstrap5
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
-r base.txt
|
||||
pre-commit
|
||||
flake8
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue