Esempio n. 1
0
def playlist(tag_id):
    if _('CLOSEUI') == 'YES':
        return redirect('/')

    tag = Tag.get_by_id(tag_id)
    videos = VideoTag.blend(tag)
    watch = request.args.get('watch') or videos[0]['slug']

    return render_template('playlist.html',
                           tag=tag,
                           watch=watch,
                           videos=videos)
Esempio n. 2
0
    def update(self):
        """updates a post"""
        
        #for catobj in self.categories:
        #    logging.info([catobj.key(),catobj.category,catkeys])
        #    if catobj.category==self.postcatkey:#AN OLD CATEGORY
        #        catkey=catobj.key()
        #    elif catobj.key() not in self.catkeys:#not used category
        #        catobj.delete()
        #    else:
        #        logging.info(catobj.key().id())
                #newcatobj=Category()
                #newcatobj.category=category
                #newcatobj.put()
                #catkey=newcatobj.key()
             
      
        post_tagsdb_values=[]
        post_tagsdb_keys=[]
        existingTags=[]
        existingTagskeys=[]
        tagsleft=[]
     
       #find the existing tags of the post
        for tagkey in self.posts_tags_db:
            if tagkey not in self.post_tags_keys:
                try:
                    tagsleft.append(Tag.get_by_id(tagkey.id()).tag)
                except AttributeError:#ops a post without a tag
                    continue
            existingTagskeys.append(tagkey)
            existingTags.append(db.get(tagkey).tag) #existing Tags
          
     
        
        for tagkey in self.post_tags_keys:post_tagsdb_values.append(db.get(tagkey).tag)#previous Tags of the post
        
         
     #   logging.info([self.posttags,type(self.posttags),type(post_tagsdb_values),post_tagsdb_values])  
        unchangedtags=[]
        returnedTags=[]
      #  logging.info(['posttags',self.posttags,post_tagsdb_values])
        if post_tagsdb_values:#post does have tags
            logging.info(post_tagsdb_values)
            unchangedtags=set(self.posttags) & set( post_tagsdb_values)#changes tags added or removed
            newtags=set(self.posttags) ^ unchangedtags#new tags for this post
            oldtags=list(set(post_tagsdb_values)^unchangedtags)
            logging.info(["new",newtags,"old",oldtags,"unchanged",unchangedtags,list(unchangedtags)])
  
            if list(unchangedtags):
                unchangedtags=list(unchangedtags)
                for tag in unchangedtags:
                    tagid=db.get(existingTagskeys[existingTags.index(tag)]).key().id()
                    returnedTags.append({"tag":tag,"tagid":tagid})
            else:unchangedtags=[]
            i=0
            logging.info(['Tags from other posts',existingTags])
            for tag in oldtags:#tags to be removed
                
                tag_key= existingTagskeys[existingTags.index(tag)]
                if tag not in  tagsleft:#delete not used tags
                    tagobj=db.get(tag_key)
                    logging.info(["deleting",tag,tagobj]) 
                    tagobj.delete()
                pos=post_tagsdb_values.index(tag)
            
          
                self.obj.tags.pop(pos-i)
          
                i+=1
        elif  self.posttags:#new tags do exist

            logging.info(self.posttags)
            newtags=set(self.posttags)#does not have tags

        else:newtags=[]
       
     
     
            
        if newtags:
            for tag in list(newtags):#add new tag and update Post
                logging.info(tag)
                if tag not in existingTags:   
                    tagobj=Tag()
                    tagobj.tag=tag
                    tagid=tagobj.put().id()
                    returnedTags.append({"tag":tag,"tagid":tagid})
                    
                else:
                   tag_key= existingTagskeys[existingTags.index(tag)]
                   tagobj=Tag.get(tag_key)
                   returnedTags.append({"tag":tagobj.tag,"tagid":tagobj.key().id()})           
                self.obj.tags.append(tagobj.key())
        if isinstance(self.postcategory,list):self.postcategory=self.postcategory[0]
        logging.info([self.catdict.values()])
        self.obj.title=self.title
        self.obj.body=self.body   
        self.obj.category=self.catdict.keys()[self.catdict.values().index(self.postcategory)]
        self.obj.updated=datetime.now()
        self.obj.put()
        createIndex([self.obj])
        tags=[]
        [tags.append({"tag":db.get(key).tag,"tagid":db.get(key).key().id()}) for key in self.obj.tags]
          
        data=[]
        updated=str(self.obj.updated.day)+" "+str(months[self.obj.updated.month])+" "+str(self.obj.updated.year)
        dateposted=str(self.obj.timestamp.day)+" "+str(months[self.obj.timestamp.month])+" "+str(self.obj.timestamp.year)    
        data.append({"title":self.obj.title,"body":self.obj.body,"category":db.get(self.obj.category.key()).category,
                         "catid": db.get(self.obj.category.key()).key().id(),"id":str(self.obj.key().id()),\
             "tags":tags,"date":dateposted,"updated":updated})
        self.deleteMemcache(self)
        self.refetch(self)
        return(data,returnedTags)
Esempio n. 3
0
def get_tag_by_id_or_404(id):
    tag = Tag.get_by_id(id)
    if not tag:
        abort(404)
    return tag
Esempio n. 4
0
def tag(id = 0):
  if request.method == 'POST':
    return Tag.edit(id, name=request.form.get('name'))

  tag = Tag.get_by_id(id)
  return render_template('tag.html', tag=tag)
Esempio n. 5
0
def get_tag_by_id_or_404(id):
	tag = Tag.get_by_id(id)
	if not tag:
		abort(404)
	return tag
Esempio n. 6
0
def edit_tag(id):
    tag = Tag.get_by_id(id)
    return render_template('tag_edit_form.html', tag=tag)
Esempio n. 7
0
def tag_details(id):
    tag = Tag.get_by_id(id)
    return render_template('tag_details.html', tag=tag)
Esempio n. 8
0
def get_tag_by_id(tag_id):
    return Tag.get_by_id(int(tag_id))