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
def install(request): try: root_user = api.actor_get(api.ROOT, settings.ROOT_NICK) if root_user: return util.RedirectFlash('/', 'Already Installed') except: root_user = None post_name = util.get_metadata('POST_NAME') default_channel = util.get_metadata('DEFAULT_CHANNEL') if request.POST: site_name = request.POST.get('site_name', None) tagline = request.POST.get('tagline', None) post_name = request.POST.get('post_name', None) root_mail = request.POST.get('root_mail', None) password = request.POST.get('password', None) confirm = request.POST.get('confirm', None) default_channel = request.POST.get('default_channel', None) try: logging.info('saving values') validate.nonce(request, 'install') validate.email(root_mail) validate.password(password) validate.password_and_confirm(password, confirm) channel = clean.channel(default_channel) admin_helper.validate_and_save_sitesettings(site_name, tagline, post_name) root_user = api.user_create_root(api.ROOT, password=password) api.email_associate(api.ROOT, root_user.nick, root_mail) channel_ref = api.channel_create(api.ROOT, nick=api.ROOT.nick, channel=channel, tags=[], type='', description='Support Channel') util.set_metadata('DEFAULT_CHANNEL', default_channel) logging.info('Installed and Redirecting to front') return util.RedirectFlash('/', 'Installed Successfully') except: exception.handle_exception(request) redirect_to = '/' c = template.RequestContext(request, locals()) return render_to_response('administration/templates/install.html', c)
def admin_channel_new(request): page = 'channel_new' title = 'Create a Channel' if request.method == 'POST': params = { 'nick': api.ROOT.nick, 'channel': request.POST.get('channel'), 'description': request.POST.get('description', ''), 'type':request.POST.get('type'), 'tags': request.POST.getlist('tags[]'), } channel_ref = api.channel_create(api.ROOT, **params) if channel_ref is not None: logging.info('Channel created %s' % channel_ref) return util.RedirectFlash('/admin/channels', "Channel created successfully") group_menuitem = 'channel' menuitem = 'channel-new' channel_types = api.get_config_values(api.ROOT, 'channel_type') c = template.RequestContext(request, locals()) return render_to_response('administration/templates/channel_new.html', c)