Exemplo n.º 1
0
def get_username(return_url):
    """
	Returns:
	A string with one of this value :
		Login
		email | <register username form>
		username | Logout | namespaces | tiddlywikis
	"""
    user = User.get_current_user()
    if user:
        if user.is_registered():
            r = """<a href="/%(username)s">%(username)s</a>:
				 <a href="%(logout)s">Logout</a> 
				| <a href="/%(username)s/namespaces">namespaces</a>
				| <a href="/%(username)s/tiddlywikis">tiddlywikis</a>
				""" % {
                'username': user.username,
                'logout': users.create_logout_url(return_url)
            }
        else:
            r = """%s | %s""" % (users.get_current_user().email(),
                                 User.create_user_form(
                                     action='/' + config.user_name,
                                     return_url=return_url))
    else:
        r = """<a href="%s">Login</a>""" % users.create_login_url(return_url)
    return r
Exemplo 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
Exemplo n.º 3
0
  def post(self):
	comment = Comment()
	if users.get_current_user():
		if User.get_current_user():
			comment.author = User.get_current_user().username
		comment.content = self.request.get('content')
		comment.put()
		self.redirect(config.comments_url)
	else:
		self.error(401)
Exemplo n.º 4
0
	def get(self, *args):
		user = User.get_current_user()
		if user:
			if user.is_registered():
				body = self.redirect('/')
			else:
				body = """%s | %s""" % (users.get_current_user().email(), 
				User.create_user_form(action='/'+config.user_name, return_url='/'))
		else:
			body = self.redirect(users.create_login_url(self.request.uri))
		self.send_page(body)
Exemplo n.º 5
0
 def get(self, *args):
     user = User.get_current_user()
     if user:
         if user.is_registered():
             body = self.redirect('/')
         else:
             body = """%s | %s""" % (users.get_current_user().email(),
                                     User.create_user_form(
                                         action='/' + config.user_name,
                                         return_url='/'))
     else:
         body = self.redirect(users.create_login_url(self.request.uri))
     self.send_page(body)
Exemplo n.º 6
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
Exemplo n.º 7
0
	def display(self, user):
		r = """
				<p>Username: %(username)s</p>
			""" % {'username': user.username}
		if User.get_current_user():
			r += """
				<p>email: %(email)s</p>
				""" % {'email': user.system_user.email()}
		return r
Exemplo n.º 8
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
Exemplo n.º 9
0
def get_username(return_url):
	"""
	Returns:
	A string with one of this value :
		Login
		email | <register username form>
		username | Logout | namespaces | tiddlywikis
	"""
	user = User.get_current_user()
	if user:
		if user.is_registered():
			r = """<a href="/%(username)s">%(username)s</a>:
				 <a href="%(logout)s">Logout</a> 
				| <a href="/%(username)s/namespaces">namespaces</a>
				| <a href="/%(username)s/tiddlywikis">tiddlywikis</a>
				""" % {'username': user.username, 'logout': users.create_logout_url(return_url)}
		else:
			r = """%s | %s""" % (users.get_current_user().email(), 
			User.create_user_form(action='/'+config.user_name, return_url=return_url))
	else:
		r = """<a href="%s">Login</a>""" % users.create_login_url(return_url)
	return r
Exemplo n.º 10
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
Exemplo n.º 11
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))
Exemplo n.º 12
0
	def get(self, *args):
		body = """
<h1>Welcome to TiddlyHome</h1>
This is the shadow page for <a href="http://tiddlyhome.appspot.com/BidiX/namespaces/TiddlyHome/tiddlers/HomePage.html">
http://tiddlyhome.appspot.com/BidiX/namespaces/TiddlyHome/tiddlers/HomePage.html</a>
		"""
		if User.get_by_username(config.TH_owner):
			homePageTiddler = Namespace.get_tiddler("HomePage")
			if homePageTiddler:
				if homePageTiddler.html:
					body = homePageTiddler.html
				else:
					body = homePageTiddler.text
		self.send_page(content_body=body)
Exemplo n.º 13
0
    def get(self, *args):
        body = """
<h1>TiddlyHome Help</h1>
This is the shadow page for <a href="http://tiddlyhome.appspot.com/BidiX/namespaces/TiddlyHome/tiddlers/HelpPage.html">
http://tiddlyhome.appspot.com/BidiX/namespaces/TiddlyHome/tiddlers/HelpPage.html</a>
		"""
        if User.get_by_username(config.TH_owner):
            homePageTiddler = Namespace.get_tiddler("HelpPage")
            if homePageTiddler:
                if homePageTiddler.html:
                    body = homePageTiddler.html
                else:
                    body = homePageTiddler.text
        self.send_page(content_body=body)
Exemplo n.º 14
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))
Exemplo n.º 15
0
	def post(self, *args):
		""""""
		#(user_id, user) = self.control_args(*args)
		User.register_user(self.request.get('username'))
		self.redirect(self.request.get('return_url'))