Заготовка для отображения записей
This commit is contained in:
parent
e224c9d5f5
commit
6ddcd00cf9
@ -1 +1 @@
|
||||
from . import users
|
||||
from . import users, diary_post
|
||||
22
data/diary_post.py
Normal file
22
data/diary_post.py
Normal file
@ -0,0 +1,22 @@
|
||||
import sqlalchemy
|
||||
from flask_login import UserMixin
|
||||
|
||||
from .db_session import SqlAlchemyBase
|
||||
|
||||
|
||||
class DiaryPost(SqlAlchemyBase, UserMixin):
|
||||
__tablename__ = 'posts'
|
||||
|
||||
id = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
primary_key=True, autoincrement=True)
|
||||
name = sqlalchemy.Column(sqlalchemy.String, nullable=True)
|
||||
text = sqlalchemy.Column(sqlalchemy.String, nullable=True)
|
||||
author = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
sqlalchemy.ForeignKey("users.id"), nullable=True)
|
||||
date = sqlalchemy.Column(sqlalchemy.DateTime, nullable=True)
|
||||
photo = sqlalchemy.Column(sqlalchemy.Text)
|
||||
public = sqlalchemy.Column(sqlalchemy.Boolean, nullable=True)
|
||||
pos_emot = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
||||
nig_emot = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
||||
case = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
||||
link = sqlalchemy.Column(sqlalchemy.Text, nullable=True)
|
||||
@ -3,6 +3,7 @@ from datetime import date
|
||||
import sqlalchemy
|
||||
from flask_login import UserMixin
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
from .db_session import SqlAlchemyBase
|
||||
|
||||
|
||||
@ -13,10 +14,10 @@ class User(SqlAlchemyBase, UserMixin):
|
||||
primary_key=True, autoincrement=True)
|
||||
name = sqlalchemy.Column(sqlalchemy.String, nullable=True)
|
||||
surname = sqlalchemy.Column(sqlalchemy.String, nullable=True)
|
||||
login = sqlalchemy.Column(sqlalchemy.String, nullable=True)
|
||||
login = sqlalchemy.Column(sqlalchemy.String, nullable=True, unique=True)
|
||||
age = sqlalchemy.Column(sqlalchemy.Integer, nullable=True)
|
||||
email = sqlalchemy.Column(sqlalchemy.String,
|
||||
index=True, unique=True, nullable=True)
|
||||
index=True, nullable=True)
|
||||
about = sqlalchemy.Column(sqlalchemy.String, nullable=True)
|
||||
photo = sqlalchemy.Column(sqlalchemy.Text)
|
||||
password = sqlalchemy.Column(sqlalchemy.String, nullable=True)
|
||||
|
||||
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
10
main.py
10
main.py
@ -1,10 +1,11 @@
|
||||
from random import randint
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask_login import LoginManager, login_user, logout_user, login_required
|
||||
from flask_login import LoginManager, login_user, logout_user, login_required, current_user
|
||||
from werkzeug.utils import redirect
|
||||
|
||||
from data import db_session
|
||||
from data.diary_post import DiaryPost
|
||||
from data.users import User
|
||||
from forms.login import LoginForm
|
||||
from forms.register import RegisterForm, Confirmation
|
||||
@ -41,6 +42,13 @@ def main_page():
|
||||
return render_template('base.html', title='moona')
|
||||
|
||||
|
||||
@app.route('/diary', methods=['GET', 'POST'])
|
||||
def diary():
|
||||
db_sess = db_session.create_session()
|
||||
posts = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id).all()
|
||||
return render_template('diary.html', title='moona', item=posts)
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
|
||||
19
static/css/diary.css
Normal file
19
static/css/diary.css
Normal file
@ -0,0 +1,19 @@
|
||||
.bad_user {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
background-color: #1daff0;
|
||||
color: #ffffff;
|
||||
width: 50%;
|
||||
height: 55%;
|
||||
-webkit-border-radius:22px;
|
||||
-moz-border-radius: 22px;
|
||||
border-radius: 22px;
|
||||
border:2px solid #FFFFFF;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.bad_centre {
|
||||
text-align: center;
|
||||
}
|
||||
#image {
|
||||
width: 70%;
|
||||
}
|
||||
62
templates/diary.html
Normal file
62
templates/diary.html
Normal file
@ -0,0 +1,62 @@
|
||||
<link rel="stylesheet" href="../static/css/diary.css">
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% if current_user.is_authenticated %}
|
||||
<div>
|
||||
{% for item in post %}
|
||||
<div>
|
||||
<h2>{{item.name}}</h2>
|
||||
<strong>{{item.text}}</strong>
|
||||
<div class="pos_emot">
|
||||
{% for item2 in item.pos_emot.split('%$%') %}
|
||||
<strong>{{item2}}</strong>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="nig_emot">
|
||||
{% for item2 in item.nig_emot.split('%$%') %}
|
||||
<strong>{{item2}}</strong>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="case">
|
||||
{% for item2 in item.case.split('%$%') %}
|
||||
<strong>{{item2}}</strong>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if item.photo != '' %}
|
||||
<div class="photo">
|
||||
<img width="100" height="100" src="../{{ item.photo }}">
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if item.link != '' %}
|
||||
{% for item2 in item.link %}
|
||||
<div class="link">
|
||||
<a href="{{ item2 }}">Ссылка {{ loop.index }}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if item.public == 1 %}
|
||||
<div class="public_true">Запись опубликована</div>
|
||||
{% else %}
|
||||
<div class="public_false">Запись приватная</div>
|
||||
{% endif %}
|
||||
<div style="style=position:absolute; width:148px; height:44px; left:255px; -webkit-border-radius:
|
||||
22px;-moz-border-radius: 22px;border-radius: 22px; border:2px solid #FFFFFF; background-color:#1daff0; top:
|
||||
98px;"><img src="../{{ current_user.photo }}" width="40" height="40" style="border-radius: 50%">
|
||||
<strong style="color: #ffffff">{{ current_user.name }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="bad_user">
|
||||
<div class="bad_centre">
|
||||
<h1 id="hz1">Вы не авторизованы в системе</h1>
|
||||
<h2 id="hz2">Поэтому вам не доступна страница личного дневника</h2><strong id="sz1">Но вы можете посмотреть
|
||||
публикации других пользователей в разделе <a href="/" style="color:#a9e4ff">Главная</a> или <a
|
||||
href="/publications" style="color:#a9e4ff">Публикации</a></strong>
|
||||
<p></p>
|
||||
<img id="image" src="../static/img/Надпись Moona без фона.png"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user