コード例 #1
0
ファイル: week3.py プロジェクト: straightDeveloper/sec-blog
	def post(self):
		title = self.request.get("subject");
		text = self.request.get("content");
		title = self.removeSpaces(title);
		text = self.removeSpaces(text);
		if not self.validatePost(title,text):
			self.writeForm(error=True,title=title,text=text);
		else:
			post = Posts(title=title,text=text);
			post.put();
			released_url = week3_permalink_url.replace('(\d+)',str( post.key.id() ) )
			time.sleep(1);
			self.redirect(released_url);
コード例 #2
0
 def post(self):
     if self.session.get("username"):
         form = PostsForm(self.request.POST)
         # Get the userID in order to associate it with the post
         username = self.session.get("username")
         user = db.GqlQuery("SELECT * FROM User WHERE username='******'"
                            % username)
         userID = user.get()
         userID = userID.key().id()
         # if the form is valid add the post to the datastore and then
         # redirect to the detail View of the post.
         if form.validate():
             newPost = Posts(title=form.title.data,
                             content=form.content.data,
                             accessLevel=form.accessLevel.data,
                             author=userID)
             newPost.put()
             self.redirect("/post/%s" % newPost.key().id())
         else:
             self.render("newPost.html", form=form,
                         username=self.session.get("username"))
     else:
         self.redirect("/register")
コード例 #3
0
ファイル: main.py プロジェクト: StevenRS00/OddJobs_CSSix2019
    def post(self):
        checkLoggedInAndRegistered(self)

        profile = users.get_current_user()

        post = Posts(
            title=self.request.get('title-first-ln'),
            description=self.request.get('description-second-ln'),
            owner=profile.nickname(),
            phone=self.request.get('phone-number'),
            complexity=self.request.get('post-type'),
        )
        post_key = post.put()
        self.redirect("/profileposts")
コード例 #4
0
ファイル: main.py プロジェクト: StevenRS00/OddJobs_CSSix2019
    def post(self):
        checkLoggedInAndRegistered(self)

        profile = users.get_current_user()

        post = Posts(title=self.request.get('title-first-ln'),
                     description=self.request.get('description-second-ln'),
                     owner=profile.nickname(),
                     phone=self.request.get('phone-number'),
                     complexity=self.request.get('post-type'))
        post_key = post.put()
        self.response.write("Posts created: " + str(post_key) + "<br>")
        self.response.write("<a href='/'>Home</a> | ")
        self.response.write("<a href='/profileposts'>My posts</a>")
コード例 #5
0
ファイル: views.py プロジェクト: CarolineM/Blog
    def post(self):
        if users.get_current_user():
            error_str = ""
            #checking upload size
            upload_files = self.get_uploads('file')
            if upload_files.__sizeof__() > blobstore.MAX_BLOB_FETCH_SIZE:
                upload_files = None
                error_str = error_str + "<p>Picture size is too large.</p>" 
                
            if upload_files:  
                blob_info = upload_files[0]
                blob_key = blob_info.key()
            else:
                blob_key = None 
        
            post_sub = self.request.get('subject')
            post_content = self.request.get('content')
            if self.request.get('video'): 
                if MediaHelper().validate_vid_url(self.request.get('video')):
                    vid_url = self.request.get('video')
                else: 
                    vid_url = None
                    error_str = error_str + "<p>The youtube url you entered is invalid.</p>"
            else:
                vid_url = None
                
            date_str = self.request.get('date')
        
            #make datetime
            if not date_str == None:
                date = datetime.strptime(date_str,'%m/%d/%Y')
                time = datetime.time(datetime.now())
                dt = datetime.combine(date, time)
            else:
                dt = None
                
            posttype = self.request.get('posttype')
            is_post = False

            post_stat = ""
            if str(posttype) == 'POST':
                post_stat = "Published"
                is_post = True
            else:
                post_stat = "Saved"
        
            #save/update post
            if not self.request.POST.get('id', None):
                post = Posts(
                  title=post_sub,
                  text=post_content,
                  status=post_stat,
                  video_url=vid_url,
                  blob_key=blob_key,
                  date=dt   
                  )
            #editing
            else:
                post = db.get(self.request.get('id'))
                post.title = post_sub
                post.text = post_content
                post.status = post_stat
                post.video_url=vid_url
                post.date=dt
                if blob_key and post.blob_key:
                    if not post.blob_key == blob_key:
                        blobstore.delete(post.blob_key.key())  
                        post.blob_key=blob_key
                    elif blob_key:
                        post.blob_key = blob_key
                    elif post.blob_key:
                        blobstore.delete(post.blob_key.key())
        
            if not self.setPageTags(post) and is_post:
                error_str = error_str + "<p>Select at least one publish area.</p>" 
                
            #save is error    
            if error_str:
                post.status = "Saved"
                
            post.put()
            if error_str:
                self.redirect('/post?post_id=' + str(post.key()) + "&error=" + error_str)
            elif is_post:
                self.redirect('/')
            else:
                self.redirect('/post?post_id=' + str(post.key()))
        else:
            message= "You must login to access this page".encode("utf8")
            self.redirect('/logout?message=' + message)
コード例 #6
0
ファイル: views.py プロジェクト: CarolineM/Blog
    def post(self):
        if users.get_current_user():
            error_str = ""
            #checking upload size
            upload_files = self.get_uploads('file')
            if upload_files.__sizeof__() > blobstore.MAX_BLOB_FETCH_SIZE:
                upload_files = None
                error_str = error_str + "<p>Picture size is too large.</p>"

            if upload_files:
                blob_info = upload_files[0]
                blob_key = blob_info.key()
            else:
                blob_key = None

            post_sub = self.request.get('subject')
            post_content = self.request.get('content')
            if self.request.get('video'):
                if MediaHelper().validate_vid_url(self.request.get('video')):
                    vid_url = self.request.get('video')
                else:
                    vid_url = None
                    error_str = error_str + "<p>The youtube url you entered is invalid.</p>"
            else:
                vid_url = None

            date_str = self.request.get('date')

            #make datetime
            if not date_str == None:
                date = datetime.strptime(date_str, '%m/%d/%Y')
                time = datetime.time(datetime.now())
                dt = datetime.combine(date, time)
            else:
                dt = None

            posttype = self.request.get('posttype')
            is_post = False

            post_stat = ""
            if str(posttype) == 'POST':
                post_stat = "Published"
                is_post = True
            else:
                post_stat = "Saved"

            #save/update post
            if not self.request.POST.get('id', None):
                post = Posts(title=post_sub,
                             text=post_content,
                             status=post_stat,
                             video_url=vid_url,
                             blob_key=blob_key,
                             date=dt)
            #editing
            else:
                post = db.get(self.request.get('id'))
                post.title = post_sub
                post.text = post_content
                post.status = post_stat
                post.video_url = vid_url
                post.date = dt
                if blob_key and post.blob_key:
                    if not post.blob_key == blob_key:
                        blobstore.delete(post.blob_key.key())
                        post.blob_key = blob_key
                    elif blob_key:
                        post.blob_key = blob_key
                    elif post.blob_key:
                        blobstore.delete(post.blob_key.key())

            if not self.setPageTags(post) and is_post:
                error_str = error_str + "<p>Select at least one publish area.</p>"

            #save is error
            if error_str:
                post.status = "Saved"

            post.put()
            if error_str:
                self.redirect('/post?post_id=' + str(post.key()) + "&error=" +
                              error_str)
            elif is_post:
                self.redirect('/')
            else:
                self.redirect('/post?post_id=' + str(post.key()))
        else:
            message = "You must login to access this page".encode("utf8")
            self.redirect('/logout?message=' + message)