Example #1
0
 def get(self):
     str_id = self.request.get('id')
     message = self.request.get('message')
     
     if not str_id or not message:
         self.response.status_int = 400
         self.response.body = "Invalid or missing id and or message."
         return
         
     devices = GqlQuery('SELECT * FROM Device WHERE __key__ = :1',
                        Key.from_path('Device', str_id))
     
     if devices.count() < 1:
         self.response.status_int = 404
         self.response.body = "Target device not registered."
         return
     
     payload = {'registration_ids': [devices.get().token], 'data': {'message': message}}
     headers = {'Content-Type': 'application/json',
                'Authorization': 'key=' + API_KEY}
     result = urlfetch.fetch(url = ANDROID_GCM_URL,
                             payload = json.dumps(payload),
                             method = urlfetch.POST,
                             headers = headers)
     
     self.response.status_int = result.status_code
     self.response.body = result.content
Example #2
0
def admin_login():
    if request.method == 'POST':
        id = request.form['username']
        pw = request.form['password']
        print id, pw
        q = GqlQuery("SELECT * FROM User WHERE id = :1", id)
        check_user = q.get()

        print check_user.password

        if check_user != None:
            if check_password(check_user.password, pw):
                session['username'] = '******'
                return redirect(url_for('admin_juboam'))

    return render_template('admin_login.html')
Example #3
0
    def get(self):
        image_url = self.request.get('image_url')
        width = int(self.request.get('width'))
        name = self.request.get('name')

        savedimages = GqlQuery(
            "SELECT * FROM Image WHERE url = :1 and width = :2", image_url,
            width)
        image = savedimages.get()
        if image:
            image_url = image.url
            tinyname = image.name
        else:
            import random
            import string
            image_re = re.compile(r'http://([\w\d\_\=\?\-\.\/\&\;\%]+)')
            if image_re.search(image_url):
                domain = image_re.search(image_url).group(0)
                ext = domain[-3:].lower()
                if ext == "jpg" or ext == "png" or ext == "gif":
                    mime = ext
                    if ext == "jpg":
                        mime = "jpeg"
                    parts = domain.split("/")
                    filename = parts[len(parts) - 1]
                    #get image
                    image_content = urlfetch.fetch(image_url).content
                    thumb = images.resize(image_content, width, width)
                    tinyname = ''.join(random.sample(string.letters * 2, 10))

                    if thumb:
                        image = Image()
                        image.url = image_url
                        image.width = width
                        image.name = tinyname
                        image.content = db.Blob(image_content)
                        image.thumb = db.Blob(thumb)
                        image.put()

        template_values = {
            'image_url': image_url,
            'width': width,
            'name': tinyname
        }
        path = os.path.join(os.path.dirname(__file__),
                            'templates/thumbnails.html')
        self.response.out.write(template.render(path, template_values))
Example #4
0
	def get(self):
		image_url = self.request.get('image_url')
		width = int(self.request.get('width'))
		name=self.request.get('name')
		
		
		savedimages = GqlQuery("SELECT * FROM Image WHERE url = :1 and width = :2", image_url, width)
		image = savedimages.get()
		if image:
			image_url=image.url
			tinyname=image.name
		else:
			import random
			import string
			image_re = re.compile(r'http://([\w\d\_\=\?\-\.\/\&\;\%]+)')
			if image_re.search(image_url):
				domain=image_re.search(image_url).group(0)
				ext = domain[-3:].lower()
				if ext == "jpg" or ext == "png" or ext == "gif":
					mime=ext
					if ext=="jpg":
						mime="jpeg"
					parts=domain.split("/")
					filename=parts[len(parts)-1]
					#get image 
					image_content = urlfetch.fetch(image_url).content
					thumb = images.resize(image_content, width, width)
					tinyname= ''.join(random.sample(string.letters*2, 10)) 

					if thumb:
						image=Image()
						image.url=image_url
						image.width=width
						image.name=tinyname
						image.content = db.Blob(image_content)
						image.thumb = db.Blob(thumb)
						image.put()
						
		template_values={
			'image_url': image_url,
			'width': width,
			'name': tinyname
		}
		path = os.path.join(os.path.dirname(__file__), 'templates/thumbnails.html')
		self.response.out.write(template.render(path, template_values))
Example #5
0
 def has_write_access(self, user_key):
     try:
         if self.owner == user_key:
             return True
         if self.public_readwrite:
             return True
         if self.group_write:
             #group_write means you need to be abuddy
             room_k = str(self.key())
             roomyQ = GqlQuery(
                 "SELECT * FROM RoomUser WHERE room = :room_key AND user =:p_user_key ",
                 room_key=room_k,
                 p_user_key=user_key)
             if roomyQ.get():
                 return True
         return False
     except:
         return False
Example #6
0
    def has_read_access(self, user):
        try:
            if self.public_read:
                return True
            if user == None:
                return False
            user_key = str(user.key())
            if self.owner == user_key:
                return True

            room_k = str(self.key())
            roomyQ = GqlQuery(
                "SELECT * FROM RoomUser WHERE room = :room_key AND user =:p_user_key ",
                room_key=room_k,
                p_user_key=user_key)
            if roomyQ.get():
                return True
            else:
                return False
        except:
            return False
Example #7
0
 def get(self):
     str_id = self.request.get('id')
     token = self.request.get('token')
     
     if not str_id or not token:
         self.response.status_int = 400
         self.response.body = "Invalid or missing id and or token."
         return
         
     objects = GqlQuery('SELECT * FROM Device WHERE __key__ = :1',
                        Key.from_path('Device', str_id))
     
     if objects.count() < 1:
         obj = Device(key=Key.from_path('Device', str_id), token=token)
     else:
         obj = objects.get()
     
     obj.put()
     
     self.response.status_int = 200
     self.response.body = "OK"
Example #8
0
    def get(self):
        import random
        import string

        image_url = self.request.get('image_url')

        width = self.request.get('width')
        if width:
            width = int(self.request.get('width'))
        else:
            width = 60

        tinyname = ''.join(random.sample(string.letters * 2, 10))

        if not width or (width < 10 or width > 1200):
            width = 90

        savedimages = GqlQuery(
            "SELECT * FROM Image WHERE url = :1 and width = :2", image_url,
            width)

        image = savedimages.get()

        if image:
            ext = image.name[-3:]
            mime = ext
            if ext == "jpg":
                mime = "jpeg"
            self.response.headers['Content-Type'] = "image/%s" % mime
            self.response.out.write(image.thumb)
            self.response.out.write(image.content)
            return

        image_re = re.compile(r'http://([\w\d\_\=\?\-\.\/\&\;\%]+)')

        if image_re.search(image_url):
            domain = image_re.search(image_url).group(0)
            ext = domain[-3:].lower()

            if ext == "jpg" or ext == "png" or ext == "gif":

                mime = ext
                if ext == "jpg":
                    mime = "jpeg"

                parts = domain.split("/")
                filename = parts[len(parts) - 1]

                #get image
                image_content = urlfetch.fetch(image_url).content
                thumb = images.resize(image_content, width, width)

                if thumb:
                    image = Image()
                    image.url = image_url
                    image.width = width
                    image.name = tinyname
                    image.content = db.Blob(image_content)
                    image.thumb = db.Blob(thumb)
                    image.put()

                    self.response.headers['Content-Type'] = "image/%s" % mime
                    self.response.out.write(thumb)
                else:
                    self.error(404)
Example #9
0
	def get(self):
		import random
		import string
		
		image_url = self.request.get('image_url')

		width=self.request.get('width')
		if width:
			width = int(self.request.get('width'))
		else:
			width=60
	
		tinyname= ''.join(random.sample(string.letters*2, 10))
		
		if not width or (width < 10 or width > 1200):
			width = 90
		
		savedimages = GqlQuery("SELECT * FROM Image WHERE url = :1 and width = :2", image_url, width)
		
		image = savedimages.get()
		
		if image:
			ext=image.name[-3:]
			mime=ext
			if ext=="jpg":
				mime="jpeg"
			self.response.headers['Content-Type'] = "image/%s" % mime
			self.response.out.write(image.thumb)
			self.response.out.write(image.content)
			return
		
		image_re = re.compile(r'http://([\w\d\_\=\?\-\.\/\&\;\%]+)')
		
		if image_re.search(image_url):
			domain=image_re.search(image_url).group(0)
			ext = domain[-3:].lower()
			
			if ext == "jpg" or ext == "png" or ext == "gif":
				
				mime=ext
				if ext=="jpg":
					mime="jpeg"
				
				parts=domain.split("/")
				filename=parts[len(parts)-1]
	
				#get image 
				image_content = urlfetch.fetch(image_url).content
				thumb = images.resize(image_content, width, width)
	
				if thumb:
					image=Image()
					image.url=image_url
					image.width=width
					image.name=tinyname
					image.content = db.Blob(image_content)
					image.thumb = db.Blob(thumb)
					image.put()

					self.response.headers['Content-Type'] = "image/%s" % mime
					self.response.out.write(thumb)
				else:
					self.error(404)