Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to prod #266

Merged
merged 14 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
Thank you for your contribution to Beslogic's <project_name> repo.
Before submitting this PR, please make sure:
-->

- [ ] The project passes automated tests (build, linting, etc.).
- [ ] You updated the project's documentation with new changes.
- [ ] You've [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) any issue this PR closes
- [ ] You reviewed your own PR and made sure there's no test/debug code or any obvious mistakes.

Make sure that the code wasn't copied from elsewhere (check one):

- [ ] This is your own original code
- [ ] You have made sure that we have permission to use the copied code and that we follow its licensing

_Add a description of your changes, including visual aid and useful links_
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
name: canopeum_backend
name: Backend PR validation

on:
push:
branches:
- main
paths:
- "canopeum_backend/**"
- ".github/workflows/canopeum_backend.yml"
- ".github/workflows/canopeum_backend_pr_validation.yml"
pull_request:
branches:
- main
- production
paths:
- "canopeum_backend/**"
- ".github/workflows/canopeum_backend.yml"
- ".github/workflows/canopeum_backend_pr_validation.yml"

env:
# Since the Django mypy extention RUNS the config file, we need a non-empty secret to avoid
# ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
SECRET_KEY_DJANGO_CANOPEUM: mypy-ext

jobs:
django-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: canopeum_backend
steps:
- uses: actions/checkout@v4
- name: Install uv using the standalone installer
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv sync --locked --extra dev
- run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
- name: Run Django Tests
run: python manage.py test
mypy:
runs-on: ubuntu-latest
defaults:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: canopeum_frontend
name: Frontend PR validation

on:
push:
branches:
- main
paths:
- "canopeum_frontend/**"
- ".github/workflows/canopeum_frontend.yml"
- ".github/workflows/canopeum_frontend_pr_validation.yml"
pull_request:
branches:
- main
- production
paths:
- "canopeum_frontend/**"
- ".github/workflows/canopeum_frontend.yml"
- ".github/workflows/canopeum_frontend_pr_validation.yml"

jobs:
Lint:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# flake8: noqa: S311 -- Accept random int generation for database seeding

import random
from collections.abc import Iterable
from datetime import timedelta
from pathlib import Path

Expand All @@ -17,6 +18,7 @@
Batch,
Batchfertilizer,
BatchSpecies,
BatchSponsor,
Comment,
Contact,
Coordinate,
Expand All @@ -28,13 +30,18 @@
Role,
Site,
Siteadmin,
Sitetreespecies,
Sitetype,
SitetypeInternationalization,
TreespeciestypeInternationalization,
Treetype,
User,
)

seeding_images_path = (
Path(canopeum_backend.settings.BASE_DIR) / "canopeum_backend" / "seeding" / "images"
)

tree_types = [
["Balsam Fir", "Sapin baumier"],
["Black Maple", "Érable noir"],
Expand Down Expand Up @@ -192,74 +199,126 @@ def create_batch_species_for_batch(batch):
"Eight Batch",
]

sponsors = [
"GreenGrow Solutions",
"ArborWorks",
"Evergreen Eco",
"Rooted Reforestation",
"TreeTech Innovations",
"Forest Guardians",
"LeafyLife Planting",
"EcoArbor",
"Sapling Services",
"Birch & Pine Planters",
"Foliage Force",
"Canopy Creations",
"GrowGreen Reforestation",
sponsor_names = [
"Green Earth Initiative",
"EcoRoots Corporation",
"Sustainable Growth Group",
"Forest Futures Fund",
"Green Horizons Alliance",
"Tree of Life Foundation",
"Evergreen Solutions",
"Leaf Legacy Group",
"Planet Guardians Inc.",
"Roots of Tomorrow",
"Nature's Canopy Collective",
"Oxygen for All Co.",
"Verdant Ventures",
"ForestFlow Enterprises",
"Seedling Sustainability Co.",
"Pure Green Partners",
"Branch Out Initiative",
"Nature Nurturers",
"Earthwise Ecosystems",
"Renewed Forest Foundation",
"EcoSphere Solutions",
"TreeMendously Green",
"Reforest Co.",
"Grow Green Initiative",
"Earthshade Sponsors",
"GreenBreathe Fund",
"Flourishing Forest Foundation",
"Sapling Supporters Co.",
"Global Green Guardians",
"Woodland Warriors",
"BranchOut Planting",
"EcoTree Partners",
"Grove Guardians",
"Sustainable Sowers",
"TimberTech Planting",
"Nature's Nurseries",
"GreenThumb Reforestation",
"Forest Frontiers",
"Arbor Alliance",
"TreeTrek Planters",
"RootRise Reforestation",
"LeafLegacy Planting",
"EcoRoot Reforestation",
"TrunkTrack Planters",
"WoodWise Reforestation",
"Boreal Bloom Planters",
"Sprout Sponsors",
"Evergreen Tomorrow Foundation",
"Roots & Shoots Initiative",
"TreeTop Trust",
"LeafLife Partners",
"The Canopy Collective",
"EcoLeaf Sponsorship",
"Pure Planet Patrons",
"Oxygen Origins Fund",
"The GreenWay Project",
"TreeTrail Trust",
"ThriveGreen Group",
"ForestFront Alliance",
"ReTree Sponsors",
"EcoPledge Foundation",
"Verdant Visions Fund",
"BranchRoots Collective",
"PlanetGreen Partnerships",
"SustainSeed Co.",
"NatureSprout Network",
"GreenFuture Trust",
"TreeLife Alliance",
]


def get_sponsors():
number_of_sponsors = random.randint(1, 5)
random.shuffle(sponsors)
return sponsors[:number_of_sponsors]
def create_sponsor_for_batch():
image_file_name = f"batch_logo{random.randint(1, 7)}.png"

with Path.open(seeding_images_path / image_file_name, "rb") as img_file:
django_file = File(img_file)

def get_sponsor():
index = random.randint(0, len(sponsors) - 1)
return sponsors[index]
asset = Asset()
asset.asset.save(image_file_name, django_file, save=True)

return BatchSponsor.objects.create(
name=sponsor_names.pop(random.randint(0, len(sponsor_names) - 1)),
url="https://uilogos.co/",
logo=asset,
)


def create_species_for_site(site: Site, batches: Iterable[Batch]):
already_added_tree_type: dict[int, Sitetreespecies] = {}
for batch in batches:
for batch_specie in BatchSpecies.objects.filter(batch=batch):
quantity = batch_specie.quantity
# Add more to the site's quantity than the batches' quantity
# so they don't appear at 100%. Except Canopeum, let's use it as a 100% example
if site.name != "Canopeum":
quantity += random.randint(0, 50)
if batch_specie.tree_type.pk in already_added_tree_type:
site_tree_specie = already_added_tree_type[batch_specie.tree_type.pk]
site_tree_specie.quantity += quantity
site_tree_specie.save()
else:
site_tree_specie = Sitetreespecies.objects.create(
site=site, tree_type=batch_specie.tree_type, quantity=quantity
)
already_added_tree_type[batch_specie.tree_type.pk] = site_tree_specie


def create_batches_for_site(site):
num_batches = random.randint(3, 8)
for i in range(num_batches):
number_of_seed = random.randint(50, 200)
plant_count = random.randint(0, number_of_seed)
survived_count = random.randint(0, plant_count)
survived_count = random.randint(100, 200)
replace_count = random.randint(0, 50)

sponsor = create_sponsor_for_batch()

batch = Batch.objects.create(
name=batch_names[i - 1],
site=site,
size=random.randint(20, 150),
sponsor=get_sponsor(),
sponsor=sponsor,
soil_condition="Good",
plant_count=plant_count,
survived_count=survived_count,
replace_count=plant_count - survived_count,
replace_count=replace_count,
total_number_seed=number_of_seed,
total_propagation=random.randint(0, number_of_seed),
)
create_batch_species_for_batch(batch)
Batchfertilizer.objects.create(
batch=batch,
fertilizer_type=Fertilizertype.objects.first(),
)
fertilizer_type = Fertilizertype.objects.first()
if fertilizer_type is not None:
Batchfertilizer.objects.create(
batch=batch,
fertilizer_type=fertilizer_type,
)
yield batch


class Command(BaseCommand):
Expand Down Expand Up @@ -315,8 +374,7 @@ def handle(self, *args, **kwargs):
self.create_roles()
self.create_users()

self.create_canopeum_site()
self.create_other_sites()
self.create_sites()

self.create_siteadmins()
self.stdout.write(self.style.SUCCESS("Data Generated"))
Expand Down Expand Up @@ -382,9 +440,6 @@ def create_site_types(self):
)

def create_assets(self):
seeding_images_path = (
Path(canopeum_backend.settings.BASE_DIR) / "canopeum_backend" / "seeding" / "images"
)
image_file_names = (
"site_img1.png",
"site_img2.jpg",
Expand Down Expand Up @@ -445,8 +500,9 @@ def create_users(self):
role=Role.objects.get(name="User"),
)

def create_canopeum_site(self):
site = Site.objects.create(
def create_sites(self):
# Canopeum's site
site1 = Site.objects.create(
name="Canopeum",
is_public=True,
site_type=Sitetype.objects.get(
Expand All @@ -466,7 +522,7 @@ def create_canopeum_site(self):
visitor_count=100,
contact=Contact.objects.create(
email="[email protected]",
phone="+1 (514) 741-5008",
phone="+1 514 741-5008",
address="721 Walker avenue, Office 200 Montréal, QC H4C 2H5",
),
image=Asset.objects.first(),
Expand All @@ -477,15 +533,16 @@ def create_canopeum_site(self):
link="https://www.canopeum-pos.com",
),
)
create_batches_for_site(site)
batches = create_batches_for_site(site1)
create_species_for_site(site1, batches)
post = Post.objects.create(
site=site,
site=site1,
body="The season is officially started; "
+ "new plants are starting to grow and our volunteers are very dedicated!",
share_count=5,
)
post.media.add(*Asset.objects.filter(asset__contains="canopeum_post_img"))
create_posts_for_site(site)
create_posts_for_site(site1)
Comment.objects.create(
body="Wow, I'm very excited to join the team!",
user=User.objects.get(email="[email protected]"),
Expand All @@ -496,8 +553,8 @@ def create_canopeum_site(self):
user=User.objects.get(email="[email protected]"),
post=post,
)
# end of Canopeum's site

def create_other_sites(self):
site_2 = Site.objects.create(
name="Maple Grove Retreat",
is_public=True,
Expand Down Expand Up @@ -530,7 +587,8 @@ def create_other_sites(self):
link="https://www.maplegroveretreat.com/events/maple-syrup-festival",
),
)
create_batches_for_site(site_2)
batches = create_batches_for_site(site_2)
create_species_for_site(site_2, batches)
create_posts_for_site(site_2)

site_3 = Site.objects.create(
Expand Down Expand Up @@ -566,7 +624,8 @@ def create_other_sites(self):
link="https://www.lakesideoasis.com/winter-getaway",
),
)
create_batches_for_site(site_3)
batches = create_batches_for_site(site_3)
create_species_for_site(site_3, batches)
create_posts_for_site(site_3)

site_4 = Site.objects.create(
Expand Down Expand Up @@ -602,7 +661,8 @@ def create_other_sites(self):
link="https://www.evergreentrail.com/guided-walks",
),
)
create_batches_for_site(site_4)
batches = create_batches_for_site(site_4)
create_species_for_site(site_4, batches)
create_posts_for_site(site_4)

def create_siteadmins(self):
Expand Down
Empty file.
Loading
Loading