def by_key(key): if not key: return None if len(key) < 3: return None if key.startswith('-') or key.endswith('-'): return None if key.find('-') == -1: return None (user_id, id) = key.split('-') return App.get('user_id = %s and id = %s', base36decode(user_id), base36decode(id))
def get(self, before_or_after=None, base36_id=None): sharedfile_id = None if base36_id: sharedfile_id = base36decode(base36_id) before_id, after_id = None, None if sharedfile_id and before_or_after == 'before': before_id = sharedfile_id elif sharedfile_id and before_or_after == 'after': after_id = sharedfile_id user = User.get('id=%s', int(self.oauth2_user_id)) if before_id: shared_files = user.sharedfiles_from_subscriptions( before_id=before_id) elif after_id: shared_files = user.sharedfiles_from_subscriptions( after_id=after_id) else: shared_files = user.sharedfiles_from_subscriptions() obj = {'friend_shake': []} for sf in shared_files: sharedfile_user = sf.user() fileobj = sf.as_json(user_context=user) obj['friend_shake'].append(fileobj) return self.write(obj)
def get(self, before_or_after=None, base36_id=None): """ path: /incoming """ current_user_obj = self.get_current_user_object() notifications_count = notification.Notification.for_user_count( current_user_obj) older_link, newer_link = None, None sharedfile_id = None if base36_id: sharedfile_id = base36decode(base36_id) before_id, after_id = None, None if sharedfile_id and before_or_after == 'before': before_id = sharedfile_id elif sharedfile_id and before_or_after == 'after': after_id = sharedfile_id # We're going to older, so ony use before_id. if before_id: sharedfiles = Sharedfile.incoming(before_id=before_id, per_page=11) # we have nothing on this page, redirect to base incoming page. if len(sharedfiles) == 0: return self.redirect('/incoming') if len(sharedfiles) > 10: older_link = "/incoming/before/%s" % sharedfiles[9].share_key newer_link = "/incoming/after/%s" % sharedfiles[0].share_key else: newer_link = "/incoming/after/%s" % sharedfiles[0].share_key # We're going to newer elif after_id: sharedfiles = Sharedfile.incoming(after_id=after_id, per_page=11) if len(sharedfiles) <= 10: return self.redirect('/incoming') else: sharedfiles.pop(0) older_link = "/incoming/before/%s" % sharedfiles[9].share_key newer_link = "/incoming/after/%s" % sharedfiles[0].share_key else: # clean home page, only has older link sharedfiles = Sharedfile.incoming(per_page=11) if len(sharedfiles) > 10: older_link = "/incoming/before/%s" % sharedfiles[9].share_key return self.render("incoming/index.html", sharedfiles=sharedfiles[0:10], current_user_obj=current_user_obj, older_link=older_link, newer_link=newer_link, notifications_count=notifications_count)
def get(self, id_, before_or_after=None, base36_id=None): user = User.get('id = %s', int(self.oauth2_user_id)) shake = Shake.get('id = %s', id_) sharedfile_id = base36decode(base36_id) if base36_id else None if before_or_after == 'before': sharedfiles = shake.sharedfiles_paginated(max_id=sharedfile_id, per_page=10) elif before_or_after == 'after': sharedfiles = shake.sharedfiles_paginated(since_id=sharedfile_id, per_page=10) else: sharedfiles = shake.sharedfiles_paginated(per_page=10) sharedfiles_output = [] for sf in sharedfiles: sf_dict = sf.as_json(user_context=user) sharedfiles_output.append(sf_dict) return self.write({'sharedfiles': sharedfiles_output})
def get_by_share_key(self, share_key): """ Returns a Sharedfile by its share_key. Deleted files don't get returned. """ sharedfile_id = base36decode(share_key) return self.get("id = %s and deleted = 0", sharedfile_id)
def get(self, before_or_after=None, base36_id=None): """ path: /incoming """ older_link, newer_link = None, None sharedfile_id = None if base36_id: sharedfile_id = base36decode(base36_id) before_id, after_id = None, None if sharedfile_id and before_or_after == 'before': before_id = sharedfile_id elif sharedfile_id and before_or_after == 'after': after_id = sharedfile_id #is this user's content filter on nsfw_mode = self.get_secure_cookie('nsfw') if nsfw_mode == '1': filtering = False else: filtering = True # We're going to older, so ony use before_id. if before_id: sharedfiles = Sharedfile.incoming(before_id=before_id, per_page=11, filter=filtering) # we have nothing on this page, redirect to base incoming page. if len(sharedfiles) == 0: return self.redirect('/incoming') if len(sharedfiles) > 10: older_link = "/incoming/before/%s" % sharedfiles[9].share_key newer_link = "/incoming/after/%s" % sharedfiles[0].share_key else: newer_link = "/incoming/after/%s" % sharedfiles[0].share_key # We're going to newer elif after_id: sharedfiles = Sharedfile.incoming(after_id=after_id, per_page=11, filter=filtering) if len(sharedfiles) <= 10: return self.redirect('/incoming') else: sharedfiles.pop(0) older_link = "/incoming/before/%s" % sharedfiles[9].share_key newer_link = "/incoming/after/%s" % sharedfiles[0].share_key else: # clean home page, only has older link sharedfiles = Sharedfile.incoming(per_page=11, filter=filtering) if len(sharedfiles) > 10: older_link = "/incoming/before/%s" % sharedfiles[9].share_key current_user_obj = self.get_current_user_object() return self.render("incoming/index.html", sharedfiles=sharedfiles[0:10], current_user_obj=current_user_obj, older_link=older_link, newer_link=newer_link, filtering=filtering)
def get(self, shake_name=None, before_or_after=None, base36_id=None): shake = Shake.get("name=%s", shake_name) older_link, newer_link = None, None sharedfile_id = None shared_files = [] if base36_id: sharedfile_id = base36decode(base36_id) max_id, since_id = None, None if sharedfile_id and before_or_after == 'before': max_id = sharedfile_id elif sharedfile_id and before_or_after == 'after': since_id = sharedfile_id current_user = self.get_current_user_object() if not shake: raise tornado.web.HTTPError(404) invitation, invitation_requests = _invitations(shake, current_user) # We're going to older, so ony use max_id. if max_id: shared_files = shake.sharedfiles_paginated(max_id=max_id,per_page=11) # we have nothing on this page, redirect to home page with out params. if len(shared_files) == 0: return self.redirect(shake.path()) if len(shared_files) > 10: older_link = "%s/before/%s" % (shake.path(), shared_files[9].share_key) newer_link = "%s/after/%s" % (shake.path(), shared_files[0].share_key) else: newer_link = "%s/after/%s" % (shake.path(), shared_files[0].share_key) # We're going to newer elif since_id: shared_files = shake.sharedfiles_paginated(since_id=since_id, per_page=11) if len(shared_files) <= 10: return self.redirect(shake.path()) else: shared_files.pop(0) older_link = "%s/before/%s" % (shake.path(), shared_files[9].share_key) newer_link = "%s/after/%s" % (shake.path(), shared_files[0].share_key) else: # clean home page, only has older link shared_files = shake.sharedfiles_paginated(per_page=11) if len(shared_files) > 10: older_link = "%s/before/%s" % (shake.path(), shared_files[9].share_key) #is this user a shake manager? managers = shake.managers() is_shake_manager = False if managers and current_user: for manager in managers: if manager.id == current_user.id: is_shake_manager = True break followers = shake.subscribers() follower_count = len(followers) return self.render("shakes/shake.html", shake=shake, shared_files=shared_files[0:10], current_user_obj=current_user, invitation=invitation, invitation_requests=invitation_requests, older_link=older_link,newer_link=newer_link, shake_editor=shake.owner(), managers=managers, is_shake_manager=is_shake_manager, followers=followers[:10], follower_count=follower_count)
def get(self, tag_name=None, before_or_after=None, base36_id=None): tag = Tag.get("name=%s", tag_name.lower()) older_link, newer_link = None, None sharedfile_id = None shared_files = [] if not tag: raise tornado.web.HTTPError(404) if base36_id: sharedfile_id = base36decode(base36_id) max_id, since_id = None, None if sharedfile_id and before_or_after == 'before': max_id = sharedfile_id elif sharedfile_id and before_or_after == 'after': since_id = sharedfile_id current_user = self.get_current_user_object() # We're going to older, so ony use max_id. if max_id: shared_files = tag.sharedfiles_paginated(max_id=max_id, per_page=11) # we have nothing on this page, redirect to home page with out params. if len(shared_files) == 0: return self.redirect("/tag" + tag.path()) if len(shared_files) > 10: older_link = "/tag%s/before/%s" % (tag.path(), shared_files[9].share_key) newer_link = "/tag%s/after/%s" % (tag.path(), shared_files[0].share_key) else: newer_link = "/tag%s/after/%s" % (tag.path(), shared_files[0].share_key) # We're going to newer elif since_id: shared_files = tag.sharedfiles_paginated(since_id=since_id, per_page=11) if len(shared_files) <= 10: return self.redirect("/tag" + tag.path()) else: shared_files.pop(0) older_link = "/tag%s/before/%s" % (tag.path(), shared_files[9].share_key) newer_link = "/tag%s/after/%s" % (tag.path(), shared_files[0].share_key) else: # clean home page, only has older link shared_files = tag.sharedfiles_paginated(per_page=11) if len(shared_files) > 10: older_link = "/tag%s/before/%s" % (tag.path(), shared_files[9].share_key) return self.render("tags/tag.html", tag=tag, shared_files=shared_files[0:10], current_user_obj=current_user, older_link=older_link, newer_link=newer_link)