def save(self, *args, **kwargs): if not self.slug: # Subdomains can't have underscores in them. self.slug = slugify(self.name).replace('_', '-') if self.slug == '': raise Exception(_("Model must have slug")) super(Project, self).save(*args, **kwargs) for owner in self.users.all(): assign('view_project', owner, self) # Add exceptions here for safety try: self.sync_supported_versions() except Exception: log.error('failed to sync supported versions', exc_info=True) try: symlink(project=self.slug) except Exception: log.error('failed to symlink project', exc_info=True) try: update_static_metadata(project_pk=self.pk) except Exception: log.error('failed to update static metadata', exc_info=True) try: branch = self.default_branch or self.vcs_repo().fallback_branch if not self.versions.filter(slug='latest').exists(): self.versions.create(slug='latest', verbose_name='latest', machine=True, type='branch', active=True, identifier=branch) # if not self.versions.filter(slug='stable').exists(): # self.versions.create(slug='stable', verbose_name='stable', type='branch', active=True, identifier=branch) except Exception: log.error('Error creating default branches', exc_info=True)
def handle(self, *args, **options): if len(args): if args[0] == "cnames": log.info("Updating all CNAME Symlinks") redis_conn = redis.Redis(**settings.REDIS) slugs = redis_conn.keys('rtd_slug:v1:*') slugs = [slug.replace("rtd_slug:v1:", "") for slug in slugs] for slug in slugs: try: log.info("Got slug from redis: %s" % slug) utils.symlink(project=slug) except Exception, e: print e else: for slug in args: utils.symlink(project=slug)
def handle(self, *args, **options): if len(args): if args[0] == "cnames": log.info("Updating all CNAME Symlinks") redis_conn = redis.Redis(**settings.REDIS) slugs = redis_conn.keys('rtd_slug:v1:*') slugs = [slug.replace("rtd_slug:v1:", "") for slug in slugs] for slug in slugs: try: log.info("Got slug from redis: %s" % slug) utils.symlink(project=slug) except Exception, e: print e else: for slug in args: utils.symlink(project=slug)
def save(self, *args, **kwargs): first_save = self.pk is None if not self.slug: # Subdomains can't have underscores in them. self.slug = slugify(self.name).replace('_', '-') if self.slug == '': raise Exception(_("Model must have slug")) super(Project, self).save(*args, **kwargs) for owner in self.users.all(): assign('view_project', owner, self) try: if self.default_branch: latest = self.versions.get(slug='latest') if latest.identifier != self.default_branch: latest.identifier = self.default_branch latest.save() except Exception: log.error('Failed to update latest identifier', exc_info=True) # Add exceptions here for safety try: self.sync_supported_versions() except Exception: log.error('failed to sync supported versions', exc_info=True) try: if not first_save: symlink(project=self.slug) except Exception: log.error('failed to symlink project', exc_info=True) try: update_static_metadata(project_pk=self.pk) except Exception: log.error('failed to update static metadata', exc_info=True) try: branch = self.default_branch or self.vcs_repo().fallback_branch if not self.versions.filter(slug='latest').exists(): self.versions.create(slug='latest', verbose_name='latest', machine=True, type='branch', active=True, identifier=branch) # if not self.versions.filter(slug='stable').exists(): # self.versions.create(slug='stable', verbose_name='stable', type='branch', active=True, identifier=branch) except Exception: log.error('Error creating default branches', exc_info=True)
def save(self, *args, **kwargs): first_save = self.pk is None if not self.slug: # Subdomains can't have underscores in them. self.slug = slugify(self.name).replace("_", "-") if self.slug == "": raise Exception(_("Model must have slug")) super(Project, self).save(*args, **kwargs) for owner in self.users.all(): assign("view_project", owner, self) try: if self.default_branch: latest = self.versions.get(slug=LATEST) if latest.identifier != self.default_branch: latest.identifier = self.default_branch latest.save() except Exception: log.error("Failed to update latest identifier", exc_info=True) # Add exceptions here for safety try: self.sync_supported_versions() except Exception: log.error("failed to sync supported versions", exc_info=True) try: if not first_save: symlink(project=self.slug) except Exception: log.error("failed to symlink project", exc_info=True) try: update_static_metadata(project_pk=self.pk) except Exception: log.error("failed to update static metadata", exc_info=True) try: branch = self.default_branch or self.vcs_repo().fallback_branch if not self.versions.filter(slug=LATEST).exists(): self.versions.create_latest(identifier=branch) # if not self.versions.filter(slug=STABLE).exists(): # self.versions.create_stable(type='branch', identifier=branch) except Exception: log.error("Error creating default branches", exc_info=True)
class Project(models.Model): #Auto fields pub_date = models.DateTimeField(_('Publication date'), auto_now_add=True) modified_date = models.DateTimeField(_('Modified date'), auto_now=True) #Generally from conf.py users = models.ManyToManyField(User, verbose_name=_('User'), related_name='projects') name = models.CharField(_('Name'), max_length=255) slug = models.SlugField(_('Slug'), max_length=255, unique=True) description = models.TextField(_('Description'), blank=True, help_text=_('The reStructuredText ' 'description of the project')) repo = models.CharField(_('Repository URL'), max_length=100, blank=True, help_text=_('Checkout URL for your code (hg, git, ' 'etc.). Ex. http://github.com/' 'ericholscher/django-kong.git')) repo_type = models.CharField(_('Repository type'), max_length=10, choices=constants.REPO_CHOICES, default='git') project_url = models.URLField(_('Project URL'), blank=True, help_text=_('The project\'s homepage'), verify_exists=False) canonical_url = models.URLField( _('Canonical URL'), blank=True, help_text= _('The official URL that the docs live at. This can be at readthedocs.org, or somewhere else. Ex. http://docs.fabfile.org' ), verify_exists=False) version = models.CharField(_('Version'), max_length=100, blank=True, help_text=_('Project version these docs apply ' 'to, i.e. 1.0a')) copyright = models.CharField(_('Copyright'), max_length=255, blank=True, help_text=_('Project copyright information')) theme = models.CharField( _('Theme'), max_length=20, choices=constants.DEFAULT_THEME_CHOICES, default=constants.THEME_DEFAULT, help_text=(u'<a href="http://sphinx.pocoo.org/theming.html#builtin-' 'themes" target="_blank">%s</a>') % _('Examples')) suffix = models.CharField(_('Suffix'), max_length=10, editable=False, default='.rst') single_version = models.BooleanField( _('Single version'), default=False, help_text= _('A single version site has no translations and only your "latest" version, served at the root of the domain. Use this with caution, only turn it on if you will <b>never</b> have multiple versions of your docs.' )) default_version = models.CharField( _('Default version'), max_length=255, default='latest', help_text=_('The version of your project that / redirects to')) # In default_branch, None max_lengtheans the backend should choose the # appropraite branch. Eg 'master' for git default_branch = models.CharField( _('Default branch'), max_length=255, default=None, null=True, blank=True, help_text=_('What branch "latest" points to. Leave empty ' 'to use the default value for your VCS (eg. ' 'trunk or master).')) requirements_file = models.CharField( _('Requirements file'), max_length=255, default=None, null=True, blank=True, help_text=_( 'Requires Virtualenv. A <a ' 'href="http://www.pip-installer.org/en/latest/cookbook.html#requirements-files">' 'pip requirements file</a> needed to build your documentation. ' 'Path from the root of your project.')) documentation_type = models.CharField( _('Documentation type'), max_length=20, choices=constants.DOCUMENTATION_CHOICES, default='sphinx', help_text=_('Type of documentation you are building. <a href="http://' 'sphinx.pocoo.org/builders.html#sphinx.builders.html.' 'DirectoryHTMLBuilder">More info</a>.')) analytics_code = models.CharField( _('Analytics code'), max_length=50, null=True, blank=True, help_text=_("Google Analytics Tracking ID (ex. UA-22345342-1). " "This may slow down your page loads.")) # Other model data. path = models.CharField(_('Path'), max_length=255, editable=False, help_text=_("The directory where conf.py lives")) conf_py_file = models.CharField( _('Python configuration file'), max_length=255, default='', blank=True, help_text=_('Path from project root to conf.py file (ex. docs/conf.py)' '. Leave blank if you want us to find it for you.')) featured = models.BooleanField(_('Featured')) skip = models.BooleanField(_('Skip')) mirror = models.BooleanField(_('Mirror'), default=False) use_virtualenv = models.BooleanField( _('Use virtualenv'), help_text=_("Install your project inside a virtualenv using setup.py " "install")) # This model attribute holds the python interpreter used to create the # virtual environment python_interpreter = models.CharField( _('Python Interpreter'), max_length=20, choices=constants.PYTHON_CHOICES, default='python', help_text=_("(Beta) The Python interpreter used to create the virtual " "environment.")) use_system_packages = models.BooleanField( _('Use system packages'), help_text=_("Give the virtual environment access to the global " "site-packages dir.")) django_packages_url = models.CharField(_('Django Packages URL'), max_length=255, blank=True) privacy_level = models.CharField( _('Privacy Level'), max_length=20, choices=constants.PRIVACY_CHOICES, default='public', help_text=_("(Beta) Level of privacy that you want on the repository. " "Protected means public but not in listings.")) version_privacy_level = models.CharField( _('Version Privacy Level'), max_length=20, choices=constants.PRIVACY_CHOICES, default='public', help_text=_("(Beta) Default level of privacy you want on built " "versions of documentation.")) # Subprojects related_projects = models.ManyToManyField( 'self', verbose_name=_('Related projects'), blank=True, null=True, symmetrical=False, through=ProjectRelationship) # Language bits language = models.CharField('Language', max_length=20, default='en', help_text="The language the project " "documentation is rendered in. " "Note: this affects your project's URL.", choices=constants.LANGUAGES) # A subproject pointed at it's main language, so it can be tracked main_language_project = models.ForeignKey('self', related_name='translations', blank=True, null=True) # Version State num_major = models.IntegerField( _('Number of Major versions'), max_length=3, default=2, null=True, blank=True, help_text=_("2 means supporting 3.X.X and 2.X.X, but not 1.X.X")) num_minor = models.IntegerField( _('Number of Minor versions'), max_length=3, default=2, null=True, blank=True, help_text=_("2 means supporting 2.2.X and 2.1.X, but not 2.0.X")) num_point = models.IntegerField( _('Number of Point versions'), max_length=3, default=2, null=True, blank=True, help_text=_("2 means supporting 2.2.2 and 2.2.1, but not 2.2.0")) tags = TaggableManager(blank=True) objects = ProjectManager() class Meta: ordering = ('slug', ) permissions = ( # Translators: Permission around whether a user can view the # project ('view_project', _('View Project')), ) def __unicode__(self): return self.name @property def subdomain(self): prod_domain = getattr(settings, 'PRODUCTION_DOMAIN') if self.canonical_domain: return self.canonical_domain else: subdomain_slug = self.slug.replace('_', '-') return "%s.%s" % (subdomain_slug, prod_domain) def sync_supported_versions(self): supported = self.supported_versions(flat=True) if supported: self.versions.filter(verbose_name__in=supported).update( supported=True) self.versions.exclude(verbose_name__in=supported).update( supported=False) self.versions.filter(verbose_name='latest').update(supported=True) def save(self, *args, **kwargs): if not self.slug: # Subdomains can't have underscores in them. self.slug = slugify(self.name).replace('_', '-') if self.slug == '': raise Exception(_("Model must have slug")) obj = super(Project, self).save(*args, **kwargs) for owner in self.users.all(): assign('view_project', owner, self) # Add exceptions here for safety try: self.sync_supported_versions() except Exception, e: log.error('failed to sync supported versions', exc_info=True) try: symlink(project=self.slug) except Exception, e: log.error('failed to symlink project', exc_info=True)