diff --git a/db/moona_data.db b/db/moona_data.db index dd37cb7..c4061c0 100644 Binary files a/db/moona_data.db and b/db/moona_data.db differ diff --git a/main.py b/main.py index 4077a8c..2498fa5 100644 --- a/main.py +++ b/main.py @@ -100,55 +100,62 @@ def main_page(): if session.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first(): emotion['is_like'] = 1 emotion_for_you.append(emotion) - you_like_that = sorted(list(map(lambda x: session.query(DiaryPost).filter(DiaryPost.id == x).first(), - map(lambda x: x.post, - session.query(Like).filter(Like.user == current_user.id).all()))), - key=lambda x: (len(x.text), 1 if x.photo else 0, -(x.date - datetime.datetime.now()).days)) - emotion_you_like_that = [] - for i in you_like_that: - emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], - 'author': session.query(User).filter(User.id == i.author).first(), 'like': None, 'is_like': 0} - if i.pos_emot: - emotion['pos_emot'] = i.pos_emot.split() + if current_user.is_authenticated: + you_like_that = sorted(list(map(lambda x: session.query(DiaryPost).filter(DiaryPost.id == x).first(), + map(lambda x: x.post, + session.query(Like).filter(Like.user == current_user.id).all()))), + key=lambda x: ( + len(x.text), 1 if x.photo else 0, -(x.date - datetime.datetime.now()).days)) + emotion_you_like_that = [] + for i in you_like_that: + emotion = {id: i.id, 'pos_emot': [], 'nig_emot': [], 'link': [], + 'author': session.query(User).filter(User.id == i.author).first(), 'like': None, 'is_like': 0} + if i.pos_emot: + emotion['pos_emot'] = i.pos_emot.split() + else: + emotion['pos_emot'] = None + if i.nig_emot: + emotion['nig_emot'] = i.nig_emot.split() + else: + emotion['nig_emot'] = None + if i.link: + emotion['link'] = i.link.split() + else: + emotion['link'] = None + like = session.query(Like).filter(Like.post == i.id).all() + if like: + emotion['like'] = len(like) + if current_user.is_authenticated: + if session.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first(): + emotion['is_like'] = 1 + emotion_you_like_that.append(emotion) + quest = session.query(Answer).filter(Answer.user == current_user.id).all() + days_reg = current_user.data_reg - datetime.date.today() + days_reg = abs(days_reg.days) + 1 + if quest: + post_quest = session.query(Quest).filter(Quest.id.in_([i.id_question for i in quest])).all() else: - emotion['pos_emot'] = None - if i.nig_emot: - emotion['nig_emot'] = i.nig_emot.split() - else: - emotion['nig_emot'] = None - if i.link: - emotion['link'] = i.link.split() - else: - emotion['link'] = None - like = session.query(Like).filter(Like.post == i.id).all() - if like: - emotion['like'] = len(like) - if current_user.is_authenticated: - if session.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first(): - emotion['is_like'] = 1 - emotion_you_like_that.append(emotion) - quest = session.query(Answer).filter(Answer.user == current_user.id).all() - days_reg = current_user.data_reg - datetime.date.today() - days_reg = abs(days_reg.days) + 1 - if quest: - post_quest = session.query(Quest).filter(Quest.id.in_([i.id_question for i in quest])).all() + post_quest = [] + while len(post_quest) < days_reg: + post_quest.append( + session.query(Quest).filter(Quest.id.notin_([i.id for i in post_quest])).first()) + ans = [] + for i in post_quest: + if i is not None: + ans_id = session.query(Answer).filter( + Answer.id_question == i.id and Answer.user.id == current_user.id).first() + if ans_id is not None: + ans.append(ans_id) + post_quest = post_quest[::-1] + ans = ans[::-1] + ans2 = {} + for i in ans: + ans2[i.id_question] = i else: - post_quest = [] - while len(post_quest) < days_reg: - post_quest.append( - session.query(Quest).filter(Quest.id.notin_([i.id for i in post_quest])).first()) - ans = [] - for i in post_quest: - if i is not None: - ans_id = session.query(Answer).filter( - Answer.id_question == i.id and Answer.user.id == current_user.id).first() - if ans_id is not None: - ans.append(ans_id) - post_quest = post_quest[::-1] - ans = ans[::-1] - ans2 = {} - for i in ans: - ans2[i.id_question] = i + you_like_that = [] + emotion_you_like_that = None + post_quest = None + ans2 = None return render_template('main.html', title='moona', for_me_post=for_you_post, emotion_for_you=emotion_for_you, you_like_that=you_like_that, emotion_you_like_that=emotion_you_like_that, question=post_quest, diff --git a/static/css/diary.css b/static/css/diary.css index af196d0..52764e2 100644 --- a/static/css/diary.css +++ b/static/css/diary.css @@ -26,9 +26,8 @@ summary { .my_author { width:40%; height:5%; - left:10%; - -webkit-border-radius: 22px; - -moz-border-radius: 22px; + margin-left:30%; + margin-right:30%; border-radius: 22px; border:2px solid #ffffff; background-color:#1daff0; @@ -43,12 +42,11 @@ summary { .card-body { background-color: #7fc3ff; } -#all_my_post, #all_my_post1 { +.all_my_post { margin-left: auto; margin-right: auto; } -#my_post, #my_post1 { - text-align: center; +.card { margin-left: auto; margin-right: auto; background-color: #7fc3ff; @@ -56,15 +54,14 @@ summary { margin-bottom: 20px; } .my_author, .my_post_zag { - margin-left: 50%; - margin-right: auto; - margin-top: -20%; + text-align: center; } .pub, .private { - width: 60%; + width: 55%; height: 10%; - margin-left: auto; - margin-right: auto; + margin-left:25%; + margin-right: 25%; + text-align: center; } #add_post { margin-top: 20px; @@ -72,6 +69,9 @@ summary { } #edit_btn, #edit_btn1 { background-color: #c5f1ff; + margin-left: 10%; + margin-right: auto; + margin-top: 15px; } input[type=text], input[type=email], input[type=password], input[type=file], input[type=number]{ padding:10px; @@ -98,7 +98,7 @@ textarea { margin-left: 20px; } #row2, #row1 { - width: 30%; + width: 32%; } #row1, #row2, #all_my_question { display:inline-block; @@ -114,9 +114,8 @@ textarea { } .question, .my_post { background-color:#7fc3ff; - border-radius: 22px; - width: 100%; margin-left: 10px; + margin-right: 10px; } .is_ans { background-color:#ddefff; @@ -138,7 +137,7 @@ table { margin-right: auto; } #row1_div, #row2_div { -width: 98%; + width: 98%; } td { margin: 20px; @@ -148,4 +147,8 @@ width: 25%; } .is_ans { width: 95%; +} +.card-text { + color:#ffffff; + text-align: center; } \ No newline at end of file diff --git a/templates/diary.html b/templates/diary.html index 0ffbd7b..b017fe4 100644 --- a/templates/diary.html +++ b/templates/diary.html @@ -19,95 +19,100 @@

Публикации

-
+
{% if my_post != [] %} {% for item in pub_post %} - -
+
{% if item.photo != None %} ... {% endif %} -
- {% if item.name != None %} -

{{item.name}}

- {% endif %} -

{{item.date}}

- {% if item.text != None %} -

{{item.text}}

- {% endif %} -
-
    -
  • - {% if emotion_pub[loop.index0]['pos_emot'] != None %} -
      - {% for item2 in emotion[loop.index0]['pos_emot'] %} -
    • -
      {{item2}}
      -
    • - {% endfor %} -
    - {% endif %} -
  • -
  • +
    + {% if item.name != None %} +

    {{item.name}}

    + {% endif %} +

    {{item.date}}

    + {% if item.text != None %} +

    {{item.text}}

    + {% endif %} +
    +
      + {% if emotion_pub[loop.index0]['pos_emot'] != None %} +
    • +
        + {% for item2 in emotion_pub[loop.index0]['pos_emot'] %} +
      • +
        {{item2}}
        +
      • + {% endfor %} +
      +
    • + {% endif %} {% if emotion_pub[loop.index0]['nig_emot'] != None %} -
        +
      • +
          {% for item2 in emotion_pub[loop.index0]['nig_emot'] %}
        • {{item2}}
        • {% endfor %} -
        +
      + {% endif %} - -
    • {% if emotion_pub[loop.index0]['link'] != None %} - +
    • {% endif %} - -
    -
    - {% if item.public == 1 or item.public == 'True' %} - - {% else %} - - {% endif %} -
    - {{ current_user.name }} -
    -
+
{% endfor %} @@ -121,26 +126,26 @@
-

Мои мысли

-
+

Мои мысли

+
{% if my_post != [] %} {% for item in my_post %} -
+
{% if item.photo != None %} ... {% endif %} -
- {% if item.name != None %} -

{{item.name}}

- {% endif %} -

{{item.date}}

- {% if item.text != None %} -

{{item.text}}

- {% endif %} -
-
    -
  • - {% if emotion_pub[loop.index0]['pos_emot'] != None %} +
    + {% if item.name != None %} +

    {{item.name}}

    + {% endif %} +

    {{item.date}}

    + {% if item.text != None %} +

    {{item.text}}

    + {% endif %} +
    +
      + {% if emotion[loop.index0]['pos_emot'] != None %} +
      • {% for item2 in emotion[loop.index0]['pos_emot'] %}
      • @@ -149,54 +154,60 @@
      • {% endfor %}
      +
    • {% endif %} - -
    • - {% if emotion_pub[loop.index0]['nig_emot'] != None %} -
        - {% for item2 in emotion_pub[loop.index0]['nig_emot'] %} + {% if emotion[loop.index0]['nig_emot'] != None %} +
      • +
          + {% for item2 in emotion[loop.index0]['nig_emot'] %}
        • {{item2}}
        • {% endfor %} -
        +
      +
    • {% endif %} - -
    • - {% if emotion_pub[loop.index0]['link'] != None %} -
        - {% for item2 in emotion_pub[loop.index0]['link'] %} + {% if emotion[loop.index0]['link'] != None %} +
      • + +
      +
    • {% endif %} - -
    -
    - {% if item.public == 1 or item.public == 'True' %} - - {% else %} - - {% endif %} -
    - {{ current_user.name }} -
    -
+
+ {% if item.public == 1 or item.public == 'True' %} + + {% else %} + + {% endif %} +
+ {{ current_user.name }} +
+
{% endfor %} diff --git a/templates/main.html b/templates/main.html index aaa9bd8..bf6693e 100644 --- a/templates/main.html +++ b/templates/main.html @@ -17,6 +17,7 @@
+ {% if current_user.is_authenticated %}

Вопросы дня

@@ -38,6 +39,9 @@ {% endfor %}
+ {% else %} +

Чтобы увидеть вопросы дня войдите в аккаунт

+ {% endif %}
@@ -225,7 +229,7 @@ {% endif %}