コード例 #1
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def on_form_not_sent (self):
        if not self.user.is_logged_in_google:
            self.content["recaptcha"] = recaptcha.client.captcha.displayhtml(settings.RECAPTCHA_PUBLIC_KEY)

        self.content["pasty_token"] = app.form.put_form_token(self.request.remote_addr)

        if self.parent_paste != None:
            self.content["pasty_code"] = cgi.escape(self.parent_paste.code)
            self.content["pasty_title"] = "Fork"
            if self.parent_paste.forks >= 1:
                self.content["pasty_title"] += str(self.parent_paste.forks + 1)
            self.content["pasty_title"] += ": " + cgi.escape(self.parent_paste.title)
            self.content["u_parent"] = app.url("%s", self.parent_paste.slug)
            self.content["parent_slug"] = self.parent_paste.slug
            self.content["u_form"] = app.url("%s/fork", self.parent_paste.slug)
        else:
            self.content["u_form"] = app.url("")

        if self.request.get("code") != "":
            self.content["pasty_code"] = cgi.escape(self.request.get("code"))

        if self.request.get("title") != "":
            self.content["pasty_title"] = cgi.escape(self.request.get("title"))

        self.display_form()

        self.delete_old_forms()
コード例 #2
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def on_form_sent (self):
        slug = app.pasty.make_unique_slug(8)

        self.content["pasty_code"] = self.form_code
        self.content["pasty_tags"] = self.form_tags
        self.content["pasty_title"] = self.form_title
        self.content["pasty_token"] = self.form_token
        self.content["pasty_slug"] = cgi.escape(slug)
        if self.parent_paste:
            self.content["u_diff"] = app.url("%s/diff/%s", self.parent_paste.slug, slug)

        if self.validate_form():
            self.put_paste(slug)
            self.increment_fork_count()
            if self.parent_paste:
                self.move_all_same_level_forks_down()
            self.increment_paste_counter()

            if self.paste.is_private():
                self.content["u_pasty"] = self.paste.get_private_url()
            else:
                self.content["u_pasty"] = self.paste.get_url()

            self.content["is_private"] = self.paste.is_private()
            self.content["u_pasty_encoded"] = cgi.escape(self.content["u_pasty"])
            self.content["u_fork"] = app.url("%s/fork", slug)
            self.content["u_add"] = app.url("")

            self.write_out("./added.html")

            app.form.delete_token(self.form_token, self.request.remote_addr)
        else:
            self.content["recaptcha"] = recaptcha.client.captcha.displayhtml(settings.RECAPTCHA_PUBLIC_KEY)
            self.display_form()
コード例 #3
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
 def get_404 (self):
     self.path.add("Paste not found")
     self.error(404)
     self.content["pasty_slug"] = cgi.escape(self.pasty_slug)
     self.content["u_paste"] = app.url("")
     self.content["u_pastes"] = app.url("pastes/")
     self.write_out("./404.html")
コード例 #4
0
ファイル: __init__.py プロジェクト: frankk00/p8ste
 def get_404(self):
     self.path.add("Paste not found")
     self.error(404)
     self.content["pasty_slug"] = cgi.escape(self.pasty_slug)
     self.content["u_paste"] = app.url("")
     self.content["u_pastes"] = app.url("pastes/")
     self.write_out("./404.html")
コード例 #5
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
    def get (self, slug):
        self.paste = self.get_paste(slug)
        self.paste_slug = slug
        self.content["paste_slug"] = self.paste_slug
        self.content["u_paste"] = app.url("%s", slug)

        if self.paste:

            self.path.add("Pastes", app.url("pastes/"))
            self.path.add(self.paste.get_title(), self.paste.get_url())

            if self.paste.is_public():
                self.remote_url = self.request.get("url")
                if self.remote_url[0:7] != "http://":
                    self.remote_url = "http://" + self.remote_url

                self.remote_content = self.fetch_url()
                self.content["remote_url"] = self.remote_url

                if self.remote_content:
                    self.get_200()
                else:
                    self.get_404_remote()
            else:
                self.content["paste_is_private"] = self.paste.is_private()
                self.content["paste_is_moderated"] = self.paste.is_moderated()
                self.content["paste_is_awaiting_approval"] = self.paste.is_waiting_for_approval()
                self.error(401)
                self.write_out("template/paste/not_public.html")
        else:
            self.get_404_paste()
コード例 #6
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def on_load (self):
        self.get_form_data()
        self.parent_paste = self.get_parent_paste()

        if self.parent_paste:
            self.content["is_fork"] = True
            self.content["u_parent_paste"] = app.url("%s", self.parent_paste.slug)
            self.content["pasty_parent_slug"] = self.parent_paste.slug

            self.path.add("Pastes", app.url("pastes/"))
            self.path.add(self.parent_paste.title, app.url("%s", self.parent_paste.slug))
            self.path.add("Fork", app.url("%s/fork", self.parent_paste_slug))

        if not self.parent_paste or self.parent_paste.is_forkable():
            if self.form_token == "":
                self.on_form_not_sent()
            else:
                self.on_form_sent()

        elif self.parent_paste:
            self.content["is_private"] = self.parent_paste.is_private()
            self.content["is_moderated"] = self.parent_paste.is_moderated()
            self.content["is_awaiting_approval"] = self.parent_paste.is_waiting_for_approval()

            self.write_out("./unforkable.html")
コード例 #7
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
    def get(self):
        self.paste_count = self.get_paste_count()

        self.content["u_pastes"] = app.url("pastes/")
        self.content["u_self"] = app.url("pastes.atom")
        self.content["paste_count"] = self.paste_count
        self.content["pastes"] = self.get_pastes()

        self.set_header("Content-Type", "application/atom+xml")
        self.write_out("./200.html")
コード例 #8
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get (self):
        self.paste_count = self.get_paste_count()

        self.content["u_pastes"] = app.url("pastes/")
        self.content["u_self"] = app.url("pastes.atom")
        self.content["paste_count"] = self.paste_count
        self.content["pastes"] = self.get_pastes()

        self.set_header("Content-Type", "application/atom+xml")
        self.write_out("./200.html")
コード例 #9
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
    def get(self, paste_slug):
        self.paste = self.get_paste(paste_slug)

        self.content["u_pastes"] = app.url("pastes/")
        self.content["u_paste"] = app.url("%s", paste_slug)
        self.content["paste_slug"] = paste_slug

        if self.paste:
            self.get_200()
        else:
            self.get_404()
コード例 #10
0
ファイル: __init__.py プロジェクト: ThQ/p8ste
    def get(self, paste_slug):
        self.paste = self.get_paste(paste_slug)

        self.content["u_pastes"] = app.url("pastes/")
        self.content["u_paste"] = app.url("%s", paste_slug)
        self.content["paste_slug"] = paste_slug

        if self.paste:
            self.get_200()
        else:
            self.get_404()
コード例 #11
0
    def get (self):
        self.set_module(__name__ + ".__init__")
        self.content["http_query"] = self.request.path
        if self.request.query != "":
            self.content["http_query"] = self.content["http_query"] + self.request.query
        self.content["http_query"] = self.content["http_query"]
        self.content["u_paste"] = app.url("")
        self.content["u_pastes"] = app.url("pastes/")

        self.error(404)
        self.use_template("./page.html")
        self.write_out()
コード例 #12
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get_200 (self):
        """
        Shows the diff if all the pastes submitted are found.
        """

        self.content["u_list"] = app.url(self.paste_slugs[0] + "+" + self.paste_slugs[1])
        self.content["u_reverse"] = app.url(self.paste_slugs[1] + "/diff/" + self.paste_slugs[0])
        tpl_pastes = [self.get_template_info_for_paste(0), self.get_template_info_for_paste(1)]
        self.content["pastes"] = tpl_pastes
        self.content["diff"] = self.get_diff()

        self.write_out("./200.html")
コード例 #13
0
    def templatize_pastes(self, pastes):
        tpl_pastes = []
        for o_paste in pastes:
            tpl_paste = {}
            tpl_paste["title"] = o_paste.get_title()
            tpl_paste["slug"] = o_paste.slug
            tpl_paste["u"] = o_paste.get_url()
            tpl_paste["u_fork"] = o_paste.get_fork_url()
            tpl_paste["u_atom"] = app.url("%s.atom", o_paste.slug)
            tpl_paste["u_raw_text"] = app.url("%s.txt", o_paste.slug)
            tpl_paste["snippet"] = o_paste.snippet
            tpl_paste["is_moderated"] = o_paste.is_moderated()
            tpl_paste["is_private"] = o_paste.is_private()
            tpl_paste["is_public"] = o_paste.is_public()
            tpl_paste[
                "is_awaiting_approval"] = o_paste.is_waiting_for_approval()
            tpl_paste["is_code_viewable"] = o_paste.is_code_viewable()
            if o_paste.user:
                tpl_paste["u_user"] = app.url("users/%s", o_paste.user.id)
            tpl_paste["user_name"] = o_paste.posted_by_user_name

            if o_paste.user:
                tpl_paste["u_gravatar"] = o_paste.user.get_gravatar(16)

            if o_paste.language and o_paste.language in smoid.languages.languages:
                tpl_paste["u_language_icon"] = smoid.languages.languages[
                    o_paste.language]['u_icon']

            if o_paste.forks > 0:
                tpl_paste["forks"] = o_paste.forks

            if o_paste.posted_at != None:
                tpl_paste["posted_at"] = o_paste.posted_at.strftime(
                    settings.DATETIME_FORMAT)
            else:
                tpl_paste["posted_at"] = ""

            if o_paste.characters:
                tpl_paste["size"] = app.util.make_filesize_readable(
                    o_paste.characters)
            tpl_paste["loc"] = o_paste.lines

            tpl_paste["language"] = {}
            tpl_paste["language"]["name"] = o_paste.get_language_name()
            tpl_paste["language"]["u_icon"] = o_paste.get_icon_url()
            tpl_paste["language"]["u"] = o_paste.get_language_url()

            tpl_pastes.append(tpl_paste)

        return tpl_pastes
コード例 #14
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
    def get_template_info_for_paste(self, paste_index):
        """
        Builds an info map about a paste for using in the template.
        """

        info = {}
        opaste = self.pastes[paste_index]

        if opaste:
            info["slug"] = opaste.slug
            info["posted_at"] = opaste.posted_at.strftime(
                settings.DATETIME_FORMAT)
            info["u"] = app.url("%s", opaste.slug)
            info["posted_by"] = opaste.posted_by_user_name

            info["language"] = opaste.get_language_name()
            info["u_language_icon"] = opaste.get_icon_url()

            if opaste.characters:
                info["size"] = app.util.make_filesize_readable(
                    opaste.characters)

            if opaste.lines:
                info["loc"] = opaste.lines

        return info
コード例 #15
0
    def refresh(self):
        guser = users.get_current_user()
        self.db_user = None
        self.id = None
        self.is_google_admin = False
        self.is_logged_in = False
        self.url = ""

        if guser:
            self.google_id = guser.user_id()
            self.google_email = guser.email()
            self.gravatar_id = hashlib.md5(self.google_email).hexdigest()
            self.is_logged_in_google = True
            self.is_google_admin = users.is_current_user_admin()
        else:
            self.google_id = ""
            self.google_email = ""
            self.gravatar_id = ""
            self.is_logged_in_google = False

        if self.google_id != "":
            qry_user = app.model.User.all()
            qry_user.filter("google_id =", self.google_id)
            self.db_user = qry_user.get()
            if self.db_user:
                self.is_logged_in = True
                self.id = self.db_user.id
                self.paste_count = self.db_user.paste_count
                self.url = app.url("users/%s", self.id)
コード例 #16
0
ファイル: user.py プロジェクト: Pragith/p8ste
    def refresh (self):
        guser = users.get_current_user()
        self.db_user = None
        self.id = None
        self.is_google_admin = False
        self.is_logged_in = False
        self.url = ""

        if guser:
            self.google_id = guser.user_id()
            self.google_email = guser.email()
            self.gravatar_id = hashlib.md5(self.google_email).hexdigest()
            self.is_logged_in_google = True
            self.is_google_admin = users.is_current_user_admin()
        else:
            self.google_id = ""
            self.google_email = ""
            self.gravatar_id = ""
            self.is_logged_in_google = False

        if self.google_id != "":
            qry_user = app.model.User.all()
            qry_user.filter("google_id =", self.google_id)
            self.db_user = qry_user.get()
            if self.db_user:
                self.is_logged_in = True
                self.id = self.db_user.id
                self.paste_count = self.db_user.paste_count
                self.url = app.url("users/%s", self.id)
コード例 #17
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
    def get_200(self):
        """
        Shows the diff if all the pastes submitted are found.
        """

        self.content["u_list"] = app.url(self.paste_slugs[0] + "+" +
                                         self.paste_slugs[1])
        self.content["u_reverse"] = app.url(self.paste_slugs[1] + "/diff/" +
                                            self.paste_slugs[0])
        tpl_pastes = [
            self.get_template_info_for_paste(0),
            self.get_template_info_for_paste(1)
        ]
        self.content["pastes"] = tpl_pastes
        self.content["diff"] = self.get_diff()

        self.write_out("./200.html")
コード例 #18
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
 def __init__(self):
     app.web.RequestHandler.__init__(self)
     self.set_module(__name__ + ".__init__")
     self.use_style(app.url("style/code.css"))
     self.parent = None
     self.pastes = []
     self.paste_count = 0
     self.paste_sep = "%2B"
コード例 #19
0
ファイル: pastes.py プロジェクト: Pragith/p8ste
    def templatize_pastes (self, pastes):
        tpl_pastes = []
        for o_paste in pastes:
            tpl_paste = {}
            tpl_paste["title"] = o_paste.get_title()
            tpl_paste["slug"] = o_paste.slug
            tpl_paste["u"] = o_paste.get_url()
            tpl_paste["u_fork"] = o_paste.get_fork_url()
            tpl_paste["u_atom"] = app.url("%s.atom", o_paste.slug)
            tpl_paste["u_raw_text"] = app.url("%s.txt", o_paste.slug)
            tpl_paste["snippet"] = o_paste.snippet
            tpl_paste["is_moderated"] = o_paste.is_moderated()
            tpl_paste["is_private"] = o_paste.is_private()
            tpl_paste["is_public"] = o_paste.is_public()
            tpl_paste["is_awaiting_approval"] = o_paste.is_waiting_for_approval()
            tpl_paste["is_code_viewable"] = o_paste.is_code_viewable()
            if o_paste.user:
                tpl_paste["u_user"] = app.url("users/%s", o_paste.user.id)
            tpl_paste["user_name"] = o_paste.posted_by_user_name

            if o_paste.user:
                tpl_paste["u_gravatar"] = o_paste.user.get_gravatar(16)

            if o_paste.language and o_paste.language in smoid.languages.languages:
                tpl_paste["u_language_icon"] = smoid.languages.languages[o_paste.language]['u_icon']

            if o_paste.forks > 0:
                tpl_paste["forks"] = o_paste.forks

            if o_paste.posted_at != None:
                tpl_paste["posted_at"] = o_paste.posted_at.strftime(settings.DATETIME_FORMAT)
            else:
                tpl_paste["posted_at"] = ""

            if o_paste.characters:
                tpl_paste["size"] = app.util.make_filesize_readable(o_paste.characters)
            tpl_paste["loc"] = o_paste.lines

            tpl_paste["language"] = {}
            tpl_paste["language"]["name"] = o_paste.get_language_name()
            tpl_paste["language"]["u_icon"] = o_paste.get_icon_url()
            tpl_paste["language"]["u"] = o_paste.get_language_url()

            tpl_pastes.append(tpl_paste)

        return tpl_pastes
コード例 #20
0
ファイル: __init__.py プロジェクト: ThQ/p8ste
 def __init__(self):
     app.web.RequestHandler.__init__(self)
     self.set_module(__name__ + ".__init__")
     self.use_style(app.url("style/code.css"))
     self.parent = None
     self.pastes = []
     self.paste_count = 0
     self.paste_sep = "%2B"
コード例 #21
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def write_out(self, template_path=""):

        if template_path != "":
            self.use_template(template_path)

        if settings.ENV == "debug":
            self.content["debug"] = True
        self.content["header_scripts"] = self.scripts
        self.content["feeds"] = self.feeds
        self.content["styles"] = self.styles
        self.content["module"] = self.module
        self.content["u_home"] = app.url("")
        self.content["u_pastes"] = app.url("pastes/")
        self.content["u_module"] = self.module_url
        self.content["u_about_thanks"] = app.url("about/thanks")
        self.content["u_about_features"] = app.url("about/features")
        self.content["u_module_history"] = self.module_history_url
        self.content["u_blank_image"] = app.url("images/blank.gif")
        self.content["APP_NAME"] = settings.APP_NAME
        self.content["path__"] = self.path.path

        if settings.ENV != "debug" and settings.USE_GANALYTICS:
            self.content["GANALYTICS_ID"] = settings.GANALYTICS_ID

        if "user-agent" in self.request.headers:
            self.content["bad_browser__"] = self.request.headers["user-agent"].find("MSIE") != -1

        if self.user.is_logged_in:
            self.content['user_signed_in__'] = True
            self.content['user_id__'] = self.user.id
            self.content['user_paste_count__'] = self.user.paste_count
            self.content["u_user__"] = self.user.url
            self.content["u_user_gravatar__"] = self.user.db_user.get_gravatar(16)
        else:
            self.content['user_signed_in__'] = False

        self.content["user_logged_in_google__"] = self.user.is_logged_in_google
        self.content["u_user_signup__"] = app.url("sign-up?url=%s", self.request.url)

        if self.user.is_logged_in_google:
            self.content['u_user_logout__'] = app.url("sign-out?url=%s", self.request.url)
        else:
            self.content['u_user_login__'] = app.url("sign-in?url=%s", self.request.url)

        if settings.ENV == "debug":
            self.content["datastore_logs"] = app.appengine.hook.datastore_logs

        tpl_path = ""
        if self.template_name.startswith("./"):
            tpl_path = self.module_directory + "/" + self.template_name[2:]
        else:
            tpl_path = self.template_name

        rendered_template = template.render(tpl_path, self.content)
        self.response.out.write(rendered_template)
コード例 #22
0
ファイル: __init__.py プロジェクト: frankk00/p8ste
    def get_thread_pastes(self):
        default_chars = self.pasty.characters
        default_loc = self.pasty.lines

        pastes = []
        dbqry = app.model.Pasty.all()
        dbqry.filter("thread =", self.pasty.thread)
        dbqry.order("thread_position")
        dbpastes = dbqry.fetch(1000)

        cur_level = 0
        paste_count = len(dbpastes)
        i = 1
        lists_opened = 0
        for dbpaste in dbpastes:
            lpaste = {}
            lpaste["title"] = dbpaste.title
            lpaste["slug"] = dbpaste.slug
            lpaste["user_name"] = dbpaste.posted_by_user_name
            lpaste["is_moderated"] = dbpaste.is_moderated
            lpaste["u"] = dbpaste.get_url()
            lpaste["u_diff"] = app.url("%s/diff/%s", self.pasty.slug,
                                       dbpaste.slug)
            lpaste["ident"] = ("    " *
                               dbpaste.thread_level)

            lpaste["language_name"] = dbpaste.get_language_name()
            lpaste["u_language_image"] = dbpaste.get_icon_url()

            if dbpaste.characters > default_chars:
                lpaste["diff_size"] = app.util.make_filesize_readable(
                    dbpaste.characters - default_chars)
                lpaste["diff_size"].append("+")
            else:
                lpaste["diff_size"] = app.util.make_filesize_readable(
                    default_chars - dbpaste.characters)
                lpaste["diff_size"].append("-")

            if dbpaste.lines > default_loc:
                lpaste["diff_loc"] = "+"
            else:
                lpaste["diff_loc"] = ""
            lpaste["diff_loc"] += str(dbpaste.lines - default_loc)

            if dbpaste.thread_level > cur_level:
                cur_level = dbpaste.thread_level
                lpaste["open_list"] = 1
                lists_opened += 1
            elif dbpaste.thread_level < cur_level:
                cur_level = dbpaste.thread_level
                lpaste["close_list"] = 1
                lists_opened -= 1
            pastes.append(lpaste)

        self.content["lists_unclosed"] = xrange(0, lists_opened)

        return pastes
コード例 #23
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
 def __init__(self):
     app.web.RequestHandler.__init__(self)
     self.set_module(__name__ + ".__init__")
     self.use_style(app.url("style/code.css"))
     self.paste1_slug = ""
     self.paste1 = None
     self.paste2_slug = ""
     self.paste2 = None
     self.pastes = []
     self.paste_slugs = []
コード例 #24
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
 def __init__ (self):
     app.web.RequestHandler.__init__(self)
     self.set_module(__name__ + ".__init__")
     self.use_style(app.url("style/code.css"))
     self.paste1_slug = ""
     self.paste1 = None
     self.paste2_slug = ""
     self.paste2 = None
     self.pastes = []
     self.paste_slugs = []
コード例 #25
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
 def __init__ (self):
     app.web.RequestHandler.__init__(self)
     self.set_module(__name__ + ".__init__")
     self.highlights = set([])
     self.has_edited_lines = False
     self.has_highlights = False
     self.edited_lines = {}
     self.lines = []
     self.line_count = 0
     self.parent = None
     self.path.add("Pastes", app.url("pastes/"))
コード例 #26
0
ファイル: __init__.py プロジェクト: frankk00/p8ste
 def __init__(self):
     app.web.RequestHandler.__init__(self)
     self.set_module(__name__ + ".__init__")
     self.highlights = set([])
     self.has_edited_lines = False
     self.has_highlights = False
     self.edited_lines = {}
     self.lines = []
     self.line_count = 0
     self.parent = None
     self.path.add("Pastes", app.url("pastes/"))
コード例 #27
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get(self):
        self.path.add("Pastes", app.url("pastes/"))

        if self.request.get("page").isdigit() and int(self.request.get("page")) > 1:
            self.page = int(self.request.get("page"))

        pastes = self.get_pastes()
        self.paste_count = self.get_paste_count()

        paging = self.make_paging()

        if paging.page_count > 1:
            self.content["pages"] = paging.pages

        self.content["u_atom"] = app.url("pastes.atom")
        self.content["paste_start"] = ((self.page - 1) * self.pastes_per_page) + 1
        self.content["paste_end"] = self.content["paste_start"] - 1 + len(pastes)
        self.content["paste_count"] = self.paste_count
        self.content["pastes"] = pastes

        self.write_out("./200.html")
コード例 #28
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
    def get_404(self):
        """
        Shows an 404 error page if one, or more, pastes were not found.
        """

        self.content["error"] = {}
        self.content["error"]["pastes_not_found"] = []
        self.content["error"]["pastes_found"] = []
        self.content["u_pastes"] = app.url("pastes/")
        i = 0
        for opaste in self.pastes:
            tpl_paste = {}
            tpl_paste["u"] = app.url("%s", self.paste_slugs[i])
            tpl_paste["slug"] = self.paste_slugs[i]
            if opaste == None:
                self.content["error"]["pastes_not_found"].append(tpl_paste)
            else:
                self.content["error"]["pastes_found"].append(tpl_paste)
            i = i + 1

        self.write_out("./404.html")
コード例 #29
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get_404 (self):
        """
        Shows an 404 error page if one, or more, pastes were not found.
        """

        self.content["error"] = {}
        self.content["error"]["pastes_not_found"] = []
        self.content["error"]["pastes_found"] = []
        self.content["u_pastes"] = app.url("pastes/")
        i = 0
        for opaste in self.pastes:
           tpl_paste = {}
           tpl_paste["u"] = app.url("%s", self.paste_slugs[i])
           tpl_paste["slug"] = self.paste_slugs[i]
           if opaste == None:
               self.content["error"]["pastes_not_found"].append(tpl_paste)
           else:
               self.content["error"]["pastes_found"].append(tpl_paste)
           i = i + 1

        self.write_out("./404.html")
コード例 #30
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get_thread_pastes (self):
        default_chars = self.pasty.characters
        default_loc = self.pasty.lines

        pastes = []
        dbqry = app.model.Pasty.all()
        dbqry.filter("thread =", self.pasty.thread)
        dbqry.order("thread_position")
        dbpastes = dbqry.fetch(1000)

        cur_level = 0
        paste_count = len(dbpastes)
        i = 1
        lists_opened = 0
        for dbpaste in dbpastes:
            lpaste = {}
            lpaste["title"] = dbpaste.title
            lpaste["slug"] = dbpaste.slug
            lpaste["user_name"] = dbpaste.posted_by_user_name
            lpaste["is_moderated"] = dbpaste.is_moderated
            lpaste["u"] = dbpaste.get_url()
            lpaste["u_diff"] = app.url("%s/diff/%s", self.pasty.slug, dbpaste.slug)
            lpaste["ident"] = ("&nbsp;&nbsp;&nbsp;&nbsp;" * dbpaste.thread_level)

            lpaste["language_name"] = dbpaste.get_language_name()
            lpaste["u_language_image"] = dbpaste.get_icon_url()

            if dbpaste.characters > default_chars:
                lpaste["diff_size"] = app.util.make_filesize_readable(dbpaste.characters - default_chars)
                lpaste["diff_size"].append("+")
            else:
                lpaste["diff_size"] = app.util.make_filesize_readable(default_chars - dbpaste.characters)
                lpaste["diff_size"].append("-")

            if dbpaste.lines > default_loc:
                lpaste["diff_loc"] = "+"
            else:
                lpaste["diff_loc"] = ""
            lpaste["diff_loc"] += str(dbpaste.lines - default_loc)

            if dbpaste.thread_level > cur_level:
                cur_level = dbpaste.thread_level
                lpaste["open_list"] = 1
                lists_opened += 1
            elif dbpaste.thread_level < cur_level:
                cur_level = dbpaste.thread_level
                lpaste["close_list"] = 1
                lists_opened -= 1
            pastes.append(lpaste)

        self.content["lists_unclosed"] = xrange(0, lists_opened)

        return pastes
コード例 #31
0
    def get(self, paste_slug):
        self.set_module(__name__ + ".__init__")

        self.paste_slug = paste_slug

        self.pastes = self.get_pastes(paste_slug)

        self.path.add("Pastes", app.url("pastes/"))
        if len(self.pastes) > 0:
            self.get_200()
        else:
            self.get_404()
コード例 #32
0
    def get_200(self):
        self.path.add(self.paste_slug, app.url("%s", self.paste_slug))
        self.path.add("Thread", app.url("threads/%s", self.paste_slug))

        tpl_pastes = self.templatize_pastes(self.pastes)

        global_size = 0
        global_loc = 0
        for o_paste in self.pastes:
            if o_paste.characters:
                global_size += o_paste.characters
            if o_paste.lines:
                global_loc += o_paste.lines

        self.content["u_atom"] = app.url("threads/%s.atom", self.paste_slug)
        self.content["thread_slug"] = self.paste_slug
        self.content["thread_size"] = app.util.make_filesize_readable(
            global_size)
        self.content["thread_loc"] = global_loc
        self.content["pastes"] = tpl_pastes
        self.content["paste_count"] = len(self.pastes)
        self.write_out("./200.html")
コード例 #33
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get (self):
        self.set_header("Content-Type", "text/xml")

        qry = app.model.Pasty.all()
        qry.order("-edited_at")
        dbpastes = qry.fetch(100, 0)
        pastes = []

        for dbpaste in dbpastes:
            p = {}
            p["u"] = app.url("%s", dbpaste.slug)
            p["edited_at"] = dbpaste.edited_at.strftime("%Y-%m-%d")
            p["freq"] = "daily"
            p["priority"] = "0.5"
            pastes.append(p)

        if len(dbpastes) > 0:
            self.content["u_index"] = app.url("pastes/")
            self.content["index_edited_at"] = dbpastes[0].edited_at.strftime("%Y-%m-%d")

        self.content["pastes"] = pastes

        self.write_out("./200.xml")
コード例 #34
0
    def get(self):
        self.path.add("Pastes", app.url("pastes/"))

        if self.request.get("page").isdigit() and int(
                self.request.get("page")) > 1:
            self.page = int(self.request.get("page"))

        pastes = self.get_pastes()
        self.paste_count = self.get_paste_count()

        paging = self.make_paging()

        if paging.page_count > 1:
            self.content["pages"] = paging.pages

        self.content["u_atom"] = app.url("pastes.atom")
        self.content["paste_start"] = (
            (self.page - 1) * self.pastes_per_page) + 1
        self.content["paste_end"] = self.content["paste_start"] - 1 + len(
            pastes)
        self.content["paste_count"] = self.paste_count
        self.content["pastes"] = pastes

        self.write_out("./200.html")
コード例 #35
0
    def get(self):
        self.set_header("Content-Type", "text/xml")

        qry = app.model.Pasty.all()
        qry.order("-edited_at")
        dbpastes = qry.fetch(100, 0)
        pastes = []

        for dbpaste in dbpastes:
            p = {}
            p["u"] = app.url("%s", dbpaste.slug)
            p["edited_at"] = dbpaste.edited_at.strftime("%Y-%m-%d")
            p["freq"] = "daily"
            p["priority"] = "0.5"
            pastes.append(p)

        if len(dbpastes) > 0:
            self.content["u_index"] = app.url("pastes/")
            self.content["index_edited_at"] = dbpastes[0].edited_at.strftime(
                "%Y-%m-%d")

        self.content["pastes"] = pastes

        self.write_out("./200.xml")
コード例 #36
0
    def get_pastes(self):
        """
        Retrieve the pastes for the current page.
        """

        pastes = []

        db = app.model.Pasty.all()
        db.order("-posted_at")
        dbpastes = db.fetch(self.pastes_per_page,
                            (self.page - 1) * self.pastes_per_page)

        if dbpastes != None:
            for opaste in dbpastes:
                dpaste = {}
                dpaste["title"] = opaste.get_title()
                dpaste["u"] = opaste.get_url()
                dpaste["snippet"] = opaste.get_snippet()

                if opaste.user:
                    dpaste["u_user"] = app.url("users/%s", opaste.user.id)
                dpaste["user_name"] = opaste.posted_by_user_name

                if opaste.user:
                    dpaste["u_gravatar"] = opaste.user.get_gravatar(16)

                dpaste["u_language_icon"] = opaste.get_icon_url()

                if opaste.forks > 0:
                    dpaste["forks"] = opaste.forks

                if opaste.posted_at != None:
                    dpaste["posted_at"] = opaste.posted_at.strftime(
                        settings.DATETIME_FORMAT)
                else:
                    dpaste["posted_at"] = ""

                if opaste.characters:
                    dpaste["size"] = app.util.make_filesize_readable(
                        opaste.characters)
                dpaste["lines"] = opaste.lines
                if opaste.language:
                    dpaste["language"] = opaste.get_language_name()
                else:
                    dpaste["language"] = ""

                pastes.append(dpaste)
        return pastes
コード例 #37
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def make_paging (self):
        """
        Makes the paging UI component.
        """

        paging = app.web.ui.CursorPaging()
        paging.page = self.page
        paging.items = self.paste_count
        paging.page_length = 10
        paging.left_margin = 2
        paging.right_margin = 2
        paging.cursor_margin = 1
        paging.page_url = app.url("pastes/?page={page}")
        paging.prepare()

        return paging
コード例 #38
0
    def make_paging(self):
        """
        Makes the paging UI component.
        """

        paging = app.web.ui.CursorPaging()
        paging.page = self.page
        paging.items = self.paste_count
        paging.page_length = 10
        paging.left_margin = 2
        paging.right_margin = 2
        paging.cursor_margin = 1
        paging.page_url = app.url("pastes/?page={page}")
        paging.prepare()

        return paging
コード例 #39
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get_pastes (self):
        """
        Retrieve the pastes for the current page.
        """

        pastes = []

        db = app.model.Pasty.all()
        db.order("-posted_at")
        dbpastes = db.fetch(self.pastes_per_page, (self.page - 1) * self.pastes_per_page)

        if dbpastes != None:
            for opaste in dbpastes:
                dpaste = {}
                dpaste["title"] = opaste.get_title()
                dpaste["u"] = opaste.get_url()
                dpaste["snippet"] = opaste.get_snippet()

                if opaste.user:
                    dpaste["u_user"] = app.url("users/%s", opaste.user.id)
                dpaste["user_name"] = opaste.posted_by_user_name

                if opaste.user:
                    dpaste["u_gravatar"] = opaste.user.get_gravatar(16)

                dpaste["u_language_icon"] = opaste.get_icon_url()

                if opaste.forks > 0:
                    dpaste["forks"] = opaste.forks

                if opaste.posted_at != None:
                    dpaste["posted_at"] = opaste.posted_at.strftime(settings.DATETIME_FORMAT)
                else:
                    dpaste["posted_at"] = ""

                if opaste.characters:
                    dpaste["size"] = app.util.make_filesize_readable(opaste.characters)
                dpaste["lines"] = opaste.lines
                if opaste.language:
                    dpaste["language"] = opaste.get_language_name()
                else:
                    dpaste["language"] = ""

                pastes.append(dpaste)
        return pastes
コード例 #40
0
ファイル: __init__.py プロジェクト: ThQ/p8ste
    def get(self, slugs):
        self.paste_slugs = set(slugs.split(self.paste_sep))

        # Retrieve the pastes from the datastore
        for slug in self.paste_slugs:
            slug = slug.strip()
            if slug != "":
                p = self.get_paste(slug)
                if p != None:
                    self.pastes.append(p)

        self.paste_count = len(self.pastes)
        if self.paste_count == 1:
            self.redirect(app.url("%s", self.pastes[0].slug))
        elif self.paste_count > 0:
            self.get_200()
        else:
            self.get_404()
コード例 #41
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
    def get(self, slugs):
        self.paste_slugs = set(slugs.split(self.paste_sep))

        # Retrieve the pastes from the datastore
        for slug in self.paste_slugs:
            slug = slug.strip()
            if slug != "":
                p = self.get_paste(slug)
                if p != None:
                    self.pastes.append(p)

        self.paste_count = len(self.pastes)
        if self.paste_count == 1:
            self.redirect(app.url("%s", self.pastes[0].slug))
        elif self.paste_count > 0:
            self.get_200()
        else:
            self.get_404()
コード例 #42
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get_template_info_for_paste (self, paste_index):
        """
        Builds an info map about a paste for using in the template.
        """

        info = {}
        opaste = self.pastes[paste_index]

        if opaste:
            info["slug"] = opaste.slug
            info["posted_at"] = opaste.posted_at.strftime(settings.DATETIME_FORMAT)
            info["u"] = app.url("%s", opaste.slug)
            info["posted_by"] = opaste.posted_by_user_name

            info["language"] = opaste.get_language_name()
            info["u_language_icon"] = opaste.get_icon_url()

            if opaste.characters:
                info["size"] = app.util.make_filesize_readable(opaste.characters)

            if opaste.lines:
                info["loc"] = opaste.lines

        return info
コード例 #43
0
ファイル: model.py プロジェクト: Pragith/p8ste
 def get_url (self):
     return app.url("%s", self.slug)
コード例 #44
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def get_200 (self):
        self.secret_key = self.request.get("key")
        user_is_poster = (self.pasty.user and self.user.db_user and self.pasty.user.id == self.user.db_user.id)

        self.lines = self.pasty.code_colored.splitlines()
        lines = ""
        code = ""

        highlights = self.pasty.get_parsed_highlights()
        complex_formating = len(highlights) > 0

        if complex_formating:
            (lines, code) = self.format_complex_code(highlights)
        else:
            (lines, code) = self.format_simple_code()

        if self.pasty.parent_paste or self.pasty.forks > 0:
            thread_pastes = self.get_thread_pastes()
        else:
            thread_pastes = []

        tpl_paste = {}
        tpl_paste["u"] = self.pasty.get_url()
        tpl_paste["u_fork"] = self.pasty.get_fork_url()
        tpl_paste["u_raw_text"] = app.url("%s.txt", self.pasty_slug)
        tpl_paste["u_atom"] = app.url("%s.atom", self.pasty_slug)
        tpl_paste["slug"] = self.pasty.slug
        tpl_paste["title"] = self.pasty.get_title()
        tpl_paste["loc"] = self.pasty.lines
        tpl_paste["lines"] = lines
        tpl_paste["code"] = code
        tpl_paste["size"] = app.util.make_filesize_readable(self.pasty.characters)
        tpl_paste["pasted_at"] = self.pasty.posted_at.strftime(settings.DATETIME_FORMAT)
        tpl_paste["is_diffable"] = self.pasty.is_diffable()
        tpl_paste["is_moderated"] = self.pasty.is_moderated()
        tpl_paste["is_private"] = self.pasty.is_private()
        tpl_paste["is_public"] = self.pasty.is_public()
        tpl_paste["is_waiting_for_approval"] = self.pasty.is_waiting_for_approval()
        tpl_paste["is_code_viewable"] = self.pasty.is_code_viewable()

        tpl_paste["language"] = {}
        tpl_paste["language"]["u"] = self.pasty.get_language_url()
        tpl_paste["language"]["u_icon"] = self.pasty.get_icon_url()
        tpl_paste["language"]["name"] = self.pasty.get_language_name()

        tpl_paste["thread"] = {}
        tpl_paste["thread"]["length"] = len(thread_pastes)

        self.content["paste"] = tpl_paste
        self.content["is_thread"] = len(thread_pastes) > 1
        self.content["thread_paste_count"] = len(thread_pastes)
        self.content["u_thread_atom"] = app.url("threads/%s.atom", self.pasty.thread)
        self.content["u_thread"] = app.url("threads/%s", self.pasty.thread)
        self.content["u_remote_diff"] = app.url("%s/diff", self.pasty.slug)
        if self.content["is_thread"] == True:
            self.content["thread_pastes"] = thread_pastes
        self.content["h1"] = "p" + self.pasty_slug
        self.content["user_name"] = self.pasty.posted_by_user_name
        if self.pasty.user:
            self.content["u_user"] = app.url("users/%s", self.pasty.user.id)
            self.content["u_gravatar"] = self.pasty.user.get_gravatar(48)

        self.content["posted_at"] = self.pasty.posted_at.strftime("%b, %d %Y at %H:%M")
        if self.pasty.language:
            lang = smoid.languages.languages[self.pasty.language]
            self.content["pasty_language_url"] = lang["home_url"]

        self.path.add(self.pasty.get_title(), self.pasty.get_url())
        self.write_out("./200.html")
コード例 #45
0
ファイル: test.py プロジェクト: longwei/PlayGround
 def test_url_with_para(self):
     input = test.url('article', 1, 2, "foo", q='some query')
     expect = 'http://localhost/article/1/2/foo?q=some+query'
     self.assertEqual(input, expect)
コード例 #46
0
 def get_url(self):
     return app.url("%s", self.slug)
コード例 #47
0
 def get_real_moderate_url(self):
     return app.url("%s/moderate?sure=yes", self.slug)
コード例 #48
0
 def get_private_url(self):
     return app.url("%s?key=%s", self.slug, self.secret_key)
コード例 #49
0
 def get_fork_url(self):
     return app.url("%s/fork", self.slug)
コード例 #50
0
ファイル: __init__.py プロジェクト: matt-d-brown/p8ste
 def __init__ (self):
     app.web.RequestHandler.__init__(self)
     self.set_module(__name__ + ".__init__")
     self.use_style(app.url("style/code.css"))
     self.paste = None
コード例 #51
0
ファイル: test.py プロジェクト: longwei/PlayGround
 def test_url(self):
     input = test.url('article', 1, 2, "foo")
     expect = "http://localhost/article/1/2/foo"
     self.assertEqual(input, expect)
コード例 #52
0
ファイル: model.py プロジェクト: Pragith/p8ste
 def get_real_moderate_url (self):
     return app.url("%s/moderate?sure=yes", self.slug)
コード例 #53
0
ファイル: url.py プロジェクト: matt-d-brown/p8ste
def url(value):
    return app.url(value)
コード例 #54
0
 def get_moderate_url(self):
     return app.url("%s/moderate", self.slug)
コード例 #55
0
ファイル: __init__.py プロジェクト: Pragith/p8ste
    def validate_form (self):
        result = True

        code = self.form_code
        token = self.form_token

        if not self.user.is_logged_in_google:

            cap_challenge = self.request.get("recaptcha_challenge_field")
            cap_response = self.request.get("recaptcha_response_field")

            captcha_response = recaptcha.client.captcha.submit(cap_challenge,
                                                                 cap_response,
                                                                 settings.RECAPTCHA_PRIVATE_KEY,
                                                                 self.request.remote_addr
                                                                )
            if not captcha_response.is_valid:
                self.content["pasty_captcha_error"] = "Please try again."
                result = False

        if result == True and not app.form.has_valid_token(self.request.remote_addr, token):
            if token != "":
                self.content["pasty_error"] = "<strong>Your form has expired</strong>, you probably took too much time to fill it. <a href=\"" + app.url("") + "\"><strong>Refresh this page</strong></a>."
            result = False

        if result == True and len(code) == 0:
            self.content["pasty_code_error"] = "You must paste some code."
            result = False

        return result
コード例 #56
0
ファイル: model.py プロジェクト: Pragith/p8ste
 def get_private_url (self):
     return app.url("%s?key=%s", self.slug, self.secret_key)