Ejemplo n.º 1
0
 def get_users_read_status(self, username):
     if not username:
         return None
     work_id = extract_numeric_id_from_olid(self.key)
     status_id = Bookshelves.get_users_read_status_of_work(
         username, work_id)
     return status_id
Ejemplo n.º 2
0
    def add(cls, username, work_id, rating, edition_id=None):
        from openlibrary.core.bookshelves import Bookshelves

        oldb = db.get_db()
        work_id = int(work_id)
        data = {'work_id': work_id, 'username': username}

        if rating not in cls.VALID_STAR_RATINGS:
            return None

        # Vote implies user read book; Update reading log status as "Already Read"
        users_read_status_for_work = Bookshelves.get_users_read_status_of_work(
            username, work_id
        )
        if users_read_status_for_work != Bookshelves.PRESET_BOOKSHELVES['Already Read']:
            Bookshelves.add(
                username,
                Bookshelves.PRESET_BOOKSHELVES['Already Read'],
                work_id,
                edition_id=edition_id,
            )

        users_rating_for_work = cls.get_users_rating_for_work(username, work_id)
        if not users_rating_for_work:
            return oldb.insert(
                'ratings',
                username=username,
                work_id=work_id,
                rating=rating,
                edition_id=edition_id,
            )
        else:
            where = "work_id=$work_id AND username=$username"
            return oldb.update('ratings', where=where, rating=rating, vars=data)
Ejemplo n.º 3
0
 def get_users_read_status(self, username):
     if not username:
         return None
     work_id = self.key.split('/')[2][2:-1]
     status_id = Bookshelves.get_users_read_status_of_work(
         username, work_id)
     return status_id
Ejemplo n.º 4
0
def get_read_status(work_key, username):
    work_id = extract_numeric_id_from_olid(work_key.split('/')[-1])
    return Bookshelves.get_users_read_status_of_work(username, work_id)
Ejemplo n.º 5
0
 def get_users_read_status(self, username):
     if not username:
         return None
     work_id = self.key.split('/')[2][2:-1]
     status_id = Bookshelves.get_users_read_status_of_work(username, work_id)
     return status_id
Ejemplo n.º 6
0
 def get_users_read_status(self, username):
     if not username:
         return None
     work_id = extract_numeric_id_from_olid(self.key)
     status_id = Bookshelves.get_users_read_status_of_work(username, work_id)
     return status_id