Example #1
0
def question_show(id):
    form                     = CommentForm(formdata=request.values)
    question                 = Question.query.filter_by(id=id).first_or_404()
    question.uni_content   = unicode(escape(question.content)).replace("\r\n", "<br />")
    
    comments                 = comments_query(1, id)

    dic_codes                = dict([(code.id,code.code_name) for code in Dic_code.query.all()])
    big_cates                = Dic_code.query.filter_by(parent_id=2).all()
    for big_cate in big_cates:
        big_cate.children = Dic_code.query.filter(Dic_code.parent_id == big_cate.type_id).order_by(Dic_code.id)

    if current_user.is_anonymous() or current_user.id != question.uid:
        question.hot = question.hot + 1
    db.session.commit()

    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 1, id)
        question.modify_time  = datetime.now()
        question.comments_num = question.comments_num + 1
        db.session.commit()
        return redirect(url_for('questions.question_show', id=id))

    return render_template('questions/question_show.html', question=question, big_cates=big_cates, \
        dic_codes=dic_codes, comments=comments, form=form)
Example #2
0
def tab_show(id):
    form     = CommentForm(formdata=request.values)
    likeform = LikeForm()
    tab      = Tab.query.filter_by(id=id).first_or_404()
    content  = unicode(escape(tab.content)).replace(' ', '&nbsp;').replace('\r\n', '<br />')
    if tab.tabs_type == 5:
        tab.tab_imgs = tab.tabs_path.split('|')

    dic_codes  = dict([(code.id,code.code_name) for code in Dic_code.query.all()])
    if tab.instrument != 13:
        instrument = dic_codes[tab.instrument] + u'谱'
    else:
        instrument = u'乐谱'

    # 查询评论 type_id: 1-问题,2-曲谱,3-二手交易,4-活动,5-艺人
    comments = comments_query(2, id)

    if current_user.is_anonymous() or current_user.id != tab.uid:
        tab.hot = tab.hot + 1
    db.session.commit()

    is_like = None
    if current_user.is_authenticated():
        is_like = Like.query.filter_by(uid=current_user.id).filter_by(like_type=1)\
                    .filter_by(like_id=id).first()

    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 2, id)
        db.session.commit()
        return redirect(url_for('tabs.tab_show', id=id))
    return render_template('tabs/tab_show.html', form=form, tab=tab, comments=comments, content=content,\
        is_like=is_like, likeform=likeform, instrument=instrument)
Example #3
0
def thread_show(art_id, thr_id):
    form                  = CommentForm()
    likeform              = LikeForm()
    artist                = Artist.query.filter_by(id=art_id).first_or_404()
    thread                = Thread.query.filter_by(id=thr_id).first_or_404()
    thread.uni_content = unicode(escape(thread.content)).replace("\r\n", "<br />")
    # 查询评论 type_id: 1-问题,2-曲谱,3-二手交易,4-活动,5-艺人
    comments_select       = comments_query(5, thr_id)

    if current_user.is_anonymous() or current_user.id != thread.uid:
        thread.hot = thread.hot + 1
    db.session.commit()

    is_like = None
    if current_user.is_authenticated():
        is_like = Like.query.filter_by(uid=current_user.id).filter_by(like_type=2)\
                    .filter_by(like_id=art_id).first()        


    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 5, thr_id)
        thread.comments_num = thread.comments_num + 1
        db.session.commit()
        comments_select  = comments_query(5, thr_id)
        return redirect(url_for('artists.thread_show', art_id=art_id, thr_id=thr_id))
        #return render_template('artists/comments_ajax.html', comments=comments_select, thread=thread)

    return render_template('artists/thread_show.html', comments=comments_select, thread=thread, form=form,\
        artist=artist, likeform=likeform, is_like=is_like)
def api_comments(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Comment.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, comments=())
    comments = yield from Comment.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
    return dict(page=p, comments=comments)
def api_create_comment(id, request, *, content):
    user = request.__user__
    if user is None:
        raise APIPermissionError('Please signin first.')
    if not content or not content.strip():
        raise APIValueError('content')
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    yield from comment.save()
    return comment
def api_delete_comments(id, request):
    check_admin(request)
    c = yield from Comment.find(id)
    if c is None:
        raise APIResourceNotFoundError('Comment')
    yield from c.remove()
    return dict(id=id)
Example #7
0
def trade_show(id):
    form    = CommentForm(formdata=request.values)
    thing   = Thing.query.filter_by(id=id).first()
    thing.thing_content = unicode(escape(thing.content)).replace(' ', '&nbsp;').replace('\r\n', '<br />')

    comments = comments_query(4, id)

    if current_user.is_anonymous() or current_user.id != thing.uid:
        thing.things_hot = thing.things_hot + 1
    db.session.commit()

    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment()
        comment.save(form, current_user.id, 4, id)
        db.session.commit()
        return redirect(url_for('trade.trade_show', id=id))

    return render_template('trade/trade_show.html', form=form, thing=thing, comments=comments)
def get_blog(id):
    blog = yield from Blog.find(id)
    comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
    for c in comments:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__': 'blog.html',
        'blog': blog,
        'comments': comments
    }
Example #9
0
    def _migrate(self):
        # Drop all tables
        print('Dropping tables...')

        auth.models.User.objects.all().delete()
        Administrator.objects.all().delete()
        User.objects.all().delete()
        Folder.objects.all().delete()
        Message.objects.all().delete()
        Announcement.objects.all().delete()
        ApplyAnnouncement.objects.all().delete()
        ApplyRoute.objects.all().delete()
        Comment.objects.all().delete()
        CommentAnnouncement.objects.all().delete()
        CommentRoute.objects.all().delete()
        Day.objects.all().delete()
        Route.objects.all().delete()
        StopAnnouncement.objects.all().delete()
        StopRoute.objects.all().delete()

        print("Dropping tables OK!")

        print('Create administrators accounts...')
        admin1 = auth.models.User.objects.create_superuser(username='admin', email='[email protected]',
                                                                   password='admin')

        print('Create administrators accounts OK!')

        print('Create users accounts...')
        user_account1 = auth.models.User.objects.create_user(username='user1', email='[email protected]',
                                                                   password='user')

        user_account2 = auth.models.User.objects.create_user(username='user2', email='[email protected]',
                                                                   password='user')
        print('Create users accounts OK!')

        print('Create administrators...')
        administrator = Administrator(user_account = admin1)
        administrator.save()

        print('Create administrators OK!')

        print('Create users...')
        user1 = User(user_account = user_account1,name = "Nombre", surnames = "Apellido1 Apellido2", city = "Sevilla",
                     birthdate = date(1993, 4, 6), phone = "666999888",searchingCar = True)
        user1.save()
        user2 = User(user_account = user_account2,name = "Nombre2", surnames = "Apellido1 Apellido2", city = "Sevilla",
                     birthdate = date(1993, 4, 6), phone = "666999888",searchingCar = True)
        user2.save()
        print('Create user OK!')

        print('Create folders...')
        folder1 = Folder(name = "1", actor = user1)
        folder1.save()
        folder2 = Folder(name = "2", actor = user1)
        folder2.save()
        folder3 = Folder(name = "3", actor = user1)
        folder3.save()

        folder4 = Folder(name = "1", actor = user2)
        folder4.save()
        folder5 = Folder(name = "2", actor = user2)
        folder5.save()
        folder6 = Folder(name = "3", actor = user2)
        folder6.save()

        folder7 = Folder(name = "1", actor = administrator)
        folder7.save()
        folder8 = Folder(name = "2", actor = administrator)
        folder8.save()
        folder9 = Folder(name = "3", actor = administrator)
        folder9.save()

        print('Create folders OK!')

        print('Create messages...')
        message1 = Message(subject = "Asunto 1", body = "Este es un mensaje de prueba enviado", folder = folder1, sender = user1,
                           recipient = user2)
        message1.save()
        message2 = Message(subject = "Asunto 1", body = "Este es un mensaje de prueba enviado", folder = folder5, sender = user1,
                           recipient = user2)
        message2.save()

        print('Create messages OK!')

        print('Create comments...')
        comment1 = Comment(subject = "Muy bueno", comment = "Muy buen conductor, totalmente recomendable", rating = 9, referrer = user1,
                           evaluated = user2)
        comment1.save()
        comment2 = Comment(subject = "Regular", comment = "Como pasajero deja mucho que desear", rating = 4, referrer = user2,
                           evaluated = user1)
        comment2.save()

        print('Create comments OK!')

        print('Create routes...')
        route1 = Route(origin = "Alcalá de Guadaíra", destination = "Facultad de Informática", description = "Viaje regular durante 3 meses",
                           kind = "1", seating = 4, unitPrice = 2.00, user = user2)
        route1.save()
        route2 = Route(origin = "Arahal", destination = "Isla de la cartuja", description = "Viaje regular durante 6 meses",
                           kind = "1", seating = 4, unitPrice = 2.00, user = user1)
        route2.save()
        print('Create routes OK!')

        print('Create stop routes...')

        stopRoute1 = StopRoute(stop = "Alcalá de Guadaíra", sequence = 1, route = route2)
        stopRoute1.save()

        print('Create stop routes OK!')

        print('Create days...')

        day1 = Day(day = 1, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day1.save()
        day2 = Day(day = 2, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day2.save()
        day3 = Day(day = 3, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day3.save()
        day4 = Day(day = 4, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day4.save()
        day5 = Day(day = 5, departTime = "7:55", returnTime = "14:00", route = route2, active = True)
        day5.save()
        day6 = Day(day = 6, route = route2, active = False)
        day6.save()
        day7 = Day(day = 7, route = route2, active = False)
        day7.save()

        day8 = Day(day = 1, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day8.save()
        day9 = Day(day = 2, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day9.save()
        day10 = Day(day = 3, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day10.save()
        day11 = Day(day = 4, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day11.save()
        day12 = Day(day = 5, departTime = "7:55", returnTime = "14:00", route = route1, active = True)
        day12.save()
        day13 = Day(day = 6, route = route1, active = False)
        day13.save()
        day14 = Day(day = 7, route = route1, active = False)
        day14.save()

        print('Create days OK!')

        print('Create applys routes...')

        applyRoute1 = ApplyRoute(comment = "Buenas, yo entro a las 9 de la mañana y salgo a las dos, te viene bien en Alcalá de Guadaíra?",
                                 route= route2, user = user1)
        applyRoute1.save()

        print('Create applys routes OK!')

        print('Create comments  routes...')

        commentRoute1 = CommentRoute(subject = "Buena ruta!", comment = "Muy buen trayecto, excelente conductor", rating = 10,
                                     user = user1, route = route2)
        commentRoute1.save()

        print('Create comments routes OK!')

        print('Create announcements ...')
        announcement1 = Announcement(origin = "Alcalá de Guadaíra", destination = "Facultad de informática", description = "Viaje puntual"
                                     , seating = 2, unitPrice = 2, date = datetime(2015, 12, 6, 16, 29, 43, 79043), user = user1)
        announcement1.save()
        print('Create announcements OK!')

        print('Create applys  announcements...')
        applyAnnouncement1 = ApplyAnnouncement(comment = "Buenas, yo entro a las 17:00 de la tarde te viene bien los arcos?",
                                               announcement=announcement1, user=user1)
        applyAnnouncement1.save()
        print('Create applys announcements OK!')

        print('Create stops  announcements...')
        stopAnnouncement1 = StopAnnouncement(stop = "Sevilla", sequence = 1, announcement = announcement1)
        stopAnnouncement1.save()
        print('Create stops announcements OK!')

        print('Create comments  announcements...')
        commentAnnouncement1 = CommentAnnouncement(subject = "Buena ruta!", comment = "Muy buen trayecto, excelente conductor", rating = 10,
                                     user = user1, announcement = announcement1)
        commentAnnouncement1.save()
        print('Create comments announcements OK!')