Skip to content

Commit 9799746

Browse files
committed
fix (improve): replace description to notes and work without app context
1 parent d3aa3f3 commit 9799746

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

ckanext/versions/logic/action.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def package_version_create(context, data_dict):
2727
)
2828

2929
# Check if the version already exists
30-
existing_version = DatasetVersion.get(name=data_dict["name"])
30+
existing_version = DatasetVersion.get(name=data_dict["name"], package_id=data_dict["package_id"])
3131
if existing_version:
3232
raise tk.ValidationError(
3333
f"Version with name '{data_dict['name']}' already exists."
@@ -36,7 +36,7 @@ def package_version_create(context, data_dict):
3636
version = DatasetVersion.create(
3737
package_id=data_dict["package_id"],
3838
name=data_dict["name"],
39-
description=data_dict.get("description"),
39+
notes=data_dict.get("notes"),
4040
data=package_dict,
4141
creator_user_id=package_dict.get("creator_user_id"),
4242
)
@@ -82,7 +82,7 @@ def package_version_show(context, data_dict):
8282
print(e)
8383
data_dict = dataset_version.as_dict().get("data", {})
8484
data_dict["version_id"] = dataset_version.id
85-
data_dict["version_description"] = dataset_version.description
85+
data_dict["version_notes"] = dataset_version.notes
8686
return data_dict
8787

8888

@@ -142,15 +142,19 @@ def _version_create_or_update(context, data_dict):
142142
:param data_dict: The data dictionary containing version details
143143
"""
144144
current_version = data_dict.get("version")
145+
notes = data_dict.get("version_notes")
146+
package_id = data_dict.get("id")
147+
existing_version = DatasetVersion.get(name=current_version, package_id=package_id)
148+
print(notes)
145149

146-
if getattr(tk.g, "update_version", False):
147-
150+
if existing_version:
148151
try:
149152
tk.get_action("package_version_update")(
150153
context,
151154
{
152155
"name": current_version,
153156
"data": data_dict,
157+
"notes": notes,
154158
},
155159
)
156160
log.info(
@@ -165,15 +169,14 @@ def _version_create_or_update(context, data_dict):
165169
"error": [f"Version with name '{current_version}' already exists."],
166170
}
167171
)
168-
169172
else:
170173
try:
171174
tk.get_action("package_version_create")(
172175
context,
173176
{
174177
"package_id": data_dict.get("id"),
175178
"name": current_version,
176-
"description": data_dict.get("description"),
179+
"notes": notes,
177180
"creator_user_id": data_dict.get("creator_user_id"),
178181
},
179182
)

ckanext/versions/logic/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def package_version_create(
1616
return {
1717
"name": [not_empty, unicode_only],
1818
"package_id": [not_empty, unicode_only, package_id_exists],
19-
"description": [ignore_missing],
19+
"notes": [ignore_missing],
2020
"created": [ignore_missing, isodate],
2121
"creator_user_id": [ignore_missing, user_id_or_name_exists],
2222
}
@@ -37,7 +37,7 @@ def package_version_update(
3737
"id": [ignore_missing, unicode_only],
3838
"name": [ignore_missing, unicode_only],
3939
"package_id": [ignore_missing, unicode_only, package_id_exists],
40-
"description": [ignore_missing],
40+
"notes": [ignore_missing],
4141
"data": [ignore_missing],
4242
"created": [ignore_missing, isodate],
4343
"creator_user_id": [ignore_missing, user_id_or_name_exists],

ckanext/versions/logic/validators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def package_version(key, data, errors, context):
1919

2020
previous_version = DatasetVersion.recent_versions(pkg.id)
2121
if previous_version and current_version == previous_version.name:
22-
tk.g.update_version = True # Even if the version is the same, we want to update it
2322
return data.get(key)
2423

2524
existing_version = DatasetVersion.get(name=current_version, package_id=pkg.id)

ckanext/versions/migration/versions/versions/908a228d3f7a.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def upgrade():
2727
sa.Column("id", UuidType, primary_key=True),
2828
sa.Column("package_id", UuidType, sa.ForeignKey("package.id"), nullable=False),
2929
sa.Column("name", sa.Unicode, nullable=False),
30-
sa.Column("description", sa.Unicode, nullable=True),
30+
sa.Column("notes", sa.Unicode, nullable=True),
3131
sa.Column("data", JSONB, nullable=False),
3232
sa.Column("creator_user_id", UuidType, sa.ForeignKey("user.id"), nullable=True),
3333
sa.Column("created", sa.DateTime, server_default=sa.func.current_timestamp()),

ckanext/versions/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DatasetVersion(DomainObject.DomainObject, tk.BaseModel):
3030
id = Column(UuidType, primary_key=True, default=UuidType.default)
3131
package_id = Column(UuidType, ForeignKey("package.id"), nullable=False)
3232
name = Column(Unicode, nullable=False)
33-
description = Column(Unicode, nullable=True)
33+
notes = Column(Unicode, nullable=True)
3434
data = Column(JSONB, nullable=False)
3535
creator_user_id = Column(UuidType, ForeignKey("user.id"), nullable=True)
3636
created = Column(DateTime, default=datetime.datetime.utcnow)

ckanext/versions/templates/package/snippets/version_info.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h3>Versions</h3>
77
<thead>
88
<tr>
99
<th scope="col">Version</th>
10-
<th scope="col">Description</th>
10+
<th scope="col">Notes</th>
1111
<th scope="col">Published</th>
1212
</tr>
1313
</thead>
@@ -23,7 +23,7 @@ <h3>Versions</h3>
2323
</a>
2424
{% endif %}
2525
</td>
26-
<td>{{ version.description or "" }}</td>
26+
<td>{{ version.notes or "" }}</td>
2727
<td>{{ version.created }}</td>
2828
</tr>
2929
{% endfor %}

0 commit comments

Comments
 (0)