Merge branch 'master' of csgitlab.ucd.ie:19206226/q-a_platform into ajax_post

 Conflicts:
	data-dev.sqlite
ajax_post
Yang Liuxin 3 years ago
commit 5f0e18063f

@ -2,13 +2,13 @@ import os
from datetime import datetime
from operator import or_
from flask import render_template, redirect, url_for, flash, request, \
current_app, make_response
current_app, make_response, jsonify
from flask_login import login_required, current_user
from sqlalchemy.sql.functions import func
from werkzeug.utils import secure_filename
from . import main
from .forms import UploadPhotoForm, CommentForm, PostMdForm
from .. import db
from .. import db, csrf
from ..models import Permission, User, Post, Comment, Notification, Like, Transaction, Activity, Collect, Want
from ..decorators import permission_required
@ -61,7 +61,8 @@ def index_transaction():
li_num = db.session.query(func.count(Want.wanter_id)).filter_by(wanted_Activity_id=item.id).scalar()
item.important = li_num
hot_activity = li.order_by(Activity.important.desc())
return render_template('index/index_transactions.html', transactions=transactions, posts5=hot, hot_activity=hot_activity)
return render_template('index/index_transactions.html', transactions=transactions, posts5=hot,
hot_activity=hot_activity)
else:
inf = request.form["search"]
return redirect(url_for('.query', content=inf))
@ -91,7 +92,8 @@ def index_activity():
li_num = db.session.query(func.count(Want.wanter_id)).filter_by(wanted_Activity_id=item.id).scalar()
item.important = li_num
hot_activity = li.order_by(Activity.important.desc())
return render_template('index/index_activities.html', activities=activities, posts5=hot, hot_activity=hot_activity)
return render_template('index/index_activities.html', activities=activities, posts5=hot,
hot_activity=hot_activity)
else:
inf = request.form["search"]
return redirect(url_for('.query', content=inf))
@ -268,7 +270,8 @@ def query_transaction():
page, per_page=current_app.config['FLASKY_FOLLOWERS_PER_PAGE'],
error_out=False)
query = pagination.items
return render_template('querytransaction.html', query=query, title="Result of query", pagination=pagination, inf=inf)
return render_template('querytransaction.html', query=query, title="Result of query", pagination=pagination,
inf=inf)
@main.route('/user/<username>')
@ -279,13 +282,14 @@ def user(username):
wanting = user.wanted_Activity
posts = user.posts.order_by(Post.timestamp.desc())
liking_posts = [{'post': item.liked_post, 'timestamp': item.timestamp} for item in liking.order_by(Like.timestamp.desc())]
liking_posts = [{'post': item.liked_post, 'timestamp': item.timestamp} for item in
liking.order_by(Like.timestamp.desc())]
transactions = user.transactions.order_by(Transaction.timestamp.desc())
activities = user.activities.order_by(Activity.timestamp.desc())
collects = collecting.order_by(Collect.timestamp.desc())
wants = wanting.order_by(Want.timestamp.desc())
return render_template('user.html', user=user, posts=posts, liking_posts=liking_posts, activities=activities,
transactionsInProfile=transactions, collects=collects, wants=wants,)
transactionsInProfile=transactions, collects=collects, wants=wants, )
@main.route('/notification')
@ -505,6 +509,30 @@ def like(post_id):
return redirect(url_for('.index', id=post_id))
@main.route('/AJAXlike/<post_id>',methods=['POST'], strict_slashes=False)
@login_required
@csrf.exempt
@permission_required(Permission.FOLLOW)
def AJAXlike(post_id):
post = Post.query.filter_by(id=post_id).first()
if post is not None:
if(current_user.is_liking(post)):
current_user.dislike(post)
post.dislike(current_user)
db.session.commit()
return jsonify({'code': 200, 'like': False, 'num':post.liker.count()})
else:
current_user.like(post)
post.like(current_user)
post.recent_activity = datetime.utcnow()
db.session.commit()
return jsonify({'code': 200, 'like': True, 'num':post.liker.count()})
@main.route('/likeinpost/<post_id>')
@login_required
@permission_required(Permission.FOLLOW)

@ -462,6 +462,7 @@ class Like(db.Model):
liked_post = db.relationship('Post', back_populates='liker', lazy='joined')
class Collect(db.Model):
__tablename__ = 'collect'
collecter_id = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)

File diff suppressed because it is too large Load Diff

@ -70,17 +70,58 @@
</a>
{# 喜欢#}
{% if not current_user.is_liking(post) %}
<a class="icon-btn" style="float:right; margin-right: 15px" href="{{ url_for('.like', post_id=post.id) }}#{{ post.id }}">
{# {% if not current_user.is_liking(post) %}#}
{# <a class="icon-btn" style="float:right; margin-right: 15px" href="{{ url_for('.like', post_id=post.id) }}#{{ post.id }}">#}
{# <span class="glyphicon glyphicon-heart-empty"></span>#}
{# <span>{{ post.liker.count() }} likes</span>#}
{# </a>#}
<a class="icon-btn" style="float:right; margin-right: 15px" href="javascript:void (0);" onclick="{
var csrftoken = $('meta[name=csrf-token]').attr('content');
var _this=this;
var span1=this.childNodes[1];
var span2=this.childNodes[3];
{#console.log(this.childNodes[3]);#}
{#console.log(this.childElementCount);#}
var sendData={
'csrf_token':csrftoken
};
$.ajax({
url: '{{ url_for('.AJAXlike', post_id=post.id) }}',
type: 'POST',
{#dataType: 'json',#}
{#contentType: 'application/json',#}
{#data: JSON.stringify(sendData),#}
success: function(result) {
console.log(result);
if(result.like){
span1.setAttribute('class', 'glyphicon glyphicon-heart');
}else{
span1.setAttribute('class', 'glyphicon glyphicon-heart-empty');
}
span2.innerText=result.num+' likes';
{#span1.setAttribute('href', '{{ url_for('.dislike', post_id=post.id) }}');#}
},
error:function(msg){
console.log(msg);
}
})
}">
{% if not current_user.is_liking(post) %}
<span class="glyphicon glyphicon-heart-empty"></span>
<span>{{ post.liker.count() }} likes</span>
</a>
{% else %}
<a class="icon-btn" style="float:right; margin-right: 15px" href="{{ url_for('.dislike', post_id=post.id) }}#{{ post.id }}">
{% else %}
<span class="glyphicon glyphicon-heart"></span>
{% endif %}
<span>{{ post.liker.count() }} likes</span>
</a>
{% endif %}
{# {% else %}#}
{# <a class="icon-btn" style="float:right; margin-right: 15px" href="{{ url_for('.dislike', post_id=post.id) }}#{{ post.id }}">#}
{# <span class="glyphicon glyphicon-heart"></span>#}
{# <span>{{ post.liker.count() }} likes</span>#}
{# </a>#}
{# {% endif %}#}
</div>
</div>
</div>

@ -24,11 +24,17 @@
{{ moment(post.timestamp).fromNow() }}
</span>
{% if current_user == post.author %}
{# 删除#}
<a class="icon-btn" href="{{ url_for('main.delete_post_inProfile', post_id=post.id)}}">
<span class="glyphicon glyphicon-trash"></span>
<span>delete</span>
</a>
{# 修改 #}
<a class="icon-btn" href="#">
<span class="glyphicon glyphicon-pencil"></span>
<span>modification</span>
</a>
{% endif %}
</div>
</div>

@ -7,13 +7,15 @@
{% block head %}
{{ super() }}
<style>
body {
padding-top: 60px;
background-color: #f5f5f5;
}
</style>
{{ super() }}
<style>
body {
padding-top: 60px;
background-color: #f5f5f5;
}
</style>
<meta name="csrf-token" content="{{ csrf_token() }}">
<script type="application/javascript" src="{{ url_for('static',filename='js/jquery-3.6.0.js') }}"></script>
{% endblock %}
@ -46,22 +48,27 @@
<ul class="nav navbar-nav navbar-right">
{% if current_user.is_authenticated %}
{# 通知#}
{# 通知#}
<li>
<a href="{{ url_for('main.notification') }}" >
<a href="{{ url_for('main.notification') }}">
<svg viewBox="0 0 1024 1024" width="20" height="20">
<defs><style type="text/css"></style></defs>
<path d="M892.343 738.743c7.314 0 21.943 0 29.257 7.314-29.257-21.943-51.2-58.514-51.2-95.086V424.23c0-168.229-117.029-307.2-285.257-343.772v-7.314C585.143 36.57 548.57 0 512 0s-80.457 36.571-80.457 73.143v7.314C270.629 117.03 153.6 256 153.6 424.23V650.97c0 36.572-21.943 73.143-51.2 95.086 7.314-7.314 14.629-7.314 29.257-7.314-29.257 0-51.2 21.943-51.2 51.2s21.943 51.2 51.2 51.2h768c29.257 0 51.2-21.943 51.2-51.2-7.314-21.943-29.257-43.886-58.514-51.2zM512 1024c73.143 0 131.657-58.514 131.657-131.657H380.343C380.343 965.486 438.857 1024 512 1024z" fill="#3BA9F6" p-id="1699">
<defs>
<style type="text/css"></style>
</defs>
<path d="M892.343 738.743c7.314 0 21.943 0 29.257 7.314-29.257-21.943-51.2-58.514-51.2-95.086V424.23c0-168.229-117.029-307.2-285.257-343.772v-7.314C585.143 36.57 548.57 0 512 0s-80.457 36.571-80.457 73.143v7.314C270.629 117.03 153.6 256 153.6 424.23V650.97c0 36.572-21.943 73.143-51.2 95.086 7.314-7.314 14.629-7.314 29.257-7.314-29.257 0-51.2 21.943-51.2 51.2s21.943 51.2 51.2 51.2h768c29.257 0 51.2-21.943 51.2-51.2-7.314-21.943-29.257-43.886-58.514-51.2zM512 1024c73.143 0 131.657-58.514 131.657-131.657H380.343C380.343 965.486 438.857 1024 512 1024z"
fill="#3BA9F6" p-id="1699">
</path>
</svg>
<span class="badge" style="margin-bottom: 10px"></span>
</a>
</li>
{# 下拉菜单#}
{# 下拉菜单#}
<li class="dropdown">
<a href="{{ url_for('main.notification') }}" class="dropdown-toggle" data-toggle="dropdown">Account<b class="caret"></b></a>
<a href="{{ url_for('main.notification') }}" class="dropdown-toggle"
data-toggle="dropdown">Account<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{{ url_for('main.user', username=current_user.username) }}">MY Profile</a></li>
<li><a href="{{ url_for('main.user', username=current_user.username) }}">MY
Profile</a></li>
<li><a href="{{ url_for('auth.change_password') }}">MY Account</a></li>
<li><a href="{{ url_for('auth.logout') }}">Log Out</a></li>
</ul>
@ -71,33 +78,43 @@
<li><a href="{{ url_for('auth.login') }}">Log In</a></li>
{% endif %}
</ul>
</div>
</ul>
</div>
</nav>
</div>
</nav>
{% endblock %}
{% block content %}
<div class="container">
<!-- flash消息显示区-->
{% for message in get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}
{% for message in get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}
{% block page_content %}
<!-- 其他模版文件中的东西-->
<!-- 其他模版文件中的东西-->
{% endblock %}
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
{% endblock %}
{% block scripts %}
<script>
var csrftoken = $("head > meta:nth-child(5)").attr('content');
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader('X-CSRFToken', csrftoken)
}
}
})
</script>
{{ super() }}
{{ moment.include_moment() }}
{% endblock %}

@ -9,6 +9,8 @@
<link href="{{ url_for('static',filename='home.css') }}" rel="stylesheet">
<link href="{{ url_for('static',filename='posts.css') }}" rel="stylesheet">
<link href="{{ url_for('static',filename='interact.css') }}" rel="stylesheet">
{% endblock %}

Binary file not shown.

@ -40,7 +40,6 @@ def check_bypass_status():
bypass_status = "fail"
geetest_dict[GEETEST_BYPASS_STATUS_KEY] = bypass_status
print("bypass状态已经获取并存入redis当前状态为-{}".format(bypass_status))
time.sleep(CYCLE_TIME)
check_bypass_status()

@ -0,0 +1,3 @@
kubectl apply -f web-methodology-deployment.yaml
kubectl apply -f web-methodology-services.yaml

@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-methodology-deployment
labels:
web: methodology
spec:
replicas: 2
selector:
matchLabels:
web: methodology
template:
metadata:
labels:
web: methodology
spec:
containers:
- name: web-methodology
image: echo0821/web-methodology
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: web-methodology-services
spec:
selector:
web: methodology
ports:
- protocol: TCP
port: 80
targetPort: 5000

@ -0,0 +1,24 @@
import unittest
from app import models
class TestModels(unittest.TestCase):
def testExist(self):
self.assertIsNotNone(models.db)
self.assertIsNotNone(models.User)
self.assertIsNotNone(models.Role)
self.assertIsNotNone(models.Permission)
self.assertIsNotNone(models.Post)
self.assertIsNotNone(models.AnonymousUser)
self.assertIsNotNone(models.Collect)
self.assertIsNotNone(models.Comment)
self.assertIsNotNone(models.Follow)
self.assertIsNotNone(models.Like)
self.assertIsNotNone(models.Activity)
self.assertIsNotNone(models.Notification)
self.assertIsNotNone(models.Want)
if __name__ == '__main__':
unittest.main()

@ -0,0 +1,22 @@
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save