def write(self, outfile, encoding): request = self.feed['request'] # Check for a callback param, validate it before use callback = request.GET.get('callback', None) if callback is not None: if not valid_jsonp_callback_value(callback): callback = None items_out = [] for item in self.items: # Include some of the simple elements from the preprocessed feed item item_out = dict((x, item[x]) for x in ( 'link', 'title', 'pubdate', 'author_name', 'author_link', )) if item['obj'].creator.email: item_out['author_avatar'] = gravatar_url( item['obj'].creator.email) # Linkify the tags used in the feed item item_out['categories'] = dict( (x, request.build_absolute_uri( reverse('demos_tag', kwargs={'tag': x}))) for x in item['categories']) # Include a few more, raw from the submission object itself. item_out.update((x, unicode(getattr(item['obj'], x))) for x in ( 'summary', 'description', )) item_out['featured'] = item['obj'].featured # Include screenshot as an absolute URL. item_out['screenshot'] = request.build_absolute_uri( item['obj'].screenshot_url(1)) # HACK: This .replace() should probably be done in the model item_out['thumbnail'] = request.build_absolute_uri( item['obj'].thumbnail_url(1)) # TODO: What else might be useful in a JSON feed of demo submissions? # Comment, like, view counts may change too much for caching to be useful items_out.append(item_out) data = items_out if callback: outfile.write('%s(' % callback) outfile.write(json.dumps(data, default=self._encode_complex)) if callback: outfile.write(')')
def fetch(self, pk): from .models import Document User = get_user_model() # first get a list of user ID recently authoring revisions document = Document.objects.get(pk=pk) recent_creator_ids = (document.revisions.order_by('-created') .values_list('creator_id', flat=True)) if not recent_creator_ids: return self.empty() # then return the ordered results given the ID list, MySQL only syntax select = collections.OrderedDict([ ('ordered_ids', 'FIELD(id,%s)' % ','.join(map(str, recent_creator_ids))), ]) contributors = list(User.objects.filter(id__in=list(recent_creator_ids), is_active=True) .extra(select=select, order_by=['ordered_ids']) .values('id', 'username', 'email')) result = [] for contributor in contributors: contributor['gravatar_34'] = gravatar_url(contributor['email'], size=34) result.append(contributor) return result
def fetch(self, pk): from .models import Document User = get_user_model() # first get a list of user ID recently authoring revisions document = Document.objects.get(pk=pk) recent_creator_ids = ( document.revisions.order_by('-created').values_list('creator_id', flat=True)) if not recent_creator_ids: return self.empty() # then return the ordered results given the ID list, MySQL only syntax select = collections.OrderedDict([ ('ordered_ids', 'FIELD(id,%s)' % ','.join(map(str, recent_creator_ids))), ]) contributors = list( User.objects.filter(id__in=list(recent_creator_ids), is_active=True).extra(select=select, order_by=['ordered_ids' ]).values( 'id', 'username', 'email')) result = [] for contributor in contributors: contributor['gravatar_34'] = gravatar_url(contributor['email'], size=34) result.append(contributor) return result
def write(self, outfile, encoding): request = self.feed['request'] # Check for a callback param, validate it before use callback = request.GET.get('callback', None) if callback is not None: if not valid_jsonp_callback_value(callback): callback = None items_out = [] for item in self.items: document = item['obj'] # Include some of the simple elements from the preprocessed item item_out = dict((x, item[x]) for x in ( 'link', 'title', 'pubdate', 'author_name', 'author_link', )) # HACK: DocumentFeed is the superclass of RevisionFeed. In this # case, current_revision is the revision itself. # TODO: Refactor this out into separate DocumentFeed and # RevisionFeed subclasses of Feed. if hasattr(document, 'current_revision'): revision = document.current_revision else: revision = document if revision.creator.email: item_out['author_avatar'] = gravatar_url( revision.creator.email) summary = revision.summary if summary: item_out['summary'] = summary # Linkify the tags used in the feed item categories = dict((x, request.build_absolute_uri( reverse('kuma.wiki.views.list_documents', kwargs={'tag': x}))) for x in item['categories']) if categories: item_out['categories'] = categories items_out.append(item_out) data = items_out if callback: outfile.write('%s(' % callback) outfile.write(json.dumps(data, default=self._encode_complex)) if callback: outfile.write(')')
def write(self, outfile, encoding): request = self.feed['request'] # Check for a callback param, validate it before use callback = request.GET.get('callback', None) if callback is not None: if not valid_jsonp_callback_value(callback): callback = None items_out = [] for item in self.items: document = item['obj'] # Include some of the simple elements from the preprocessed item item_out = dict((x, item[x]) for x in ( 'link', 'title', 'pubdate', 'author_name', 'author_link', )) # HACK: DocumentFeed is the superclass of RevisionFeed. In this # case, current_revision is the revision itself. # TODO: Refactor this out into separate DocumentFeed and # RevisionFeed subclasses of Feed. if hasattr(document, 'current_revision'): revision = document.current_revision else: revision = document item_out['author_avatar'] = gravatar_url(revision.creator) summary = revision.summary if summary: item_out['summary'] = summary # Linkify the tags used in the feed item categories = dict( (x, request.build_absolute_uri( reverse('kuma.wiki.views.list_documents', kwargs={'tag': x}))) for x in item['categories'] ) if categories: item_out['categories'] = categories # TODO: What else might be useful in a JSON feed of documents? items_out.append(item_out) data = items_out if callback: outfile.write('%s(' % callback) outfile.write(json.dumps(data, default=self._encode_complex)) if callback: outfile.write(')')
def write(self, outfile, encoding): request = self.feed['request'] # Check for a callback param, validate it before use callback = request.GET.get('callback', None) if callback is not None: if not valid_jsonp_callback_value(callback): callback = None items_out = [] for item in self.items: # Include some of the simple elements from the preprocessed feed item item_out = dict((x, item[x]) for x in ( 'link', 'title', 'pubdate', 'author_name', 'author_link', )) if item['obj'].creator.email: item_out['author_avatar'] = gravatar_url(item['obj'].creator) # Linkify the tags used in the feed item item_out['categories'] = dict( (x, request.build_absolute_uri(reverse('demos_tag', kwargs={'tag': x}))) for x in item['categories'] ) # Include a few more, raw from the submission object itself. item_out.update((x, unicode(getattr(item['obj'], x))) for x in ( 'summary', 'description', )) item_out['featured'] = item['obj'].featured # Include screenshot as an absolute URL. item_out['screenshot'] = request.build_absolute_uri( item['obj'].screenshot_url(1)) # HACK: This .replace() should probably be done in the model item_out['thumbnail'] = request.build_absolute_uri( item['obj'].thumbnail_url(1)) # TODO: What else might be useful in a JSON feed of demo submissions? # Comment, like, view counts may change too much for caching to be useful items_out.append(item_out) data = items_out if callback: outfile.write('%s(' % callback) outfile.write(json.dumps(data, default=self._encode_complex)) if callback: outfile.write(')')
def write(self, outfile, encoding): request = self.feed["request"] # Check for a callback param, validate it before use callback = request.GET.get("callback", None) if callback is not None: if not valid_jsonp_callback_value(callback): callback = None items_out = [] for item in self.items: document = item["obj"] # Include some of the simple elements from the preprocessed item item_out = dict((x, item[x]) for x in ("link", "title", "pubdate", "author_name", "author_link")) # HACK: DocumentFeed is the superclass of RevisionFeed. In this # case, current_revision is the revision itself. # TODO: Refactor this out into separate DocumentFeed and # RevisionFeed subclasses of Feed. if hasattr(document, "current_revision"): revision = document.current_revision else: revision = document if revision.creator.email: item_out["author_avatar"] = gravatar_url(revision.creator.email) summary = revision.summary if summary: item_out["summary"] = summary # Linkify the tags used in the feed item categories = dict( (x, request.build_absolute_uri(reverse("kuma.wiki.views.list_documents", kwargs={"tag": x}))) for x in item["categories"] ) if categories: item_out["categories"] = categories items_out.append(item_out) data = items_out if callback: outfile.write("%s(" % callback) outfile.write(json.dumps(data, default=self._encode_complex)) if callback: outfile.write(")")
def write(self, outfile, encoding): request = self.feed["request"] # Check for a callback param, validate it before use callback = request.GET.get("callback", None) if callback is not None: if not valid_jsonp_callback_value(callback): callback = None items_out = [] for item in self.items: # Include some of the simple elements from the preprocessed feed item item_out = dict((x, item[x]) for x in ("link", "title", "pubdate", "author_name", "author_link")) if item["obj"].creator.email: item_out["author_avatar"] = gravatar_url(item["obj"].creator.email) # Linkify the tags used in the feed item item_out["categories"] = dict( (x, request.build_absolute_uri(reverse("demos_tag", kwargs={"tag": x}))) for x in item["categories"] ) # Include a few more, raw from the submission object itself. item_out.update((x, unicode(getattr(item["obj"], x))) for x in ("summary", "description")) item_out["featured"] = item["obj"].featured # Include screenshot as an absolute URL. item_out["screenshot"] = request.build_absolute_uri(item["obj"].screenshot_url(1)) # HACK: This .replace() should probably be done in the model item_out["thumbnail"] = request.build_absolute_uri(item["obj"].thumbnail_url(1)) # TODO: What else might be useful in a JSON feed of demo submissions? # Comment, like, view counts may change too much for caching to be useful items_out.append(item_out) data = items_out if callback: outfile.write("%s(" % callback) outfile.write(json.dumps(data, default=self._encode_complex)) if callback: outfile.write(")")