示例#1
0
    def post(self):
        """Accepts a URL argument and saves it to the database
        """
        url = self.get_argument('url')

        if not url.startswith('http'):
            url = 'http://%s' % (url)

        logging.info(self.current_user.to_primitive())
        link_item = {
            'owner': self.current_user.id,
            'username': self.current_user.username,
            'created_at': datetime.utcnow(),
            'updated_at': datetime.utcnow(),
            'url': url,
        }

        item = ListItem(link_item)
        item.validate()
        save_listitem(self.db_conn, item)
        return self.redirect('/list')
示例#2
0
    def post(self):
        """Accepts a URL argument and saves it to the database
        """
        url = self.get_argument('url')

        if not url.startswith('http'):
            url = 'http://%s' % (url)
            
        link_item = {
            'owner': self.current_user.id,
            'username': self.current_user.username,
            'created_at': self.current_time,
            'updated_at': self.current_time,
            'url': url,
        }

        item = ListItem(**link_item)
        item.validate()
        save_listitem(self.db_conn, item)
            
        return self.redirect('/')
示例#3
0
    def post(self):
        """Accepts a URL argument and saves it to the database
        """
        url = self.get_argument("url")

        if not url.startswith("http"):
            url = "http://%s" % (url)

        logging.info(self.current_user.to_primitive())
        link_item = {
            "owner": self.current_user.id,
            "username": self.current_user.username,
            "created_at": datetime.utcnow(),
            "updated_at": datetime.utcnow(),
            "url": url,
        }

        item = ListItem(link_item)
        item.validate()
        save_listitem(self.db_conn, item)
        return self.redirect("/list")
示例#4
0
class ItemEditHandler(BaseHandler, Jinja2Rendering):
    """
    """
    def _load_item(self, owner_id, item_id):
        """Helper for loading a single item, if `item_id` is good.
        """
        if item_id:
            try:
                item_id = ObjectIdField().for_python(item_id)
            except:
                return None

        item_qs = load_listitems(self.db_conn,
                                 owner_id=self.current_user.id,
                                 item_id=item_id)

        items = list(item_qs)
        if len(items) != 1:
            return None
        else:
            item = items[0]

        return item

    @web_authenticated
    def get(self, item_id):
        """Renders a template with link info for editing stored data
        """
        item = self._load_item(self.current_user.id, item_id)

        skip_fields = [
            'deleted', 'archived', 'created_at', 'updated_at', 'liked',
            'owner_username'
        ]
        form_fields = listitem_form(skip_fields=skip_fields, values=item)
        return self.render_template('linklists/item_submit.html',
                                    form_fields=form_fields)

    @web_authenticated
    def post(self, item_id):
        """Accepts a URL argument and saves it to the database
        """
        item_data = self._load_item(self.current_user.id, item_id)
        item = ListItem(**item_data)

        title = self.get_argument('title')
        url = self.get_argument('url')
        tags = self.get_argument('tags')

        # TODO The URLField should probably handle this somehow
        if not url.startswith('http'):
            url = 'http://%s' % (url)

        tag_list = tags.split(',')

        item.updated_at = self.current_time
        item.title = title
        item.url = url
        item.tags = tag_list

        try:
            item.validate()
        except Exception, e:
            logging.error('Item validatiom failed')
            logging.error(e)
            return self.render_error(500)

        save_listitem(self.db_conn, item)
        return self.redirect('/')
示例#5
0
class ItemAddHandler(BaseHandler, Jinja2Rendering):
    """
    """
    @web_authenticated
    def get(self):
        """Renders a template with our links listed
        """
        # Check for data to autopopulate fields with
        values = {}
        url = self.get_argument('url')
        title = self.get_argument('title')

        if url is not None:
            values['url'] = url
        if title is not None:
            values['title'] = title

        skip_fields = [
            'deleted', 'archived', 'created_at', 'updated_at', 'liked',
            'owner_username'
        ]
        form_fields = listitem_form(skip_fields=skip_fields, values=values)
        return self.render_template('linklists/item_submit.html',
                                    form_fields=form_fields)

    @web_authenticated
    def post(self):
        """Accepts a URL argument and saves it to the database
        """
        title = self.get_argument('title')
        url = self.get_argument('url')
        tags = self.get_argument('tags')

        # TODO The URLField should probably handle this somehow
        if not url.startswith('http'):
            url = 'http://%s' % (url)

        tag_list = None
        if tags:
            tag_list = tags.split(',')

        link_item = {
            'owner_id': self.current_user.id,
            'owner_username': self.current_user.username,
            'created_at': self.current_time,
            'updated_at': self.current_time,
            'title': title,
            'url': url,
            'tags': tag_list,
        }

        item = ListItem(**link_item)

        try:
            item.validate()
        except Exception, e:
            logging.error('Item validatiom failed')
            logging.error(e)
            return self.render_error(500)

        save_listitem(self.db_conn, item)
        return self.redirect('/')