def get(self): userAgent = self.request.headers.get('User-Agent', None) # Long expiry - so don't need to generate unless an upload has taken place expiry_seconds = 60 * 60 * 24 * 7 memcachedKey = 'rss-output' output = '' memcacheEnabled = capabilities.CapabilitySet('memcache').is_enabled() if memcacheEnabled: try: output = memcache.get(memcachedKey) except KeyError: output = '' if output is None or len(output) == 0: q = models.GeneratedItem.query(models.GeneratedItem.id == memcachedKey) pregenerated = q.get() if pregenerated is None: count = 200 recentItemsSearch = models.GalleryItem.query(models.GalleryItem.type == 'photo').order( -models.GalleryItem.updated).fetch(count) when = datetime.datetime.now() builddate = when recentItems = [] if recentItemsSearch: latestDate = None for item in recentItemsSearch: if utils.is_public_publishable_path(item.path): recentItems.append(item) if latestDate is None: latestDate = item.updated else: if latestDate < item.updated: latestDate = item.updated if latestDate <> None: when = latestDate template_vals = {'host': self.request.host_url, 'items': recentItems, 'pubdate': when, 'builddate': builddate} output = utils.render_template("rss.html", template_vals) pregenerated = models.GeneratedItem( id=memcachedKey, text=output, updated=when) pregenerated.put(); else: output = pregenerated.text if memcacheEnabled: memcache.set(memcachedKey, output, expiry_seconds) utils.add_response_headers(self.request, self.response.headers) self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400 self.response.headers['Pragma'] = 'public' self.response.headers['Content-Type'] = 'application/rss+xml' self.response.out.write(output)
def synchronize_common(contents): decoded = json.loads(contents) version = decoded["version"] items_written = 0 logging.info("Decoded Version: " + str(version)) for item in decoded["items"]: path = item["Path"] logging.info("Path: " + path) original_album_path = item["OriginalAlbumPath"] if original_album_path is None: original_album_path = '' title = item["Title"] type = item["Type"] description = item["Description"] rating = None # item["Rating"] hash = utils.generate_url_hash(path) indexSection = hash[:1] location = extract_location(item) children = extract_children(item) breadcrumbs = extract_breadcrumbs(item) metadata = extract_metadata(item) keywords = extract_keywords(item) foundImageSizes = extract_image_sizes(item) firstSibling = extract_sibling(item, "First") previousSibling = extract_sibling(item, "Previous") nextSibling = extract_sibling(item, "Next") lastSibling = extract_sibling(item, "Last") q = models.GalleryItem.query(models.GalleryItem.id == hash) dbItem = q.get() if dbItem is None: dbItem = models.GalleryItem( id=hash, path=path, originalAlbumPath=original_album_path, indexSection=indexSection, title=title, type=type, description=description, rating=rating, location=location, children=children, breadcrumbs=breadcrumbs, resizes=foundImageSizes, metadata=metadata, keywords=keywords, firstSibling=firstSibling, previousSibling=previousSibling, nextSibling=nextSibling, lastSibling=lastSibling ) dbItem.put() items_written = items_written + 1 logging.info('Created: ' + path) if type == 'photo' and utils.is_public_publishable_path(path) and utils.is_publishable(dbItem): publishItem = models.PublishableItem(id=dbItem.id) publishItem.put() else: if path <> dbItem.path or original_album_path <> dbItem.originalAlbumPath or indexSection <> dbItem.indexSection or dbItem.title <> title or dbItem.type <> type or dbItem.description <> description or dbItem.location <> location or children_changed( dbItem.children, children) or breadcrumbs_changed(dbItem.breadcrumbs, breadcrumbs) or resizes_changed(dbItem.resizes, foundImageSizes) or metadata_changed( dbItem.metadata, metadata) or keywords_changed(dbItem.keywords, keywords) or sibling_changed( dbItem.firstSibling, firstSibling) or sibling_changed(dbItem.previousSibling, previousSibling) or sibling_changed( dbItem.nextSibling, nextSibling) or sibling_changed(dbItem.lastSibling, lastSibling): dbItem.path = path dbItem.originalAlbumPath = original_album_path dbItem.indexSection = indexSection dbItem.title = title dbItem.type = type dbItem.description = description dbItem.rating = rating dbItem.location = location dbItem.children = children dbItem.breadcrumbs = breadcrumbs dbItem.resizes = foundImageSizes dbItem.metadata = metadata dbItem.keywords = keywords dbItem.firstSibling = firstSibling dbItem.previousSibling = previousSibling dbItem.nextSibling = nextSibling dbItem.lastSibling = lastSibling dbItem.updated = datetime.datetime.now() dbItem.put() items_written = items_written + 1 logging.info('updated: ' + path) else: logging.info('Unchanged: ' + path) for deletedItem in decoded["deletedItems"]: logging.info('Deleting: ' + deletedItem) hash = utils.generate_url_hash(deletedItem) if delete_item(hash): items_written = items_written + 1 delete_published_item(hash) if items_written > 0: invalidateOutputCaches() pubsubhubub.queue_update() return items_written