Заготовка для отображения записей, заготовка для добавления записей

This commit is contained in:
mrmur 2022-04-06 18:08:43 +05:00
parent 6ddcd00cf9
commit 775e34d506
10 changed files with 110 additions and 28 deletions

View File

@ -18,5 +18,4 @@ class DiaryPost(SqlAlchemyBase, UserMixin):
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)

Binary file not shown.

View File

@ -1,3 +1,5 @@
#1daff0
#a9e4ff
#42e6ec
#c5f1ff
#7fc3ff

14
forms/post.py Normal file
View File

@ -0,0 +1,14 @@
from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed
from wtforms import StringField, TextAreaField, FileField, BooleanField
from wtforms.validators import DataRequired
class AddPost(FlaskForm):
name = StringField('Название')
text = TextAreaField('Расскажите, что нового?')
photo = FileField('Прикрепите фото', validators=[FileAllowed(['jpg', 'png'])])
public = BooleanField('Опубликовать?')
pos_emot = TextAreaField('Какие позитивные эмоции вы испытываете?')
nig_emot = TextAreaField('Какие негативные эмоции вы испытываете?')
link = TextAreaField('Вы можете оставить тут ссылки через пробел')

View File

@ -9,7 +9,7 @@ class RegisterForm(FlaskForm):
name = StringField('Имя', validators=[DataRequired()])
surname = StringField('Фамилия', validators=[DataRequired()])
login = StringField('Логин', validators=[DataRequired()])
age = IntegerField('Age', validators=[DataRequired()])
age = IntegerField('Возраст', validators=[DataRequired()])
about = TextAreaField('Расскажите о себе', default='')
photo = FileField('Фото', validators=[FileAllowed(['jpg', 'png'])])
password = PasswordField('Пароль', validators=[DataRequired()])

13
main.py
View File

@ -42,11 +42,19 @@ def main_page():
return render_template('base.html', title='moona')
@app.route('/add_post', methods=['GET', 'POST'])
def add_post():
return render_template('post.html')
@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)
if current_user.is_authenticated:
posts = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id).all()
else:
posts = None
return render_template('diary.html', title='moona', post=posts)
@app.route('/logout')
@ -83,6 +91,7 @@ def confirmation():
if not send_msg:
secret_code = secret_key()
mail(f'Ваш секретный код: {secret_code}', form.email.data, 'Moona Код')
print(secret_code)
send_msg = True
if conf.validate_on_submit():
if str(conf.code_key.data).strip() == str(secret_code).strip():

View File

@ -17,3 +17,32 @@ text-align: center;
#image {
width: 70%;
}
#all_my_post {
width: 30%;
margin-left: auto;
margin-right: auto;
}
#my_post {
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 25px;
background-color: #7fc3ff;
border-radius: 22px;
}
.my_author, .my_post_zag {
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 25px;
}
#pub, #private {
width: 60%;
height: 10%;
margin-left: auto;
margin-right: auto;
}
#add_post {
margin-top: 20px;
margin-left: 85%;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

@ -4,47 +4,58 @@
{% block content %}
{% if current_user.is_authenticated %}
<div>
<a href="/add_post" id="add_post" class="btn btn-primary" style="background-color:#1daff0"><strong>Добавить
запись</strong></a>
</div><h1 class="my_post_zag">Мои записи</h1>
<div class="card" style="width: 18rem;" id="all_my_post">
{% for item in post %}
<div>
<h2>{{item.name}}</h2>
<strong>{{item.text}}</strong>
<div class="card-body" id="my_post">
<h2 class="card-title" id="my_post_zag" style="color:#c5f1ff">{{item.name}}</h2>
<strong class="card-text" id="my_text" style="color:#ffffff">{{item.text}}</strong>
{% if item.pos_emot != None %}
<div class="pos_emot">
{% for item2 in item.pos_emot.split('%$%') %}
{% for item2 in item.pos_emot %}
<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 != '' %}
{% if item.nig_emot != None %}
<div class="nig_emot">
{% for item2 in item.nig_emot %}
<strong>{{item2}}</strong>
{% endfor %}
</div>
{% endif %}
{% if item.case != None %}
<div class="case">
{% for item2 in item.case %}
<strong>{{item2}}</strong>
{% endfor %}
</div>
{% endif %}
{% if item.photo != None %}
<div class="photo">
<img width="100" height="100" src="{{ item.photo }}">
</div>
{% endif %}
{% if item.link != None %}
{% 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>
{% if item.public == 1 or item.public == 'True' %}
<div class="alert alert-success" role="alert" id="pub">Запись опубликована {{item.public}}</div>
{% else %}
<div class="public_false">Запись приватная</div>
<div class="alert alert-danger" role="alert" id="ptivate">Запись приватная</div>
{% endif %}
<div style="style=position:absolute; width:148px; height:44px; left:255px; -webkit-border-radius:
<div class="my_author" 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>
<strong style="color:#ffffff">{{item.date}}</strong>
</div>
{% endfor %}
</div>

18
templates/post.html Normal file
View File

@ -0,0 +1,18 @@
<link rel="stylesheet" href="../static/css/diary.css">
{% extends "base.html" %}
{% block content %}
{% if current_user.is_authenticated %}
{% 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 %}