Example #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', {})
Example #2
0
    def get(self, app_id=None, filename=None):
        app = models.App.get_by_id(long(app_id))

        if app:
            # pull down the raw content for the filename in the gist
            raw_gist_content = github.get_raw_gist_content(
                app.gist_id, filename)

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

            # set mimetype for file
            mimetype = mimetypes.guess_type(filename)[0]
            if mimetype:
                self.response.headers['Content-Type'] = mimetype
            else:
                self.response.headers['Content-Type'] = 'text/plain'

            # only show the content if the app's perms allow it
            params = {'app_content': raw_gist_content}
            if app.public == True:
                return self.render_template('app/app_content.html', **params)
            else:
                try:
                    if long(app.owner.id()) == long(self.user_id):
                        return self.render_template('app/app_content.html',
                                                    **params)
                    else:
                        return self.render_template(
                            'errors/default_error.html')
                except:
                    return self.render_template('errors/default_error.html')
        else:
            return self.render_template('errors/default_error.html')
Example #3
0
    def get(self, app_id=None, filename=None):
        app = models.App.get_by_id(long(app_id))

        if app:
            # pull down the raw content for the filename in the gist
            raw_gist_content = github.get_raw_gist_content(app.gist_id, filename)

            if not raw_gist_content:
                return self.render_template('errors/default_error.html')
            
            # set mimetype for file
            mimetype = mimetypes.guess_type(filename)[0]
            if mimetype:
                self.response.headers['Content-Type'] = mimetype
            else:
                self.response.headers['Content-Type'] = 'text/plain'

            # only show the content if the app's perms allow it
            params = {'app_content': raw_gist_content}
            if app.public == True:
                return self.render_template('app/app_content.html', **params)
            else:
                try:
                    if long(app.owner.id()) == long(self.user_id):
                        return self.render_template('app/app_content.html', **params)
                    else:
                        return self.render_template('errors/default_error.html')
                except:
                    return self.render_template('errors/default_error.html')
        else:
            return self.render_template('errors/default_error.html')
Example #4
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)
Example #5
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)
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
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
            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)
Example #10
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', {})
Example #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)
Example #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)
Example #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)