Esempio n. 1
0
	def list_in_html(self, type_url, namespace):
		results = Tiddler.list_for(namespace)
		r = "<ul>\n"
		for tiddler in results:
			r += "<li><a href=\"%s/%s\">%s</a></li>\n"%(type_url, util.url_encode(tiddler.title),tiddler.title)
		r += "</ul>\n"
		return r
Esempio n. 2
0
	def post(self, *args):
		""""""
		previous_title = self.request.get('previous_title')
		title = self.request.get('title')
		tags = self.request.get('tags')
		text = self.request.get('text')
		return_url = self.request.get('return_url')
		error = ""
		if self.namespace and self.namespace.own_by(self.current_user):
			if previous_title and (previous_title != title):
				previous_tiddler = Tiddler.get_by_key_name(previous_title,parent=self.namespace)
				if not previous_tiddler:
					error = "can't delete previous tiddler '%s'" % previous_title
				else:
					previous_tiddler.delete()
			modifier = self.current_user.username
			if not User.get_by_username(modifier) or not User.get_by_username(modifier).is_registered():
				error = "Current user not registered"
			if (error):
				body = self.create_form(self.type_url,self.type_url,error,title,tags,text)
				self.send_page(body)
			else:
				tiddler = Tiddler.create_or_update(self.namespace, modifier=modifier, title=title, tags=tags, text=text, newTitle=title)
				self.redirect(return_url+"/"+util.url_encode(tiddler.title))
		else:
			if self.namespace:
				self.error(401)
			else:
				self.error(404)
			return
Esempio n. 3
0
 def list_in_html(self, type_url, owner, for_user):
     results = Namespace.query_for_user(owner, for_user)
     r = "<ul>\n"
     for namespace in results:
         r += '<li><a href="%s/%s">%s</a></li>\n' % (type_url, util.url_encode(namespace.name), namespace.name)
     r += "</ul>\n"
     return r
Esempio n. 4
0
	def display(self, tiddlywiki):
		owner = tiddlywiki.parent()
		if tiddlywiki.private_access:
			access = 'private'
		else:
			access = 'public'
		r = """
name: %(name)s<br>
namespace: %(namespace_name)s<br>
owner: %(owner_name)s<br>
access: %(access)s<br>
title: %(title)s<br>
subtitle: %(subtitle)s<br>
		"""%{'name': tiddlywiki.name, 'namespace_name': tiddlywiki.namespace.name, 'owner_name': owner.username, 'access': access, \
			'title': tiddlywiki.title, 'subtitle': tiddlywiki.subtitle}
		r += "Tiddlers:<br>"
		r+="<ul>\n"
		tiddlers = []
		for t in tiddlywiki.tiddlers:
			t = Tiddler.get(t)
			if t:
				tiddlers.append((t.title, t))
		tiddlers.sort()
		for (title, tiddler) in tiddlers:
			if tiddler:
				r+='<li><a href=\"/'+util.url_encode(owner.username)+'/'+config.namespace_name+'/'+util.url_encode(tiddlywiki.namespace.name)+'/'+config.tiddler_name+'/'+util.url_encode(tiddler.title)+'\">'+tiddler.title+'<a></li>\n'
		r+="</ul>\n"
		return r
Esempio n. 5
0
 def list_in_html(self, type_url, owner, for_user):
     results = Namespace.query_for_user(owner, for_user)
     r = "<ul>\n"
     for namespace in results:
         r += "<li><a href=\"%s/%s\">%s</a></li>\n" % (
             type_url, util.url_encode(namespace.name), namespace.name)
     r += "</ul>\n"
     return r
Esempio n. 6
0
 def list_in_html(self, type_url, namespace):
     results = Tiddler.list_for(namespace)
     r = "<ul>\n"
     for tiddler in results:
         r += "<li><a href=\"%s/%s\">%s</a></li>\n" % (
             type_url, util.url_encode(tiddler.title), tiddler.title)
     r += "</ul>\n"
     return r
Esempio n. 7
0
    def display_in_xml(self, out):
        #get template
        path = os.path.join(os.path.dirname(__file__), 'empty.xml')
        f = open(path)
        try:
            data = f.read()
        finally:
            f.close()
        path = os.path.join(os.path.dirname(__file__), 'item.xml')
        f = open(path)
        try:
            item = f.read()
        finally:
            f.close()

        #find storearea
        items = ''
        tiddlers = []
        for t in self.tiddlers:
            t = Tiddler.get(t)
            if t and t.modified:
                tiddlers.append((t.modified, t))
            else:
                tiddlers.append((datetime.today(), t))
        tiddlers.sort()
        tiddlers.reverse()
        for (modified, t) in tiddlers:
            if t:
                if t.html:
                    text = util.html_escape(t.html)
                else:
                    text = util.html_escape(t.text)
                items += item % {
                    'title':
                    t.title,
                    'text':
                    text,
                    'tag':
                    t.tags,
                    'link':
                    config.TH_url + self.owner.username + '/' +
                    config.namespace_name + '/' + self.namespace.name + '/' +
                    config.tiddler_name + '/' + util.url_encode(t.title) +
                    '.html',
                    'date':
                    modified.strftime("%Y-%m-%d %H:%M"),
                }

        data = data % {
            'title': self.title,
            'link': 'http://bidix.appspot.com/',
            'description': self.subtitle,
            'username': self.owner.username,
            'pubDate': datetime.utcnow().strftime("%Y-%m-%d %H:%M"),
            'lastBuildDate': datetime.utcnow().strftime("%Y-%m-%d %H:%M"),
            'items': items,
        }
        out.write(data)
Esempio n. 8
0
	def list_in_html(cls, user, type_url):
		query = db.Query(Tiddlywiki)
		query.ancestor(user)
		results = query.fetch(9999)
		r = "<ul>\n"
		for tiddlywiki in results:
			r += "<li><a href=\"%s/%s\">%s</a></li>\n"%(type_url, util.url_encode(tiddlywiki.name),tiddlywiki.name)
		r += "</ul>\n"
		return r
Esempio n. 9
0
 def list_in_html(cls, user, type_url):
     query = db.Query(Tiddlywiki)
     query.ancestor(user)
     results = query.fetch(9999)
     r = "<ul>\n"
     for tiddlywiki in results:
         r += "<li><a href=\"%s/%s\">%s</a></li>\n" % (
             type_url, util.url_encode(tiddlywiki.name), tiddlywiki.name)
     r += "</ul>\n"
     return r
Esempio n. 10
0
 def post(self, *args):
     """"""
     # fields from form
     previous_name = self.request.get('previous_name')
     name = self.request.get('name')
     authors = self.request.get('authors')
     readers = self.request.get('readers')
     access = self.request.get('access')
     return_url = self.request.get('return_url')
     owner_name = self.request.get('owner')
     owner = User.get_by_username(owner_name)
     error = ""
     if not owner:
         owner = self.current_user
     if access == 'on':
         private_access = True
         access = 'CHECKED'
     else:
         private_access = False
         access = ''
     if previous_name:
         previous_namespace = Namespace.get_by_key_name(previous_name,
                                                        parent=owner)
         if not previous_namespace or not previous_namespace.own_by(
                 self.current_user):
             self.error(401)
             return
         if previous_name != name:
             if not previous_namespace:
                 error = "can't delete previous namespace '%s'" % previous_name
             else:
                 previous_namespace.delete()
     if (error):
         body = self.create_form(self.type_url,
                                 self.type_url,
                                 error=error,
                                 owner=owner,
                                 owner=owner_name,
                                 name=name,
                                 previous_name=previous_name,
                                 authors=authors,
                                 readers=readers,
                                 access=access)
     else:
         namespace = Namespace.create_or_update(
             name=name,
             owner=owner,
             authors=authors,
             readers=readers,
             private_access=private_access)
         self.redirect(return_url + "/" + util.url_encode(namespace.name))
Esempio n. 11
0
    def initialize(self, request, response):
        """
			W: Vérifier l'existence des ressources ????
		"""
        super(Handler, self).initialize(request, response)
        # Attributes
        if 'suffix' in self.url_groupdict:
            self.suffix = self.url_groupdict['suffix']
        else:
            self.suffix = ''
        if self.suffix:
            self.type_url = self.ressource_url = self.request.path_info[0:(
                len(self.request.path_info) -
                len(self.suffix))]  # without suffix
        else:
            self.type_url = self.ressource_url = self.request.path_info
        self.current_user = None
        if User.get_current_user() and User.get_current_user().is_registered():
            self.current_user = User.get_current_user()
        # Attributes present only if ressource reference it
        if 'username' in self.url_groupdict:
            self.user = User.get_by_username(
                util.url_decode(self.url_groupdict['username']))
        if 'namespace_id' in self.url_groupdict:
            self.namespace = Namespace.get_by_key_name(util.url_decode(
                self.url_groupdict['namespace_id']),
                                                       parent=self.user)
        if 'tiddler_id' in self.url_groupdict:
            self.tiddler = Tiddler.get_by_key_name(util.url_decode(
                self.url_groupdict['tiddler_id']),
                                                   parent=self.namespace)
        if 'tiddlywiki_id' in self.url_groupdict:
            self.tiddlywiki = Tiddlywiki.get_by_key_name(util.url_decode(
                self.url_groupdict['tiddlywiki_id']),
                                                         parent=self.user)
        # set type_url
        if 'type' in self.url_groupdict:
            t = self.type = self.url_groupdict['type']
            if self.user:
                self.type_url = '/' + util.url_encode(self.user.username)
            else:
                self.type_url = '/' + self.url_groupdict['username']
            if t == 'namespaces':
                self.type_url += '/' + config.namespace_name
            elif t == 'tiddlers':
                self.type_url += '/' + config.namespace_name + '/' + self.url_groupdict[
                    'namespace_id'] + '/' + config.tiddler_name
            elif t == 'tiddlywikis':
                self.type_url += '/' + config.tiddlywiki_name
Esempio n. 12
0
 def post(self, *args):
     """"""
     # fields from form
     previous_name = self.request.get("previous_name")
     name = self.request.get("name")
     authors = self.request.get("authors")
     readers = self.request.get("readers")
     access = self.request.get("access")
     return_url = self.request.get("return_url")
     owner_name = self.request.get("owner")
     owner = User.get_by_username(owner_name)
     error = ""
     if not owner:
         owner = self.current_user
     if access == "on":
         private_access = True
         access = "CHECKED"
     else:
         private_access = False
         access = ""
     if previous_name:
         previous_namespace = Namespace.get_by_key_name(previous_name, parent=owner)
         if not previous_namespace or not previous_namespace.own_by(self.current_user):
             self.error(401)
             return
         if previous_name != name:
             if not previous_namespace:
                 error = "can't delete previous namespace '%s'" % previous_name
             else:
                 previous_namespace.delete()
     if error:
         body = self.create_form(
             self.type_url,
             self.type_url,
             error=error,
             owner=owner,
             owner=owner_name,
             name=name,
             previous_name=previous_name,
             authors=authors,
             readers=readers,
             access=access,
         )
     else:
         namespace = Namespace.create_or_update(
             name=name, owner=owner, authors=authors, readers=readers, private_access=private_access
         )
         self.redirect(return_url + "/" + util.url_encode(namespace.name))
Esempio n. 13
0
 def post(self, *args):
     """"""
     previous_title = self.request.get('previous_title')
     title = self.request.get('title')
     tags = self.request.get('tags')
     text = self.request.get('text')
     return_url = self.request.get('return_url')
     error = ""
     if self.namespace and self.namespace.own_by(self.current_user):
         if previous_title and (previous_title != title):
             previous_tiddler = Tiddler.get_by_key_name(
                 previous_title, parent=self.namespace)
             if not previous_tiddler:
                 error = "can't delete previous tiddler '%s'" % previous_title
             else:
                 previous_tiddler.delete()
         modifier = self.current_user.username
         if not User.get_by_username(modifier) or not User.get_by_username(
                 modifier).is_registered():
             error = "Current user not registered"
         if (error):
             body = self.create_form(self.type_url, self.type_url, error,
                                     title, tags, text)
             self.send_page(body)
         else:
             tiddler = Tiddler.create_or_update(self.namespace,
                                                modifier=modifier,
                                                title=title,
                                                tags=tags,
                                                text=text,
                                                newTitle=title)
             self.redirect(return_url + "/" +
                           util.url_encode(tiddler.title))
     else:
         if self.namespace:
             self.error(401)
         else:
             self.error(404)
         return
Esempio n. 14
0
	def initialize(self, request, response):
		"""
			W: Vérifier l'existence des ressources ????
		"""
		super(Handler, self).initialize(request, response)
		# Attributes
		if 'suffix' in self.url_groupdict:
			self.suffix = self.url_groupdict['suffix']
		else:
			self.suffix = ''
		if self.suffix:
			self.type_url = self.ressource_url = self.request.path_info[0:(len(self.request.path_info)-len(self.suffix))] # without suffix
		else:
			self.type_url = self.ressource_url = self.request.path_info
		self.current_user = None 
		if User.get_current_user() and User.get_current_user().is_registered():
			self.current_user = User.get_current_user()
		# Attributes present only if ressource reference it
		if 'username' in self.url_groupdict:
			self.user = User.get_by_username(util.url_decode(self.url_groupdict['username']))
		if 'namespace_id' in self.url_groupdict:
			self.namespace = Namespace.get_by_key_name(util.url_decode(self.url_groupdict['namespace_id']), parent=self.user) 
		if 'tiddler_id' in self.url_groupdict:
			self.tiddler = Tiddler.get_by_key_name(util.url_decode(self.url_groupdict['tiddler_id']),parent=self.namespace)
		if 'tiddlywiki_id' in self.url_groupdict:
			self.tiddlywiki = Tiddlywiki.get_by_key_name(util.url_decode(self.url_groupdict['tiddlywiki_id']),parent=self.user)
		# set type_url
		if 'type' in self.url_groupdict:
			t = self.type = self.url_groupdict['type']
			if self.user:
				self.type_url = '/'+util.url_encode(self.user.username)
			else:
				self.type_url = '/'+self.url_groupdict['username']
			if t == 'namespaces':
				self.type_url += '/'+config.namespace_name
			elif t == 'tiddlers':
				self.type_url += '/' + config.namespace_name + '/' + self.url_groupdict['namespace_id'] + '/' + config.tiddler_name
			elif t == 'tiddlywikis':
				self.type_url += '/'+config.tiddlywiki_name
Esempio n. 15
0
	def post(self, *args):
		"""
		"""
		ressource_menu = ""
		error = ""
		name = self.request.get('name')
		namespace_name = self.request.get('namespace_name')
		access = self.request.get('access')
		title = self.request.get('title')
		subtitle = self.request.get('subtitle')
		if access == 'on':
			private_access = True
			access='CHECKED'
		else:
			private_access = False
		namespace = None
		tiddlers = []
		try:
			if namespace_name:
				namespace = Namespace.get_by_key_name(namespace_name, parent=self.user)
			else:
				#use tiddlywiki name as default namespace_name
				namespace_name = name
				namespace = Namespace.get_by_key_name(namespace_name, parent=self.user)
				if not namespace:
					# then create default namespace
					namespace = Namespace.create_or_update(name, self.user, private_access=private_access)
			if not namespace:
				error = "Namespace '%s' unknown"%namespace_name
			else:
				for tiddler in Tiddler.list_for(namespace):
					if self.request.get(util.url_encode(tiddler.title)) == 'on':
						tiddlers.append(tiddler.key())
			return_url = self.request.get('return_url')
		except OwnerException, e:
			error = e
Esempio n. 16
0
	def create_form(self, action,return_url='/', error='', namespace=None, name='', previous_name='', private_access= False, title='', subtitle='', tiddlers=''):
		namespace_name = ''
		if namespace:
			namespace_name = namespace.name
		access = ''
		if private_access:
			access = 'CHECKED'		
		r = """
<form action="%(action)s" method="POST">
<input type="hidden" name="return_url" value="%(return_url)s">
<input type="hidden" name="previous_name" value="%(previous_name)s">
<strong>%(error)s</strong><P>
	Name: <input name=name value="%(name)s" size=80><br>
	Namespace: <input name=namespace_name value="%(namespace_name)s" size=80><br>
	Private access: <input type="checkbox" name="access" %(access)s><br>
	Title:  <input name=title value="%(title)s" size=80><br>
	Sub title:  <input name=subtitle value="%(subtitle)s" size=80><br>
		""" % {'action': action, 'return_url': return_url, 'error': error, 'name': name, 'namespace_name': namespace_name, 'previous_name':  previous_name, \
				'access': access, 'title': title, 'subtitle': subtitle}
		if namespace:
			r += "\nTiddlers: <ul>"
			namespace_name = namespace.name		
			tiddlers_in_namespace = Tiddler.list_for(namespace)
			for tiddler in tiddlers_in_namespace:
				if tiddler.key() in tiddlers:
					checked = 'CHECKED'
				else:
					checked = ''
				r += """<li><input type=CHECKBOX NAME="%s" %s ><a href="/namespace/%s/tiddler/%s">%s</a></li>""" % (util.url_encode(tiddler.title), checked, util.url_encode(namespace.name), util.url_encode(tiddler.title), tiddler.title)
		r += """
		</ul>
	<input type=submit label="Submit">
</form>
		"""
		return r
Esempio n. 17
0
	def display_in_xml(self, out):
		#get template
		path = os.path.join(os.path.dirname(__file__), 'empty.xml')
		f = open(path)
		try:
			data = f.read()
		finally:
			f.close()
		path = os.path.join(os.path.dirname(__file__), 'item.xml')
		f = open(path)
		try:
			item = f.read()
		finally:
			f.close()
			
		#find storearea
		items = ''
		tiddlers = []
		for t in self.tiddlers:
			t = Tiddler.get(t)
			if t and t.modified:
				tiddlers.append((t.modified, t))
			else:
				tiddlers.append((datetime.today(),t))
		tiddlers.sort()
		tiddlers.reverse()
		for (modified, t) in tiddlers:
			if t:
				if t.html:
					text = util.html_escape(t.html)
				else:
					text = util.html_escape(t.text)
				items += item%{
					'title': t.title,
					'text': text,
					'tag': t.tags,
					'link': config.TH_url+self.owner.username+'/'+config.namespace_name+'/'+self.namespace.name+'/'+config.tiddler_name+'/'+util.url_encode(t.title) +'.html',
					'date': modified.strftime("%Y-%m-%d %H:%M"),
			}
		
		data = data%{
			'title': self.title, 
			'link': 'http://bidix.appspot.com/',
			'description': self.subtitle,
			'username': self.owner.username,
			'pubDate': datetime.utcnow().strftime("%Y-%m-%d %H:%M"),
			'lastBuildDate': datetime.utcnow().strftime("%Y-%m-%d %H:%M"),
			'items': items,
			}
		out.write(data)