Example #1
0
 def _add_repo_entry(self, root, repo, repo_conf):
     entry_el = ET.SubElement(root, 'entry')
     ET.SubElement(entry_el, 'id').text = self.build_absolute_uri(
         '/',
         repo.key().name())
     if repo_conf.language_menu_options:
         default_lang = repo_conf.language_menu_options[0]
         title_el = ET.SubElement(entry_el, 'title', {'lang': default_lang})
         title_el.text = repo_conf.repo_titles[default_lang]
     ET.SubElement(entry_el, 'updated').text = utils.format_utc_timestamp(
         repo_conf.updated_date)
     content_el = ET.SubElement(entry_el, 'content', {'type': 'text/xml'})
     repo_el = ET.SubElement(content_el, GPF + 'repo')
     for lang, title in repo_conf.repo_titles.items():
         ET.SubElement(repo_el, GPF + 'title', {'lang': lang}).text = title
     ET.SubElement(repo_el, GPF + 'read_auth_key_required').text = (
         'true' if repo_conf.read_auth_key_required else 'false')
     ET.SubElement(repo_el, GPF + 'search_auth_key_required').text = (
         'true' if repo_conf.search_auth_key_required else 'false')
     ET.SubElement(
         repo_el,
         GPF + 'test_mode').text = ('true' if repo.test_mode else 'false')
     center = repo_conf.map_default_center or [0, 0]
     location_el = ET.SubElement(repo_el, GPF + 'location')
     ET.SubElement(location_el, GEORSS +
                   'point').text = ('%f %f' % (center[0], center[1]))
Example #2
0
 def add_feed_elements(self, root):
     ET.SubElement(root, 'id').text = self.build_absolute_uri()
     ET.SubElement(root, 'title').text = RepoFeedView._TITLE
     if self.env.repo == 'global':
         repos = model.Repo.all().filter(
             'activation_status !=', model.Repo.ActivationStatus.STAGING)
     else:
         repo = model.Repo.get(self.env.repo)
         if repo.activation_status == model.Repo.ActivationStatus.ACTIVE:
             repos = [repo]
         else:
             raise django.http.Http404()
     repo_confs = {}
     for repo in repos:
         repo_id = repo.key().name()
         repo_conf = config.Configuration(repo_id, include_global=False)
         repo_confs[repo_id] = repo_conf
     updated_dates = [conf.updated_date for conf in repo_confs.values()]
     # If there's no non-staging repositories, it's not really clear what
     # updated_date should be; we just use the current time.
     latest_updated_date = (max(updated_dates)
                            if updated_dates else utils.get_utcnow())
     ET.SubElement(
         root,
         'updated').text = utils.format_utc_timestamp(latest_updated_date)
     for repo in repos:
         if repo.activation_status == model.Repo.ActivationStatus.ACTIVE:
             self._add_repo_entry(root, repo, repo_confs[repo.key().name()])
Example #3
0
def convert_time(text, offset):
    """Converts a textual date and time into an RFC 3339 UTC timestamp."""
    if utils.DATETIME_RE.match(text.strip()):  # don't apply offset
        return text
    match = re.search(r'(\d\d\d\d)[/-](\d+)[/-](\d+) *(\d+):(\d+)', text)
    if match:
        y, l, d, h, m = map(int, match.groups())
        timestamp = calendar.timegm((y, l, d, h, m, 0)) - offset*3600
        return utils.format_utc_timestamp(timestamp)
    return text  # keep the original text so it shows up in the error message
Example #4
0
 def write_entry(self, file, repo, indent):
     repo_config = config.Configuration(repo)
     file.write(indent + '<entry>\n')
     write_element(file, 'id', '%s/%s' % (ROOT_URL, repo), indent + '  ')
     write_element(file, 'published',
                   format_utc_timestamp(repo_config.published_date),
                   indent + '  ')
     write_element(file, 'updated',
                   format_utc_timestamp(repo_config.updated_date),
                   indent + '  ')
     default_language = (repo_config.language_menu_options or [])[:1]
     self.write_titles(file, 'title', default_language,
                       repo_config.repo_titles, indent + '  ')
     file.write(indent + '  <content type="text/xml">\n')
     file.write(indent + '    <gpf:repo>\n')
     self.write_fields(file, repo_config, indent + ' ' * 6)
     file.write(indent + '    </gpf:repo>\n')
     file.write(indent + '  </content>\n')
     file.write(indent + '</entry>\n')
Example #5
0
 def write_entry(self, file, repo, indent):
     repo_config = config.Configuration(repo)
     file.write(indent + '<entry>\n')
     write_element(file, 'id', '%s/%s' % (ROOT_URL, repo),
                   indent + '  ')
     write_element(file, 'published',
                   format_utc_timestamp(repo_config.published_date),
                   indent + '  ')
     write_element(file, 'updated',
                   format_utc_timestamp(repo_config.updated_date),
                   indent + '  ')
     default_language = (repo_config.language_menu_options or [])[:1]
     self.write_titles(file, 'title', default_language,
                       repo_config.repo_titles, indent + '  ')
     file.write(indent + '  <content type="text/xml">\n')
     file.write(indent + '    <gpf:repo>\n')
     self.write_fields(file, repo_config, indent + ' ' * 6)
     file.write(indent + '    </gpf:repo>\n')
     file.write(indent + '  </content>\n')
     file.write(indent + '</entry>\n')
Example #6
0
 def write_feed(self, file, repos, url, title, updated):
     file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
     file.write('<feed xmlns="http://www.w3.org/2005/Atom"\n')
     file.write('      xmlns:gpf="%s"\n' % self.GPF_NAMESPACE_URI)
     file.write('      xmlns:georss="%s">\n' % self.GEORSS_NAMESPACE_URI)
     indent = '  '
     write_element(file, 'id', url, indent)
     write_element(file, 'title', title, indent)
     write_element(file, 'updated', format_utc_timestamp(updated), indent)
     for repo in repos:
         self.write_entry(file, repo, indent)
     file.write('</feed>\n')
Example #7
0
 def write_feed(self, file, repos, url, title, updated):
     file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
     file.write('<feed xmlns="http://www.w3.org/2005/Atom"\n')
     file.write('      xmlns:gpf="%s"\n' % self.GPF_NAMESPACE_URI)
     file.write('      xmlns:georss="%s">\n' % self.GEORSS_NAMESPACE_URI)
     indent = '  '
     write_element(file, 'id', url, indent)
     write_element(file, 'title', title, indent)
     write_element(file, 'updated', format_utc_timestamp(updated), indent)
     for repo in repos:
         self.write_entry(file, repo, indent)
     file.write('</feed>\n')