def _get_branches_names(self, req): # Find all branches and yield them repos = self.env.get_repository(req.authname) node = get_existing_node(req, repos, self._branches_path, repos.youngest_rev) undisplayed_branches = self._get_undisplayed_branches() for branch_node in node.get_entries(): branch_name = _get_branch_name(branch_node.path, self._branches_path, self._trunk_path) # Branches are directories under the branches directory if node.isdir and (branch_name not in undisplayed_branches): yield branch_name
def source( req, argument_text, env, aswiki =False): from trac.versioncontrol.web_ui.util import get_existing_node, get_path_rev_line ## XXX above .util is shaded by trac.util? path,rev,line = get_path_rev_line( argument_text) from trac.mimeview import Mimeview, get_mimetype, content_to_unicode repos = env.get_repository() # req.authname) node = get_existing_node( env, repos, path, rev) content = node.get_content().read() if aswiki: mimetype = 'text/x-trac-wiki' r = wiki_to_html( content_to_unicode( env, content, mimetype), env=env, req=req) else: mimetype = get_mimetype( os.path.basename( path) ) or 'text/plain ' mimeview = Mimeview( env) #charset = mimeview.get_charset( content, mimetype) #node.content_type? #content = util.to_utf8( content, charset ) r = mimeview.render( req, mimetype, content) return r, None
def add_catalog(self, req): data = {} errors = [] data['fpath'] = fpath = req.args.get('fpath') data['project_id'] = project_id = req.args.get('project_id') def add_error(error): errors.append(error) data['error'] = tag.ul(*[tag.li(e) for e in errors]) return data if not project_id: return add_error(_("You must first create a project")) if not fpath or fpath == '/': return add_error(_("You must define the catalog path")) repos = self.env.get_repository(req.authname) revision = repos.youngest_rev try: node = get_existing_node(req, repos, fpath, revision) except NoSuchChangeset, e: raise ResourceNotFound(e.message, _('Invalid Changeset Number'))
def add_locale(self, req): data = {} errors = [] catalog_template_id = req.args.get('catalog_template', None) locale = req.args.get('locale') locale_admins = req.args.getlist('admins') def add_error(error): errors.append(error) data['error'] = tag.ul(*[tag.li(e) for e in errors if e]) data['locale'] = locale return data if not catalog_template_id: errors.append(_("You must first create a catalog template")) if not locale: return add_error(_("You must define the new catalog's locale")) if not locale_admins: return add_error(_("You must define at least one locale admin")) Session = session(self.env) catalog = Session.query(Catalog).get(catalog_template_id) num_plurals = get_plural(locale=locale).num_plurals _locale = Session.query(Locale).filter_by(locale=locale, catalog_id=catalog.id).first() if _locale: data['locale'] = _locale return add_error(_("Locale Exists Already")) locale = Locale(catalog, locale, num_plurals) for sid in locale_admins: locale.admins.append(LocaleAdmin(locale, sid)) catalog.locales.append(locale) Session.commit() perm = PermissionSystem(self.env) sids_without_necessary_perms = [] for admin in locale.admins: if not 'L10N_MODERATE' in perm.get_user_permissions(admin.sid): sids_without_necessary_perms.append(admin.sid) if sids_without_necessary_perms: msg = ngettext( "%s does not have the required permissions to administrate." % \ ', '.join(["'%s'" % s for s in sids_without_necessary_perms]), "%s don't have the required permissions to administrate." % \ ', '.join(["'%s'" % s for s in sids_without_necessary_perms]), len(sids_without_necessary_perms)) add_error(tag(msg, _(" Don't forget to "), tag.a(_('update permissions'), href=req.href.admin('general', 'perm')), '.')) add_notice(req, _("Locale added.")) # Are we importing existing data locale_catalog_path = req.args.get('catalog') include_fuzzy = req.args.get('include_fuzzy') == '1' if not locale_catalog_path or locale_catalog_path == '/': return data repos = self.env.get_repository(req.authname) revision = repos.youngest_rev try: node = get_existing_node(req, repos, locale_catalog_path, revision) except NoSuchChangeset, e: raise ResourceNotFound(e.message, _('Invalid Changeset Number'))