Пример #1
0
def main_view(request):
    if request.method == "POST":
        if not 'owner' in request.POST or not request.POST['owner']:
            request.POST['owner'] = request.user.pk

        form = AddRecordForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
    else:
        form = AddRecordForm()

    images = CatRecord.objects.filter(is_private=False).order_by('id')[:10]
    if len(images) % 2 == 1:
        last_image = images[len(images)-1]
    else:
        last_image = None

    images_left = images[::2]
    images_right = images[1::2]
    images_list = zip(images_left, images_right)

    context = RequestContext(request)
    context['friend_token'] = CatUser.objects.get(pk=request.user.pk).friend_token
    context['form'] = form
    context['images'] = images_list
    context['last_image'] = last_image
    return render_to_response('index.html', context)
Пример #2
0
def AddUseRecordView(request):
    if request.method == 'GET':

        form = AddRecordForm
        return render_to_response('include/userecord/adduserecord.html',
                                  RequestContext(request, {'form': form}))
    else:
        form = AddRecordForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/userecord/')
        else:
            form = AddRecordForm
            return render(request, 'include/userecord/adduserecord.html',
                          {'form': form})
Пример #3
0
def add_record():
    forbidden_pattern = "[0-9'\.&@:?!()$#^]"
    form = AddRecordForm(request.form)
    if (request.method == "POST") and form.validate():
        book = form.book.data.strip()
        author = (form.author.data).strip()
        if re.match(forbidden_pattern, author):
            flash("Author name cant be number")
            return render_template("add.html", form=form)
        else:
            present_book = db_session.query(Book.id).filter(func.lower(Book.name) == func.lower(book)).first()
            if present_book:
                flash("Such book already exist in library")
                return render_template("add.html", form=form)
            else:
                methods.save_author_book(author=author, book=book)
                return redirect(url_for("show_library"))
    elif request.method == "POST":
        flash("Fill in fields, please")
        return render_template("add.html", form=form)
    return render_template("add.html", form=form)
Пример #4
0
def add_record():
    forbidden_pattern = "[0-9'\.&@:?!()$#^]"
    form = AddRecordForm(request.form)
    if (request.method == 'POST') and form.validate():
        book = form.book.data.strip()
        author = (form.author.data).strip()
        if re.match(forbidden_pattern, author):
            flash("Author name cant be number")
            return render_template('add.html', form=form)
        else:
            present_book = db_session.query(Book.id).filter(
                func.lower(Book.name) == func.lower(book)).first()
            if present_book:
                flash('Such book already exist in library')
                return render_template('add.html', form=form)
            else:
                methods.save_author_book(author=author, book=book)
                return redirect(url_for('show_library'))
    elif request.method == 'POST':
        flash("Fill in fields, please")
        return render_template('add.html', form=form)
    return render_template('add.html', form=form)
Пример #5
0
def EditUseRecordView(request, record_id):
    try:
        obj_list = UserRecord.objects.get(id=record_id)
        if request.method == 'POST':
            form = AddRecordForm(request.POST, instance=obj_list)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/userecord/')
        else:
            form = AddRecordForm(instance=obj_list)
            return render(request, 'include/userecord/edituserecord.html',
                          {'form': form})
    except UserRecord.DoesNotExist:
        raise PermissionDenied