Пример #1
0
def import_user_feedsources_from_opml(user,opml_txt):
  feeds_and_tags = import_feedsources_from_opml(opml_txt)
  profile = UserProfile.objects.get(owner=user)
  classif_data_to_save = []
  for feed,tags in feeds_and_tags.items():
    profile.web_feeds.add(feed)
    profile.sources.add(feed.source)
    valid_tags = [t for t in tags if len(t)<=TAG_NAME_MAX_LENGTH]
    if len(valid_tags)!=len(tags):
      invalid_tags = [t for t in tags if len(t)>TAG_NAME_MAX_LENGTH]
      logger.error("Could not import some source tags with too long names (%s>%s)"\
                   % (",".join(str(len(t)) for t in invalid_tags),
                      TAG_NAME_MAX_LENGTH))
    classif_data_to_save.append(set_item_tag_names(user,feed,valid_tags))
  with transaction.commit_on_success():
    for cd in classif_data_to_save:
      cd.save()
Пример #2
0
def import_user_feedsources_from_opml(user,opml_txt):
  feeds_and_tags = import_feedsources_from_opml(opml_txt)
  profile = UserProfile.objects.get(owner=user)
  classif_data_to_save = []
  for feed,tags in feeds_and_tags.items():
    profile.web_feeds.add(feed)
    profile.sources.add(feed.source)
    valid_tags = [t for t in tags if len(t)<=TAG_NAME_MAX_LENGTH]
    if len(valid_tags)!=len(tags):
      invalid_tags = [t for t in tags if len(t)>TAG_NAME_MAX_LENGTH]
      logger.error("Could not import some source tags with too long names (%s>%s)"\
                   % (",".join(str(len(t)) for t in invalid_tags),
                      TAG_NAME_MAX_LENGTH))
    classif_data_to_save.append(set_item_tag_names(user,feed,valid_tags))
  with transaction.atomic():
    for cd in classif_data_to_save:
      cd.save()
Пример #3
0
    def setUp(self):
        # Create 2 users but only create sources for one of them.
        self.user1 = User.objects.create_user(username="******", password="******")
        # self.user1_profile = UserProfile.objects.create(user=self.user1)
        # self.user2 = User.objects.create_user(username="******",password="******")
        # self.user2_profile = UserProfile.objects.create(user=self.user2)
        date = datetime.now(timezone.utc)
        r1 = Reference.objects.create(url="http://mouf",
                                      title="f1",
                                      pub_date=date)
        self.fs1 = WebFeed.objects.create(xmlURL="http://mouf/rss.xml",
                                          last_update_check=date,
                                          source=r1)
        r3 = Reference.objects.create(url="http://greuh",
                                      title="f3",
                                      pub_date=date)
        self.fs3 = WebFeed.objects.create(xmlURL="http://greuh/rss.xml",
                                          last_update_check=date,
                                          source=r3)
        # create an opml snippet
        opml_txt = """\
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
  <head>
  <title>My Subcriptions</title>
  </head>
  <body>
  <outline title="News" text="News">
    <outline text="Richard Stallman's Political Notes"
         title="Richard Stallman's Political Notes" type="rss"
         xmlUrl="http://stallman.org/rss/rss.xml" htmlUrl="http://stallman.org/archives/polnotes.html"/>
    <outline text="Mouf"
         title="Mouf" type="rss"
         xmlUrl="http://mouf/rss.xml" htmlUrl="http://mouf"/>
    <outline text="Dave&#39;s LifeLiner" title="Dave&#39;s LifeLiner"
         type="rss" xmlUrl="http://www.scripting.com/rss.xml" htmlUrl="http://scripting.com/"/>
  </outline>
  <outline title="Culture" text="Culture">
    <outline text="Open Culture" title="Open Culture" type="rss"
         xmlUrl="http://www.openculture.com/feed" htmlUrl="http://www.openculture.com"/>
  </outline>
  </body>
</opml>
"""
        self.feeds_and_tags = import_feedsources_from_opml(opml_txt)
Пример #4
0
  def setUp(self):
    # Create 2 users but only create sources for one of them.
    self.user1 = User.objects.create_user(username="******",password="******")
    # self.user1_profile = UserProfile.objects.create(user=self.user1)
    # self.user2 = User.objects.create_user(username="******",password="******")
    # self.user2_profile = UserProfile.objects.create(user=self.user2)
    date = datetime.now(timezone.utc)
    r1 = Reference.objects.create(url="http://mouf",title="f1",pub_date=date)
    self.fs1 = WebFeed.objects.create(xmlURL="http://mouf/rss.xml",
                                      last_update_check=date,
                                      source=r1)
    r3 = Reference.objects.create(url="http://greuh",title="f3",pub_date=date)
    self.fs3 = WebFeed.objects.create(xmlURL="http://greuh/rss.xml",
                                      last_update_check=date,
                                      source=r3)
    # create an opml snippet
    opml_txt = """\
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
  <head>
  <title>My Subcriptions</title>
  </head>
  <body>
  <outline title="News" text="News">
    <outline text="Richard Stallman's Political Notes"
         title="Richard Stallman's Political Notes" type="rss"
         xmlUrl="http://stallman.org/rss/rss.xml" htmlUrl="http://stallman.org/archives/polnotes.html"/>
    <outline text="Mouf"
         title="Mouf" type="rss"
         xmlUrl="http://mouf/rss.xml" htmlUrl="http://mouf"/>
    <outline text="Dave&#39;s LifeLiner" title="Dave&#39;s LifeLiner"
         type="rss" xmlUrl="http://www.scripting.com/rss.xml" htmlUrl="http://scripting.com/"/>
  </outline>
  <outline title="Culture" text="Culture">
    <outline text="Open Culture" title="Open Culture" type="rss"
         xmlUrl="http://www.openculture.com/feed" htmlUrl="http://www.openculture.com"/>
  </outline>
  </body>
</opml>
"""
    self.feeds_and_tags = import_feedsources_from_opml(opml_txt)