Пример #1
0
def add_work(request):
    if check_if_logged_in(request):
        if request.method == 'GET':
            return render(request, 'SMDAdmin/add_work.html',
                          {'author_list': artExpo_works.list_all_authors()})
        elif request.method == 'POST':
            post_data = request.POST
            work_id = artExpo_works.new_art_work(post_data['work_name'],
                                                 post_data['author_id'],
                                                 post_data['work_description'])
            work = artExpo_works.get_work(work_id)
            author = artExpo_works.get_author(work['author'])
            return render(
                request, 'SMDAdmin/work_detail.html', {
                    'AlertMessage': '添加成功, 作品id: ' + str(work_id),
                    'Back_Url': '/smdadmin/works',
                    'work_id': work_id,
                    'work_name': work['name'],
                    'author_name': author['name'],
                    'author_id': work['author'],
                    'author_list': artExpo_works.list_all_authors(),
                    'work_description': work['description']
                })
    else:
        raise Http404
Пример #2
0
def Author(request, authorNo):
    author_info = artExpo_works.get_author(authorNo)
    if 'error' in author_info:
        raise Http404
    else:
        return render(
            request, 'author.html', {
                'author_name': author_info['name'],
                'description': author_info['description'],
                'author_id': authorNo
            })
Пример #3
0
def Works(request, workNo):
    work_info = artExpo_works.get_work(workNo)
    if 'error' in work_info:
        raise Http404
    else:
        author_name = artExpo_works.get_author(work_info['author'])['name']
        return render(
            request, 'works.html', {
                'work_name': work_info['name'],
                'work_id': workNo,
                'author_name': author_name,
                'author_id': work_info['author'],
                'work_des': work_info['description']
            })
Пример #4
0
def author_detail(request, author_id):
    if check_if_logged_in(request):
        author_info = artExpo_works.get_author(author_id)
        if 'error' in author_info:
            raise Http404
        else:
            return render(
                request, 'SMDAdmin/author_detail.html', {
                    'author_name': author_info['name'],
                    'description': author_info['description'],
                    'author_id': author_id
                })
    else:
        raise Http404
Пример #5
0
def work_detail(request, work_id):
    if check_if_logged_in(request):
        work = artExpo_works.get_work(work_id)
        author = artExpo_works.get_author(work['author'])
        return render(
            request, 'SMDAdmin/work_detail.html', {
                'work_id': work_id,
                'work_name': work['name'],
                'author_name': author['name'],
                'author_id': work['author'],
                'author_list': artExpo_works.list_all_authors(),
                'work_description': work['description']
            })
    else:
        raise Http404
Пример #6
0
def reward(request, workNo):
    if request.method == "POST":
        if int(request.POST['coins']) <= 0:
            return render(request, 'reward_bullshit.html', {'work_id': workNo})
        if artExpo_users.get_coins(request.session['username']) >= int(
                request.POST['coins']):
            artExpo_works.add_coin(workNo, int(request.POST['coins']))
            artExpo_users.use_coins(request.session['username'],
                                    request.POST['coins'])
            return render(
                request, 'reward_success.html', {
                    'coins_left':
                    artExpo_users.get_coins(request.session['username']),
                    'work_id':
                    workNo
                })
        else:
            return render(
                request, 'reward_failed.html', {
                    'work_id':
                    workNo,
                    'coins_left':
                    artExpo_users.get_coins(request.session['username'])
                })
    else:
        if 'username' not in request.session or request.session[
                'username'] == '':
            request.session['cont'] = '/artexpo/reward/' + str(workNo) + '/'
            return render(request, 'artExpo_Login.html',
                          {'AlertMessage': '还没有登录哦'})
        work_info = artExpo_works.get_work(workNo)
        if 'error' in work_info:
            raise Http404
        else:
            author_name = artExpo_works.get_author(work_info['author'])['name']
            return render(
                request, 'reward.html', {
                    'work_name': work_info['name'],
                    'work_id': workNo,
                    'author_name': author_name,
                    'author_id': work_info['author'],
                    'work_des': work_info['description']
                })
Пример #7
0
def add_author(request):
    if check_if_logged_in(request):
        if request.method == 'POST':
            post_data = request.POST
            author_id = artExpo_works.new_author(post_data['name'],
                                                 post_data['description'])
            author = artExpo_works.get_author(author_id)
            return render(
                request, 'SMDAdmin/author_detail.html', {
                    'AlertMessage': '添加成功, 作者id: ' + str(author_id),
                    'Back_Url': '/smdadmin/authors',
                    'author_id': author_id,
                    'author_name': author['name'],
                    'author_list': artExpo_works.list_all_authors(),
                    'author_description': author['description']
                })
        else:
            return render(request, 'SMDAdmin/add_author.html')
    else:
        raise Http404