# 3. tarkista onko url jo olemassa channel-tasolla channelurlquery=ChannelUrl.query(ChannelUrl.url==urlinstance.key, ChannelUrl.channel==channelinstance.key) channelurlinstance=channelurlquery.get() if not channelurlinstance: l=list(string.ascii_uppercase) l.append('Z') DEFAULT_COUNTER_NAME=chr(now.isocalendar()[0]-2010+65)+l[(now.isocalendar()[1]-1)/2] #logging.debug('DEFAULT_COUNTER_NAME: %s' % (DEFAULT_COUNTER_NAME)) counter.increment(DEFAULT_COUNTER_NAME) key_name=DEFAULT_COUNTER_NAME+str(counter.get_count(DEFAULT_COUNTER_NAME)) #logging.debug('key_name %s' % (key_name)) channelurlinstance=ChannelUrl(id=key_name,channel=channelinstance.key,url=urlinstance.key) channelurlinstance.put() #logging.debug('New channelurl %s/%s' % (channel,url)) else: #logging.info('OLDIE! %s %s' % (channelurlinstance.channel.name,channelurlinstance.url.url)) logging.info('Old channelurl %s %s' % (channel,url)) old_url=True old_post=Post.query(Post.channelurl==channelurlinstance.key).order(Post.date).get() try: old_date=old_post.date.strftime("%d.%m.%y %H:%M") except: try: old_date=old_post.idate.strftime("%d.%m.%y %H:%M") except: old_date='' old_user=old_post.user
def post(self): if users.get_current_user(): node.author = users.get_current_user() post_channel = self.request.get('post_channel', '') post_user = self.request.get('post_user', '') post_url = self.request.get('post_url', '') # Add http:// when needed if not post_url.startswith('http'): post_url = 'http://' + post_url logging.debug('Post: C=%s U=%s P=%s' % (post_channel, post_user, post_url)) # 1. tarkista onko olemassa jo ko. Url, lisää jos ei, muuten päivitä (udate, valid?): valid-juttu joo ehkä jos tarpeen, ei muuten url = Url.all().filter('url =', post_url).get() if not url: url = Url() url.url = post_url url.put() # Title name = ''.join( re.findall('[a-zA-Z0-9_-]', post_channel + '_' + post_url))[:500] try: taskqueue.add(name=name, queue_name='urlfetch', url='/tasks/title', params={'post_url': post_url}) except taskqueue.TombstonedTaskError: logging.warning('TombstonedError %s' % post_url) except taskqueue.TaskAlreadyExistsError: logging.warning('TaskAlredyExists: %s' % post_url) # 2. tarkista onko olemassa jo ko. Channel, lisää jos ei channel = Channel.all().filter('name =', post_channel).get() if not channel: channel = Channel() channel.name = post_channel if post_channel.startswith('!'): channel.private = True channel.put() # 3. tarkista onko url jo olemassa channel-tasolla channelurl = ChannelUrl.all().filter('url =', url).filter('channel =', channel).get() if not channelurl: channelurl = ChannelUrl() channelurl.channel = channel channelurl.url = url #channelurl.user=post_user channelurl.put() else: logging.info('OLDIE! %s %s' % (channelurl.channel.name, channelurl.url.url)) # 4. Lisätään postaus post = Post() post.channelurl = channelurl post.user = post_user post.put()