Пример #1
0
def page_edit_about(request):
    shop = request.shop
    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    try:
        about = About.objects.filter(shop=shop).get()
    except About.DoesNotExist:
        about = Page(shop=shop)
        about.save()

    if request.method == "POST":
        form = AboutForm(request.POST)
        if form.is_valid():
            about.title = form.cleaned_data['title']
            about.body = form.cleaned_data['body']
            about.meta_content = form.cleaned_data['meta_content']
            about.save()
            request.flash['message'] = unicode(_("Page successfully saved."))
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('page_edit_about'))
    else:
        form = AboutForm(instance=about)

    return render_to_response('store_admin/web_store/pages_edit_about.html', {
        'form': form,
        'static_pages': static_pages,
        'dynamic_pages': dynamic_pages
    }, RequestContext(request))
Пример #2
0
def page_edit_about(request):
    shop = request.shop
    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    try:
        about = About.objects.filter(shop=shop).get()
    except About.DoesNotExist:
        about = Page(shop=shop)
        about.save()

    if request.method == "POST":
        form = AboutForm(request.POST)
        if form.is_valid():
            about.title = form.cleaned_data['title']
            about.body = form.cleaned_data['body']
            about.meta_content = form.cleaned_data['meta_content']
            about.save()
            request.flash['message'] = unicode(_("Page successfully saved."))
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('page_edit_about'))
    else:
        form = AboutForm(instance=about)

    return render_to_response('store_admin/web_store/pages_edit_about.html',
                              {'form': form, 'static_pages': static_pages, 'dynamic_pages': dynamic_pages},
                              RequestContext(request))
Пример #3
0
def about():
    form = AboutForm()
    if request.method == "POST" and form.validate_on_submit():
        s3_client = s3_session.resource("s3")
        file = request.files["image"]

        if file:

            if file.filename == "":
                flash("Image must have file name.")
                return redirect(request.url)

            if not allowed_image(file.filename, current_app):
                flash("That image extension is not allowed.")
                return redirect(request.url)

            filename = secure_filename(str(
                uuid.uuid4())) + f".{image_ext(file.filename)}"
            s3_client.Bucket(current_app.config["S3_BUCKET"]).put_object(
                Key=filename, Body=file, ACL="public-read")

        else:
            filename = None

        new_about = About(
            intro=form.intro.data,
            image=filename,
            general=current_user,
        )

        db.session.add(new_about)
        db.session.commit()
        return redirect(url_for("main_page.home") + "#About")

    return render_template("form_page.html", form=form, title="About")
Пример #4
0
def page_edit_about(request):
    shop = request.shop
    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    try:
        about = About.objects.filter(shop=shop).get()
    except:
        about = Page(shop=shop)
        about.save()
    form = AboutForm(request.POST or None, instance=about)
    if form.is_valid():
        form.save()
        request.flash['message'] = unicode(_("Page successfully saved."))
        request.flash['severity'] = "success"
        return HttpResponseRedirect(reverse('page_edit_about'))
    return render_to_response('store_admin/web_store/pages_edit_about.html',
                              {'form': form, 'static_pages': static_pages, 'dynamic_pages': dynamic_pages},
                              RequestContext(request))    
Пример #5
0
def edit_about():
    about_info = About.query.filter_by(general_id=current_user.id).first()
    image = about_info.image

    edit_about = AboutForm(
        intro=about_info.intro,
        image=None,
    )

    if edit_about.validate_on_submit():
        s3_client = s3_session.resource("s3")
        file = request.files["image"]

        if file:

            if file.filename == "":
                flash("Image must have file name.")
                return redirect(request.url)

            if not allowed_image(file.filename, current_app):
                flash("That image extension is not allowed.")
                return redirect(request.url)

            try:
                s3_client.Object(current_app.config["S3_BUCKET"],
                                 image).delete()
            except:
                pass

            filename = secure_filename(str(
                uuid.uuid4())) + f".{image_ext(file.filename)}"
            s3_client.Bucket(current_app.config["S3_BUCKET"]).put_object(
                Key=filename, Body=file, ACL="public-read")
            about_info.image = filename

        about_info.intro = edit_about.intro.data
        db.session.commit()
        return redirect(url_for("main_page.home") + "#About")
    return render_template("form_page.html",
                           form=edit_about,
                           image=image,
                           title="About")
Пример #6
0
def home(current_username = None):
	if current_user.is_authenticated :
		if User.query.filter_by(username = current_username).first():
			current_username = current_username = User.query.filter_by(username = current_username).first().username
		else :
			current_username = None
		#print(current_username)
		Logout_Form = LogoutForm()
		About_Form = AboutForm()
		Login_Form = LoginForm()
		return render_template('home.html',current_username = current_username,LogoutForm= Logout_Form,LoginForm = Login_Form,AboutForm = About_Form)
	return redirect(url_for('login'))
Пример #7
0
def about():
    form = AboutForm()
    return render_template('about.html', title='About', form=form)