Skip to content

Commit

Permalink
feat: add monthly shared hosting packages
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Feb 10, 2025
1 parent 81c0ad1 commit 4519d46
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
34 changes: 25 additions & 9 deletions weblate_web/management/commands/sync_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
DEDICATED_LIMIT,
DEDICATED_PREFIX,
HOSTED_PREFIX,
MONTHLY_SUFFIX,
PACKAGE_NAMES,
PACKAGES,
)
Expand Down Expand Up @@ -57,18 +58,33 @@ def get_packages(self) -> Generator[tuple[PackageCategory, str, str, int, int]]:
limit,
price,
)
yield (
PackageCategory.PACKAGE_SHARED,
f"Weblate hosting ({name} strings, monthly)",
f"{HOSTED_PREFIX}{name.lower()}{MONTHLY_SUFFIX}",
limit,
price // 10,
)

def handle(self, *args, **options) -> None:
for category, verbose, name, limit, price in self.get_packages():
package, created = Package.objects.get_or_create(
limit_hosted_strings=limit,
category=category,
defaults={
"verbose": verbose,
"name": name,
"price": price,
},
)
created = False
try:
package = Package.objects.get(name=name)
except Package.DoesNotExist:
if name.endswith(MONTHLY_SUFFIX):
packages = Package.objects.filter(name__endswith=MONTHLY_SUFFIX)
else:
packages = Package.objects.exclude(name__endswith=MONTHLY_SUFFIX)
package, created = packages.get_or_create(
limit_hosted_strings=limit,
category=category,
defaults={
"verbose": verbose,
"name": name,
"price": price,
},
)
if created:
self.stdout.write(f"Created {verbose}")
else:
Expand Down
1 change: 1 addition & 0 deletions weblate_web/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DEDICATED_LIMIT = 160000
DEDICATED_PREFIX = "dedicated:"
HOSTED_PREFIX = "hosted:"
MONTHLY_SUFFIX = "-m"


def package_name(number: int) -> str:
Expand Down

0 comments on commit 4519d46

Please sign in to comment.