Beispiel #1
0
    def get(self,randomID):
    
      util.insertUsersideCookies(self)

      randomID = randomID.replace("/","")
      sketch = Sketch.get_by_randomID(randomID)
      
      # this big blot inserted by Davide Della Casa
      self.session = True
      user = UserInfo()
      user.whoIs(self)

      sketch.sourceCodeForTextArea = sourcecode_for_text_area(sketch.sourceCode)

      if ((sketch.author_user_id == user.user_id) or (user.is_current_user_admin)):
			template_values = {
			'sketch': sketch,
			'published': sketch.published,
			'action': "editBlog",
			'headerTitle':"Edit sketch",
			}
			self.generate(self.template_path,template_values)
      else:
			if self.request.method == 'GET':
				self.redirect("/403.html")
			else:
				self.error(403)   # User didn't meet role.
Beispiel #2
0
    def get(self, randomID):

        util.insertUsersideCookies(self)

        randomID = randomID.replace("/", "")
        sketch = Sketch.get_by_randomID(randomID)

        # this big blot inserted by Davide Della Casa
        self.session = True
        user = UserInfo()
        user.whoIs(self)

        sketch.sourceCodeForTextArea = sourcecode_for_text_area(
            sketch.sourceCode)

        if ((sketch.author_user_id == user.user_id)
                or (user.is_current_user_admin)):
            template_values = {
                'sketch': sketch,
                'published': sketch.published,
                'action': "editBlog",
                'headerTitle': "Edit sketch",
            }
            self.generate(self.template_path, template_values)
        else:
            if self.request.method == 'GET':
                self.redirect("/403.html")
            else:
                self.error(403)  # User didn't meet role.
Beispiel #3
0
    def get(self,randomID):

      util.insertUsersideCookies(self)

      randomID = randomID.replace("/","")
      sketch = Sketch.get_by_randomID(randomID)
      
      # this big blot inserted by Davide Della Casa
      self.session = True
      user = UserInfo()
      user.whoIs(self)

      sketch.sourceCodeForTextArea = sourcecode_for_text_area(sketch.sourceCode)
      sketch.blogdate = "";
      sketch.entrytype="";
      sketch.status="published";

      sketch.author_email = user.email
      sketch.author_user_id = user.user_id
      if user.user:
      	sketch.author_nickname = user.nickname
      else:
      	sketch.author_nickname = "anonymous"

      
      # this big blot inserted by Davide Della Casa
      template_values = {
      	'sketch': sketch,
      	'action': "copyBlog",
      	'published': sketch.published,
      	'headerTitle':"Copy sketch",

      }
      self.generate('newSketchTemplate.html',template_values)
Beispiel #4
0
    def get(self, randomID):

        util.insertUsersideCookies(self)

        randomID = randomID.replace("/", "")
        sketch = Sketch.get_by_randomID(randomID)

        # this big blot inserted by Davide Della Casa
        self.session = True
        user = UserInfo()
        user.whoIs(self)

        sketch.sourceCodeForTextArea = sourcecode_for_text_area(
            sketch.sourceCode)
        sketch.blogdate = ""
        sketch.entrytype = ""
        sketch.status = "published"

        sketch.author_email = user.email
        sketch.author_user_id = user.user_id
        if user.user:
            sketch.author_nickname = user.nickname
        else:
            sketch.author_nickname = "anonymous"

        # this big blot inserted by Davide Della Casa
        template_values = {
            'sketch': sketch,
            'action': "copyBlog",
            'published': sketch.published,
            'headerTitle': "Copy sketch",
        }
        self.generate('newSketchTemplate.html', template_values)
Beispiel #5
0
    def get(self,randomID,perm_stem):

        cpedialog = util.getCPedialog()
        sketch = db.Query(Sketch).filter('randomID =',randomID).get()
        if(sketch is None):
            self.redirect('/index.html')
				
        # if the page is viewed for the first time, we don't find the cookie
        # so we add the cookie and we increment the pageviews.
        # otherwise if we find the cookie then it means that the page has been viewed already
        # so we just read the counter without incrementing
        c = Cookie.SimpleCookie(self.request.headers.get('Cookie'))
        if "viewed" not in c.keys():
          # set the "viewed" cookie here so that we don't increment the counter at the next visit
          self.response.headers.add_header('Set-Cookie', 'viewed=%s; expires=Fri, 31-Dec-2020 23:59:59 GMT' % "yes")
          numberOfViews = pagecount.IncrPageCount(randomID, 1)
          if sketch is not None and sketch.author_string_user_id != 'anonymous':
            authorViews = pagecount.IncrPageCount(sketch.author_string_user_id, 1)
        else:
          numberOfViews = pagecount.GetPageCount(randomID)


        # in case the user log-ins from a sketch view page, then when he lands on the same
        # page after the login page, we need to write all the cookies on the client side
        # so this is what we are doing here.
        util.insertUsersideCookies(self)

        template_values = {
          'sketch': sketch,
          'headerTitle':"Playground",
          'numberOfViews':numberOfViews,
          #'blog': blog,
          #'reactions': reactions,
          }
        self.generate(self.template,template_values)
Beispiel #6
0
  def get(self):
      
      util.insertUsersideCookies(self)

      template_values = {
      	'action': "addBlog",
      	'isNew': True, # DDC
      	'published': True, # DDC
      	'headerTitle':"Add a sketch",
      }
      #self.generate('blog_add.html',template_values)
      self.generate(self.template_path,template_values)
Beispiel #7
0
    def get(self):

        util.insertUsersideCookies(self)

        template_values = {
            'action': "addBlog",
            'isNew': True,  # DDC
            'published': True,  # DDC
            'headerTitle': "Add a sketch",
        }
        #self.generate('blog_add.html',template_values)
        self.generate(self.template_path, template_values)
Beispiel #8
0
  def get(self):
        next = None
        PAGESIZE = 30

        util.insertUsersideCookies(self)

        self.session = True
        user = UserInfo()
        user.whoIs(self)

        bookmark = self.request.get("bookmark")
        if bookmark:
        	bookmark = Key(self.request.get("bookmark"))
        else:
        	if user.user:
        		bookmark = Key.from_path('MySketchesSketch','-%023d' % (int(user.user_id)) + SKETCH_ZEROS)
        	else:
        		bookmark = Key.from_path('MySketchesSketch','-%023d' % (0) + SKETCH_ZEROS)

        if user.user:
        	endKey =  Key.from_path('MySketchesSketch','-%023d' % (int(user.user_id) + 1) + SKETCH_ZEROS)
        else:
        	endKey =  Key.from_path('MySketchesSketch','-%023d' % (1) + SKETCH_ZEROS)
        
        logging.info('starting key  ' + str(bookmark))
        logging.info('starting key  name' + bookmark.name())

        

        q = db.GqlQuery("SELECT * FROM MySketchesSketch WHERE __key__ >= :1 AND __key__ < :2",bookmark,endKey)

        sketches = q.fetch(PAGESIZE+1)
        if len(sketches) == PAGESIZE + 1:
        	next = str(sketches[-1].key())
        	sketches = sketches[:PAGESIZE]
        	logging.info('next key  ' + next)
        	logging.info('next key name ' + sketches[-1].key().name())
        
        if next is None:
        	next = ""

        for sketch in sketches:
        	sketch.stringtags = util.shorten(" ".join(sketch.tags),18)
			
        template_values = {
          'sketches':sketches,
          'bookmark':bookmark,
          'next':next,
          'action':"mySketches",
          'headerTitle':"My sketches",
          }
        self.generate('galleryTemplate.html',template_values)
Beispiel #9
0
  def get(self):
        next = None
        PAGESIZE = 30

        util.insertUsersideCookies(self)

        user = UserInfo()
        user.whoIs(self)

        if user.email == '*****@*****.**':
        	self.generate('limboPage.html')
        	return;

        bookmark = self.request.get("bookmark")
        if bookmark:
        	bookmark = Key(self.request.get("bookmark"))
        else:
        	bookmark = Key.from_path('GallerySketch',SKETCH_ZEROS)

        logging.info('starting key  ' + str(bookmark))
        logging.info('starting key  name' + bookmark.name())
        q = db.GqlQuery("SELECT * FROM GallerySketch WHERE __key__ >= :1", bookmark)
        sketches = q.fetch(PAGESIZE+1)
        
        if len(sketches) == PAGESIZE + 1:
        	next = str(sketches[-1].key())
        	sketches = sketches[:PAGESIZE]
        	logging.info('next key  ' + next)
        	logging.info('next key name ' + sketches[-1].key().name())

        if next is None:
        	next = ""


        for sketch in sketches:
        	sketch.stringtags = util.shorten(" ".join(sketch.tags),18)
			
        template_values = {
          'sketches':sketches,
          'bookmark':bookmark,
          'next':next,
          'action':"gallery",
          'headerTitle':"Gallery",
          }
        self.generate('galleryTemplate.html',template_values)
Beispiel #10
0
  def get(self,randomID):
        next = None
        PAGESIZE = 5

        """
        if not authorized.checkIfUserIsInWhiteList():
        	self.redirect(authorized.getLoginPage())
        """

        util.insertUsersideCookies(self)

        self.session = True
        user = UserInfo()
        user.whoIs(self)


        bookmark = self.request.get("bookmark")
        if bookmark:
        	bookmark = Key(self.request.get("bookmark"))
        else:
        	bookmark = Key.from_path('SketchComment',"-" + randomID + 'sketch00000000000000000000')
        	
        endKey =  Key.from_path('SketchComment',"-" + randomID +      'sketch99999999999999999999')

        q = db.GqlQuery("SELECT * FROM SketchComment WHERE __key__ >= :1 AND __key__ < :2", bookmark, endKey)
        sketchComments = q.fetch(PAGESIZE+1)
        if len(sketchComments) == PAGESIZE + 1:
        	next = str(sketchComments[-1].key())
        	sketchComments = sketchComments[:PAGESIZE]
        
        if next is None:
        	next = ""

        for sketchComment in sketchComments:
        	sketchComment.keyname = sketchComment.key().name()

			
        template_values = {
          'sketchComments':sketchComments,
          'bookmark':bookmark,
          'next':next,
          'randomID':randomID,
          }
        self.generate('commentsTemplate.html',template_values)
Beispiel #11
0
    def get(self, randomID, perm_stem):

        cpedialog = util.getCPedialog()
        sketch = db.Query(Sketch).filter('randomID =', randomID).get()
        if (sketch is None):
            self.redirect('/index.html')

        # if the page is viewed for the first time, we don't find the cookie
        # so we add the cookie and we increment the pageviews.
        # otherwise if we find the cookie then it means that the page has been viewed already
        # so we just read the counter without incrementing
        c = Cookie.SimpleCookie(self.request.headers.get('Cookie'))
        if "viewed" not in c.keys():
            # set the "viewed" cookie here so that we don't increment the counter at the next visit
            self.response.headers.add_header(
                'Set-Cookie',
                'viewed=%s; expires=Fri, 31-Dec-2020 23:59:59 GMT' % "yes")
            numberOfViews = pagecount.IncrPageCount(randomID, 1)
            if sketch is not None and sketch.author_string_user_id != 'anonymous':
                authorViews = pagecount.IncrPageCount(
                    sketch.author_string_user_id, 1)
        else:
            numberOfViews = pagecount.GetPageCount(randomID)

        # in case the user log-ins from a sketch view page, then when he lands on the same
        # page after the login page, we need to write all the cookies on the client side
        # so this is what we are doing here.
        util.insertUsersideCookies(self)

        template_values = {
            'sketch': sketch,
            'headerTitle': "Playground",
            'numberOfViews': numberOfViews,
            #'blog': blog,
            #'reactions': reactions,
        }
        self.generate(self.template, template_values)
Beispiel #12
0
    def get(self):

        util.insertUsersideCookies(self)

        user = UserInfo()
        user.whoIs(self)

        if user.email == '*****@*****.**':
            self.generate('limboPage.html')
            return

        q = db.GqlQuery("SELECT * FROM GallerySketch")
        sketches = q.fetch(28)

        counter = 28
        for sketch in sketches:
            sketch.stringtags = util.shorten(" ".join(sketch.tags), 18)
            sketch.counter = counter
            counter = counter + 1

        template_values = {
            'sketches': sketches,
        }
        self.generate('frontPageTemplate.html', template_values)
Beispiel #13
0
  def get(self):

        util.insertUsersideCookies(self)
        
        user = UserInfo()
        user.whoIs(self)

        if user.email == '*****@*****.**':
        	self.generate('limboPage.html')
        	return;
        
        q = db.GqlQuery("SELECT * FROM GallerySketch")
        sketches = q.fetch(28)

        counter = 28
        for sketch in sketches:
        	sketch.stringtags = util.shorten(" ".join(sketch.tags),18)
        	sketch.counter = counter
        	counter = counter + 1
			
        template_values = {
          'sketches':sketches,
          }
        self.generate('frontPageTemplate.html',template_values)
Beispiel #14
0
  def get(self,originaluserIDasString):
        next = None
        PAGESIZE = 30

        util.insertUsersideCookies(self)

        # we get it in the form davidedc-2jaidlbSQRSE and we only want 2jaidlbSQRSE
        userIDasString = originaluserIDasString.partition('-')[2]
        logging.info('most weird: sometimes this ends with justcorners.js : ' + userIDasString)
        userIDasString = userIDasString.partition('/')[0]
        
        if userIDasString != "anonymous":
        	userIDasString = '%023d' % (util.toBase10(userIDasString,62))
        	logging.info('coverting to 23 digits: ' + userIDasString)
        	logging.info('after cleanup, query starts from ' + "-"+userIDasString + ZERO_FILL)
        	logging.info('query ends at ' + '-%023d' % (int(userIDasString) + 1) + ZERO_FILL)
        else:
        	userIDasString = '%023d' % (0)
        	logging.info('searching for anonymous sketches, user id is 23 zeroes')

        self.session = True
        user = UserInfo()
        user.whoIs(self)

		# we'll be using this variable later and it better not be null
        if user.user_id == None:
        	user.user_id = "0";
			
        logging.info('comparing ' + ('%023d' % int(user.user_id)) + " to " + userIDasString)
        if ('%023d' % int(user.user_id)) != userIDasString:
        	logging.info('user is looking at someone else\'s sketches, showing only public sketches from AuthorSketchesSketch table')
        	bookmark = self.request.get("bookmark")
        	if self.request.get("bookmark"):
        		bookmark = Key(self.request.get("bookmark"))
        	else:
        		bookmark = Key.from_path('AuthorSketchesSketch',"-"+userIDasString + ZERO_FILL)
        	endKey =  Key.from_path('AuthorSketchesSketch','-%023d' % (int(userIDasString) + 1) + ZERO_FILL)
        	q = db.GqlQuery("SELECT * FROM AuthorSketchesSketch WHERE __key__ >= :1 AND __key__ < :2",bookmark,endKey)
        else:
        	logging.info('user is looking at his own sketches, showing private and public sketches from MySketchesSketch table')
        	if self.request.get("bookmark"):
        		bookmark = Key(self.request.get("bookmark"))
        	else:
        		bookmark = Key.from_path('MySketchesSketch','-%023d' % (int(user.user_id)) + SKETCH_ZEROS)
        	endKey =  Key.from_path('MySketchesSketch','-%023d' % (int(user.user_id) + 1) + SKETCH_ZEROS)
        	q = db.GqlQuery("SELECT * FROM MySketchesSketch WHERE __key__ >= :1 AND __key__ < :2",bookmark,endKey)


        logging.info('starting key  ' + str(bookmark))
        logging.info('end key  ' + str(endKey))


        sketches = q.fetch(PAGESIZE+1)
        logging.info('number of sketches found: ' + str(len(sketches)))
        if len(sketches) == PAGESIZE + 1:
        	next = str(sketches[-1].key())
        	sketches = sketches[:PAGESIZE]
        
        if next is None:
        	next = ""

        for sketch in sketches:
        	sketch.stringtags = util.shorten(" ".join(sketch.tags),18)
			
        template_values = {
          'sketches':sketches,
          'bookmark':bookmark,
          'next':next,
          'action':"sketchesByUploader",
          'userIDasString':originaluserIDasString,
          'headerTitle':"By submitter",
          }
        self.generate('galleryTemplate.html',template_values)
Beispiel #15
0
  def get(self):
        
        originaluserIDasString = "anonymous"
        # this big blot inserted by Davide Della Casa
        self.session = True
        user = UserInfo()
        user.whoIs(self)

        if not user.is_current_user_admin:
        	self.redirect('/index.html')

        next = None
        PAGESIZE = 30

        util.insertUsersideCookies(self)

        # we get it in the form davidedc-2jaidlbSQRSE and we only want 2jaidlbSQRSE
        userIDasString = "anonymous"
        userIDasString = '%023d' % (0)
        logging.info('searching for anonymous sketches, user id is 23 zeroes')

        self.session = True
        user = UserInfo()
        user.whoIs(self)

		# we'll be using this variable later and it better not be null
        if user.user_id == None:
        	user.user_id = "0";
			
        logging.info('comparing ' + ('%023d' % int(user.user_id)) + " to " + userIDasString)
        logging.info('admin looking at anonymous sketches')
        # note that we can fetch the sketches from the AuthorSketchesSketch table
        # because all anonymous sketches are public.
        bookmark = self.request.get("bookmark")
        if self.request.get("bookmark"):
        	bookmark = Key(self.request.get("bookmark"))
        else:
        	bookmark = Key.from_path('AuthorSketchesSketch',"-"+userIDasString + ZERO_FILL)
        endKey =  Key.from_path('AuthorSketchesSketch','-%023d' % (int(userIDasString) + 1) + ZERO_FILL)
        q = db.GqlQuery("SELECT * FROM AuthorSketchesSketch WHERE __key__ >= :1 AND __key__ < :2",bookmark,endKey)


        logging.info('starting key  ' + str(bookmark))
        logging.info('end key  ' + str(endKey))


        ANONYMOUSSKETCHESFETCHSIZE = 1000
        sketches = q.fetch(ANONYMOUSSKETCHESFETCHSIZE+1)
        logging.info('number of sketches found: ' + str(len(sketches)))
        if len(sketches) == ANONYMOUSSKETCHESFETCHSIZE + 1:
        	next = str(sketches[-1].key())
        	sketches = sketches[:ANONYMOUSSKETCHESFETCHSIZE]
        
        if next is None:
        	next = ""

        for sketch in sketches:
        	sketch.stringtags = util.shorten(" ".join(sketch.tags),18)
			
        template_values = {
          'sketches':sketches,
          'bookmark':bookmark,
          'next':next,
          'action':"sketchesByUploader",
          'userIDasString':originaluserIDasString,
          'headerTitle':"By submitter",
          }
        self.generate('allAnonymousSketchesTemplate.html',template_values)