Beispiel #1
0
 def _recipe_list(self, tiddlers, recipe_name):
     representation_link = '%s/recipes/%s/tiddlers' % (
         self._server_prefix(), encode_name(recipe_name))
     representations = self._tiddler_list_header(representation_link)
     user_object = get_user_object(self.environ)
     recipe = self.environ['tiddlyweb.store'].get(Recipe(recipe_name))
     publicity = ''
     try:
         recipe.policy.allows(user_object, 'manage')
         policy = recipe.policy
         if policy.read == [user_object['name']]:
             publicity = 'private'
         elif policy.read == []:
             publicity = 'public'
         else:
             publicity = 'custom'
         delete = True
     except (UserRequiredError, ForbiddenError):
         policy = None
         delete = False
     data = {
         'title': 'TiddlyHoster Recipe %s' % recipe.name,
         'policy': policy,
         'publicity': publicity,
         'delete': delete,
         'recipe': recipe,
         'tiddlers': tiddlers,
         'representations': representations
     }
     del self.environ['tiddlyweb.title']
     return send_template(self.environ, 'recipelist.html', data)
Beispiel #2
0
 def _recipe_list(self, tiddlers, recipe_name):
     representation_link = '%s/recipes/%s/tiddlers' % (
             self._server_prefix(), encode_name(recipe_name))
     representations = self._tiddler_list_header(representation_link)
     user_object = get_user_object(self.environ)
     recipe = self.environ['tiddlyweb.store'].get(Recipe(recipe_name))
     publicity = ''
     try:
         recipe.policy.allows(user_object, 'manage')
         policy = recipe.policy
         if policy.read == [user_object['name']]:
             publicity = 'private'
         elif policy.read == []:
             publicity = 'public'
         else:
             publicity = 'custom'
         delete = True
     except (UserRequiredError, ForbiddenError):
         policy = None
         delete = False
     data = {'title': 'TiddlyHoster Recipe %s' % recipe.name,
             'policy': policy,
             'publicity': publicity,
             'delete': delete,
             'recipe': recipe,
             'tiddlers': tiddlers,
             'representations': representations}
     del self.environ['tiddlyweb.title']
     return send_template(self.environ, 'recipelist.html', data)
Beispiel #3
0
def get_tiddler_edit(environ, start_response):
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    title = environ['tiddlyweb.query'].get('title', [''])[0]
    bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    username = usersign['name']

    if not 'MEMBER' in usersign['roles']:
        raise HTTP404('bad edit')

    if not title and not bag_name:
        tiddler = get_profile(store, usersign, username)
        page_title = 'Edit Profile'
        return_url = '%s/home' % server_base_url(environ)
    elif not title:
        tiddler = Tiddler('', bag_name)
        page_title = 'Edit New Tiddler'
        return_url = ''
    else:
        tiddler = Tiddler(title, bag_name)
        page_title = 'Edit %s' % title
        return_url = tiddler_url(environ, tiddler)
        try:
            tiddler = store.get(tiddler)
        except StoreError:
            pass
    bag = Bag(tiddler.bag)
    bag = store.get(bag)
    bag.policy.allows(usersign, 'write')

    data = {}
    data['tiddler'] = tiddler
    data['return_url'] = return_url
    data['title'] = page_title
    return send_template(environ, 'profile_edit.html', data)
    def list_tiddlers(self, bag):
        """
        If the URL is a list of bag tiddlers, we present a bag
        editing interface. Otherwise we use the parent serialization.
        """
        if (self.environ['wsgiorg.routing_args'][1].get('tiddler_name')):
            return HTMLSerialization.list_tiddlers(self, bag)

        try:
            name = self.environ['wsgiorg.routing_args'][1]['bag_name']
        except KeyError: # not a bag link
            return HTMLSerialization.list_tiddlers(self, bag)

        representation_link = '%s/bags/%s/tiddlers' % (
                self._server_prefix(), encode_name(bag.name))
        representations = self._tiddler_list_header(representation_link)
        user_object = get_user_object(self.environ)
        publicity = ''
        try:
            bag.policy.allows(user_object, 'manage')
            policy = bag.policy
            publicity = determine_publicity(user_object, policy)
        except (UserRequiredError, ForbiddenError):
            policy = None
        try:
            bag.policy.allows(user_object, 'delete')
            delete = True
        except (UserRequiredError, ForbiddenError):
            delete = False
        data = {'title': 'TiddlyHoster Bag %s' % bag.name, 'policy': policy,
                'publicity': publicity, 'delete': delete,
                'bag': bag, 'representations': representations}
        del self.environ['tiddlyweb.title']
        return send_template(self.environ, 'baglist.html', data)
Beispiel #5
0
def get_tiddler_edit(environ, start_response):
    usersign = environ["tiddlyweb.usersign"]
    store = environ["tiddlyweb.store"]
    title = environ["tiddlyweb.query"].get("title", [""])[0]
    bag_name = environ["tiddlyweb.query"].get("bag", [""])[0]
    username = usersign["name"]

    if not "MEMBER" in usersign["roles"]:
        raise HTTP404("bad edit")

    if not title and not bag_name:
        tiddler = get_profile(store, usersign, username)
        page_title = "Edit Profile"
        return_url = "%s/home" % server_base_url(environ)
    elif not title:
        tiddler = Tiddler("", bag_name)
        page_title = "Edit New Tiddler"
        return_url = ""
    else:
        tiddler = Tiddler(title, bag_name)
        page_title = "Edit %s" % title
        return_url = tiddler_url(environ, tiddler)
        try:
            tiddler = store.get(tiddler)
        except StoreError:
            pass
    bag = Bag(tiddler.bag)
    bag = store.get(bag)
    bag.policy.allows(usersign, "write")

    data = {}
    data["tiddler"] = tiddler
    data["return_url"] = return_url
    data["title"] = page_title
    return send_template(environ, "profile_edit.html", data)
Beispiel #6
0
def get_tiddler_edit(environ, start_response):
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    title = environ['tiddlyweb.query'].get('title', [''])[0]
    bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    username = usersign['name']

    if not 'MEMBER' in usersign['roles']:
        raise HTTP404('bad edit')

    if not title and not bag_name:
        tiddler = get_profile(store, usersign, username)
        page_title = 'Edit Profile'
        return_url = '%s/home' % server_base_url(environ)
    elif not title:
        tiddler = Tiddler('', bag_name)
        page_title = 'Edit New Tiddler'
        return_url = ''
    else:
        tiddler = Tiddler(title, bag_name)
        page_title = 'Edit %s' % title
        return_url = tiddler_url(environ, tiddler)
        try:
            tiddler = store.get(tiddler)
        except StoreError:
            pass
    bag = Bag(tiddler.bag)
    bag = store.get(bag)
    bag.policy.allows(usersign, 'write')

    data = {}
    data['tiddler'] = tiddler
    data['return_url'] = return_url
    data['title'] = page_title
    return send_template(environ, 'profile_edit.html', data)
Beispiel #7
0
 def _bag_list(self, tiddlers):
     if '/feedbag' in self.environ['selector.matches'][0]:
         representation_link = '%s/feedbag' % (self._server_prefix())
         bag = Bag('feedbag')
         bag.policy.manage = ["NONE"]
         bag.policy.delete = ["NONE"]
         bag.desc = 'Recent Public Stuff'
     else:
         name = self.environ['wsgiorg.routing_args'][1]['bag_name']
         name = urllib.unquote(name)
         name = name.decode('utf-8')
         representation_link = '%s/bags/%s/tiddlers' % (
                 self._server_prefix(), encode_name(name))
         bag = self.environ['tiddlyweb.store'].get(Bag(name))
     representations = self._tiddler_list_header(representation_link)
     user_object = get_user_object(self.environ)
     publicity = ''
     try:
         bag.policy.allows(user_object, 'manage')
         policy = bag.policy
         publicity = determine_publicity(user_object, policy)
     except (UserRequiredError, ForbiddenError):
         policy = None
     try:
         bag.policy.allows(user_object, 'delete')
         delete = True
     except (UserRequiredError, ForbiddenError):
         delete = False
     data = {'title': 'TiddlyHoster Bag %s' % bag.name, 'policy': policy,
             'publicity': publicity, 'delete': delete,
             'bag': bag, 'tiddlers': tiddlers, 'representations': representations}
     del self.environ['tiddlyweb.title']
     return send_template(self.environ, 'baglist.html', data)
Beispiel #8
0
def user_page(environ, start_response):
    userpage = environ['wsgiorg.routing_args'][1]['userpage']
    user = environ['tiddlyweb.usersign']

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ['tiddlyweb.store']

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass  # roles will be empty
    if 'MEMBER' not in userpage_user.list_roles():
        raise HTTP404('%s has no page' % userpage)

    user_friend_names = get_friends(store, user['name'])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage),
                               user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage),
                               user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {
        'bags': kept_bags,
        'user_friends': user_friend_names,
        'friends': friends,
        'recipes': kept_recipes,
        'favorites': kept_favorites,
        'bookmarks': kept_bookmarks,
        'home': userpage,
        'profile': profile_html,
        'notice': {
            'html': notice_html,
            'modified': notice_tiddler.modified
        },
        'title': userpage,
        'email': email,
        'email_md5': email_md5,
        'user': get_user_object(environ)
    }

    return send_template(environ, 'profile.html', data)
Beispiel #9
0
 def _templatize(self, output):
     if isinstance(output, basestring):
         output = [output]
     data = {
         'output': output,
         'title': self.environ['tiddlyweb.title'],
     }
     return send_template(self.environ, 'pretty.html', data)
Beispiel #10
0
 def _templatize(self, output):
     if isinstance(output, basestring):
         output = [output]
     data = {
             'output': output,
             'title': self.environ['tiddlyweb.title'],
     }
     return send_template(self.environ, 'pretty.html', data)
Beispiel #11
0
def members_list(environ, start_response):
    store = environ["tiddlyweb.store"]
    member_names = sorted(get_member_names(store))
    members = []
    for member in member_names:
        email = get_email_tiddler(store, member)
        email_md5 = md5(email.lower()).hexdigest()
        members.append((member, email_md5))
    return send_template(environ, "members.html", {"members": members, "title": "Members"})
Beispiel #12
0
def members_list(environ, start_response):
    store = environ['tiddlyweb.store']
    member_names = sorted(get_member_names(store))
    members = []
    for member in member_names:
        email = get_email_tiddler(store, member)
        email_md5 = md5(email.lower()).hexdigest()
        members.append((member, email_md5))
    return send_template(environ, 'members.html', {'members': members}) 
Beispiel #13
0
def user_page(environ, start_response):
    userpage = environ['wsgiorg.routing_args'][1]['userpage']
    user = environ['tiddlyweb.usersign']

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ['tiddlyweb.store']

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass # roles will be empty
    if 'MEMBER' not in userpage_user.list_roles():
        raise HTTP404('%s has no page' % userpage)

    user_friend_names = get_friends(store, user['name'])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage),
            user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage),
            user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {'bags': kept_bags,
            'user_friends': user_friend_names,
            'friends': friends,
            'recipes': kept_recipes,
            'favorites': kept_favorites,
            'bookmarks': kept_bookmarks,
            'home': userpage,
            'profile': profile_html,
            'notice': {'html': notice_html,
                'modified': notice_tiddler.modified},
            'title': userpage,
            'email': email,
            'email_md5': email_md5,
            'user': get_user_object(environ)}

    return send_template(environ, 'profile.html', data)
Beispiel #14
0
def user_page(environ, start_response):
    userpage = environ["wsgiorg.routing_args"][1]["userpage"]
    user = environ["tiddlyweb.usersign"]

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ["tiddlyweb.store"]

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass  # roles will be empty
    if "MEMBER" not in userpage_user.list_roles():
        raise HTTP404("%s has no page" % userpage)

    user_friend_names = get_friends(store, user["name"])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage), user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage), user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {
        "bags": kept_bags,
        "user_friends": user_friend_names,
        "friends": friends,
        "recipes": kept_recipes,
        "favorites": kept_favorites,
        "bookmarks": kept_bookmarks,
        "home": userpage,
        "profile": profile_html,
        "notice": {"html": notice_html, "modified": notice_tiddler.modified},
        "title": userpage,
        "email": email,
        "email_md5": email_md5,
        "user": get_user_object(environ),
    }

    return send_template(environ, "profile.html", data)
Beispiel #15
0
 def __call__(self, environ, start_response):
     output = self.application(environ, start_response)
     if self._needs_title(environ):
         if isinstance(output, basestring):
             output = [output]
         data = {
                 'output': output,
                 'title': environ['tiddlyweb.title'],
                 }
         return send_template(environ, 'pretty.html', data)
     return output
Beispiel #16
0
def members_list(environ, start_response):
    store = environ['tiddlyweb.store']
    member_names = sorted(get_member_names(store))
    members = []
    for member in member_names:
        email = get_email_tiddler(store, member)
        email_md5 = md5(email.lower()).hexdigest()
        members.append((member, email_md5))
    return send_template(environ, 'members.html', {
        'members': members,
        'title': 'Members'
    })
Beispiel #17
0
def uploader(environ, start_response):
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    if not 'MEMBER' in usersign['roles']:
        raise HTTP404('bad edit')
    try:
        bag = Bag(bag_name)
        bag = store.get(bag)
        bag.policy.allows(usersign, 'write')
    except NoBagError:
        raise HTTP404('bad edit')
    data = {}
    data['bag'] = bag_name
    return send_template(environ, 'uploader.html', data)
Beispiel #18
0
def uploader(environ, start_response):
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    if not 'MEMBER' in usersign['roles']:
        raise HTTP404('bad edit')
    try:
        bag = Bag(bag_name)
        bag = store.get(bag)
        bag.policy.allows(usersign, 'write')
    except NoBagError:
        raise HTTP404('bad edit')
    data = {}
    data['bag'] = bag_name
    return send_template(environ, 'uploader.html', data)
Beispiel #19
0
def uploader(environ, start_response):
    usersign = environ["tiddlyweb.usersign"]
    store = environ["tiddlyweb.store"]
    bag_name = environ["tiddlyweb.query"].get("bag", [""])[0]
    username = usersign["name"]
    if not "MEMBER" in usersign["roles"]:
        raise HTTP404("bad edit")
    try:
        bag = Bag(bag_name)
        bag = store.get(bag)
        bag.policy.allows(usersign, "write")
    except NoBagError:
        raise HTTP404("bad edit")
    data = {}
    data["bag"] = bag_name
    return send_template(environ, "uploader.html", data)
Beispiel #20
0
def get_profiler(environ, start_response):
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    username = usersign['name']

    if not 'MEMBER' in usersign['roles']:
        raise HTTP404('bad edit')

    tiddler = get_profile(store, usersign, username)
    bag = Bag(tiddler.bag)
    bag.skinny = True
    bag = store.get(bag)
    bag.policy.allows(usersign, 'write')

    return_url = '%s/home' % server_base_url(environ)

    data = {}
    data['tiddler'] = tiddler
    data['return_url'] = return_url
    return send_template(environ, 'profile_edit.html', data)
Beispiel #21
0
 def _bag_list(self, tiddlers):
     if '/feedbag' in self.environ['selector.matches'][0]:
         representation_link = '%s/feedbag' % (self._server_prefix())
         bag = Bag('feedbag')
         bag.policy.manage = ["NONE"]
         bag.policy.delete = ["NONE"]
         bag.desc = 'Recent Public Stuff'
     else:
         name = self.environ['wsgiorg.routing_args'][1]['bag_name']
         name = urllib.unquote(name)
         name = name.decode('utf-8')
         representation_link = '%s/bags/%s/tiddlers' % (
             self._server_prefix(), encode_name(name))
         bag = self.environ['tiddlyweb.store'].get(Bag(name))
     representations = self._tiddler_list_header(representation_link)
     user_object = get_user_object(self.environ)
     publicity = ''
     try:
         bag.policy.allows(user_object, 'manage')
         policy = bag.policy
         publicity = determine_publicity(user_object, policy)
     except (UserRequiredError, ForbiddenError):
         policy = None
     try:
         bag.policy.allows(user_object, 'delete')
         delete = True
     except (UserRequiredError, ForbiddenError):
         delete = False
     data = {
         'title': 'TiddlyHoster Bag %s' % bag.name,
         'policy': policy,
         'publicity': publicity,
         'delete': delete,
         'bag': bag,
         'tiddlers': tiddlers,
         'representations': representations
     }
     del self.environ['tiddlyweb.title']
     return send_template(self.environ, 'baglist.html', data)
Beispiel #22
0
def get_createrecipe(environ, start_response):
    return send_template(environ, "recipe.html", {"timestamp": int(time.time()), "title": "Create Recipe"})
Beispiel #23
0
def front(environ, start_response):
    return send_template(environ, 'home.html')
Beispiel #24
0
def front(environ, start_response):
    user = environ["tiddlyweb.usersign"]
    if user["name"] != "GUEST" and "MEMBER" in user["roles"]:
        raise HTTP302(server_base_url(environ) + "/" + encode_name(user["name"]))
    return send_template(environ, "home.html", {"title": "Welcome"})
Beispiel #25
0
def get_createrecipe(environ, start_response):
    return send_template(environ, 'recipe.html', {
        'timestamp': int(time.time()), 'title': 'Create Recipe'}) 
Beispiel #26
0
def login(environ, start_response):
    user = environ['tiddlyweb.usersign']
    if user['name'] != 'GUEST' and 'MEMBER' in user['roles']:
        raise HTTP302(server_base_url(environ) + '/' + encode_name(user['name']))
    return send_template(environ, 'login.html')
Beispiel #27
0
def front(environ, start_response):
    user = environ['tiddlyweb.usersign']
    if user['name'] != 'GUEST' and 'MEMBER' in user['roles']:
        raise HTTP302(
            server_base_url(environ) + '/' + encode_name(user['name']))
    return send_template(environ, 'home.html', {'title': 'Welcome'})
Beispiel #28
0
def get_createbag(environ, start_response):
    return send_template(environ, 'bag.html', {
        'timestamp': int(time.time()),
        'title': 'Create Bag'
    })
Beispiel #29
0
def get_createrecipe(environ, start_response):
    return send_template(environ, 'recipe.html', {
        'timestamp': int(time.time()),
        'title': 'Create Recipe'
    })
Beispiel #30
0
def get_createbag(environ, start_response):
    return send_template(environ, 'bag.html', {
        'timestamp': int(time.time()), 'title': 'Create Bag'}) 
Beispiel #31
0
def get_createbag(environ, start_response):
    return send_template(environ, "bag.html", {"timestamp": int(time.time()), "title": "Create Bag"})