Example #1
0
def add_site():
    form = SitePostForm(request.form)
    if form.validate_on_submit():
        prev_site = Site.objects.first()
        if prev_site is not None:
            prev_site.delete()
        site = Site(title=form.title.data, domain=form.domain.data,\
                motto=form.motto.data)
        if form.logo.file:
            filename = secure_filename(form.logo.file.filename)
            size = 190,190
            try:
                os.chdir(os.path.join(UPLOAD_FOLDER, 'orig'))
                form.logo.file.save(filename)
                image = Picture.open(filename)
                os.chdir('../medium')
                image.thumbnail(size, Picture.ANTIALIAS)
                image.save(filename)
                site.logo = os.path.join(STATIC_PATH, 'medium', filename)
            except:
                flash("error in file: %s's upload" % filename)
        try:
            site.save()
            return redirect(url_for('admin_index'))
        except:
            flash("there was an error saving site %s" % site.title)
            return redirect(url_for('admin_index'))
    else:
        flash("There was an error with your submission")
        return redirect(url_for('admin_index'))
Example #2
0
def init_db():
    sites = Site.objects()
    sites.delete()
    # Should probably add something for setting up the site
    title = raw_input("What are you naming this site?\n")
    domain = raw_input("What is the site's domain?\n")
    motto = raw_input("What is the site's motto? (optional)\n")
    logo = raw_input("What is the relative path to the logo?\n \
            ex: '/static/uploads/brainBadge.png' \n")

    site = Site(title=title, motto=motto, domain=domain, logo=logo)
    try:
        site.save()
    except:
        print "Sorry, something went wrong..."
        userreponse = raw_input("try again? [Y,n]")
        if userresponse == 'Y' or userresponse == 'y' or userresponse == '\n':
            init_db()
    depends = [
            {   'title' : u'Flask',
                'url'   : u'http://flask.pocoo.org/',
                'imgurl': u'http://flask.pocoo.org/static/logo.png',
                'authors': ['Armin Ronacher'],
                },
            {   'title' : u'jQuery',
                'url'   : u'http://jquery.com/',
                'imgurl':
                u'http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif',
                'authors': ['John Resig'],
                },
            ]
    for dep in depends:
        dependency =\
        Dependency(title=dep['title'],authors=dep['authors'],url=dep['url'],\
            imgurl=dep['imgurl'])
        try:
            dependency.save()
        except:
            flash("problem")