Beispiel #1
0
    def get(self):
        ord = self.request.get('o', 'a')
        if ord not in ('a','f'):
            ord = 'a'
        next = None
        # Paging by http://google-appengine.googlegroups.com/web/efficient_paging_using_key_instead_of_a_dedicated_unique_property.txt
        bookmark = self.request.get('from')
        if bookmark:
            try:
                ord, first, key = self.load_bookmark(bookmark)
            except (ValueError, TypeError):
                return self.redirect("/")

            replays = Replay.all(keys_only=True).filter(self.SORT[ord][1], first).filter('__key__ >=', key).order('__key__').fetch(ON_PAGE+1)
            if len(replays) < ON_PAGE + 1:
                replays.extend(Replay.all(keys_only=True).filter(self.SORT[ord][2], first).order(self.SORT[ord][0]).order('__key__').fetch(ON_PAGE+1-len(replays)))
        else:
            replays = Replay.all(keys_only=True).order(self.SORT[ord][0]).order('__key__').fetch(ON_PAGE+1)

        replays = Replay.get(replays)

        if len(replays) == ON_PAGE+1:
            next = self.dump_bookmark(ord, replays[ON_PAGE])
            replays = replays[:-1]

        self.respond('main', {'title':'browse replays',
                              'replays': replays,
                              'next': next})
Beispiel #2
0
    def get(self):
        if 'id' in self.request.GET:
            try:
                replay = Replay.get_by_id(int(self.request.get('id')))
            except ValueError:
                replay = None
        elif 'name' in self.request.GET:
            replay = Replay.all().filter('filename =', self.request.get('name')).get()
            if replay is None:
                return self.not_found()
            return self.redirect('/down?id=%s' % replay.key().id(), permanent=True)
        elif 'hash' in self.request.GET:
            replay = Replay.all().filter('hash = ', self.request.get('hash')).get()

        if replay is None:
            return self.not_found()

        filename = replay.filename
        content = replay.content.content

        # To inspect details for the below code, see http://greenbytes.de/tech/tc2231/
        if u'WebKit' in self.request.user_agent:
            # Safari 3.0 and Chrome 2.0 accepts UTF-8 encoded string directly.
            filename_header = 'filename=%s' % filename.encode('utf-8')
        elif u'MSIE' in self.request.user_agent:
            # IE does not support internationalized filename at all.
            # It can only recognize internationalized URL, so we do the trick via routing rules.
            filename_header = ''
        else:
            # For others like Firefox, we follow RFC2231 (encoding extension in HTTP headers).
            filename_header = 'filename*=UTF-8\'\'%s' % urllib.quote(filename.encode('utf-8'))

        self.response.headers['Content-Type'] = "application/octet-stream"
        self.response.headers['Content-Disposition'] = 'attachment; ' + filename_header
        self.response.out.write(content)
Beispiel #3
0
    def get(self):
        next = None
        # Paging by http://google-appengine.googlegroups.com/web/efficient_paging_using_key_instead_of_a_dedicated_unique_property.txt
        bookmark = self.request.get('from')
        if bookmark:
            try:
                type, search, value, key = self.load_bookmark(bookmark)
            except (ValueError, TypeError):
                return self.redirect("/")

            replays = Replay.all(keys_only=True).filter('%s =' % type, value).filter('__key__ >=', key).order('__key__').fetch(ON_PAGE+1)
            if len(replays) < ON_PAGE + 1:
                replays.extend(Replay.all(keys_only=True).filter('%s >' % type, value).filter('%s <' % type, search + u'\ufffd').order(type).order('__key__').fetch(ON_PAGE+1-len(replays)))
        else:
            if self.request.get('player'):
                type = 'players'
                search = self.request.get('player')
            elif self.request.get('file'):
                type = 'filename'
                search = self.request.get('file')
            else:
                return self.redirect('/')
            replays = Replay.all(keys_only=True).filter('%s >=' % type, search).filter('%s <' % type, search + u'\ufffd').order(type).order('__key__').fetch(ON_PAGE+1)

        replays = Replay.get(replays)

        if len(replays) == ON_PAGE+1:
            next = self.dump_bookmark(type, search, replays[ON_PAGE])
            replays = replays[:-1]

        self.respond('main', {'title': "%s search results for '%s'" % (type, search),
                              'replays': replays,
                              'next': next})
Beispiel #4
0
    def get(self):
        if 'id' in self.request.GET:
            key = self.request.get('id')
            parsed = ReplayParse.get_by_key_name(key)
        elif 'name' in self.request.GET:
            replay = Replay.all().filter('filename =', self.request.get('name')).get()
            if replay is None:
                return self.not_found()
            return self.redirect('/view?id=%s' % Replay.parsed.get_value_for_datastore(replay).name(), permanent=True)
        else:
            return self.redirect("/")

        if parsed is None:
            return self.not_found()

        self.respond('view', {'settings': parsed.settings,
                              'frames': parsed.frames,
                              'parsed': parsed})