Ejemplo n.º 1
0
    def post(self):
        """Creates a new tag for the logged in user"""
        user = utils.get_current_user()
        title = self.request.get('title')
        new_title = self.request.get('newTitle') or None
        
        if not user:
            self.error(403)
            return
        
        if not title:
            self.error(400)

        # Create new tag
        if not new_title:
            m = Tag.all().ancestor(user).filter('title_lower =', title.lower()).get()
            
            if m:
                # Not unique
                self.error(409)
                return

            m = Tag(
                parent=user,
                title=title,
                title_lower=title.lower(),
            )
            m.put()

        # Rename Tag
        else:
            m = Tag.all().ancestor(user).filter('title_lower =', new_title.lower()).get()
            if m:
                # Not unique
                self.error(409)
                return

            m = Tag.all().ancestor(user).filter('title_lower =', title.lower()).get()
            if not m:
                # Original tag not found
                self.error(404)
                return

            m.title = new_title
            m.title_lower = new_title.lower()
            m.save()

        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.out.write('ok')
Ejemplo n.º 2
0
 def get(self,format):
     tags = Tag.all().run()
     db.delete(tags)
     
     firstLevelTags = [
         "ActionScript",
         "Asp",
         "BASIC",
         "C",
         "C++",
         "Clojure",
         "COBOL",
         "ColdFusion",
         "Erlang",
         "Fortran",
         "Groovy",
         "Haskell",
         "Java",
         "JavaScript",
         "Lisp",
         "Perl",
         "PHP",
         "Python",
         "Ruby",
         "Scala",
         "Scheme",
         "haxe",
         "nodejs",
         'framework',
         'tool',
         'wiki',
         'tutorial',
         'howto',
         'library',
         'service',
         'language'
     ]
     
     for tag in firstLevelTags:
         t = Tag(name=tag.lower())
         t.put()
         
     entries = Entry.all()
     for e in entries:
         newtags = getTagKeys(e.tagsRaw)
         e.tags = newtags
         e.put()
         
     simplewebapp.formatResponse(format, self, "OK")
     
Ejemplo n.º 3
0
    def post(self):

        if users.is_current_user_admin():
            key = self.request.get('key')
            if key:
                e = db.get(key)

            else:
                e = Entry()

            type = self.request.get('type')
            if not type:
                type = 'link'
            title = self.request.get('title')
            e.title = title.replace('&', '&amp;').replace('<', '&lt;').replace(
                '>', '&gt;')
            url = self.request.get('url')
            purl = self.request.get('purl')
            if type == 'pic' and not key:
                e.url = purl.replace('&', '&amp;').replace('<',
                                                           '&lt;').replace(
                                                               '>', '&gt;')
            else:
                e.url = url.replace('&', '&amp;').replace('<', '&lt;').replace(
                    '>', '&gt;')
            content = self.request.get('content')
            e.content = content
            if not key:
                e.addtime += datetime.timedelta(hours=+8)
            e.private = bool(int(self.request.get('private')))
            e.type = type
            if type == 'pic' and not key:
                if url:
                    try:
                        result = urlfetch.fetch(url)
                        if result.status_code == 200:
                            e.image = db.Blob(result.content)
                    except:
                        self.response.out.write('获取图片超时!')
                        return
                else:
                    myfile = self.request.get("myfile")
                    if not myfile:
                        self.response.out.write('没有选择文件!')
                        return
                    try:
                        e.image = db.Blob(myfile)
                    except:
                        self.response.out.write('文件上传失败!')
                        return

            if key:  #更新数据
                for oldtag in e.tags:
                    tag = Tag.all().filter('name', oldtag)
                    if (tag.count(1) > 0):
                        t = tag.get()
                        if type == 'link':
                            t.count_link -= 1
                        if type == 'note':
                            t.count_note -= 1
                        if type == 'pic':
                            t.count_pic -= 1
                        t.put()
            else:  #新增数据
                max_pageCount = 900  #超过此数据,则pageid递增
                entry = Entry.all().order('-addtime')
                if entry.count() > 0:
                    cur_pageid = entry.get().pageid
                else:
                    cur_pageid = 0

                cur_pageCount = entry.filter('pageid =',
                                             cur_pageid).count(1000)

                if cur_pageCount >= max_pageCount:
                    e.pageid = cur_pageid + 1
                else:
                    e.pageid = cur_pageid

            e.tags = []
            tag_names = self.request.get('tags').split()
            for tag_name in tag_names:
                tag = Tag.all().filter('name', tag_name)
                if (tag.count(1) > 0):
                    t = tag.get()
                    if type == 'link':
                        t.count_link += 1
                    if type == 'note':
                        t.count_note += 1
                    if type == 'pic':
                        t.count_pic += 1

                    t.usetime = datetime.datetime.now()
                    t.put()
                else:
                    t = Tag()
                    t.name = tag_name
                    if type == 'link':
                        t.count_link = 1
                    if type == 'note':
                        t.count_note = 1
                    if type == 'pic':
                        t.count_pic = 1

                    t.usetime = datetime.datetime.now()
                    t.put()
                e.tags.append(db.Category(tag_name))
            e.put()
            self.redirect('/' + type + '/')
        else:
            self.redirect(users.create_login_url(self.request.uri))
Ejemplo n.º 4
0
	def post(self):





		if users.is_current_user_admin():
			key  = self.request.get('key')
			if key :
				e = db.get(key)



			else:
				e = Entry()

			type = self.request.get('type')
			if not type:
				type = 'link'
			title = self.request.get('title')
			e.title = title.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			url = self.request.get('url')
			purl= self.request.get('purl')
			if type == 'pic' and not key:
				e.url = purl.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			else:
				e.url = url.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			content = self.request.get('content')
			e.content = content
			if not key:
				e.addtime +=datetime.timedelta(hours=+8)
			e.private = bool(int(self.request.get('private')))
			e.type = type
			if type =='pic' and not key:
				if url:
					try:
						result = urlfetch.fetch(url)
						if result.status_code == 200:
							e.image = db.Blob(result.content)
					except :
						self.response.out.write('获取图片超时!')
						return
				else:
					myfile = self.request.get("myfile")
					if not myfile:
						self.response.out.write( '没有选择文件!')
						return
					try:
						e.image = db.Blob(myfile)
					except :
						self.response.out.write( '文件上传失败!')
						return

			if key:#更新数据
				for oldtag in e.tags:
					tag = Tag.all().filter('name',oldtag)
					if(tag.count(1)>0):
						t = tag.get()
						if type == 'link':
							t.count_link -=1
						if type == 'note':
							t.count_note -=1
						if type == 'pic':
							t.count_pic -=1
						t.put()
			else:#新增数据
				max_pageCount =900 #超过此数据,则pageid递增
				entry = Entry.all().order('-addtime')
				if entry.count()>0:
					cur_pageid = entry.get().pageid
				else:
					cur_pageid = 0
				
				cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000)
				
				if cur_pageCount>=max_pageCount:
					e.pageid = cur_pageid+1
				else:
					e.pageid = cur_pageid
				
			e.tags = []
			tag_names = self.request.get('tags').split()
			for tag_name in tag_names:
				tag = Tag.all().filter('name',tag_name)
				if(tag.count(1)>0):
					t = tag.get()
					if type == 'link':
						t.count_link +=1
					if type == 'note':
						t.count_note +=1
					if type == 'pic':
						t.count_pic +=1

					t.usetime = datetime.datetime.now()
					t.put()
				else:
					t = Tag()
					t.name = tag_name
					if type == 'link':
						t.count_link =1
					if type == 'note':
						t.count_note =1
					if type == 'pic':
						t.count_pic =1

					t.usetime = datetime.datetime.now()
					t.put()
				e.tags.append(db.Category(tag_name))
			e.put()
			self.redirect('/'+type+'/')
		else:
			self.redirect(users.create_login_url(self.request.uri))
Ejemplo n.º 5
0
	def post(self):
		#********************** User Auth **************************#
		user = users.get_current_user()
		nickname = ''
		if user:
			nickname=user.nickname()
		if nickname:
			key  = self.request.get('key')
			if key :
				e = db.get(key)
				if e.user != nickname:
					e = Entry()
					e.user = nickname
			else:
				e = Entry()
				e.user = nickname
			type = self.request.get('type')
			if not type:
				type = 'link'
			tz = self.request.get('tz')
			if tz[0:1]=='-':
				tz = int(tz[1:])
				tz = -tz
			else:
				tz = int(tz[1:])
				tz = +tz
			
			title = self.request.get('title')
			e.title = title.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			url = self.request.get('url')
			purl= self.request.get('purl')
			if type == 'pic' and not key:
				e.url = purl.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			else:
				e.url = url.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			content = self.request.get('content')
			e.content = content
			if not key:
				e.addtime +=datetime.timedelta(hours=tz)
			e.private = bool(int(self.request.get('private')))
			e.type = type
			if type =='pic' and not key:
				if url:
					try:
						result = urlfetch.fetch(url)
						if result.status_code == 200:
							e.image = db.Blob(result.content)
					except :
						self.response.out.write('Fetch picture fail! You can <a href="/add?type=pic">upload</a> it manually')
						return
				else:
					myfile = self.request.get("myfile")
					if not myfile:
						self.response.out.write( 'No file specified!')
						return
					try:
						e.image = db.Blob(myfile)
					except :
						self.response.out.write( 'Uploading fail!')
						return

			if key:#更新数据
				for oldtag in e.tags:
					tag = Tag.all().filter("user",nickname).filter('name',oldtag)
					if(tag.count(1)>0):
						t = tag.get()
						if type == 'link':
							t.count_link -=1
						if type == 'note':
							t.count_note -=1
						if type == 'pic':
							t.count_pic -=1
						t.put()
			else:#新增数据
				max_pageCount =900 #超过此数据,则pageid递增
				entry = Entry.all().order('-addtime')
				if entry.count()>0:
					cur_pageid = entry.get().pageid
				else:
					cur_pageid = 0
				
				cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000)
				
				if cur_pageCount>=max_pageCount:
					e.pageid = cur_pageid+1
				else:
					e.pageid = cur_pageid
				
			e.tags = []
			tag_names = self.request.get('tags').split()
			for tag_name in tag_names:
				tag = Tag.all().filter("user",nickname).filter('name',tag_name)
				if(tag.count(1)>0):
					t = tag.get()
					if type == 'link':
						t.count_link +=1
					if type == 'note':
						t.count_note +=1
					if type == 'pic':
						t.count_pic +=1
					t.user = nickname
					t.usetime = datetime.datetime.now()
					t.put()
				else:
					t = Tag()
					t.name = tag_name
					if type == 'link':
						t.count_link =1
					if type == 'note':
						t.count_note =1
					if type == 'pic':
						t.count_pic =1
					t.user = nickname
					t.usetime = datetime.datetime.now()
					t.put()
				e.tags.append(db.Category(tag_name))
			e.put()
			self.redirect('/'+type+'/'+nickname)
		else:
			self.redirect(users.create_login_url(self.request.uri))
Ejemplo n.º 6
0
    def post(self):
        #********************** User Auth **************************#
        user = users.get_current_user()
        nickname = ''
        if user:
            nickname = user.nickname()
        if nickname:
            key = self.request.get('key')
            if key:
                e = db.get(key)
                if e.user != nickname:
                    e = Entry()
                    e.user = nickname
            else:
                e = Entry()
                e.user = nickname
            type = self.request.get('type')
            if not type:
                type = 'link'
            tz = self.request.get('tz')
            if tz[0:1] == '-':
                tz = int(tz[1:])
                tz = -tz
            else:
                tz = int(tz[1:])
                tz = +tz

            title = self.request.get('title')
            e.title = title.replace('&', '&amp;').replace('<', '&lt;').replace(
                '>', '&gt;')
            url = self.request.get('url')
            purl = self.request.get('purl')
            if type == 'pic' and not key:
                e.url = purl.replace('&', '&amp;').replace('<',
                                                           '&lt;').replace(
                                                               '>', '&gt;')
            else:
                e.url = url.replace('&', '&amp;').replace('<', '&lt;').replace(
                    '>', '&gt;')
            content = self.request.get('content')
            e.content = content
            if not key:
                e.addtime += datetime.timedelta(hours=tz)
            e.private = bool(int(self.request.get('private')))
            e.type = type
            if type == 'pic' and not key:
                if url:
                    try:
                        result = urlfetch.fetch(url)
                        if result.status_code == 200:
                            e.image = db.Blob(result.content)
                    except:
                        self.response.out.write(
                            'Fetch picture fail! You can <a href="/add?type=pic">upload</a> it manually'
                        )
                        return
                else:
                    myfile = self.request.get("myfile")
                    if not myfile:
                        self.response.out.write('No file specified!')
                        return
                    try:
                        e.image = db.Blob(myfile)
                    except:
                        self.response.out.write('Uploading fail!')
                        return

            if key:  #更新数据
                for oldtag in e.tags:
                    tag = Tag.all().filter("user",
                                           nickname).filter('name', oldtag)
                    if (tag.count(1) > 0):
                        t = tag.get()
                        if type == 'link':
                            t.count_link -= 1
                        if type == 'note':
                            t.count_note -= 1
                        if type == 'pic':
                            t.count_pic -= 1
                        t.put()
            else:  #新增数据
                max_pageCount = 900  #超过此数据,则pageid递增
                entry = Entry.all().order('-addtime')
                if entry.count() > 0:
                    cur_pageid = entry.get().pageid
                else:
                    cur_pageid = 0

                cur_pageCount = entry.filter('pageid =',
                                             cur_pageid).count(1000)

                if cur_pageCount >= max_pageCount:
                    e.pageid = cur_pageid + 1
                else:
                    e.pageid = cur_pageid

            e.tags = []
            tag_names = self.request.get('tags').split()
            for tag_name in tag_names:
                tag = Tag.all().filter("user",
                                       nickname).filter('name', tag_name)
                if (tag.count(1) > 0):
                    t = tag.get()
                    if type == 'link':
                        t.count_link += 1
                    if type == 'note':
                        t.count_note += 1
                    if type == 'pic':
                        t.count_pic += 1
                    t.user = nickname
                    t.usetime = datetime.datetime.now()
                    t.put()
                else:
                    t = Tag()
                    t.name = tag_name
                    if type == 'link':
                        t.count_link = 1
                    if type == 'note':
                        t.count_note = 1
                    if type == 'pic':
                        t.count_pic = 1
                    t.user = nickname
                    t.usetime = datetime.datetime.now()
                    t.put()
                e.tags.append(db.Category(tag_name))
            e.put()
            self.redirect('/' + type + '/' + nickname)
        else:
            self.redirect(users.create_login_url(self.request.uri))