Example #1
0
    def tagimage(self, imageurl, pageid, latcoord, longcoord, hood, username):
        imageurl = util.convertimageurl(imageurl)
        query = db.GqlQuery("SELECT * FROM ImageModel where imageurl = :1",
                            imageurl)
        image = query.get()

        if image is None:
            image = ImageModel(usernameupdated=username,
                               imageurl=imageurl,
                               pageid=int(pageid),
                               latcoord=latcoord,
                               longcoord=longcoord,
                               neighborhood=hood)
        else:
            image.usernameupdated = username
            image.imageurl = imageurl
            image.pageid = int(pageid)
            image.latcoord = latcoord
            image.longcoord = longcoord
            image.neighborhood = hood

        try:
            image.put()
            user = util.getuser(username)
            if (user is not None):
                user.count = user.count + 1
            else:
                user = UserModel(username=username, count=1)

            user.put()
            return True
        except Exception, err:
            logging.error(str(err))
            return False
Example #2
0
    def username(self):
        """Return default username to be used in commits.

        Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
        and stop searching if one of these is set.
        If not found and ui.askusername is True, ask the user, else use
        ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname".
        """
        user = os.environ.get("HGUSER")
        if user is None:
            user = self.config("ui", "username")
            if user is not None:
                user = os.path.expandvars(user)
        if user is None:
            user = os.environ.get("EMAIL")
        if user is None and self.configbool("ui", "askusername"):
            user = self.prompt(_("enter a commit username:"******"No username found, using '%s' instead\n") % user)
            except KeyError:
                pass
        if not user:
            raise util.Abort(_('no username supplied (see "hg help config")'))
        if "\n" in user:
            raise util.Abort(
                _("username %s contains a newline\n") % repr(user))
        return user
Example #3
0
    def username(self):
        """Return default username to be used in commits.

        Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
        and stop searching if one of these is set.
        If not found and ui.askusername is True, ask the user, else use
        ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname".
        """
        user = os.environ.get("HGUSER")
        if user is None:
            user = self.config("ui", "username")
            if user is not None:
                user = os.path.expandvars(user)
        if user is None:
            user = os.environ.get("EMAIL")
        if user is None and self.configbool("ui", "askusername"):
            user = self.prompt(_("enter a commit username:"******"No username found, using '%s' instead\n") % user)
            except KeyError:
                pass
        if not user:
            raise util.Abort(_('no username supplied (see "hg help config")'))
        if "\n" in user:
            raise util.Abort(_("username %s contains a newline\n") % repr(user))
        return user
Example #4
0
	def tagimage(self, imageurl, pageid, latcoord, longcoord, hood, username):
		imageurl = util.convertimageurl(imageurl)	
		query = db.GqlQuery("SELECT * FROM ImageModel where imageurl = :1", imageurl)
		image = query.get()
		
		if image is None:
			image = ImageModel(usernameupdated=username, imageurl=imageurl, pageid=int(pageid), latcoord=latcoord, longcoord=longcoord, neighborhood=hood)
		else:
			image.usernameupdated = username
			image.imageurl = imageurl
			image.pageid = int(pageid)
			image.latcoord = latcoord
			image.longcoord = longcoord
			image.neighborhood = hood	
		
		try:
			image.put()
			user = util.getuser(username)
			if (user is not None):
				user.count = user.count + 1
			else:
				user = UserModel(username=username, count=1)
					
			user.put()
			return True
		except Exception, err:
			logging.error(str(err))
			return False
Example #5
0
 def updateuser(self, username, hood):
     user = util.getuser(username)
     if (user is not None):
         try:
             user.neighborhood = hood
             user.put()
             return True
         except Exception, err:
             logging.error(str(err))
Example #6
0
	def updateuser(self, username, hood):
		user = util.getuser(username)
		if (user is not None):
			try:
				user.neighborhood = hood
				user.put()
				return True
			except Exception, err:
				logging.error(str(err))
Example #7
0
    def adduser(self, username):
        user = util.getuser(username)
        if (user is not None):
            return False

        user = UserModel(username=username, count=0)
        try:
            user.put()
            return True
        except Exception, err:
            logging.error(str(err))
Example #8
0
	def adduser(self, username):
		user = util.getuser(username)
		if (user is not None):
			return False
			
		user = UserModel(username=username, count=0)
		try:
			user.put()
			return True
		except Exception, err:
			logging.error(str(err))
Example #9
0
def update():
    if request.method == 'POST':
        data = {k: v[0] for k, v in dict(request.form).items()}
        print data
        res = util.update(data)
        if res['code'] == 0:
            return redirect('/userlist')
        else:
            return render_template('update.html', res=res)
    else:
        uid = request.args.get('id')
        data = {'id': uid}
        res = util.getuser(data)
        print res
        return render_template('update.html', res=res)
Example #10
0
	def getfirstuntaggedimage(self, username, hood):
		user = util.getuser(username)
		modelimage = None
		
		# make a call to the imagemodel KV store, passing the hood desired, and getting back the imageid, pageid and image url of the first one that has no geo coords, and is not in the user's ignored list		
		dbhood = util.underscoredistricturl(hood)
		query = db.GqlQuery("SELECT * FROM ImageModel where latcoord = null and longcoord = null and neighborhood = :1 order by updatetime asc", dbhood)
		images = query.fetch(len(user.ignored_images) + 1) #get one more than the amount of items in the ignored images list, so we are guaranteed to have at least one left once the list is filtered
		for singleimage in images: # now return the first image that is not in the user's ignored images list
			if singleimage.imageurl not in user.ignored_images: 
				modelimage = singleimage
				break
			else:
				logging.info("Ignoring %s", singleimage.imageurl)
		
		return modelimage
Example #11
0
	def ignoreimage(self, imageurl, username):

		imageurl = util.convertimageurl(imageurl)	

		try:
			user = util.getuser(username)
			if (user is not None):
				user.count = user.count + 1
			else:
				user = UserModel(username=username, count=1)

			user.ignored_images.append(imageurl)
			user.put()
			return True
		except Exception, err:
			logging.error(str(err))
			return False
Example #12
0
    def ignoreimage(self, imageurl, username):

        imageurl = util.convertimageurl(imageurl)

        try:
            user = util.getuser(username)
            if (user is not None):
                user.count = user.count + 1
            else:
                user = UserModel(username=username, count=1)

            user.ignored_images.append(imageurl)
            user.put()
            return True
        except Exception, err:
            logging.error(str(err))
            return False
Example #13
0
    def getfirstuntaggedimage(self, username, hood):
        user = util.getuser(username)
        modelimage = None

        # make a call to the imagemodel KV store, passing the hood desired, and getting back the imageid, pageid and image url of the first one that has no geo coords, and is not in the user's ignored list
        dbhood = util.underscoredistricturl(hood)
        query = db.GqlQuery(
            "SELECT * FROM ImageModel where latcoord = null and longcoord = null and neighborhood = :1 order by updatetime asc",
            dbhood)
        images = query.fetch(
            len(user.ignored_images) + 1
        )  #get one more than the amount of items in the ignored images list, so we are guaranteed to have at least one left once the list is filtered
        for singleimage in images:  # now return the first image that is not in the user's ignored images list
            if singleimage.imageurl not in user.ignored_images:
                modelimage = singleimage
                break
            else:
                logging.info("Ignoring %s", singleimage.imageurl)

        return modelimage
Example #14
0
    def username(self):
        """Return default username to be used in commits.

        Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
        and stop searching if one of these is set.
        If not found, use ($LOGNAME or $USER or $LNAME or
        $USERNAME) +"@full.hostname".
        """
        user = os.environ.get("HGUSER")
        if user is None:
            user = self.config("ui", "username")
        if user is None:
            user = os.environ.get("EMAIL")
        if user is None:
            try:
                user = '******' % (util.getuser(), socket.getfqdn())
                self.warn(_("No username found, using '%s' instead\n") % user)
            except KeyError:
                pass
        if not user:
            raise util.Abort(_("Please specify a username."))
        if "\n" in user:
            raise util.Abort(_("username %s contains a newline\n") % `user`)
        return user
Example #15
0
File: ui.py Project: carlgao/lenga
    def username(self):
        """Return default username to be used in commits.

        Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
        and stop searching if one of these is set.
        If not found, use ($LOGNAME or $USER or $LNAME or
        $USERNAME) +"@full.hostname".
        """
        user = os.environ.get("HGUSER")
        if user is None:
            user = self.config("ui", "username")
        if user is None:
            user = os.environ.get("EMAIL")
        if user is None:
            try:
                user = '******' % (util.getuser(), socket.getfqdn())
                self.warn(_("No username found, using '%s' instead\n") % user)
            except KeyError:
                pass
        if not user:
            raise util.Abort(_("Please specify a username."))
        if "\n" in user:
            raise util.Abort(_("username %s contains a newline\n") % `user`)
        return user
Example #16
0
                    util.toxml(('response', [('success', False)])))

        elif (op == 'update' and hood is not None):
            try:
                success = self.updateuser(username, hood)
                a = ('response', [('username', username),
                                  ('success', success)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))

        elif (username is not None):
            try:
                user = util.getuser(username)
                success, score = self.getusercount(username, oldusernames)
                a = ('response', [('username', username),
                                  ('neighborhood', user.neighborhood),
                                  ('score', score),
                                  ('updated', user.updatetime),
                                  ('success', success)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))

        #else:
        #self.response.out.write(util.toxml(('response',[('success',False)])))
Example #17
0
			except Exception, err:
				logging.error(err)
				self.response.out.write(util.toxml(('response',[('success',False)])))
						
		elif (op == 'update' and hood is not None):
			try:
				success = self.updateuser(username,hood)
				a=('response',[('username',username),('success',success)])
				self.response.out.write(util.toxml(a))
			except Exception, err:
				logging.error(err)
				self.response.out.write(util.toxml(('response',[('success',False)])))
				
		elif (username is not None):
			try:
				user = util.getuser(username)
				success, score = self.getusercount(username, oldusernames)
				a=('response',[('username',username),('neighborhood',user.neighborhood),('score',score),('updated',user.updatetime),('success',success)])
				self.response.out.write(util.toxml(a))
			except Exception, err:
				logging.error(err)
				self.response.out.write(util.toxml(('response',[('success',False)])))	
				
		#else:
			#self.response.out.write(util.toxml(('response',[('success',False)])))

	def adduser(self, username):
		user = util.getuser(username)
		if (user is not None):
			return False