Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 12 additions & 12 deletions src/lsst/cmservice/web_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
from sqlalchemy.ext.asyncio import async_scoped_session
from starlette.exceptions import HTTPException as StarletteHTTPException

from lsst.cmservice import db
from lsst.cmservice.common.enums import LevelEnum
from lsst.cmservice.config import config
from lsst.cmservice.web_app.pages.campaigns import get_campaign_details, search_campaigns
from lsst.cmservice.web_app.pages.campaigns import get_all_campaigns, get_campaign_details, search_campaigns
from lsst.cmservice.web_app.pages.group_details import get_group_by_id
from lsst.cmservice.web_app.pages.job_details import get_job_by_id
from lsst.cmservice.web_app.pages.script_details import get_script_by_id
Expand Down Expand Up @@ -96,16 +95,15 @@ async def get_campaigns(
) -> HTMLResponse:
try:
async with session.begin():
production_list = {}
productions = await db.Production.get_rows(session)
for p in productions:
children = await p.children(session)
production_campaigns = []
for c in children:
campaign_details = await get_campaign_details(session, c)
production_campaigns.append(campaign_details)
production_list[p.name] = production_campaigns

production_list: dict[str, list] = {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this a collections.defaultdict would avoid the need for an if-statement later.

campaigns = await get_all_campaigns(session)
for campaign in campaigns:
production_name = campaign.fullname.split("/")[0]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think production_name will eventually become part of the campaign object, so moving this string-parsing into get_campaign_details would make it easier to adjust in the future.

campaign_details = await get_campaign_details(session, campaign)
if production_name in production_list:
production_list[production_name].append(campaign_details)
else:
production_list[production_name] = [campaign_details]
return templates.TemplateResponse(
name="pages/campaigns.html",
request=request,
Expand All @@ -124,11 +122,13 @@ async def error_page(
request: Request,
error_code: int,
) -> HTMLResponse:
referer = request.headers.get("referer")
response = templates.TemplateResponse(
name="pages/error.html",
request=request,
context={
"error_code": error_code,
"referer": referer if referer is not None else request.url_for("get_campaigns"),
},
)
return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</svg>
</div>
<input name="search_term" id="search" class="block bg-teal-50 border-0 py-1.5 pl-10 text-teal-600 ring-1 ring-inset ring-teal-600 placeholder:text-teal-500 sm:text-sm sm:leading-6" placeholder="Search Campaigns">
<span class="pl-3 uppercase text-teal-600 text-sm leading-8 font-mono drop-shadow-xl">+ new production</span>
</div>
</form>
<h1 class="text-sm font-bold leading-tight tracking-tight text-gray-400 pb-3 font-mono uppercase pt-8">Search results for: <span class="italic underline">{{search_term}}</span></h1>
Expand Down
2 changes: 1 addition & 1 deletion src/lsst/cmservice/web_app/templates/pages/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
{% block content %}
<div class="w-full px-4" id="error-eman">
<div class="text-2xl font-bold"> Something Went Wrong </div>
<a href="{{request.headers.get('referer')}}" class="text-teal-600 underline-offset-4"> Go Back </a>
<a href="{{ referer }}" class="text-teal-600 underline-offset-4"> Go Back </a>
</div>
{% endblock %}
11 changes: 1 addition & 10 deletions tests/web_app/test_campaigns_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from lsst.cmservice import db
from lsst.cmservice.common.enums import StatusEnum
from lsst.cmservice.db import Campaign, Production
from lsst.cmservice.db import Campaign
from lsst.cmservice.web_app.pages.campaigns import get_campaign_details


Expand All @@ -17,14 +17,6 @@ def mock_session() -> typing.Generator:
yield Mock()


@pytest.fixture()
def first_production() -> Production:
return Production(
id=1,
name="first_production",
)


@pytest.fixture()
def mock_collections() -> dict:
return {
Expand Down Expand Up @@ -53,7 +45,6 @@ def first_campaign(
campaign = Campaign(
id=1,
name="first_campaign",
parent_id=1,
fullname="first_production/first_campaign",
spec_id=1,
spec_block_id=1,
Expand Down