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

feat: Add new fields to create & update api's #250

Merged
merged 10 commits into from
Oct 21, 2024
163 changes: 163 additions & 0 deletions products.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
Products:
- name: "Ubuntu Frame"
slug: "ubuntu-frame"
- name: "Support"
slug: "support"
- name: "ESM"
slug: "esm"
- name: "MicroCloud"
slug: "microcloud"
- name: "Cube"
slug: "cube"
- name: "Managed Apps"
slug: "managed-apps"
- name: "Ubuntu Core / Snapd"
slug: "ubuntu-core-snapd"
- name: "Ubuntu Pro"
petesfrench marked this conversation as resolved.
Show resolved Hide resolved
slug: "ubuntu-pro"
- name: "Snapcraft"
slug: "snapcraft"
- name: "Security"
slug: "security"
- name: "Edge"
slug: "edge"
- name: "Launchpad"
slug: "launchpad"
- name: "Industrial"
slug: "industrial"
- name: "Security - Tech"
slug: "security-tech"
- name: "Security Notices"
slug: "security-notices"
- name: "Smart Displays (Mir)"
slug: "smart-displays-mir"
- name: "Multipass"
slug: "multipass"
- name: "Data - Big Data"
slug: "data-big-data"
- name: "Charm Collection"
slug: "charm-collection"
- name: "Smart Home"
slug: "smart-home"
- name: "Embedding"
slug: "embedding"
- name: "Charmed Openstack"
slug: "charmed-openstack"
- name: "Observability"
slug: "observability"
- name: "FIPS"
slug: "fips"
- name: "Canonical Openstack"
slug: "canonical-openstack"
- name: "Canonical K8s"
slug: "canonical-k8s"
- name: "Identity"
slug: "identity"
- name: "Finance"
slug: "finance"
- name: "Real-Time Kernel"
slug: "real-time-kernel"
- name: "Blender"
slug: "blender"
- name: "Robotics"
slug: "robotics"
- name: "Kernel Factory"
slug: "kernel-factory"
- name: "WSL"
slug: "wsl"
- name: "Managed Infra"
slug: "managed-infra"
- name: "Microstack"
slug: "microstack"
- name: "Appliance Portfolio"
slug: "appliance-portfolio"
- name: "Ubuntu Pro"
slug: "ubuntu-pro"
- name: "Networking"
slug: "networking"
- name: "Juju"
slug: "juju"
- name: "Snap Store"
slug: "snap-store"
- name: "Public Cloud"
slug: "public-cloud"
- name: "Charmed K8s"
slug: "charmed-k8s"
- name: "Store"
slug: "store"
- name: "Microcloud/LXD"
slug: "microcloud-lxd"
- name: "Rocks"
slug: "rocks"
- name: "AI/ML"
slug: "ai-ml"
- name: "Pro for devices"
slug: "pro-for-devices"
- name: "Charm Hub"
slug: "charm-hub"
- name: "Kernel"
slug: "kernel"
- name: "Anbox"
slug: "anbox"
- name: "Juggle"
slug: "juggle"
- name: "Microk8s"
slug: "microk8s"
- name: "Desktop"
slug: "desktop"
- name: "Embedded"
slug: "embedded"
- name: "HPC"
slug: "hpc"
- name: "Data - SQL"
slug: "data-sql"
- name: "Livepatch"
slug: "livepatch"
- name: "GSI"
slug: "gsi"
- name: "Landscape"
slug: "landscape"
- name: "Telco"
slug: "telco"
- name: "Jaas"
slug: "jaas"
- name: "Automotive"
slug: "automotive"
- name: "Robotics Developers"
slug: "robotics-developers"
- name: "MAAS"
slug: "maas"
- name: "EdgeX"
slug: "edgex"
- name: "Kubeflow / AI"
slug: "kubeflow-ai"
- name: "Data Platform"
slug: "data-platform"
- name: "AKS/EKS/GKE"
slug: "aks-eks-gke"
- name: "Ubuntu Core / Snapd Ux"
slug: "ubuntu-core-snapd-ux"
- name: "Ubuntu Core / Snapd Docs"
slug: "ubuntu-core-snapd-docs"
- name: "Hardening"
slug: "hardening"
- name: "Kernos"
slug: "kernos"
- name: "Ceph"
slug: "ceph"
- name: "Server"
slug: "server"
- name: "UA-A (Adv/Std/Ess)"
slug: "ua-a-adv-std-ess"
- name: "Data - NoSQL"
slug: "data-nosql"
- name: "IOT Management"
slug: "iot-management"
- name: "HW Certification"
slug: "hw-certification"
- name: "Raspberrypi"
slug: "raspberrypi"
- name: "Other"
slug: "other"
- name: "LXD"
slug: "lxd"
2 changes: 1 addition & 1 deletion webapp/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AssetSearchParams:
name: str = ""
start_date: str = None
end_date: str = None
sf_campg_id: str = ""
salesforce_campaign_id: str = ""
language: str = ""

def __post_init__(self):
Expand Down
19 changes: 19 additions & 0 deletions webapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,26 @@ def as_json(self):
"created": self.created.strftime("%a, %d %b %Y %H:%M:%S"),
"file_path": self.file_path,
"tags": ", ".join([tag.name for tag in self.tags]),
"products": ", ".join([product.name for product in self.products]),
"deprecated": self.deprecated,
"asset_type": self.asset_type,
"name": self.name,
"author": (
{
"first_name": (
self.author.first_name if self.author else None
),
"last_name": (
self.author.last_name if self.author else None
),
"email": self.author.email if self.author else None,
}
if self.author
else None
petesfrench marked this conversation as resolved.
Show resolved Hide resolved
),
"google_drive_link": self.google_drive_link,
"salesforce_campaign_id": self.salesforce_campaign_id,
"language": self.language,
}


Expand Down
4 changes: 3 additions & 1 deletion webapp/param_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def parse_asset_search_params() -> AssetSearchParams:
name=request.args.get("name", "").strip(),
start_date=request.args.get("start_date", None),
end_date=request.args.get("end_date", None),
sf_campg_id=request.args.get("sf_campg_id", "").strip(),
salesforce_campaign_id=request.args.get(
"salesforce_campaign_id", ""
).strip(),
language=request.args.get("language", "").strip(),
)
57 changes: 52 additions & 5 deletions webapp/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def home():
search_params.name,
search_params.start_date,
search_params.end_date,
search_params.sf_campg_id,
search_params.salesforce_campaign_id,
search_params.language,
]
):
Expand All @@ -68,7 +68,7 @@ def home():
name=search_params.name,
start_date=search_params.start_date,
end_date=search_params.end_date,
sf_campg_id=search_params.sf_campg_id,
salesforce_campaign_id=search_params.salesforce_campaign_id,
language=search_params.language,
)
else:
Expand All @@ -92,8 +92,26 @@ def create():
if flask.request.method == "POST":
petesfrench marked this conversation as resolved.
Show resolved Hide resolved
tags = flask.request.form.get("tags", "")
tags = re.split(",|\\s", tags)

products = flask.request.form.get("products", "")
products = re.split(",|\\s", products)
google_drive_link = flask.request.form.get("google_drive_link", "")
salesforce_campaign_id = flask.request.form.get(
"salesforce_campaign_id", ""
)
language = flask.request.form.get("language", "")
deprecated = (
flask.request.form.get("deprecated", "false").lower() == "true"
)
optimize = flask.request.form.get("optimize", True)
asset_type = flask.request.form.get("asset_type", "")
author_email = flask.request.form.get("author_email", "")
author_first_name = flask.request.form.get("author_first_name", "")
author_last_name = flask.request.form.get("author_last_name", "")
author = {
"email": author_email,
"first_name": author_first_name,
"last_name": author_last_name,
}

for asset_file in flask.request.files.getlist("assets"):
try:
Expand All @@ -105,6 +123,13 @@ def create():
friendly_name=name,
optimize=optimize,
tags=tags,
products=products,
asset_type=asset_type,
author=author,
google_drive_link=google_drive_link,
salesforce_campaign_id=salesforce_campaign_id,
language=language,
deprecated=deprecated,
)

created_assets.append(asset)
Expand Down Expand Up @@ -137,11 +162,33 @@ def update():
flask.flash("Asset not found", "negative")

elif request.method == "POST":
tags = request.form.get("tags")
tags = request.form.get("tags").split(",")
products = request.form.get("products", "").split(",")
deprecated = strtobool(request.form.get("deprecated", "false"))
asset_type = request.form.get("asset_type", "")
google_drive_link = request.form.get("google_drive_link", "")
salesforce_campaign_id = request.form.get("salesforce_campaign_id", "")
language = request.form.get("language", "")
author_email = flask.request.form.get("author_email", "")
author_first_name = flask.request.form.get("author_first_name", "")
author_last_name = flask.request.form.get("author_last_name", "")
author = {
"email": author_email,
"first_name": author_first_name,
"last_name": author_last_name,
}

try:
asset = asset_service.update_asset(
file_path, tags=tags.split(","), deprecated=deprecated
file_path=file_path,
tags=tags,
deprecated=deprecated,
products=products,
asset_type=asset_type,
author=author,
google_drive_link=google_drive_link,
salesforce_campaign_id=salesforce_campaign_id,
language=language,
)
flask.flash("Asset updated", "positive")
except AssetNotFound:
Expand Down
Loading
Loading