Ejemplo n.º 1
0
  def setUp(self):
    # Create 2 users but only create sources for one of them.
    self.user = User.objects.create_user(username="uA",password="pA")
    self.user_profile = UserProfile.objects.create(owner=self.user)
    self.other_user = User.objects.create_user(username="uB",password="pB")
    self.other_user_profile = UserProfile.objects.create(owner=self.other_user)
    date = datetime.now(timezone.utc)
    r1 = Reference.objects.create(url="http://mouf",title="f1",pub_date=date)
    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)
    fs3 = WebFeed.objects.create(xmlURL="http://greuh/rss.xml",
                                 last_update_check=date,
                                 source=r3)
    self.user_profile.web_feeds.add(fs1)
    self.user_profile.web_feeds.add(fs3)
    self.user_profile.sources.add(r1)
    self.user_profile.sources.add(r3)
    # also add plain sources
    s1 = Reference.objects.create(url="http://s1",title="s1",pub_date=date)
    s3 = Reference.objects.create(url="http://s3",title="s3",pub_date=date)
    self.user_profile.sources.add(s1)
    self.user_profile.sources.add(s3)
    # 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>
"""
    import_user_feedsources_from_opml(self.user,opml_txt)
Ejemplo n.º 2
0
def run():
  if settings.DEMO and not User.objects.filter(username=settings.DEMO_USER_NAME).exists():
    print("DEMO mode: Creating demo user.")
    demo_user = User(username=settings.DEMO_USER_NAME)
    demo_user.set_password(settings.DEMO_USER_PASSWD)
    demo_user.save()
    demo_profile = UserProfile.objects.create(owner=demo_user)
    demo_profile.save()
    print("DEMO mode: Importing default bookmarks and feeds for demo user.")
    import_user_bookmarks_from_ns_list(demo_user,
                                       NS_BOOKMARKS_TXT \
                                       + "".join(NS_BOOKMARKS_TXT_MORE_TEMPLATE \
                                                 % (i,i) for i in range(200)))
    import_user_feedsources_from_opml(demo_user,OPML_TXT)
    print("DEMO mode: demo user setup finished.")
Ejemplo n.º 3
0
def startup():
  from django.contrib.auth.models import User
  from wom_user.models import UserProfile
   
  from wom_user.tasks import import_user_feedsources_from_opml
  from wom_user.tasks import import_user_bookmarks_from_ns_list

  print("DEMO mode: Ensuring demo user is available.")
  if settings.DEMO and not User.objects.filter(username=settings.DEMO_USER_NAME).exists():
    raise Warning("DEMO mode: Creating demo user.")
    demo_user = User(username=settings.DEMO_USER_NAME)
    demo_user.set_password(settings.DEMO_USER_PASSWD)
    demo_user.save()
    demo_profile = UserProfile.objects.create(owner=demo_user)
    demo_profile.save()
    print("DEMO mode: Importing default bookmarks and feeds for demo user.")
    import_user_bookmarks_from_ns_list(demo_user,
                                       NS_BOOKMARKS_TXT \
                                       + "".join(NS_BOOKMARKS_TXT_MORE_TEMPLATE \
                                                 % (i,i) for i in range(200)))
    import_user_feedsources_from_opml(demo_user,OPML_TXT)
    print("DEMO mode: demo user setup finished.")
Ejemplo n.º 4
0
def handle_uploaded_opml(opmlUploadedFile,user):
  import_user_feedsources_from_opml(user,opmlUploadedFile.read())
Ejemplo n.º 5
0
def handle_uploaded_opml(opmlUploadedFile,user):
  if opmlUploadedFile.name.endswith(".opml") \
     or opmlUploadedFile.name.endswith(".xml"):
    import_user_feedsources_from_opml(user,opmlUploadedFile.read())
  else:
    raise ValueError("Uploaded file '%s' is not OPML !" % opmlUploadedFile.name)