Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Archive dataset feature and pin several dependencies (#2172)
* Archive dataset feature * Pin faulty deps * order deps * pin some potentially troublesome deps
- Loading branch information
Showing
14 changed files
with
243 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.content.archived { | ||
opacity: 0.6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
from datetime import datetime | ||
|
||
from flask import current_app | ||
|
||
from udata import theme, i18n | ||
from udata.models import Discussion, Message | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def archive(dataset, comment=False): | ||
"""Archive a dataset""" | ||
if dataset.archived: | ||
log.warning('Dataset %s already archived, bumping date', dataset) | ||
dataset.archived = datetime.now() | ||
dataset.save() | ||
|
||
if comment: | ||
log.info('Posting comment for dataset %s...', dataset) | ||
lang = current_app.config['DEFAULT_LANGUAGE'] | ||
title = current_app.config['ARCHIVE_COMMENT_TITLE'] | ||
user_id = current_app.config['ARCHIVE_COMMENT_USER_ID'] | ||
if user_id: | ||
with i18n.language(lang): | ||
msg = theme.render('comments/dataset_archived.txt') | ||
message = Message(content=msg, posted_by=user_id) | ||
discussion = Discussion( | ||
user=user_id, discussion=[message], subject=dataset, | ||
title=title) | ||
discussion.save() | ||
else: | ||
log.warning('ARCHIVE_COMMENT_USER_ID not set, skipping comment') | ||
|
||
log.info('Archived dataset %s', dataset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% trans %}This dataset has been archived by our administration team. | ||
|
||
An archived dataset is considered out of date by a combination of factors. | ||
It does not appear in the search results and has a special layout warning the site's users. | ||
|
||
If you think this is a mistake, you can contact the site administrator.{% endtrans %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import pytest | ||
|
||
from udata.core.dataset.actions import archive | ||
from udata.core.dataset.factories import VisibleDatasetFactory | ||
from udata.core.discussions.models import Discussion | ||
from udata.core.user.factories import UserFactory | ||
|
||
|
||
@pytest.mark.usefixtures('clean_db') | ||
class DatasetActionsTest: | ||
|
||
def test_dataset_archive(self, app): | ||
user = UserFactory() | ||
app.config['ARCHIVE_COMMENT_USER_ID'] = user.id | ||
|
||
dataset = VisibleDatasetFactory() | ||
|
||
archive(dataset, comment=True) | ||
|
||
dataset.reload() | ||
assert dataset.archived is not None | ||
discussions = Discussion.objects.filter(subject=dataset) | ||
assert len(discussions) == 1 | ||
assert 'archived' in discussions[0].discussion[0].content |
Oops, something went wrong.