|
| 1 | +# Copyright (c) nexB Inc. and others. All rights reserved. |
| 2 | +# http://nexb.com and https://github.com/nexB/vulnerablecode/ |
| 3 | +# The VulnerableCode software is licensed under the Apache License version 2.0. |
| 4 | +# Data generated with VulnerableCode require an acknowledgment. |
| 5 | +# |
| 6 | +# You may not use this software except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 9 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 10 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | +# specific language governing permissions and limitations under the License. |
| 12 | +# |
| 13 | +# When you publish or redistribute any data created with VulnerableCode or any VulnerableCode |
| 14 | +# derivative work, you must accompany this data with the following acknowledgment: |
| 15 | +# |
| 16 | +# Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 17 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 18 | +# VulnerableCode should be considered or used as legal advice. Consult an Attorney |
| 19 | +# for any legal advice. |
| 20 | +# VulnerableCode is a free software tool from nexB Inc. and others. |
| 21 | +# Visit https://github.com/nexB/vulnerablecode/ for support and download. |
| 22 | + |
| 23 | +from django import forms |
| 24 | + |
| 25 | +from vulnerabilities.models import Package, PackageRelatedVulnerability, Vulnerability |
| 26 | + |
| 27 | + |
| 28 | +def get_package_types(): |
| 29 | + pkg_types = [(i.type, i.type) for i in Package.objects.distinct("type").all()] |
| 30 | + pkg_types.append((None, "package type")) |
| 31 | + return pkg_types |
| 32 | + |
| 33 | + |
| 34 | +def get_package_namespaces(): |
| 35 | + pkg_namespaces = [ |
| 36 | + (i.namespace, i.namespace) |
| 37 | + for i in Package.objects.distinct("namespace").all() |
| 38 | + if i.namespace |
| 39 | + ] |
| 40 | + pkg_namespaces.append((None, "package namespace")) |
| 41 | + return pkg_namespaces |
| 42 | + |
| 43 | + |
| 44 | +class PackageForm(forms.Form): |
| 45 | + |
| 46 | + type = forms.ChoiceField(choices=get_package_types) |
| 47 | + namespace = forms.ChoiceField(choices=get_package_namespaces, required=False) |
| 48 | + name = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "package name"})) |
| 49 | + version = forms.CharField( |
| 50 | + widget=forms.TextInput(attrs={"placeholder": "package version"}), required=False |
| 51 | + ) |
| 52 | + |
| 53 | + |
| 54 | +class CVEForm(forms.Form): |
| 55 | + |
| 56 | + cve_id = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "vulnerability id"})) |
0 commit comments