✨
This commit is contained in:
@ -18,5 +18,5 @@ def show(group_id):
|
||||
if (group is not None):
|
||||
return render_template('group_show.html', group=group, posts=posts)
|
||||
else:
|
||||
return "Der findes ingen gruppe med det id"
|
||||
return f"Der findes ikke en gruppe med id {group_id}."
|
||||
|
||||
|
@ -1,12 +1,22 @@
|
||||
from flask import render_template, url_for, flash, redirect, request, Blueprint
|
||||
from bank import app, conn, bcrypt
|
||||
from aula.forms import TransferForm, DepositForm, AddCustomerForm
|
||||
from flask_login import current_user, login_required
|
||||
import sys, datetime
|
||||
from flask import render_template, Blueprint
|
||||
from flask_login import login_required, current_user
|
||||
from aula.models import get_thread
|
||||
|
||||
Group = Blueprint('Threads', __name__)
|
||||
Threads = Blueprint('Threads', __name__)
|
||||
|
||||
@login_required()
|
||||
@Group.route("threads/index", methods=['GET'])
|
||||
def index():
|
||||
return render_template()
|
||||
@Threads.route("/threads", methods=['GET'])
|
||||
@login_required
|
||||
def threads():
|
||||
threads_data = current_user.get_threads()
|
||||
return render_template("threads.html", threads=threads_data)
|
||||
|
||||
@Threads.route("/threads/<int:thread_id>", methods=['GET'])
|
||||
@login_required
|
||||
def show(thread_id):
|
||||
thread = get_thread(thread_id)
|
||||
if thread is None:
|
||||
return f"Der findes ikke en tråd med id {thread_id}."
|
||||
elif not current_user.in_thread(thread_id):
|
||||
return f"Du har ikke adgang til tråden med id {thread_id}."
|
||||
else:
|
||||
return render_template("thread_show.html", thread=thread, messages=thread.get_messages())
|
||||
|
@ -16,8 +16,10 @@ login_manager.login_message_category = 'info'
|
||||
|
||||
from aula.Login.routes import Login
|
||||
from aula.Group.routes import Group
|
||||
from aula.Threads.routes import Threads
|
||||
|
||||
app.register_blueprint(Login)
|
||||
app.register_blueprint(Group)
|
||||
app.register_blueprint(Threads)
|
||||
|
||||
#from bank import routes
|
||||
|
@ -1,4 +1,5 @@
|
||||
# write all your SQL queries in this file.
|
||||
from datetime import datetime, timedelta
|
||||
from flask_login import UserMixin
|
||||
|
||||
from aula import conn, login_manager
|
||||
@ -61,9 +62,42 @@ class Message(tuple):
|
||||
self.content = message_data[1]
|
||||
self.thread_id = message_data[2]
|
||||
self.author_id = message_data[3]
|
||||
self.created_date = message_data[4]
|
||||
self.author = None
|
||||
self._created_date = message_data[4]
|
||||
self._get_author()
|
||||
super().__init__()
|
||||
|
||||
def _get_author(self):
|
||||
cur = conn.cursor()
|
||||
sql_call = """
|
||||
SELECT * FROM users WHERE user_id = %s
|
||||
"""
|
||||
cur.execute(sql_call, (self.author_id,))
|
||||
self.author = User(cur.fetchone())
|
||||
|
||||
@property
|
||||
def created_date(self):
|
||||
now = datetime.now()
|
||||
if now.date() == self._created_date.date():
|
||||
return self._created_date.strftime("Idag %X")
|
||||
elif now.date() == self._created_date.date() + timedelta(days=1):
|
||||
return self._created_date.strftime("Igår %X")
|
||||
elif now < self._created_date + timedelta(days=7):
|
||||
dag = [
|
||||
"Mandag",
|
||||
"Tirsdag",
|
||||
"Onsdag",
|
||||
"Torsdag",
|
||||
"Fredag",
|
||||
"Lørdag",
|
||||
"Søndag",
|
||||
][int(self._created_date.strftime("%w"))]
|
||||
return self._created_date.strftime(f"{dag} %X")
|
||||
elif now.strftime("%y") == self._created_date.strftime("%y"):
|
||||
return self._created_date.strftime("%d/%m %X")
|
||||
else:
|
||||
return self._created_date.strftime("%d/%m/%y %X")
|
||||
|
||||
class Post(tuple):
|
||||
def __init__(self, post_data):
|
||||
self.post_id = post_data[0]
|
||||
@ -85,7 +119,6 @@ class Post(tuple):
|
||||
"""
|
||||
cur.execute(sql_call, (self.author_id,))
|
||||
self.author = User(cur.fetchone())
|
||||
print(self.author)
|
||||
|
||||
def _get_group(self):
|
||||
cur = conn.cursor()
|
||||
@ -100,20 +133,20 @@ class Thread(tuple):
|
||||
self.thread_id = thread_data[0]
|
||||
self.title = thread_data[1]
|
||||
self.group_id = thread_data[2]
|
||||
self.creator_id = thread_data[3]
|
||||
super().__init__()
|
||||
|
||||
def get_message(self):
|
||||
def get_messages(self):
|
||||
cur = conn.cursor()
|
||||
sql_call = """
|
||||
SELECT * FROM message
|
||||
WHERE message.thread_id = %s.thread_id
|
||||
SELECT * FROM messages
|
||||
WHERE thread_id = %s
|
||||
ORDER BY created_date ASC
|
||||
"""
|
||||
cur.execute(sql_call, (self.group_id,))
|
||||
Thread = Thread(cur.fetchall()) if cur.rowcount > 0 else None
|
||||
cur.execute(sql_call, (self.thread_id,))
|
||||
messages = cur.fetchall() if cur.rowcount > 0 else None
|
||||
result = []
|
||||
for thread_data in Thread:
|
||||
result.append(Thread(thread_data))
|
||||
for message_data in messages:
|
||||
result.append(Message(message_data))
|
||||
cur.close()
|
||||
return result
|
||||
|
||||
@ -190,23 +223,33 @@ class User(tuple, UserMixin):
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
def get_all_threads(self):
|
||||
|
||||
def get_threads(self):
|
||||
cur = conn.cursor()
|
||||
sql_call = """
|
||||
SELECT * FROM threads WHERE group_id =
|
||||
(SELECT groups.group_id FROM
|
||||
groups INNER JOIN users_groups ON groups.group_id = users_groups.group_id
|
||||
WHERE users_groups.user_id = %s )
|
||||
SELECT * FROM threads WHERE thread_id IN
|
||||
(
|
||||
SELECT thread_id FROM users_threads
|
||||
WHERE user_id = %s
|
||||
)
|
||||
"""
|
||||
cur.execute(sql_call, (self.group_id,))
|
||||
Thread = Thread(cur.fetchall()) if cur.rowcount > 0 else None
|
||||
cur.execute(sql_call, (self.user_id,))
|
||||
threads = cur.fetchall() if cur.rowcount > 0 else None
|
||||
result = []
|
||||
for thread_data in Thread:
|
||||
for thread_data in threads:
|
||||
result.append(Thread(thread_data))
|
||||
cur.close()
|
||||
return result
|
||||
|
||||
|
||||
def in_thread(self, thread_id):
|
||||
cur = conn.cursor()
|
||||
sql_call = """
|
||||
SELECT * FROM users_threads WHERE
|
||||
user_id = %s AND
|
||||
thread_id = %s
|
||||
"""
|
||||
cur.execute(sql_call, (self.user_id, thread_id))
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
|
||||
def insert_users(user_id, first_name, last_name, password, email, adresse, role):
|
||||
@ -267,3 +310,14 @@ def get_group(group_id):
|
||||
cur.close()
|
||||
return group
|
||||
|
||||
def get_thread(thread_id):
|
||||
cur = conn.cursor()
|
||||
sql = """
|
||||
SELECT * FROM threads
|
||||
WHERE thread_id = %s
|
||||
"""
|
||||
cur.execute(sql, (thread_id,))
|
||||
thread = Thread(cur.fetchone()) if cur.rowcount > 0 else None
|
||||
cur.close()
|
||||
return thread
|
||||
|
||||
|
@ -14,12 +14,26 @@ INSERT INTO public.groups(group_id, name, hidden) VALUES
|
||||
|
||||
INSERT INTO users_groups (user_id, group_id) VALUES (5000, 1000), (5001, 1001);
|
||||
|
||||
INSERT INTO threads(thread_id ,title, group_id) VALUES
|
||||
INSERT INTO threads(thread_id ,title, group_id) VALUES
|
||||
(2000, 'Anbefalinger til fodboldsko?', 1000);
|
||||
|
||||
INSERT INTO messages (message_id, content, thread_id, author_id) VALUES (4000,'Eleverne har ondt i fødderne når de spiller fodbild. Hvem kender et godt skomærke?', 2000, 5000);
|
||||
INSERT INTO messages (message_id, content, thread_id, author_id, created_date) VALUES
|
||||
(4000,'Eleverne har ondt i fødderne når de spiller fodbild. Hvem kender et godt skomærke?', 2000, 5000, NOW() - INTERVAL '3.189 day'),
|
||||
(4005,'Jeg tror min søn har nogle han er glad for. Jeg spørger ham lige 😀', 2000, 5002, NOW() - INTERVAL '2.951 day'),
|
||||
(4010,'Tak 👍', 2000, 5000, NOW() - INTERVAL '1.894 day'),
|
||||
(4001,'Er det meningen vi skal give dem sko med????', 2000, 5001, NOW() - INTERVAL '1.05 hour'),
|
||||
(4002,'Rachel, giver du ikke dine børn sko med til fodbold?', 2000, 5002, NOW() - INTERVAL '0.95 hour'),
|
||||
(4003,'Hvad er der galt med dig?', 2000, 5003, NOW() - INTERVAL '0.94 hour'),
|
||||
(4004,'Jeg troede de lånte sko af skolen!', 2000, 5001, NOW() - INTERVAL '0.91 hour'),
|
||||
(4006,'Er det noget der nogensinde sket?', 2000, 5003, NOW() - INTERVAL '0.908 hour'),
|
||||
(4007,'Kan vi ikke godt komme tilbage til pointen?', 2000, 5000, NOW() - INTERVAL '0.9 hour'),
|
||||
(4008,'Hvorfor er det ligepludselig mig der skal holde styr på om skolen uddeler sko eller ej?', 2000, 5001, NOW() - INTERVAL '0.898 hour'),
|
||||
(4009,'Fordi du er dit barns mor?', 2000, 5003, NOW() - INTERVAL '0.89 hour');
|
||||
|
||||
INSERT INTO users_threads (user_id, thread_id) VALUES (5000, 2000);
|
||||
INSERT INTO users_threads (user_id, thread_id) VALUES
|
||||
(5000, 2000),
|
||||
(5001, 2000),
|
||||
(5002, 2000),
|
||||
(5003, 2000);
|
||||
|
||||
INSERT INTO posts (post_id, group_id, author_id, title, content) VALUES (6000, 1000, 5001, 'Fodbold på torsdag', 'HUSK BOLDEN DENNE GANG!!');
|
||||
|
@ -1,8 +1,8 @@
|
||||
body {
|
||||
background: #fafafa;
|
||||
color: #333333;
|
||||
margin-top: 5rem;
|
||||
font-family: Lato, sans-serif;
|
||||
min-height: 80vh;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
@ -19,6 +19,81 @@ h1, h2, h3, h4, h5, h6 {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.thread-name {
|
||||
color: #333333;
|
||||
text-decoration: none !important;
|
||||
font-size: larger;
|
||||
}
|
||||
|
||||
.author-name {
|
||||
color: #333333;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.thread {
|
||||
border-radius: 20px !important;
|
||||
height: 80vh;
|
||||
}
|
||||
|
||||
.messages {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: auto;
|
||||
height: 60vh;
|
||||
overflow: scroll;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.message-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
margin-bottom: 10px !important;
|
||||
}
|
||||
|
||||
.message-container .message {
|
||||
position: inherit;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: fit-content;
|
||||
max-width: 40%;
|
||||
border-radius: 20px !important;
|
||||
padding-top: 5px !important;
|
||||
padding-bottom: 10px !important;
|
||||
padding-left: 15px !important;
|
||||
padding-right: 15px !important;
|
||||
background-color: rgb(22, 97, 148) !important;
|
||||
color: #ffffff !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
.message-container .timestamp {
|
||||
align-self: flex-start;
|
||||
margin-right: 5px;
|
||||
margin-left: 5px;
|
||||
margin-bottom: 0;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.message-container.self .timestamp {
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.message p {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.message-container.self .message {
|
||||
background-color: rgb(84 158 199) !important;
|
||||
right: 0;
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.message a.author-name {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
|
||||
.group-name {
|
||||
align-self: flex-end;
|
||||
position: inherit;
|
||||
|
@ -1,11 +1,12 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<h1>{{ group.name }}</h1>
|
||||
<hr>
|
||||
{% for post in posts %}
|
||||
<article class="media content-section">
|
||||
<div class="media-body">
|
||||
<div class="article-metadata">
|
||||
<a class="mr-2" href="#">{{ post.author.first_name }} {{ post.author.last_name }}</a>
|
||||
<a class="mr-2 author-name" href="#">{{ post.author.first_name }} {{ post.author.last_name }}</a>
|
||||
<small class="text-muted">{{ post.date_posted }}</small>
|
||||
</div>
|
||||
<h2><a class="article-title" href="#">{{ post.title }}</a></h2>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<article class="media content-section">
|
||||
<div class="media-body">
|
||||
<div class="article-metadata">
|
||||
<a class="mr-2" href="#">{{ post.author.first_name }} {{ post.author.last_name }}</a>
|
||||
<a class="mr-2 author-name" href="#">{{ post.author.first_name }} {{ post.author.last_name }}</a>
|
||||
<small class="text-muted">{{ post.date_posted }}</small>
|
||||
</div>
|
||||
<h2><a class="article-title" href="#">{{ post.title }}</a></h2>
|
||||
|
@ -32,7 +32,7 @@
|
||||
<div class="navbar-nav mr-auto">
|
||||
<a class="nav-item nav-link" href="{{ url_for('Login.home') }}">Forside</a>
|
||||
<a class="nav-item nav-link" href="{{ url_for('Group.groups') }}">Grupper</a>
|
||||
<a class="nav-item nav-link" href="/">Tråde</a>
|
||||
<a class="nav-item nav-link" href="{{ url_for('Threads.threads') }}">Tråde</a>
|
||||
</div>
|
||||
<!-- Navbar Right Side -->
|
||||
<div class="navbar-nav">
|
||||
@ -50,15 +50,6 @@
|
||||
<main role="main" class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
|
22
aula/templates/thread_show.html
Normal file
22
aula/templates/thread_show.html
Normal file
@ -0,0 +1,22 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="thread content-section">
|
||||
<h1>{{ thread.title }}</h1>
|
||||
<hr>
|
||||
<div class="messages">
|
||||
{% for message in messages %}
|
||||
{% if message.author_id == current_user.user_id %}
|
||||
<div class="message-container self">
|
||||
{% else %}
|
||||
<div class="message-container">
|
||||
{% endif %}
|
||||
<div class="content-section message">
|
||||
<a class="author-name" href="#">{{ message.author.first_name }}</a>
|
||||
<p>{{ message.content }}</p>
|
||||
</div>
|
||||
<p class="timestamp">{{ message.created_date }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
@ -1,46 +1,10 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<form method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="form-group">
|
||||
{{ form.sourceAccount.label(class="form-control-label") }}
|
||||
{{ form.sourceAccount(class="form-control")}}
|
||||
</div>
|
||||
<fieldset class="form-group">
|
||||
<div class="form-group">
|
||||
{{ form.amount.label(class="form-control-label") }}
|
||||
{% if form.amount.errors %}
|
||||
{{ form.amount(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.password.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.amount(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
{{ form.targetAccount.label(class="form-control-label") }}
|
||||
{{ form.targetAccount(class="form-control") }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.submit(class="btn btn-outline-info") }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="content-section">
|
||||
<p>Dropdown customer account tuples:</p>
|
||||
<ul class="list-group">
|
||||
{% for n in drop_cus_acc %}
|
||||
<li class="list-group-item list-group-item-light">{{n}}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<br>
|
||||
<p>Same list with a filter: {{ drop_cus_acc|join(', ') }}</p>
|
||||
</div>
|
||||
|
||||
<h1>Tråde</h1>
|
||||
<hr>
|
||||
{% for thread in threads %}
|
||||
<div class="content-section">
|
||||
<a class="thread-name" href="{{ url_for('Threads.show', thread_id = thread.thread_id) }}"">{{thread.title}}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
||||
|
Reference in New Issue
Block a user