add new question

ajax_post
bug_creator 3 years ago
parent ee04c354f6
commit 13a51a87a1

@ -9,7 +9,7 @@ from werkzeug.utils import secure_filename
from . import main
from .forms import UploadPhotoForm, CommentForm, PostMdForm
from .. import db, csrf
from ..models import Permission, User, Post, Comment, Notification, Like, Transaction, Activity, Collect, Want
from ..models import Permission, User, Post, Comment, Notification, Like, Transaction, Activity, Collect, Want, Question
from ..decorators import permission_required
@ -282,13 +282,14 @@ def user(username):
wanting = user.wanted_Activity
posts = user.posts.order_by(Post.timestamp.desc())
questions=user.questions.order_by(Question.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,
return render_template('user.html', user=user, posts=posts, questions=questions,liking_posts=liking_posts, activities=activities,
transactionsInProfile=transactions, collects=collects, wants=wants, )
@ -672,3 +673,35 @@ def new_post_md():
flash("You have just posted a posting", 'success')
return redirect(url_for('.index'))
return render_template('new_posting/new_mdpost.html', form=form)
@main.route('/new_question_md', methods=['GET', 'POST'])
@login_required
def new_question_md():
form = PostMdForm()
if current_user.can(Permission.WRITE) and form.validate_on_submit():
title = request.form.get('title')
body = form.body.data
if request.form.get('anonymous') == "on":
is_anonymous = True
else:
is_anonymous = False
if title == "":
flash("Title cannot be None!")
return render_template('new_posting/new_mdpost.html', form=form)
body_html = request.form['test-editormd-html-code']
question = Question(title=title,
body=body,
body_html=body_html,
is_anonymous=is_anonymous,
author=current_user._get_current_object())
question.recent_activity = datetime.utcnow()
db.session.add(question)
db.session.commit()
if question.is_anonymous:
flash("You have just posted a posting anonymously", 'success')
else:
flash("You have just posted a posting", 'success')
return redirect(url_for('.index'))
return render_template('new_posting/new_mdquestion.html', form=form)

@ -0,0 +1,46 @@
<ul class="posts list-unstyled">
{% for post in questions %}
{% if post.is_anonymous==False %}
<li class="post">
<div class="post-box">
<div class="post-content">
<h3 class="post-title">
<a href="{{ url_for('.post', id=post.id) }}">{{ post.title }}</a>
</h3>
<div class="post-body">
<p>
{% if post.body_html %}
{{ post.body_html |safe|striptags|truncate(260,killwords=Flase,leeway=0) }}
{% else %}
{{ post.body |truncate(200,killwords=Flase,leeway=0)}}
{% endif %}
<small><a href="{{ url_for('.post', id=post.id) }}"><B>Read More</B></a></small>
</p>
</div>
<div class="post-footer">
<span class="post-date">
<span class="glyphicon glyphicon-time"></span>
{{ 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>
</div>
</li>
{% endif %}
{% endfor %}
</ul>

@ -330,7 +330,7 @@
<div class="inner2-left col-sm-3">
<div class="new-posts">
<div>
<a href="{{ url_for('.new_post_md') }}">
<a href="{{ url_for('.new_question_md') }}">
<svg class="icon" viewBox="0 0 1024 1024" version="1.1" width="40" height="40">
<defs>
<style type="text/css"></style>
@ -344,7 +344,7 @@
</svg>
</a>
</div>
<div class="icon-word">New Post</div>
<div class="icon-word">Question</div>
</div>
</div>
<div class="inner2-left col-sm-3">

@ -0,0 +1,105 @@
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}New Post (Markdown) {% endblock %}
{%block styles%}
{{super()}}
<link rel="stylesheet" href="{{url_for('static',filename='editormd/css/editormd.min.css')}}">
{%endblock%}
{%block scripts%}
{{super()}}
<script src="{{ url_for('static',filename='editormd/examples/js/jquery.min.js') }}"></script>
<script src="{{ url_for('static',filename='editormd/editormd.min.js') }}"></script>
<script>
window.onload = function(){
document.getElementById('title').addEventListener('keydown',function(e){
if(e.keyCode!=13) return;
e.preventDefault();
this.value += '';
});
};
</script>
<script>
var testEditor;
$(function(){
testEditor=editormd("test-editormd",{
placeholder:'This editor supports Markdown editing, write on the left, preview on the right',
{#width:'1130px',#}
height:'600px',
syncScrolling : "single",
path:"{{url_for('static',filename='editormd/lib/')}}",
saveHTMLToTextarea: true,
emoji: true,
taskList: true,
toolbarIcons : function() { //自定义工具栏
return ["undo","redo","search","|","bold","del","italic","quote",
"uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|",
"list-ul","list-ol","hr","|","link","reference-link","image",
"table","code","preformatted-text","code-block","datetime",
"emoji","pagebreak","|","clear","watch","preview"]
},
});
})
</script>
{%endblock%}
{% block page_content %}
<div>
{% if current_user.can(Permission.WRITE) %}
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<div class="form-control col-md-12" style="margin-bottom: 20px;margin-top: 20px;width: 100%;height: auto">
{# <label class="WriteIndex-titleInput Input-wrapper Input-wrapper--multiline">#}
<textarea id="title" name="title" rows="1" class="Input" maxlength="30"
placeholder="Enter Title (Max: 30 letters)"
style="
-webkit-tap-highlight-color: rgba(26,26,26,0);
-webkit-box-flex: 1;
{# flex: 1 1;#}
{# padding: 0;#}
font-family: inherit;
resize: none;
{# color: #1a1a1a;#}
overflow: hidden;
{# min-height: 44px;#}
display: block;
width: 100%;
border: 0;
font-size: 24px;
{# line-height: 1.4;#}
{# font-weight: 600;#}
outline: none;
box-shadow: none;
height: 100%;"></textarea>
{# </label>#}
</div>
{{form.hidden_tag()}}
<div id="test-editormd" class="form-control col-md-12" style="width: 100%">
{{form.body(class="form-control",style="display:none;",id="ts")}}
</div>
<div style="text-align: right;margin-bottom: 20px" >
<div class="checkbox" style="display: inline-block;">
<label>
<input name="anonymous" type="checkbox"> anonymous
</label>
</div>
<button type="submit" class="btn btn-primary" style="width: 120px;margin-left: 20px">submit</button>
</div>
</form>
{% endif %}
</div>
{% endblock %}

@ -91,7 +91,10 @@
<div class="tabbable">
<ul class="nav post-nav">
<li class="active" id="btn-1">
<a href="#panel-1" data-toggle="tab">MyPosts</a>
<a href="#panel-1" data-toggle="tab">My answers</a>
</li>
<li id="btn-7">
<a href="#panel-7" data-toggle="tab">My questions</a>
</li>
<li id="btn-2">
<a href="#panel-2" data-toggle="tab">Likes</a>
@ -117,6 +120,11 @@
<div class="tab-pane active" id="panel-1">
<ul class="posts list-unstyled">
{% include 'Posts/_postsInProfile.html' %}
</ul>
</div>
<div class="tab-pane active" id="panel-7">
<ul class="posts list-unstyled">
{% include 'Posts/_answersInProfile.html' %}
</ul>
</div>
<div class="tab-pane" id="panel-2">
@ -164,18 +172,23 @@
var l4 = document.getElementById('btn-4')
var l5 = document.getElementById('btn-5')
var l6 = document.getElementById('btn-6')
var l7 = document.getElementById('btn-7')
var content1 = document.getElementById('panel-1')
var content2 = document.getElementById('panel-2')
var content3 = document.getElementById('panel-3')
var content4 = document.getElementById('panel-4')
var content5 = document.getElementById('panel-5')
var content6 = document.getElementById('panel-6')
var content7 = document.getElementById('panel-7')
l1.onclick = function () {
this.className = 'active'
{#this.className = 'active'#}
content7.className=''
content1.className = 'active'
l7.className=''
l2.className = ''
content7.className='tab-pane'
content2.className = 'tab-pane'
l5.className = ''
content5.className = 'tab-pane'
@ -192,6 +205,29 @@
}
l7.onclick = function () {
{#this.className = 'active'#}
{#content1.className=''#}
content7.className = 'active'
l1.className=''
l2.className = ''
content2.className = 'tab-pane'
content1.className='tab-pane'
l5.className = ''
content5.className = 'tab-pane'
{% if user.can(Permission.ACTIVITY) %}
l4.className = ''
content4.className = 'tab-pane'
{% else %}
l3.className = ''
content3.className = 'tab-pane'
l6.className = ''
content6.className = 'tab-pane'
{% endif %}
}
l2.onclick = function () {
this.className = 'active'
content2.className = 'active'

Loading…
Cancel
Save