Exemplo n.º 1
0
def build_channels(api_user, nick, channels, path, taxonomy, country=False):
  res = []
  tags = build_tags(channels, taxonomy, path)
  for channel in channels:
    tags = [path, path+'/'+channel]
    if(country):
      rel_ref = Relation(owner='/tag_geo/Global', relation='tags_hierarchical', target=path+'/'+channel)
      rel_ref = rel_ref.put()
      tags.append('/tag_geo/Global')
    description = 'Group P.O.Box for %s' % channel
    try:
      channel_ref = api.channel_create(api_user, nick=nick, channel=channel.title().replace(' ', ''), tags=tags, description=description)
    except exception.ApiException:
      logging.info('Channel Exists')
      nick = api.clean.channel(channel.title().replace(' ', ''))
      query = Actor.gql('WHERE nick=:1', nick)
      channel_ref = query.get()
      if channel_ref:
        if not path in channel_ref.tags:
          channel_ref.tags.append(path)
          channel_key = channel_ref.put()

    res.append(channel_ref)
  logging.info('End Creating Channels')
  return res
Exemplo n.º 2
0
def build_tags(tags, taxonomy, path):
  keys = []
  for tag in tags:
    #creating tag
    logging.info('Creating Tag %s' % (tag))
    tag_ref = ChannelTag(term=tag, taxonomy=taxonomy, path=path)
    key = tag_ref.put()

    #creating relation
    if(path != key.name()):
      rel_ref = Relation(owner=path, relation='tags_hierarchical', target=key.name())
      rel_ref = rel_ref.put()
      logging.info("Relation: %s -> %s" % (path, key.name()))

    keys.append(key)
    logging.info("India: %s" % key.name())

  return keys
Exemplo n.º 3
0
def _get_config_values(owner):
  query = Relation.gql('WHERE relation = :1 and owner = :2',
                       'config_values',
                        owner)
  return [value.target for value in query.fetch(100)]