def init_tags(): #Top tags #""" tag_ref = ChannelTag(term='Global', taxonomy='tag_country', path='/tag_geo') key_global = tag_ref.put() #Regions regions = ['Africa','Asia','Central America and Caribbean', 'Europe','Middle East and North Africa','North America', 'Oceania','Polar Regions','South America'] regions_keys = build_tags(regions, 'tag_geo', '/tag_geo') #""" """ query = Relation.gql('WHERE owner=:1', '/tag_geo') regions = query.fetch(9999) countries_tags = [] for region in regions: query = Relation.gql('WHERE relation=:1 and owner=:2', 'tags_hierarchical', region.target) countries_tags.extend(query.fetch(9999)) for country in countries_tags: country_ref = Relation(owner='/tag_geo/Global', relation='tags_hierarchical', target=country.target) country_ref.put() query = Relation.gql('WHERE owner=:1 and relation=:2', '/tag_geo/Global', 'tags_hierarchical') countries = query.fetch(9999) #""" util.set_metadata('DEFAULT_TAG', '/tag_geo/Global') util.set_metadata('ROOT_TAG', '/tag_geo') return regions #, countries
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(request): page = 'channel' title = 'Channels Settings' enable_channels = util.get_metadata('ENABLE_CHANNELS') enable_channel_types = util.get_metadata('ENABLE_CHANNEL_TYPES') if request.POST: enable_channels = request.POST.get('enable_channels', False) enable_channel_types = request.POST.get('enable_channel_types', False) try: validate.nonce(request, 'admin_channel') validate.bool_checkbox(enable_channels) validate.bool_checkbox(enable_channel_types) util.set_metadata('ENABLE_CHANNELS', str(enable_channels), 0, {'type':'bool'}) util.set_metadata('ENABLE_CHANNEL_TYPES', str(enable_channel_types), 0, {'type':'bool'}) except exception.ValidationError: exception.handle_exception(request) c = template.RequestContext(request, locals()) return render_to_response('administration/templates/channel.html', c)
def validate_and_save_string(name, value, min=1, max=100, message=""): validate.length(value, min, max, message) return util.set_metadata(name, value)