Beispiel #1
0
    def get(self, app_id = None):
        # load app info to check ownership, etc.
        app = models.App.get_by_id(long(app_id))

        # pull down the readme.md file and render to HTML
        raw_gist_content = github.get_raw_gist_content(app.gist_id, config.gist_markdown_name)
        app_html = markdown.markdown(raw_gist_content)

        # show it if current user is the owner or it's been made public
        try:
            if long(app.owner.id()) == long(self.user_id):
                params = {
                    'app_id': app_id,
                    'app_title': app.name, 
                    'app_description': app.description, 
                    'app_html': app_html,
                    'app_public': app.public,
                    'app_gist_id': app.gist_id,
                }
                return self.render_template('app/app_detail.html', **params)
        except:
            pass

        if app.public == True:
            params = {
                'app_id': app_id, 
                'app_title': app.name, 
                'github_author': app.github_author, 
                'app_description': app.description, 
                'app_html': app_html
            }
            return self.render_template('app/app_public_detail.html', **params)
        else:
            params = {}
            return self.redirect_to('apps', {})
Beispiel #2
0
    def get(self):
        # load articles in from db and github, stuff them in an array
        date_format = "%a, %d %b %Y"
        articles = models.Article.get_all()
        blog_title = "StackGeek Blog"
        epoch_start = datetime.datetime(1970, 1, 1)
        blog_last_updated = epoch_start

        entries = []
        for article in articles[0:10]:
            raw_gist_content = github.get_raw_gist_content(
                article.gist_id, config.gist_article_markdown_name)

            if raw_gist_content:
                owner_info = models.User.get_by_id(article.owner.id())

                # sanitize javascript
                article_html = bleach.clean(
                    markdown.markdown(raw_gist_content), config.bleach_tags,
                    config.bleach_attributes)
                article_title = bleach.clean(article.title)
                article_summary = bleach.clean(article.summary)

                if article.updated > blog_last_updated:
                    blog_last_updated = article.updated
                entry = {
                    'slug': article.slug,
                    'user_slug': "%s/" % owner_info.username,
                    'created': article.created,
                    'updated': article.updated,
                    'title': article_title,
                    'summary': article_summary,
                    'html': article_html,
                    'article_host': self.request.host,
                }

                if not article.draft:
                    entries.append(entry)

        # didn't get any matches in our loop
        date_format = "%a, %d %b %Y %H:%M:%S GMT"
        if blog_last_updated == epoch_start:
            blog_last_updated = datetime.datetime.utcnow().strftime(
                date_format)
        else:
            blog_last_updated = blog_last_updated.strftime(date_format)

        params = {
            'blog_title': blog_title,
            'blog_last_updated': blog_last_updated,
            'author': 'StackGeek and Various Site Contributers',
            'slug': '',
            'bio': config.site_bio,
            'entries': entries,
        }

        self.response.headers['Content-Type'] = 'application/xml'
        return self.render_template('blog/feed.xml', **params)
Beispiel #3
0
    def get(self, slug = None):
        # look up our article
        article = models.Article.get_by_slug(slug)
        
        if not article:
            return self.render_template('errors/default_error.html')

        raw_gist_content = github.get_raw_gist_content(article.gist_id, config.gist_article_markdown_name)

        # if there's content on Github to serve
        if raw_gist_content:
            owner_info = models.User.get_by_id(article.owner.id())
            
            # load name
            if not owner_info.name:
                name = owner_info.username
            else:
                name = "%s %s" % (owner_info.name, owner_info.last_name)

            # load github use
            try:
                github_username = social_user.uid
            except:
                github_username = None

            # load articles in from db and github, stuff them in an array
            date_format = "%a, %d %b %Y"

            # sanitize javascript
            article_html = bleach.clean(markdown.markdown(raw_gist_content), config.bleach_tags, config.bleach_attributes)
            article_title = bleach.clean(article.title)
            article_summary = bleach.clean(article.summary)
            article_host = self.request.host

            # serve page if we have contents
            created = article.created.strftime(date_format)
            entry = {
                'created': created, 
                'article_id': article.key.id(), 
                'article_title': article_title,
                'article_html': article_html, 
                'article_slug': article.slug,
                'article_owner': owner_info.username,
                'article_host': self.request.host,
            }
            # pack and stuff into template
            params = {
                'name': name,
                'github_username': github_username, 
                'menu_choice': 'blog', 
                'entry': entry,
            }
            return self.render_template('blog/blog_article_detail.html', **params)
        
        else:
            params = {}
            return self.render_template('errors/default_error.html', **params)
Beispiel #4
0
    def get(self, username=None):
        # load articles in from db and github, stuff them in an array
        articles = models.Article.get_blog_posts(1)

        # loop through all articles
        blogposts = []
        for article in articles:
            # if there's content on Github to serve
            raw_gist_content = github.get_raw_gist_content(article.gist_id)

            # if github gist exists for the entry
            if raw_gist_content:
                article_html = bleach.clean(markdown.markdown(raw_gist_content), config.bleach_tags, config.bleach_attributes)
                article_title = bleach.clean(article.title)
                
                # created and by whom
                date_format = "%a, %d %b %Y"
                created = article.created.strftime(date_format)
                owner_info = models.User.get_by_id(article.owner.id())
                # build entry
                entry = {
                    'created': created,
                    'article_id': article.key.id(),
                    'article_title': article_title,
                    'article_type': article.article_type, 
                    'article_html': article_html,
                    'article_slug': article.slug,
                    'article_owner': owner_info.username,
                    'article_host': self.request.host,
                }   
                blogposts.append(entry)

        # show other recent articles in sidebar
        articles = models.Article.get_blog_posts(5)
        archives = []
        for article in articles:
            owner_info = models.User.get_by_id(article.owner.id())
            article_title = bleach.clean(article.title)
            entry = {
                'article_title': article_title,
                'article_type': article.article_type, 
                'article_slug': article.slug,
                'article_owner': owner_info.username,
                'article_host': self.request.host,
            }
            archives.append(entry)

        # see if we have any blog posts - unlikely we don't
        if len(blogposts) > 0:
            params = {'blogpost': blogposts[0], 'archives': archives} 
        else:
            params = {'blogpost': {} }

        return self.render_template('site/home.html', **params)
Beispiel #5
0
    def get(self):
        # load articles in from db and github, stuff them in an array
        date_format = "%a, %d %b %Y"
        articles = models.Article.get_all()
        blog_title = "StackGeek Blog"
        epoch_start = datetime.datetime(1970, 1, 1)
        blog_last_updated = epoch_start

        entries = []
        for article in articles[0:10]:
            raw_gist_content = github.get_raw_gist_content(article.gist_id, config.gist_article_markdown_name)

            if raw_gist_content:
                owner_info = models.User.get_by_id(article.owner.id())
                
                # sanitize javascript
                article_html = bleach.clean(markdown.markdown(raw_gist_content), config.bleach_tags, config.bleach_attributes)
                article_title = bleach.clean(article.title)
                article_summary = bleach.clean(article.summary)

                if article.updated > blog_last_updated:
                    blog_last_updated = article.updated
                entry = {
                    'slug': article.slug,
                    'user_slug': "%s/" % owner_info.username,
                    'created': article.created, 
                    'updated': article.updated, 
                    'title': article_title, 
                    'summary': article_summary, 
                    'html': article_html,
                    'article_host': self.request.host,
                }

                if not article.draft:
                    entries.append(entry)

        # didn't get any matches in our loop
        date_format = "%a, %d %b %Y %H:%M:%S GMT"
        if blog_last_updated == epoch_start:
            blog_last_updated = datetime.datetime.utcnow().strftime(date_format) 
        else:
            blog_last_updated = blog_last_updated.strftime(date_format)

        params = {
            'blog_title': blog_title, 
            'blog_last_updated': blog_last_updated,
            'author': 'StackGeek and Various Site Contributers',
            'slug': '',
            'bio': config.site_bio, 
            'entries': entries,
        }
        
        self.response.headers['Content-Type'] = 'application/xml'
        return self.render_template('blog/feed.xml', **params)
Beispiel #6
0
    def get(self):
        # load articles in from db and github, stuff them in an array
        date_format = "%a, %d %b %Y"
        articles = models.Article.get_all()
        blogposts = []

        # loop through all articles
        for article in articles:
            # if there's content on Github to serve
            raw_gist_content = github.get_raw_gist_content(
                article.gist_id, config.gist_article_markdown_name)

            if raw_gist_content:
                # sanitize javascript
                article_html = bleach.clean(
                    markdown.markdown(raw_gist_content), config.bleach_tags,
                    config.bleach_attributes)
                article_title = bleach.clean(article.title)
                article_summary = bleach.clean(article.summary)

                # created and by whom
                created = article.created.strftime(date_format)
                owner_info = models.User.get_by_id(article.owner.id())

                # build entry
                entry = {
                    'created': created,
                    'article_id': article.key.id(),
                    'article_title': article_title,
                    'article_type': article.article_type,
                    'article_html': article_html,
                    'article_summary': article_summary,
                    'article_slug': article.slug,
                    'article_owner': owner_info.username,
                    'article_host': self.request.host,
                }

                logging.info("value is: %s" % article.draft)
                # append article if it's a guide, it's public, and not a draft
                if not article.draft:
                    blogposts.append(entry)

        # pack and stuff into template
        params = {'blogposts': blogposts}
        return self.render_template('blog/blog.html', **params)
    def get(self):
        # load articles in from db and github, stuff them in an array
        date_format = "%a, %d %b %Y"
        articles = models.Article.get_all()
        blogposts = []
        
        # loop through all articles
        for article in articles:
            # if there's content on Github to serve
            try:
                raw_gist_content = github.get_raw_gist_content(article.gist_id)
            except:
                continue

            if raw_gist_content:
                # sanitize javascript
                article_html = bleach.clean(markdown.markdown(raw_gist_content), config.bleach_tags, config.bleach_attributes)
                article_title = bleach.clean(article.title)
                article_summary = bleach.clean(article.summary)

                # created and by whom
                created = article.created.strftime(date_format)
                owner_info = models.User.get_by_id(article.owner.id())
                
                # build entry
                entry = {
                    'created': created,
                    'article_id': article.key.id(),
                    'article_title': article_title,
                    'article_type': article.article_type, 
                    'article_html': article_html,
                    'article_summary': article_summary,
                    'article_slug': article.slug,
                    'article_owner': owner_info.username,
                    'article_host': self.request.host,
                }
                
                # append article if it's a guide, it's public, and not a draft            
                if article.article_type == 'post' and article.public and not article.draft:
                    blogposts.append(entry)
        
        # pack and stuff into template
        params = {'blogposts': blogposts}
        return self.render_template('blog/blog.html', **params)
Beispiel #8
0
def get_gist_content(gist_id):
    content = memcache.get('%s:content' % gist_id)
    if content is not None:
        return content
    else:
        logging.info("Got a cache miss for %s." % gist_id)
        try:
            # go fetch the gist using the gist_id
            http = httplib2.Http(cache=None, timeout=10, proxy_info=None)
            headers, content = http.request('https://api.github.com/gists/%s?client_id=%s&client_secret=%s' % (gist_id, config.github_client_id, config.github_client_secret), method='GET', body=None, headers=None)
            
            if headers['status'] == '404':
                logging.info("looked for gist ID %s but didn't find it.  404 bitches.")
                return False

            # strip bad UTF-8 stuff if it exists (like in a gist with a .png)
            content = content.decode('utf-8', 'replace')
            gist = simplejson.loads(content)


            # see if we have .md or .rst file matching our filenames in config
            if config.gist_markdown_name in gist['files']:
                gist_content_url = gist['files'][config.gist_markdown_name]['raw_url']
                headers, content = http.request(gist_content_url, method='GET', headers=None)
                gist_html = markdown.markdown(content)
            elif config.gist_restructuredtext_name in gist['files']:
                gist_content_url = gist['files'][config.gist_restructuredtext_name]['raw_url']
                headers, content = http.request(gist_content_url, method='GET', headers=None)
                parts = publish_parts(source=content, writer_name='html4css1', settings_overrides={'title': '', 'report_level': 'quiet', '_disable_config': True})
                gist_html = parts['html_body'].replace('class="docinfo"', 'class="table table-striped"').replace('class="docutils', 'class="table table-striped table-bordered')
            else:
                logging.info("not finding a valid markdown file to display for content")
                return False
            
            if not memcache.add('%s:content' % gist_id, gist_html, config.memcache_expire_time):
                logging.info("memcache add of content from gist %s failed." % gist_id)

            return gist_html

        except:
            logging.info("got an exception while talking to github")
            return False
Beispiel #9
0
    def get(self, app_id=None):
        # load app info to check ownership, etc.
        app = models.App.get_by_id(long(app_id))

        # pull down the readme.md file and render to HTML
        raw_gist_content = github.get_raw_gist_content(
            app.gist_id, config.gist_markdown_name)
        app_html = markdown.markdown(raw_gist_content)

        # show it if current user is the owner or it's been made public
        try:
            if long(app.owner.id()) == long(self.user_id):
                params = {
                    'app_id': app_id,
                    'app_title': app.name,
                    'app_description': app.description,
                    'app_html': app_html,
                    'app_public': app.public,
                    'app_gist_id': app.gist_id,
                }
                return self.render_template('app/app_detail.html', **params)
        except:
            pass

        if app.public == True:
            params = {
                'app_id': app_id,
                'app_title': app.name,
                'github_author': app.github_author,
                'app_description': app.description,
                'app_html': app_html
            }
            return self.render_template('app/app_public_detail.html', **params)
        else:
            params = {}
            return self.redirect_to('apps', {})
Beispiel #10
0
def get_gist_content(gist_id):
    content = memcache.get('%s:content' % gist_id)
    if content is not None:
        return content
    else:
        logging.info("Got a cache miss for %s." % gist_id)
        try:
            # go fetch the gist using the gist_id
            http = httplib2.Http(cache=None, timeout=10, proxy_info=None)
            headers, content = http.request(
                'https://api.github.com/gists/%s?client_id=%s&client_secret=%s'
                % (gist_id, config.github_client_id,
                   config.github_client_secret),
                method='GET',
                body=None,
                headers=None)

            if headers['status'] == '404':
                logging.info(
                    "looked for gist ID %s but didn't find it.  404 bitches.")
                return False

            # strip bad UTF-8 stuff if it exists (like in a gist with a .png)
            content = content.decode('utf-8', 'replace')
            gist = simplejson.loads(content)

            # see if we have .md or .rst file matching our filenames in config
            if config.gist_markdown_name in gist['files']:
                gist_content_url = gist['files'][
                    config.gist_markdown_name]['raw_url']
                headers, content = http.request(gist_content_url,
                                                method='GET',
                                                headers=None)
                gist_html = markdown.markdown(content)
            elif config.gist_restructuredtext_name in gist['files']:
                gist_content_url = gist['files'][
                    config.gist_restructuredtext_name]['raw_url']
                headers, content = http.request(gist_content_url,
                                                method='GET',
                                                headers=None)
                parts = publish_parts(source=content,
                                      writer_name='html4css1',
                                      settings_overrides={
                                          'title': '',
                                          'report_level': 'quiet',
                                          '_disable_config': True
                                      })
                gist_html = parts['html_body'].replace(
                    'class="docinfo"', 'class="table table-striped"').replace(
                        'class="docutils',
                        'class="table table-striped table-bordered')
            else:
                logging.info(
                    "not finding a valid markdown file to display for content")
                return False

            if not memcache.add('%s:content' % gist_id, gist_html,
                                config.memcache_expire_time):
                logging.info("memcache add of content from gist %s failed." %
                             gist_id)

            return gist_html

        except:
            logging.info("got an exception while talking to github")
            return False
Beispiel #11
0
    def get(self, username = None):
        owner_info = models.User.get_by_id(long(self.user_id))
        
        # load name
        if not owner_info.name:
            name = bleach.clean(owner_info.username)
        else:
            name = "%s %s" % (bleach.clean(owner_info.name), bleach.clean(owner_info.last_name))
        blog_title = "StackGeek Blog - %s" % name

        # load bio
        if not owner_info.bio:
            bio = "User has not completed their bio."
        else:
            bio = bleach.clean(owner_info.bio)
        
        # load avatar
        if not owner_info.gravatar_url:
            gravatar_url = config.gravatar_url_stub
        else:
            gravatar_url = owner_info.gravatar_url

        # load 10 articles in from db and github, stuff them in an array
        articles = models.Article.get_by_user(owner_info.key)
        entries = []
        epoch_start = datetime.datetime(1970, 1, 1)
        blog_last_updated = epoch_start

        for article in articles[0:10]:
            # if there's content on Github to serve
            raw_gist_content = github.get_raw_gist_content(article.gist_id)
            
            if raw_gist_content:
            # sanitize javascript
                article_html = bleach.clean(markdown.markdown(raw_gist_content), config.bleach_tags, config.bleach_attributes)
                article_title = bleach.clean(article.title)
                article_summary = bleach.clean(article.summary)

                if article.updated > blog_last_updated:
                    blog_last_updated = article.updated
                entry = {
                    'article_path': '#', 
                    'created': article.created, 
                    'updated': article.updated, 
                    'title': article_title, 
                    'summary': article_summary, 
                    'html': article_html,
                    'host': self.request.host,
                }

                if raw_gist_content and not article.draft:
                    entries.append(entry)

        date_format = "%a, %d %b %Y %H:%M:%S GMT"
        if blog_last_updated == epoch_start:
            blog_last_updated = datetime.datetime.utcnow().strftime(date_format) 
        else:
            blog_last_updated = blog_last_updated.strftime(date_format)

        params = {
            'blog_title': blog_title, 
            'blog_last_updated': blog_last_updated, 
            'bio': owner_info.bio, 
            'entries': entries,
        }
        self.response.headers['Content-Type'] = 'application/atom+xml' 
        return self.render_template('blog/feed.xml', **params)
Beispiel #12
0
    def get(self, username = None):
        owner_info = models.User.get_by_username(username)

        if not owner_info:
            params = {}
            return self.redirect_to('home', **params)

        # load name
        if not owner_info.name:
            name = bleach.clean(owner_info.username)
        else:
            name = "%s %s" % (bleach.clean(owner_info.name), bleach.clean(owner_info.last_name))

        # find the browsed user's github username (used for follow button)
        owner_social_user = models.SocialUser.get_by_user_and_provider(owner_info.key, 'github')

        # load github usernames
        try:
            owner_github_username = owner_social_user.uid
            github_username = social_user.uid
        except:
            owner_github_username = None
            github_username = None

        # load bio
        if not owner_info.bio:
            bio = "User has not completed their bio."
        else:
            bio = bleach.clean(owner_info.bio)
        
        # load avatar
        if not owner_info.gravatar_url:
            gravatar_url = config.gravatar_url_stub
        else:
            gravatar_url = owner_info.gravatar_url

        # load articles in from db and github, stuff them in seperate arrays
        date_format = "%a, %d %b %Y"
        articles = models.Article.get_by_user(owner_info.key)
        blogposts = []
        guides = []
        
        # loop through all articles and build a list of both posts and articles
        for article in articles:
            # if there's content on Github to serve
            raw_gist_content = github.get_raw_gist_content(article.gist_id)
            
            if raw_gist_content:
                # sanitize javascript            
                article_html = bleach.clean(markdown.markdown(raw_gist_content), config.bleach_tags, config.bleach_attributes)
                article_title = bleach.clean(article.title)
                article_summary = bleach.clean(article.summary)
                article_host = self.request.host

                created = article.created.strftime(date_format)
                entry = {
                    'created': created,
                    'article_id': article.key.id(), 
                    'article_title': article_title, 
                    'article_html': article_html,
                    'article_type': article.article_type,
                    'article_slug': article.slug,
                    'article_summary': article_summary,
                    'article_host': self.request.host,
                    'article_owner': bleach.clean(owner_info.username), # TODO: may not be correct if they have forked another user's article?
                }
                
                # we switch between adding to the two lists here
                # will need video handling eventually
                if raw_gist_content and not article.draft:
                    if article.article_type == 'post':
                        blogposts.append(entry)
                    else:
                        guides.append(entry)

        # add extra single entry items, and then add the posts and guides seperately
        params = {
            'bio': bio,
            'name': name,
            'blog_username': username,
            'owner_github_username': owner_github_username,
            'gravatar_url': gravatar_url, 
            'twitter_widget_id': owner_info.twitter_widget_id, 
            'blogposts': blogposts, 
            'guides': guides,
        }
        return self.render_template('blog/blog_user.html', **params)
Beispiel #13
0
    def get(self, slug=None):
        # look up our article
        article = models.Article.get_by_slug(slug)

        if not article:
            return self.render_template('errors/default_error.html')

        raw_gist_content = github.get_raw_gist_content(
            article.gist_id, config.gist_article_markdown_name)

        # if there's content on Github to serve
        if raw_gist_content:
            owner_info = models.User.get_by_id(article.owner.id())

            # load name
            if not owner_info.name:
                name = owner_info.username
            else:
                name = "%s %s" % (owner_info.name, owner_info.last_name)

            # load github use
            try:
                github_username = social_user.uid
            except:
                github_username = None

            # load articles in from db and github, stuff them in an array
            date_format = "%a, %d %b %Y"

            # sanitize javascript
            article_html = bleach.clean(markdown.markdown(raw_gist_content),
                                        config.bleach_tags,
                                        config.bleach_attributes)
            article_title = bleach.clean(article.title)
            article_summary = bleach.clean(article.summary)
            article_host = self.request.host

            # serve page if we have contents
            created = article.created.strftime(date_format)
            entry = {
                'created': created,
                'article_id': article.key.id(),
                'article_title': article_title,
                'article_html': article_html,
                'article_slug': article.slug,
                'article_owner': owner_info.username,
                'article_host': self.request.host,
            }
            # pack and stuff into template
            params = {
                'name': name,
                'github_username': github_username,
                'menu_choice': 'blog',
                'entry': entry,
            }
            return self.render_template('blog/blog_article_detail.html',
                                        **params)

        else:
            params = {}
            return self.render_template('errors/default_error.html', **params)