示例#1
0
 def post(form):
     topic = Topic()
     topic.title = form.title.data
     topic.content = html_clean(form.content.data)
     topic.is_markdown = True if form.choice.data == 1 else False
     topic.uid = make_uid()
     topic.author = current_user
     tags = sp(',|;|,|;| ', form.tags.data)
     tags = [x for x in list(set(tags)) if x != ''][:4]
     post_tags = []
     for tag in tags:
         if tag != '':
             exsit_tag = Tags.query.filter_by(tagname=tag).first()
             if exsit_tag is not None:
                 post_tags.append(exsit_tag)
                 if exsit_tag not in current_user.following_tags:
                     current_user.following_tags.append(exsit_tag)
             else:
                 t = Tags()
                 t.tagname = tag
                 post_tags.append(t)
                 current_user.following_tags.append(t)
     topic.tags = post_tags
     topic.board_id = form.category.data
     db.session.add(topic)
     db.session.commit()
     current_user.following_topics.append(topic)
     topic.board.count.topics += 1
     topic.board.count.all_topics += 1
     db.session.commit()
     RedisData.set_topics()
     return topic
示例#2
0
 def set_topics(form):
     topic = Topic()
     topic.title = form.title.data
     topic.content = form.content.data
     topic.uid = make_uid()
     topic.author = current_user
     tags = sp(',|;|,|;| ', form.tags.data)
     tags = list(set(tags))[:4]
     post_tags = []
     for tag in tags:
         if tag != '':
             exsit_tag = Tags.query.filter_by(tagname = tag).first()
             if exsit_tag is not None:
                 post_tags.append(exsit_tag)
             else:
                 t = Tags()
                 t.tagname = tag
                 post_tags.append(t)
     topic.tags = post_tags
     topic.board_id = form.category.data
     db.session.add(topic)
     db.session.commit()
     topic.board.count.topics += 1
     topic.board.count.all_topics += 1
     db.session.commit()
     RedisData.set_topics()
示例#3
0
def question(class_url):
    error = None
    form = QuestionForm()
    fileform = PhotoForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        choice = form.choice.data
        tags = form.tags.data
        tags = sp(',|;|,|;| ', tags)
        tags = list(set(tags))[:4]
        post_tags = []
        for tag in tags:
            if tag != '':
                t = Tags(author=current_user.name, name=tag)
                post_tags.append(t)
        question = Questions(title=title, content=content, kind=g.forums_url)
        question.tags = post_tags
        if choice == 'Markdown':
            question.is_markdown = True
        board = Board_S.load_by_name(class_url)
        board.count.topic += 1
        board.count.all_topic += 1
        board.board_f.count.topic += 1
        board.board_f.count.all_topic += 1
        question.board_id = board.id
        question.author_id = current_user.id
        current_user.infor.score -= 5
        '''随机赠送'''
        random_gift()
        db.session.add(question)
        db.session.commit()
        '''使用redis记录'''
        RedisData.set_question()
        RedisData.set_user()
        return jsonify(judge=True, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        board = Board_S.query.join(Board_F).\
            filter(Board_F.enname_f == g.forums_url).\
            filter(Board_S.enname_s == class_url).first_or_404()
        return render_template('question/question.html',
                               fileform=fileform,
                               form=form,
                               board=board)
示例#4
0
def question(group):
    group = Group.load_by_name(group)
    form = QuestionForm()
    fileform = PhotoForm()
    error = None
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        choice = form.choice.data
        tags = form.tags.data
        tags = sp(',|;|,|;| ', tags)
        tags = list(set(tags))[:4]
        post_tags = []
        for tag in tags:
            if tag != '':
                t = Tags(author=current_user.name, name=tag)
                post_tags.append(t)
        question = Questions(title=title, content=content, kind=group.kind)
        question.tags = post_tags
        if choice == 'Markdown':
            question.is_markdown = True
        question.is_group = True
        question.group_id = group.id
        question.author_id = current_user.id
        group.count.topic += 1
        group.count.all_topic += 1
        current_user.infor.score -= 5
        '''随机赠送'''
        random_gift()
        db.session.add(question)
        db.session.commit()
        '''使用redis记录'''
        RedisData.set_question()
        RedisData.set_user()
        return jsonify(judge=True, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        return render_template('group/question.html',
                               group=group,
                               form=form,
                               fileform=fileform)
示例#5
0
def question(group):
    group = Group.load_by_name(group)
    form = QuestionForm()
    fileform = PhotoForm()
    error = None
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        choice = form.choice.data
        tags = form.tags.data
        tags = sp(',|;|,|;| ', tags)
        tags = list(set(tags))[:4]
        post_tags = []
        for tag in tags:
            if tag != '':
                t = Tags(author=current_user.name, name=tag)
                post_tags.append(t)
        question = Questions(title=title, content=content, kind=group.kind)
        question.tags = post_tags
        if choice == 'Markdown':
            question.is_markdown = True
        question.is_group = True
        question.group_id = group.id
        question.author_id = current_user.id
        group.count.topic += 1
        group.count.all_topic += 1
        current_user.infor.score -= 5
        '''随机赠送'''
        random_gift()
        db.session.add(question)
        db.session.commit()
        '''使用redis记录'''
        RedisData.set_question()
        RedisData.set_user()
        return jsonify(judge=True, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        return render_template('group/question.html',
                               group=group,
                               form=form,
                               fileform=fileform)
示例#6
0
 def put(form, topicId):
     topic = Topic.query.filter_by(uid=topicId).first_or_404()
     topic.title = form.title.data
     topic.content = html_clean(form.content.data)
     topic.is_markdown = True if form.choice.data == 1 else False
     tags = sp(',|;|,|;| ', form.tags.data)
     tags = [x for x in list(set(tags)) if x != ''][:4]
     post_tags = []
     for tag in tags:
         if tag != '':
             exsit_tag = Tags.query.filter_by(tagname=tag).first()
             if exsit_tag is not None:
                 post_tags.append(exsit_tag)
                 if exsit_tag not in current_user.following_tags:
                     current_user.following_tags.append(exsit_tag)
             else:
                 t = Tags()
                 t.tagname = tag
                 post_tags.append(t)
                 current_user.following_tags.append(t)
     topic.tags = post_tags
     topic.board_id = form.category.data
     db.session.commit()
     return topic
示例#7
0
"""
Tired of summing up numbers by hand for your night job as an accountant, you are
writing your own calculator that allows you to type in a lot of numbers and sums
them for you. Naturally, your calculator begins with a sum of 0.

Every time you reach an input value of 0 output the sum so far, and reset the
sum to 0.
"""

#import sys, re
#import sys as s, re as r
from sys import stdin as s
from re import findall as f, split as sp

# Original
#print '\n'.join([str(ans) for ans in [sum(x) for x in [map(int, v) for v in [line.split() for line in re.findall('.*?0', ' '.join(re.split('\\s', ' '.join(sys.stdin.readlines()))))]]]])

# Better
#print '\n'.join([str(sum(map(int, line.split()))) for line in re.findall('.*?0', ' '.join(re.split('\\s', sys.stdin.read())))])

# Betterer
#print '\n'.join([str(sum(map(int, line.split()))) for line in r.findall('.*?0', ' '.join(s.stdin.read().split('\\s')))])

# Cheat on those imports!
print '\n'.join([str(sum(map(int, l.split()))) for l in f('.*?0', ' '.join(sp('\\s', s.read())))])
示例#8
0
"""
Tired of summing up numbers by hand for your night job as an accountant, you are
writing your own calculator that allows you to type in a lot of numbers and sums
them for you. Naturally, your calculator begins with a sum of 0.

Every time you reach an input value of 0 output the sum so far, and reset the
sum to 0.
"""

#import sys, re
#import sys as s, re as r
from sys import stdin as s
from re import findall as f, split as sp

# Original
#print '\n'.join([str(ans) for ans in [sum(x) for x in [map(int, v) for v in [line.split() for line in re.findall('.*?0', ' '.join(re.split('\\s', ' '.join(sys.stdin.readlines()))))]]]])

# Better
#print '\n'.join([str(sum(map(int, line.split()))) for line in re.findall('.*?0', ' '.join(re.split('\\s', sys.stdin.read())))])

# Betterer
#print '\n'.join([str(sum(map(int, line.split()))) for line in r.findall('.*?0', ' '.join(s.stdin.read().split('\\s')))])

# Cheat on those imports!
print '\n'.join([
    str(sum(map(int, l.split())))
    for l in f('.*?0', ' '.join(sp('\\s', s.read())))
])