Example #1
0
 def prepare(self):
     logging.debug('EmbedHandlerBase preparing')
     self.keypair_queryset = KeypairQueryset(self.application.get_settings('mysql'), self.application.db_conn)
     if not self.keypair_queryset.authenticate(self.q_api_key, self.q_api_secret):
         logging.debug('embed_head key secret invalid')
         return self.render_template('embed_head_error.html', **context)
     ## Hook up our Comment Queryset object here
     ## We need this evertime because table name changes
     ## We should probably just chnages the state, not create a new object
     ## TODO: This will change soon as Brubeck handles this decision better
     table = self.table 
     logging.debug('table: %s' % table)
     if table == None:
         logging.debug('QoorateQueryset preparing')
         logging.debug("q_short_name: %s" % self.q_short_name)
         self.qoorate_queryset = QoorateQueryset(self.application.get_settings('mysql'), self.application.db_conn)
         self.set_table()
         table = self.qoorate.refTable
         #self._table = table
         logging.debug('new table: %s' % self.table)
     self.comment_item_queryset = CommentItemQueryset(self.application.get_settings('mysql'), self.application.db_conn, table)
     self.comment_queryset = CommentQueryset(self.application.get_settings('mysql'), self.application.db_conn, table)
Example #2
0
class EmbedMixin(object):
    """this loads the initial comments for a page"""

    def get_head_resources(self, qoorate_base_uri):
        return [
            ( "link", (
                    ('href', "%s/css/%s/embed-base.css" % (qoorate_base_uri, self.preferences['THEME'])),
                    ('media', "all"),
                    ('rel', "stylesheet"),
                    ('type', "text/css"),
                )
            ),
            ( "link", (
                    ('href', "%s/css/%s/embed-layout.css" % (qoorate_base_uri, self.preferences['THEME'])),
                    ('media', "all"),
                    ('rel', "stylesheet"),
                    ('type', "text/css"),
                )
            ),
            ( "link", (
                    ('href', "%s/css/%s/embed-decor.css" % (qoorate_base_uri, self.preferences['THEME'])),
                    ('media', "all"),
                    ('rel', "stylesheet"),
                    ('type', "text/css"),
                )
            ),
            ( "link", (
                    ('href', "%s/css/%s/embed-fonts.css" % (qoorate_base_uri, self.preferences['THEME'])),
                    ('media', "all"),
                    ('rel', "stylesheet"),
                    ('type', "text/css"),
                )
            ),
            ( "link", (
                    ('href', "%s/css/%s/embed-mobile.css" % (qoorate_base_uri, self.preferences['THEME'])),
                    ('media', "all"),
                    ('rel', "stylesheet"),
                    ('type', "text/css"),
                )
            ),
            ( "link", (
                    ('href', "%s/css/%s/embed.css" % (qoorate_base_uri, self.preferences['THEME'])),
                    ('media', "all"),
                    ('rel', "stylesheet"),
                    ('type', "text/css"),
                )
            ),
            
            # This is inline now
            #( "jsconf", (
            #        ('src', "%s/js/embed.conf.js" % qoorate_base_uri),
            #        ('type', "text/javascript"),
            #    )
            #),
            ( "script", (
                    ('src', "%s/js/jquery-1.7.2.min.js" % qoorate_base_uri),
                    ('type', "text/javascript"),
                )
            ),
            ( "script", (
                    ('src', "%s/js/embed.js" % qoorate_base_uri),
                    ('type', "text/javascript"),
                )
            ),
            ( "script", (
                    ('src', "%s/js/fileuploader.js" % qoorate_base_uri),
                    ('type', "text/javascript"),
                )
            ),
            ( "script", (
                    ('src', "%s/js/jquery.cookie.js" % qoorate_base_uri),
                    ('type', "text/javascript"),
                )
            ),
            ( "script", (
                    ('src', "%s/js/jquery-ui-1.8.22.custom.min.js" % qoorate_base_uri),
                    ('type', "text/javascript"),
                )
            ),
        ]

    def prepare(self):
        logging.debug('EmbedHandlerBase preparing')
        self.keypair_queryset = KeypairQueryset(self.application.get_settings('mysql'), self.application.db_conn)
        if not self.keypair_queryset.authenticate(self.q_api_key, self.q_api_secret):
            logging.debug('embed_head key secret invalid')
            return self.render_template('embed_head_error.html', **context)
        ## Hook up our Comment Queryset object here
        ## We need this evertime because table name changes
        ## We should probably just chnages the state, not create a new object
        ## TODO: This will change soon as Brubeck handles this decision better
        table = self.table 
        logging.debug('table: %s' % table)
        if table == None:
            logging.debug('QoorateQueryset preparing')
            logging.debug("q_short_name: %s" % self.q_short_name)
            self.qoorate_queryset = QoorateQueryset(self.application.get_settings('mysql'), self.application.db_conn)
            self.set_table()
            table = self.qoorate.refTable
            #self._table = table
            logging.debug('new table: %s' % self.table)
        self.comment_item_queryset = CommentItemQueryset(self.application.get_settings('mysql'), self.application.db_conn, table)
        self.comment_queryset = CommentQueryset(self.application.get_settings('mysql'), self.application.db_conn, table)
        # self._url_args only has a list 
        # we need a dictonary with the named parameters
        # so, we reparse the url

    def get_content_context(self):
        logging.debug("get_content_context")
        #self.set_table()
        logging.debug("table: %s" % self.table)
        comments = self.comment_item_queryset.load_comments_by_table_and_location(self.table, 
            self.location, 
            parentOffset = self.moreIndex, 
            parentCount=self.settings['PARENT_PAGE_SIZE'], 
            childCount=self.settings['CHILD_PAGE_SIZE'])
        contributions = self.comment_queryset.get_count_by_table_and_location(self.table, self.location)
        contribution_text = "Be the First to Contribute"
        if contributions == 1:
            contribution_text = "%d Contribution" % contributions
        elif contributions > 1:
            contribution_text = "%d Contributions" % contributions
        parent_tag = 'p' + self.table[1:]
        context = {
            'app': self.application.get_settings('app'),
            'location': self.location,
            'qoorate_url': self.qoorate_url,
            'parent_tag': parent_tag,
            'q_short_name': self.q_short_name,
            'comments': comments,
            'contribution_text': contribution_text,
            'current_user': self.current_user,
            'related_user': None,
            'thumbnailLargeHash': None,
            'parentCount': self.parentCount,
            'childCount': self.childCount,
            'moreIndex': self.moreIndex,
            'has_more_contributions': self.has_more_contributions(comments),
            'confjs': self.preferences['EMBED_CONF_JS'],
            'theme': self.preferences['THEME'],
            'is_admin': self.is_admin,
        }
        return context;