예제 #1
0
파일: admin.py 프로젝트: octaflop/synapse
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'))
예제 #2
0
파일: helpers.py 프로젝트: octaflop/synapse
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")
예제 #3
0
파일: helpers.py 프로젝트: octaflop/synapse
def reset_db():
    try:
        posts = Post.objects()
        sites = Site.objects()
        users = User.objects()
        images = Image.objects()
        deps = Dependency.objects()
        flatpages = FlatPage.objects()

        posts.delete()
        sites.delete()
        users.delete()
        deps.delete()
        flatpages.delete()
        return "all images, posts, sites, and users deleted successfully!"
    except:
        print "There was an error..."