Esempio n. 1
0
 def _q_index(self):
     cookie = get_cookie('user')
     if cookie == 'Peter':
         this_session = get_session()
         this_session.set_user('Peter')
     if not get_user():
         body = Template.Kind_Body % (Template.Kind_Top,"Not Login!","")
         html = Template.HTML % ("Not login!",body)
         return html
     get_response().set_cookie('user','Peter',path='/',expires="Thu 01-Jan-2020 00:00:00 GMT")
     sql = """SELECT * FROM kind"""
     count,res = execute_sql_in_4bbs(sql,"SHOW")
     list = ""
     for e in res:
         list += "<div>"
         list += "Kind_id:<span>" + str(e[0]) + "</span><span>----</span>"
         list += "Kind_name:<span>" + str(e[1]) + "</span><span>----</span>"
         list += "Kind_count:<span>" + str(e[2]) + "</span><span>----</span>"
         list += "Kind_shortname:<span>" + str(e[3]) + "</span><span>----</span>"
         list += '<a href="/kind/delete?kind_id=' + str(e[0]) + '">Delete</a><span>----</span>'
         list += '<a href="/kind/edit?kind_id=' + str(e[0]) + '">Edit</a>'
         list += "</div>"
     body = Template.Kind_Body %(Template.Kind_Top,list,"")
     html = Template.HTML % ("Kind Index",body)
     return html 
Esempio n. 2
0
    def _q_lookup(self, component):
        if component == 'all':
            snooper = rss.PackageSnooper(self.package, register=False)
        elif component == 'failed':
            snooper = rss.PackageSnooper(self.package, only_failures=True,
                                         register=False)
#        elif component == 'no_recent_build':
#            pass
        else:
            response = quixote.get_response()
            response.set_status(404)
            return "No such feed"

        package_url = urls.base_url + '/' + urls.package_url_template
        per_result_url = urls.base_url + '/' + urls.per_result_url_template
        source_url = urls.base_url + '/rss2/_generic/%s/%s' % \
                     (self.package, component)

        xml = snooper.generate_rss(self.coord, package_url, per_result_url,
                                   source_url=source_url)

        response = quixote.get_response()
        response.set_content_type('text/xml')
        
        return xml
Esempio n. 3
0
 def create_account(self):
     request = quixote.get_request()
     user = request.form['username']
     password = request.form['password']
     account = Account(user, password)
     if accountmanager.exists_username(user):
         return self.account_name_taken()
     accountmanager.add_account(account)
     quixote.get_response().set_cookie('user', user, path='/')
     return quixote.redirect('./')
Esempio n. 4
0
 def _set_cookie(self, value, **attrs):
     config = get_publisher().config
     name = config.session_cookie_name
     if config.session_cookie_path:
         path = config.session_cookie_path
     else:
         path = get_request().get_environ('SCRIPT_NAME')
         if not path.endswith("/"):
             path += "/"
     domain = config.session_cookie_domain
     get_response().set_cookie(name, value, domain=domain,
                               path=path, **attrs)
     return name
Esempio n. 5
0
    def handle_upload(self):
        request = quixote.get_request()
        response = quixote.get_response()
        
        user = auth.login_user()
        perm = self.db.permissions(user)

        mayupload = (user and user.mayUpload) or (perm and perm.mayUpload)

        if not mayupload:
            raise AccessError('You may not upload images')

        if 'image' not in request.form:
            response.set_status(204)    # no content
            return ''

        added = []
        skipped = {}
        if isinstance(request.form['image'], list):
            for img in request.form['image']:
                self.do_upload(img, user, added, skipped)
        else:
            img = request.form['image']
            self.do_upload(img, user, added, skipped)
            
        added = [ image.Image(self, id) for id in added ]
        added = [ (p.path(), p.meta.get_meta()) for p in added ]

        http.json_response()
        response.set_status(201)        # created
        
        return json.write({ 'added': added, 'skipped': skipped })
Esempio n. 6
0
 def _set_cookie(self, value, **attrs):
     config = get_publisher().config
     name = config.session_cookie_name
     if config.session_cookie_path:
         path = config.session_cookie_path
     else:
         path = get_request().get_environ('SCRIPT_NAME')
         if not path.endswith("/"):
             path += "/"
     domain = config.session_cookie_domain
     get_response().set_cookie(name,
                               value,
                               domain=domain,
                               path=path,
                               **attrs)
     return name
Esempio n. 7
0
 def add_comment(self):
     response = quixote.get_response()
     request = quixote.get_request()
     number = request.form['id']
     comment = request.form['comment']
     image.add_comment(number, comment)
     return quixote.redirect('./image?id='+str(number))
Esempio n. 8
0
    def _q_index(self, request):
        """ Returns the raw data of a Picture """
        request = quixote.get_request()
        response = quixote.get_response()

        p = self.pic()
        
        if not self.collection.mayViewOrig(p):
            raise AccessError('You may not view this original image')

        etag = self.etag('orig')

        response.buffered = False
        response.set_content_type(p.mimetype)
        response.set_header('Content-Disposition',
                            'inline; filename="%d-orig.%s"' % \
                            (self.id, ImageTransform.extmap[p.mimetype]))
        response.set_header('Content-MD5',
                            p.md5hash.decode('hex').encode('base64')[:-1])
        response.set_header('ETag', etag)

        if self.if_none_match(etag):
            response.set_status(304)    # not modified
            return ''

        return Stream(p.getimagechunks(), p.datasize)
Esempio n. 9
0
    def _q_lookup(self, request, component):
        request = quixote.get_request()
        response = quixote.get_response()

        if component not in self.get_fields:
            raise TraversalError('No meta key "%s"' % component)

        http.json_response()
        
        if request.get_method() in ('POST', 'PUT'):
            if '_json' in request.form:
                data = json.read(request.form['_json'])
                
                # Return a callable thing
                def set_a_meta(request):
                    ret = self.set_meta(component, data)
                    ref = request.get_environ('HTTP_REFERER')
                    if ref is not None:
                        p = self.image.pic()
                        response.redirect(ref + '#pic%d' % p.id)

                    http.json_response()
                    return json.write(ret)

                return set_a_meta
            
            respose.set_status(204)     # no content
            return ''
        
        p = self.image.pic()
        return json.write(self.get_fields[component](p))
Esempio n. 10
0
 def image_raw(self):
     response = quixote.get_response()
     img = image.get_latest_image()
     print img[1]
     response.set_content_type('image/%s' % img[1])
     
     return img[0]
Esempio n. 11
0
 def get_score(self):
 	request = quixote.get_request()
 	response = quixote.get_response()
 	
 	the_int = int(request.form['special'])
 	score   = image.get_score(the_int)
 	return score
Esempio n. 12
0
File: view.py Progetto: ctb/willow
    def add_bookmark(self):
        request = quixote.get_request()
        response = quixote.get_response()
        form = request.form

        sequence = form.get('sequence')
        start = int(form.get('start'))
        stop = int(form.get('stop'))
        color = form.get('color', 'green')
        
        name = form.get('name', '')
        if not name:
            template = env.get_template('BasicView/add_bookmark.html')
            return template.render(locals())

        ###

        bookmarks.add_bookmark(name, self.genome_name, sequence, start, stop,
                               +1, color)

        self._load_bookmarks()

        url = request.get_url(1)
        url += '/go?sequence=%s&start=%d&stop=%d' % (quote_plus(sequence),
                                                    start, stop)
        return response.redirect(url)
Esempio n. 13
0
    def get_comments(self):
        response = quixote.get_response()
        request = quixote.get_request()

        try:
            i = int(request.form['num'])
        except:
            i = -1

        all_comments = []
        for comment in image.get_comments(i):
            all_comments.append("""\
    <comment>
     <text>%s</text>
    </comment>
    """ % (comment))

        xml = """
    <?xml version="1.0"?>
    <comments>
    %s
    </comments>
    """ % ("".join(all_comments))

        return xml
Esempio n. 14
0
    def _q_index(self, request):
        request = quixote.get_request()
        response = quixote.get_response()

        if request.get_method() in ('POST', 'PUT'):
            if '_json' in request.form:
                ret = {}
                try:
                    changes = json.read(request.form['_json'])

                    for n,v in changes.items():
                        ret[n] = self.set_meta(n, v)

                    ref = request.get_environ('HTTP_REFERER')
                    if ref is not None:
                        p = self.image.pic()
                        response.redirect(ref + '#pic%d' % p.id)

                    http.json_response()
                    return json.write(ret)
                except json.ReadException:
                    raise QueryError('badly formatted JSON')

            response.set_status(204) # no content
            return ''
            
        meta = self.get_meta()

        http.json_response()
        return json.write(meta)
Esempio n. 15
0
    def _q_traverse(self, paths):
        # can't use _q_lookup; quixote unescapes %2F in paths before '?'
        if len(paths) == 1 and paths[0] == '':
            return self._q_index()

        filename = "/".join(paths)

        print 'LOOKING FOR:', filename
        
        response = quixote.get_response()
        for fileobj in self.file_list:
            if fileobj.filename == filename:
                enc_filename = filename.replace('\\', '\\\\').replace('"', '\\"')
                response.set_content_type('application/binary')
                response.set_header('Content-Disposition',
                                    'filename=%s' % enc_filename)

                fp = fileobj.open()
                data = fp.read()
                fp.close()
                
                response.set_body(data)
                return

        response.set_status(404)
        response.set_body('not found')
Esempio n. 16
0
 def image_thumbnail(self):
     request = quixote.get_request()
     i = request.form['i']
     img, contentType = image.get_thumbnail_from_form(i)
     response = quixote.get_response()
     response.set_content_type(contentType)
     return img
Esempio n. 17
0
    def __call__(self):
        if not self.follow_symlinks and os.path.islink(self.path):
            raise errors.TraversalError(private_msg="Path %r is a symlink"
                                        % self.path)
        request = quixote.get_request()
        response = quixote.get_response()

        if self.cache_time is None:
            response.set_expires(None) # don't set the Expires header
        else:
            # explicitly allow client to cache page by setting the Expires
            # header, this is even more efficient than the using
            # Last-Modified/If-Modified-Since since the browser does not need
            # to contact the server
            response.set_expires(seconds=self.cache_time)

        try:
            stat = os.stat(self.path)
        except OSError:
            raise errors.TraversalError
        last_modified = formatdate(stat.st_mtime)
        if last_modified == request.get_header('If-Modified-Since'):
            # handle exact match of If-Modified-Since header
            response.set_status(304)
            return ''

        # Set the Content-Type for the response and return the file's contents.
        response.set_content_type(self.mime_type)
        if self.encoding:
            response.set_header("Content-Encoding", self.encoding)

        response.set_header('Last-Modified', last_modified)

        return FileStream(open(self.path, 'rb'), stat.st_size)
Esempio n. 18
0
 def image_raw(self):
     response = quixote.get_response()
     request = quixote.get_request()
     i = request.form['i']
     img = image.get_image(int(i))
     response.set_content_type('image/%s' % img[1])
     return img[0]
Esempio n. 19
0
    def _q_traverse(self, paths):
        # can't use _q_lookup; quixote unescapes %2F in paths before '?'
        if len(paths) == 1 and paths[0] == "":
            return self._q_index()

        filename = "/".join(paths)

        print "LOOKING FOR:", filename

        response = quixote.get_response()
        for fileobj in self.file_list:
            if fileobj.filename == filename:
                enc_filename = filename.replace("\\", "\\\\").replace('"', '\\"')
                response.set_content_type("application/binary")
                response.set_header("Content-Disposition", "filename=%s" % enc_filename)

                fp = fileobj.open()
                data = fp.read()
                fp.close()

                response.set_body(data)
                return

        response.set_status(404)
        response.set_body("not found")
Esempio n. 20
0
    def __call__(self):
        if not self.follow_symlinks and os.path.islink(self.path):
            raise errors.TraversalError(private_msg="Path %r is a symlink" %
                                        self.path)
        request = quixote.get_request()
        response = quixote.get_response()

        if self.cache_time is None:
            response.set_expires(None)  # don't set the Expires header
        else:
            # explicitly allow client to cache page by setting the Expires
            # header, this is even more efficient than the using
            # Last-Modified/If-Modified-Since since the browser does not need
            # to contact the server
            response.set_expires(seconds=self.cache_time)

        try:
            stat = os.stat(self.path)
        except OSError:
            raise errors.TraversalError
        last_modified = formatdate(stat.st_mtime, usegmt=True)
        if last_modified == request.get_header('If-Modified-Since'):
            # handle exact match of If-Modified-Since header
            response.set_status(304)
            return ''

        # Set the Content-Type for the response and return the file's contents.
        response.set_content_type(self.mime_type)
        if self.encoding:
            response.set_header("Content-Encoding", self.encoding)

        response.set_header('Last-Modified', last_modified)

        return FileStream(open(self.path, 'rb'), stat.st_size)
Esempio n. 21
0
 def image_raw(self):
     request = quixote.get_request()
     key = request.form['key']
     response = quixote.get_response()
     img = image.get_image(key)
     response.set_content_type('image/%s' % img.filetype)
     
     return img.data
Esempio n. 22
0
 def get_thumb(self):
     request = quixote.get_request()
     response = quixote.get_response()        
     number = int(request.form['id'])
     img = image.get_image(number)
     thumb = image.generate_thumbnail(img[0])
     response.set_content_type('image/png')        
     return thumb
Esempio n. 23
0
    def image_raw_id(self):
        response = quixote.get_response()
        request = quixote.get_request()
        imageId = request.form['id']

        img = image.get_image_by_id(imageId)
        response.set_content_type('image/{0}'.format(img[1]))
        return img[0]
Esempio n. 24
0
 def __call__(self, req):
     # Add an ETag header for better caching.
     response = quixote.get_response()
     stat = os.stat(self.path)
     goo=str(stat.st_mtime)+self.path
     response.set_header('ETag', sha.sha(goo).digest().encode('hex'))
     
     return StaticFile.__call__(self)
Esempio n. 25
0
 def get_image(self):
     response = quixote.get_response()
     request = quixote.get_request()
     toGet = request.get_cookie("img_id")
     if image.has_image(int(toGet)):
         img_db = image.get_image(int(toGet))
         response.set_content_type(guess_type(img_db[1])[0])
         return img_db[0]
     return "You have no image!"
Esempio n. 26
0
    def viewThumb(self):
		
		request = quixote.get_request()
		response = quixote.get_response()
		the_int = int(request.form['i'])
		
		results = {"image": the_int}
		
		return html.render('viewThumb.html', results)
Esempio n. 27
0
    def _q_lookup(self, component):
        try:
            snooper = rss.build_snoopers[component]
        except KeyError:
            response = quixote.get_response()
            response.set_status(404)
            return "404: no such component"

        package_url = urls.base_url + "/" + urls.package_url_template
        per_result_url = urls.base_url + "/" + urls.per_result_url_template
        source_url = urls.base_url + "/rss2/" + component

        xml = snooper.generate_rss(self.coord, package_url, per_result_url, source_url=source_url)

        response = quixote.get_response()
        response.set_content_type("text/xml")

        return xml
Esempio n. 28
0
    def get_im(self):
		request = quixote.get_request()
		response = quixote.get_response()
	
		the_int = int(request.form['special'])
		img = image.get_image(the_int)
		
		response.set_content_type('image/%s' % img[1])
		return img[0]
Esempio n. 29
0
    def style(self):

        response = quixote.get_response()
        request = quixote.get_request()

        style = retrieve_style(request)

        response.set_content_type('text/css')

        return style.data
Esempio n. 30
0
 def decrease_score(self):
 	request = quixote.get_request()
 	response = quixote.get_response()
 	
 	try:
 		the_int = int(request.form['special'])
 	except:
 		the_int = -1
 		
 	image.decrease_score(the_int)
Esempio n. 31
0
    def decrement_score(self):
        response = quixote.get_response()
        request = quixote.get_request()

        try:
            i = int(request.form['num'])
        except:
            i = -1

        image.decrement_image_score(i)
Esempio n. 32
0
    def get_score(self):
        response = quixote.get_response()
        request = quixote.get_request()

        try:
            i = int(request.form['num'])
        except:
            i = -1

        return image.get_image_score(i)
Esempio n. 33
0
 def get_thumb(self):
     request = quixote.get_request()
     response = quixote.get_response()
     
     the_int = int(request.form['special'])
     img = image.get_image(the_int)
     thumb = image.generate_thumbnail(img[0])
     response.set_content_type('image/png')
     
     return thumb
Esempio n. 34
0
    def _q_lookup(self, component):
        try:
            snooper = rss.build_snoopers[component]
        except KeyError:
            response = quixote.get_response()
            response.set_status(404)
            return "404: no such component"

        package_url = urls.base_url + '/' + urls.package_url_template
        per_result_url = urls.base_url + '/' + urls.per_result_url_template
        source_url = urls.base_url + '/rss2/' + component

        xml = snooper.generate_rss(self.coord, package_url, per_result_url,
                                   source_url=source_url)
        
        response = quixote.get_response()
        response.set_content_type('text/xml')
        
        return xml
Esempio n. 35
0
def set_session_cookie(session_id, **attrs):
    """Create a cookie in the HTTP response for 'session_id'.
    """
    config = get_publisher().config
    name = config.session_cookie_name
    if config.session_cookie_path:
        path = config.session_cookie_path
    else:
        path = get_request().get_environ('SCRIPT_NAME')
        if not path.endswith('/'):
            path += '/'
    domain = config.session_cookie_domain
    attrs = attrs.copy()
    if config.session_cookie_secure:
        attrs['secure'] = 1
    if config.session_cookie_httponly:
        attrs['httponly'] = 1
    get_response().set_cookie(name, session_id, domain=domain, path=path,
                              **attrs)
    return name
Esempio n. 36
0
    def redirect(self):
        request = quixote.get_request()
        response = quixote.get_response()
        url = request.get_url(1)
        
        form = request.form
        if 'package' in form:
            package = form['package'].strip()
            if package:
                return response.redirect('%s/%s/' % (url, package))

        return response.redirect('%s' % (url,))
Esempio n. 37
0
File: nextbus.py Progetto: ctb/meep
    def get_next_bus(self):
        request = quixote.get_request()
        response = quixote.get_response()
        response.set_content_type('application/json')
        form = request.form

        #return """{"route_num": "22", "stop_number": 2586, "route_name": "HASLETT-MERIDIAN MALL-MSU", "time": "6:17a"}"""

        lat = form['lat']
        lon = form['lon']
        stop_number = get_closest_stop(lat, lon)
        data = get_next_bus_time(stop_number)
        data['stop_number'] = stop_number

        x = json.dumps(data)
        return x
Esempio n. 38
0
    def _q_lookup(self, component):
        if component == 'latest':
            d = self.coord.get_unique_tagsets_for_package(self.package)
            if not d:
                response = quixote.get_response()
                response.set_status(404)
                response.set_body("no results for this package")
                return 
            
            latest = d.itervalues().next()
            latest_time = latest[0]['time']
            for it in d.itervalues():
                if it[0]['time'] > latest_time:
                    latest = it
                    latest_time = latest[0]['time']

            component = latest[0]['result_key']
            
        return ResultInfo(self.coord, self.package, component)
Esempio n. 39
0
 def format(self):
     get_response().set_header('WWW-Authenticate',
                               'Basic realm="%s"' % self.realm)
     return AccessError.format(self)
Esempio n. 40
0
 def _q_index(self):
     request = quixote.get_request()
     response = quixote.get_response()
     response.redirect(request.get_url(2))
Esempio n. 41
0
 def __call__(self):
     response = quixote.get_response()
     response.set_content_type(self.mime_type, self.encoding)
     if self.cache_time:
         response.set_expires(seconds=self.cache_time)
     return self.data
Esempio n. 42
0
 def plaintext(self):
     response = get_response()
     response.set_content_type("text/plain")
     return "hello, world"
Esempio n. 43
0
    def format(self):
        import quixote

        allowed_methods = ', '.join(self.allowed_methods)
        quixote.get_response().set_header('Allow', allowed_methods)
        return 'Allowed methods are: %s' % allowed_methods