diff --git a/pgml-dashboard/app/models.py b/pgml-dashboard/app/models.py index 01d87ac78..3928fad8a 100644 --- a/pgml-dashboard/app/models.py +++ b/pgml-dashboard/app/models.py @@ -318,17 +318,20 @@ class UploadedData(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - def create_table(self, file): + def create_table(self, file, has_header=False): if file.content_type == "text/csv": reader = csv.reader(codecs.iterdecode(file, "utf-8")) headers = next(reader) - columns = ", ".join(map(lambda x: f"{x.replace(' ', '_').lower()} FLOAT4", headers)) + + if has_header: + columns = ", ".join(map(lambda x: f"{x.replace(' ', '_').lower()} TEXT", headers)) + else: + columns = ", ".join(map(lambda x: f"column_{x} TEXT", range(len(headers)))) with transaction.atomic(): sql = f"CREATE TABLE data_{self.pk} (" + columns + ")" with connection.cursor() as cursor: cursor.execute(sql) - file.seek(0) - cursor.copy_expert(f"COPY data_{self.pk} FROM STDIN CSV HEADER", file) + cursor.copy_expert(f"COPY data_{self.pk} FROM STDIN CSV {'HEADER' if has_header else ''}", file) diff --git a/pgml-dashboard/app/static/css/base.css b/pgml-dashboard/app/static/css/base.css index ef09a57ce..29ee3e955 100644 --- a/pgml-dashboard/app/static/css/base.css +++ b/pgml-dashboard/app/static/css/base.css @@ -685,3 +685,39 @@ body.uploader section li { body.uploader strong { font-weight: bold; } + +body.uploader label { + user-select: none; + cursor: pointer; +} + +/* + * Checkbox + */ +input[type=checkbox] { + /* Reset style */ + appearance: none; + + background: transparent; + border: 1px solid var(--gray-5); + + height: 1.6em; + width: 1.6em; + + border-radius: 3px; + + display: inline-flex; + align-items: center; + justify-content: center; + position: relative; + + cursor: pointer; +} + +input[type=checkbox]:checked:after { + content: '\2714'; + font-size: 1em; + position: absolute; + color: var(--highlite-green); + filter: brightness(0.75); +} diff --git a/pgml-dashboard/app/templates/uploader/index.html b/pgml-dashboard/app/templates/uploader/index.html index e0d01aee7..ef3921e79 100644 --- a/pgml-dashboard/app/templates/uploader/index.html +++ b/pgml-dashboard/app/templates/uploader/index.html @@ -11,15 +11,13 @@
Hmm, something went wrong. Please make sure:
+Hmm, something went wrong. Make sure:
{% else %} -You can upload your datasets using the CSV format. Before uploading, please make sure:
+You can upload your datasets using the CSV format. Before uploading, make sure:
{% endif %},
) delimitedIf you are exporting data from a PostgreSQL database, you can use psql
to generate a valid CSV file:
If you are exporting data from a PostgreSQL database, you can use psql
to generate a valid CSV file with a header:
\copy your_table_name TO 'output.csv' CSV HEADER