Exemple #1
0
def dashboard_add_genre(request):
    context = RequestContext(request)
    if request.method == 'POST':
        form = GenreForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/movies/dashboard')
        return render_to_response("movie_library/dashboard/add_genre.html", {"form": form, 'dashboard_active':'active'}, context)

    elif request.method == 'GET':
        form = GenreForm()
        return render_to_response("movie_library/dashboard/add_genre.html", {"form": form, 'dashboard_active':'active'}, context)
Exemple #2
0
def addgenre():
    """ Добавление жанра (только админ) """
    form = GenreForm()
    session = db_session.create_session()
    if form.validate_on_submit():
        if session:
            genre = Genre(genre=form.genre.data)
            session.add(genre)
            session.commit()
            return redirect("/")
        return redirect('/logout')
    return render_template('addgenre.html',
                           title='Добавление жанра',
                           form=form)
Exemple #3
0
def create(request):
    if request.POST:
        form = GenreForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/genre/all')
    else:
        form = GenreForm()

    args = {}
    args.update(csrf(request))

    args['form'] = form

    return render(request, 'create_genre.html', args)
Exemple #4
0
def genre():
    """
    Creates form to select preferred genre
    """
    search_form = SearchForm()
    form = GenreForm()

    return render_template('genres.html',
                           title='Select Genre',
                           form=form,
                           search_form=search_form)
def genre_edit_form(genre_id):
	form = GenreForm()

	if genre_id is not None:
		genre = models.Genre.query.get_or_404(genre_id)
	else:
		genre = models.Genre(name='')

	if form.validate_on_submit():
		genre.name = form.name.data
		genre.alt_names = form.alt_names.data

		db.session.add(genre)
		db.session.commit()

		return redirect('/genre')

	return render_template('genre_edit.html',
						   title='Genre Edit ' + str(genre.name),
						   genre=genre,
						   form=form)
Exemple #6
0
def voteGenre(request, pk):
    if (Book.objects.filter(id=pk).count() == 0):
        return notExists(request)
    if (request.method == 'GET'):
        form = GenreForm()
    else:
        form = GenreForm(request.POST)
        if (form.is_valid()):
            genreName = form.cleaned_data['name']
            obj, created = GenreScore.objects.get_or_create(
                book=Book.objects.filter(id=pk)[0],
                genre=Genre.objects.filter(name=genreName)[0],
                user=request.user)
            if (not created):
                obj.delete()
            return redirect(request.POST['next'])
    genres = [genre.unicode().encode('utf8') for genre in Genre.objects.all()]
    return render(request, 'books/form.html', {
        'pk': pk,
        'genres': genres,
        'form': form,
        'next': request.GET['next']
    })
Exemple #7
0
def edit_authors(id):
    """ Страница "Редактирование жанра" """
    form = GenreForm()
    if request.method == "GET":
        session = db_session.create_session()
        genre = session.query(Genre).filter(Genre.id == id,
                                            current_user.id == 1).first()
        if genre:
            form.genre.data = genre.genre
        else:
            abort(404)
    if form.validate_on_submit():
        session = db_session.create_session()
        genre = session.query(Genre).filter(Genre.id == id,
                                            current_user.id == 1).first()
        if genre:
            genre.genre = form.genre.data
            session.commit()
            return redirect('/genres')
        else:
            abort(404)
    return render_template('addgenre.html',
                           title='Редактирование жанров',
                           form=form)
Exemple #8
0
def dashboard_add_genre(request):
    context = RequestContext(request)
    if request.method == 'POST':
        form = GenreForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/movies/dashboard')
        return render_to_response("movie_library/dashboard/add_genre.html", {
            "form": form,
            'dashboard_active': 'active'
        }, context)

    elif request.method == 'GET':
        form = GenreForm()
        return render_to_response("movie_library/dashboard/add_genre.html", {
            "form": form,
            'dashboard_active': 'active'
        }, context)
Exemple #9
0
def table():
    form1 = StockForm()
    form2 = GenreForm()

    chosen_genre[0] = form2.genre.data

    final_change = 0

    msg = ''
    if form1.validate_on_submit():
        ticker = form1.ticker.data
        quantity = form1.quantity.data

        if ticker not in tickerSet:
            msg = 'Please enter a valid ticker.'
            # return render_template('table.html', stocksList=stocksList, msg=msg, form=form, final_change=final_change)
        elif ticker in stocksList:
            stocksList[ticker]['quantity'] += quantity
        else:
            stocksList[ticker] = {'name': ticker}
            stocksList[ticker]['quantity'] = quantity
        symbols_list = ''
        for s in list(stocksList.keys()):
            symbols_list += s + ','
        symbols_list = symbols_list[:-1]
        PARAMS = {'symbol': symbols_list, 'api_token': api_token}

        response = requests.get(
            'https://api.worldtradingdata.com/api/v1/stock', params=PARAMS)
        data = response.json()

        for stock in data['data']:
            final_change += float(stock['day_change']) * float(
                stocksList[stock['symbol']]['quantity'])
            FINAL_CHANGE[0] = final_change
            stocksList[stock['symbol']]['current_price'] = stock['price']
            stocksList[stock['symbol']]['opening_price'] = stock['price_open']
            stocksList[stock['symbol']]['change'] = round(
                float(stock['day_change']) *
                float(stocksList[stock['symbol']]['quantity']), 2)

        for stock in stocksList:
            if stocksList[stock]['change'] >= 0:
                stocksList[stock]['change'] = '+' + str(
                    stocksList[stock]['change'])
                stocksList[stock]['color'] = "w3-text-green"
            else:
                stocksList[stock]['color'] = "w3-text-red"

    if request.method == 'POST':
        return render_template('table.html',
                               stockList=stocksList,
                               form1=form1,
                               form2=form2,
                               genres=genres)
    else:
        return render_template('table.html',
                               stockList=stocksList,
                               form1=form1,
                               form2=form2,
                               genres=genres)