def user(self): from drawquest.apps.drawquest_auth.models import User if self.ugq: return UserDetails.from_id(self.author_id) try: return User.details_by_username('QuestBot')() except User.DoesNotExist: return UserDetails.from_id(self.author_id)
def user(self): from drawquest.apps.drawquest_auth.models import User if self.ugq: return UserDetails.from_id(self.author_id) try: return User.details_by_username('QuestBot')() except User.DoesNotExist: return UserDetails.from_id(self.author_id)
def share_page(request, short_id): try: comment_id = get_mapping_id_from_short_id(short_id) except ValueError: raise Http404 comment = get_object_or_404(QuestComment, id=comment_id) comment_details = comment.details() quest_details = QuestDetails.from_id(comment_details.quest_id) author_details = UserDetails.from_id(comment.author_id) ctx = { "quest": quest_details, "quest_template_url": "", "comment": comment_details, "author": author_details, "private_profile": bool(UserKV(comment.author_id).web_profile_privacy.get()), } if quest_details.content: ctx.update( { "quest_template_url": quest_details.content.get_absolute_url_for_image_type("gallery"), "original_quest_template_url": quest_details.content.get_absolute_url_for_image_type("original"), } ) return r2r_jinja("quest_comments/share_comment_page.html", ctx, request)
def __init__(self, data={}, actor=None, key=None): """ Automatically records a timestamp as well. """ if data.get('type', self.TYPE) != self.TYPE: raise TypeError("Incompatible activity type.") self._data = { 'ts': Services.time.time(), 'type': self.TYPE, } if actor: #TODO have a UserDetails for example.com too to get rid of this branch. if settings.PROJECT == 'canvas': self._data['actor'] = { 'username': actor.username, 'id': actor.id } elif settings.PROJECT == 'drawquest': self._data['actor'] = UserDetails.from_id(actor.id).to_client() self._data.update(data) if 'id' not in self._data: from apps.activity.models import Activity db_activity = Activity.from_redis_activity(self, key=key) self._data['id'] = db_activity.id
def from_user(cls, actor, followee): data = { 'details_url': '/user/{0}'.format(actor.username), 'is_actor_anonymous': False, 'followee': UserDetails.from_id(followee.id), } return cls(data, actor=actor)
def from_user(cls, actor, followee): data = { 'details_url': '/user/{0}'.format(actor.username), 'is_actor_anonymous': False, 'followee': UserDetails.from_id(followee.id), } return cls(data, actor=actor)
def share_page(request, short_id): try: comment_id = get_mapping_id_from_short_id(short_id) except ValueError: raise Http404 comment = get_object_or_404(QuestComment, id=comment_id) comment_details = comment.details() quest_details = QuestDetails.from_id(comment_details.quest_id) author_details = UserDetails.from_id(comment.author_id) ctx = { 'quest': quest_details, 'quest_template_url': '', 'comment': comment_details, 'author': author_details, 'private_profile': bool(UserKV(comment.author_id).web_profile_privacy.get()), } if quest_details.content: ctx.update({ 'quest_template_url': quest_details.content.get_absolute_url_for_image_type('gallery'), 'original_quest_template_url': quest_details.content.get_absolute_url_for_image_type('original'), }) return r2r_jinja('quest_comments/share_comment_page.html', ctx, request)
def _details(self): base = util.loads(self.data) base.update({"id": self.id, "ts": self.timestamp, "activity_type": self.activity_type}) # TODO have a UserDetails for example.com too to get rid of this branch. if self.actor_id: base["actor"] = UserDetails.from_id(self.actor_id).to_client() return base
def search_users(request, query): try: query.decode('ascii') except UnicodeEncodeError: return {'users': []} if len(query.strip() ) > 20: # Some fudge here since we have fuzzy matching. return {'users': []} sqs = SearchQuerySet() conn = sqs.query.backend.conn hits = conn.search({ 'from': 0, 'size': knobs.SEARCH_RESULTS_PER_PAGE, 'query': { 'text': { 'text': sqs.query.clean(query), }, }, })['hits']['hits'] user_ids = [ long(hit['_source'][DJANGO_ID]) for hit in hits[:knobs.SEARCH_RESULTS_PER_PAGE] ] try: exact_match = User.objects.get(username=query, is_active=True) try: user_ids.remove(exact_match.id) except ValueError: pass user_ids.insert(0, exact_match.id) except User.DoesNotExist: pass users = [] for user_id in user_ids: user_redis = UserRedis(user_id) #TODO instead of hacking this on here, have a new Details subclass. result = {'user': UserDetails.from_id(user_id).to_client()} result['follower_count'] = user_redis.new_followers.zcard() result['following_count'] = user_redis.new_following.zcard() if request.user.is_authenticated() and request.user.id != user_id: result['viewer_is_following'] = request.user.is_following(user_id) users.append(result) return { 'users': users, }
def _details(self): base = util.loads(self.data) base.update({ 'id': self.id, 'ts': self.timestamp, 'activity_type': self.activity_type, }) #TODO have a UserDetails for example.com too to get rid of this branch. if self.actor_id: base['actor'] = UserDetails.from_id(self.actor_id).to_client() return base
def search_users(request, query): try: query.decode('ascii') except UnicodeEncodeError: return {'users': []} if len(query.strip()) > 20: # Some fudge here since we have fuzzy matching. return {'users': []} sqs = SearchQuerySet() conn = sqs.query.backend.conn hits = conn.search({ 'from': 0, 'size': knobs.SEARCH_RESULTS_PER_PAGE, 'query': { 'text': { 'text': sqs.query.clean(query), }, }, })['hits']['hits'] user_ids = [long(hit['_source'][DJANGO_ID]) for hit in hits[:knobs.SEARCH_RESULTS_PER_PAGE]] try: exact_match = User.objects.get(username=query, is_active=True) try: user_ids.remove(exact_match.id) except ValueError: pass user_ids.insert(0, exact_match.id) except User.DoesNotExist: pass users = [] for user_id in user_ids: user_redis = UserRedis(user_id) #TODO instead of hacking this on here, have a new Details subclass. result = {'user': UserDetails.from_id(user_id).to_client()} result['follower_count'] = user_redis.new_followers.zcard() result['following_count'] = user_redis.new_following.zcard() if request.user.is_authenticated() and request.user.id != user_id: result['viewer_is_following'] = request.user.is_following(user_id) users.append(result) return { 'users': users, }
def following(user, viewer=None, offset='top', direction='next', request=None): """ The users that `user` is following. """ if direction != 'next': raise ValueError("Following only supports 'next' - scrolling in one direction.") if request is None or (request.idiom == 'iPad' and request.app_version_tuple <= (3, 1)): user_ids = user.redis.new_following.zrange(0, -1) pagination = None else: user_ids, pagination = _paginate(user.redis.new_following, offset, request=request) users = UserDetails.from_ids(user_ids) if request is None or request.app_version_tuple < (3, 0): users = _sorted(users) return _for_viewer(users, viewer=viewer), pagination
def get_reactions(self): """ Includes just stars and playbacks, for now, interleaved by timestamp. """ stars = self.get_stars() for star in stars: star['reaction_type'] = 'star' playbacks = [{ 'id': playback.id, 'user': UserDetails.from_id(playback.viewer_id), 'timestamp': playback.timestamp, 'reaction_type': 'playback', } for playback in self.playbacks.all()] reactions = itertools.chain(stars, playbacks) return sorted(reactions, key=lambda reaction: reaction['timestamp'], reverse=True)
def share_page(request, short_id): try: comment_id = get_mapping_id_from_short_id(short_id) except ValueError: raise Http404 comment = get_object_or_404(QuestComment, id=comment_id) comment_details = comment.details() quest_details = QuestDetails.from_id(comment_details.quest_id) author_details = UserDetails.from_id(comment.author_id) return r2r_jinja('quest_comments/share_page.html', { 'quest': quest_details, 'comment': comment_details, 'author': author_details, }, request)
def get_reactions(self): """ Includes just stars and playbacks, for now, interleaved by timestamp. """ stars = self.get_stars() for star in stars: star['reaction_type'] = 'star' playbacks = [{ 'id': playback.id, 'user': UserDetails.from_id(playback.viewer_id), 'timestamp': playback.timestamp, 'reaction_type': 'playback', } for playback in self.playbacks.all()] reactions = itertools.chain(stars, playbacks) return sorted(reactions, key=lambda reaction: reaction['timestamp'], reverse=True)
def _details(self): base = util.loads(self.data) base.update({ 'id': self.id, 'ts': self.timestamp, 'activity_type': self.activity_type, }) #TODO have a UserDetails for example.com too to get rid of this branch. if self.actor: if settings.PROJECT == 'canvas': base['actor'] = { 'id': self.actor.id, 'username': self.actor.username, } elif settings.PROJECT == 'drawquest': base['actor'] = UserDetails.from_id(self.actor.id).to_client() return base
def _details(self): base = util.loads(self.data) base.update({ 'id': self.id, 'ts': self.timestamp, 'activity_type': self.activity_type, }) #TODO have a UserDetails for example.com too to get rid of this branch. if self.actor: if settings.PROJECT == 'canvas': base['actor'] = { 'id': self.actor.id, 'username': self.actor.username, } elif settings.PROJECT == 'drawquest': base['actor'] = UserDetails.from_id(self.actor.id).to_client() return base
def get_reactions(self): """ Includes just stars and playbacks, for now, interleaved by timestamp. """ stars = self.get_stars() for star in stars: star["reaction_type"] = "star" playbacks = [ { "id": playback.id, "user": UserDetails.from_id(playback.viewer_id), "timestamp": playback.timestamp, "reaction_type": "playback", } for playback in self.playbacks.all() ] reactions = itertools.chain(stars, playbacks) return sorted(reactions, key=lambda reaction: reaction["timestamp"], reverse=True)
def _details(self): base = util.loads(self.data) base.update( { "id": self.id, "ts": self.timestamp, "activity_type": dict((v, k) for k, v in ACTIVITY_TYPE_IDS.items())[self.activity_type], } ) if self.quest_id: base["quest_id"] = self.quest_id if self.comment_id: base["comment_id"] = self.comment_id # TODO have a UserDetails for example.com too to get rid of this branch. if self.actor_id: base["actor"] = UserDetails.from_id(self.actor_id).to_client() return base
def __init__(self, data={}, actor=None, key=None): """ Automatically records a timestamp as well. """ if data.get('type', self.TYPE) != self.TYPE: raise TypeError("Incompatible activity type.") self._data = { 'ts': Services.time.time(), 'type': self.TYPE, } if actor: #TODO have a UserDetails for example.com too to get rid of this branch. if settings.PROJECT == 'canvas': self._data['actor'] = {'username': actor.username, 'id': actor.id} elif settings.PROJECT == 'drawquest': self._data['actor'] = UserDetails.from_id(actor.id).to_client() self._data.update(data) if 'id' not in self._data: from apps.activity.models import Activity db_activity = Activity.from_redis_activity(self, key=key) self._data['id'] = db_activity.id
def _details(self): base = util.loads(self.data) base.update({ 'id': self.id, 'ts': self.timestamp, 'activity_type': dict((v, k) for k, v in ACTIVITY_TYPE_IDS.items())[self.activity_type], }) if self.quest_id: base['quest_id'] = self.quest_id if self.comment_id: base['comment_id'] = self.comment_id #TODO have a UserDetails for example.com too to get rid of this branch. if self.actor_id: base['actor'] = UserDetails.from_id(self.actor_id).to_client() return base
def user(self): return UserDetails.from_id(self.author_id)
def user(self): return UserDetails.from_id(self.author_id)
def user(self): if not getattr(self, '_memoized_user', None): self._memoized_user = UserDetails.from_id(self.author_id) return self._memoized_user
def user(self): if not getattr(self, '_memoized_user', None): self._memoized_user = UserDetails.from_id(self.author_id) return self._memoized_user