Files
website-v2/versions/models.py
Lacey Williams Henschel 7e847cc17f - Move GitHub retrieval and parser classes to the core/ app from the libraries/ app; moved tests, too, and updated import statements
- Add `verbose` flag to `import_versions` to allow user to silence the output
- Removed some unused options from `import_versions`
- Moved the exclusion logic in `import_versions` to its own function
- Stop getting the `github_url` from the github API. Instead, generate it from the tag. (reason: in older tags, the best URL GitHub gives us is a less-useful one to a _commit_ and not a tag. We can generate the url, though.)
- Move the retrieval of the `release_date` to its own task, so it can be loaded async. (reason: it's a separate API call per version to get the date)
- Make `release_date` optional on the `Version` model (reason: make the field easier to load async)
- Simplify logic to retrieve `release_date` and just always retrieve it from the commit
- Stop loading the version `description` from GitHub. We don't use it on the frontend anyway, and in all but the most recent couple of versions, the `description` is the comment from the commit, which is usually not useful.
2023-08-31 15:32:16 -07:00

96 lines
3.1 KiB
Python
Executable File

from django.db import models
from django.utils.functional import cached_property
from django.utils.text import slugify
from .managers import VersionManager, VersionFileManager
class Version(models.Model):
name = models.CharField(
max_length=256, null=False, blank=False, help_text="Version name"
)
slug = models.SlugField(blank=True, null=True)
release_date = models.DateField(auto_now=False, auto_now_add=False, null=True)
description = models.TextField(blank=True)
active = models.BooleanField(
default=True,
help_text="Control whether or not this version is available on the website",
)
github_url = models.URLField(
max_length=500,
blank=True,
null=True,
help_text="The URL of the Boost version's GitHub repository.",
)
data = models.JSONField(default=dict)
objects = VersionManager()
def __str__(self):
return self.name
def save(self, *args, **kwargs):
if not self.slug:
self.slug = self.get_slug()
return super(Version, self).save(*args, **kwargs)
def get_slug(self):
if self.slug:
return self.slug
name = self.name.replace(".", " ")
return slugify(name)[:50]
@cached_property
def display_name(self):
return self.name.replace("boost-", "")
@cached_property
def boost_url_slug(self):
"""Return the slug for the version that is used in the Boost URL to get to
the existing Boost docs. The GitHub slug and the Boost slug don't match, so
this method converts the GitHub slug to the Boost slug.
Example:
- "boost-1.75.0" --> "boost_1_75_0"
- "develop" --> "develop"
"""
return self.slug.replace("-", "_").replace(".", "_")
@cached_property
def boost_release_notes_url(self):
"""Return the URL path to the release notes for this version of Boost on
the existing Boost.org website.
"""
return f"https://www.boost.org/users/history/version_{self.boost_url_slug}.html"
@cached_property
def documentation_url(self):
"""Return the URL path to documentation for this version of Boost.
This maps to the appropriate directory in the S3 bucket. See the
static content config file for the mapping from the site_path to the
S3 path."""
site_path = "/doc/libs/"
slug = self.slug.replace("-", "_").replace(".", "_")
return f"{site_path}{slug}/index.html"
class VersionFile(models.Model):
Unix = "Unix"
Windows = "Windows"
OPERATING_SYSTEM_CHOICES = (
(Unix, "Unix"),
(Windows, "Windows"),
)
version = models.ForeignKey(
Version, related_name="downloads", on_delete=models.CASCADE
)
operating_system = models.CharField(
choices=OPERATING_SYSTEM_CHOICES, max_length=15, default=Unix
)
checksum = models.CharField(max_length=64, unique=True, default=None)
url = models.URLField()
display_name = models.CharField(max_length=256, blank=True, null=True)
objects = VersionFileManager()