-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature/package approve #3
base: master
Are you sure you want to change the base?
Changes from 10 commits
b49437e
b8cba5a
75395d5
609c793
0f6cccc
daadd48
8e63b69
5e8417e
4ea13ff
a7de217
5e1c335
1460cb6
1ac9211
3f8d225
5d296b0
8edd1ad
9f0d999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,26 +24,31 @@ def get_groups(): | |
return groups | ||
|
||
|
||
def get_recently_updated_datasets(limit=5): | ||
def get_recently_updated_datasets(limit=5, user=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this needed? FYI, if you don't explicitly provide a user in the context CKAN will use the one logged in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forget to mention in PR description. Did this cause we probably don't want pending datasets to appear in recently updated and the most popular dataset. Both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@amercader hmm... now I remember, the main reason was, cause tests started failing I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The avoiding of pending datasets coming up should he handled at the search level. The implementation of Anyway if you relied on the check on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zelima can you revisit this and see if the change is actually needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 9f0d999 |
||
''' | ||
Returns recent created or updated datasets. | ||
:param limit: Limit of the datasets to be returned. Default is 5. | ||
:type limit: integer | ||
:param user: user name | ||
:type user: string | ||
|
||
:returns: a list of recently created or updated datasets | ||
:rtype: list | ||
''' | ||
try: | ||
pkg_search_results = toolkit.get_action('package_search')(data_dict={ | ||
'sort': 'metadata_modified desc', | ||
'rows': limit, | ||
})['results'] | ||
pkg_search_results = toolkit.get_action('package_search')( | ||
context={'user': user}, | ||
data_dict={ | ||
'sort': 'metadata_modified desc', | ||
'rows': limit | ||
})['results'] | ||
|
||
except toolkit.ValidationError, search.SearchError: | ||
return [] | ||
else: | ||
pkgs = [] | ||
for pkg in pkg_search_results: | ||
package = toolkit.get_action('package_show')( | ||
package = toolkit.get_action('package_show')(context={'user': user}, | ||
data_dict={'id': pkg['id']}) | ||
modified = datetime.strptime( | ||
package['metadata_modified'].split('T')[0], '%Y-%m-%d') | ||
|
@@ -52,15 +57,20 @@ def get_recently_updated_datasets(limit=5): | |
return pkgs | ||
|
||
|
||
def get_most_popular_datasets(limit=5): | ||
def get_most_popular_datasets(limit=5, user=None): | ||
''' | ||
Returns most popular datasets based on total views. | ||
:param limit: Limit of the datasets to be returned. Default is 5. | ||
:type limit: integer | ||
:param user: user name | ||
:type user: string | ||
|
||
:returns: a list of most popular datasets | ||
:rtype: list | ||
''' | ||
data = pkg_search_results = toolkit.get_action('package_search')(data_dict={ | ||
data = pkg_search_results = toolkit.get_action('package_search')( | ||
context={'user': user}, | ||
data_dict={ | ||
'sort': 'views_total desc', | ||
'rows': limit, | ||
})['results'] | ||
|
@@ -105,3 +115,17 @@ def get_total_views_for_dataset(id): | |
return dataset.get('tracking_summary').get('total') | ||
except Exception: | ||
return 0 | ||
|
||
|
||
def is_admin(user): | ||
""" | ||
Returns True if user is admin of any organisation | ||
|
||
:param user: user name | ||
:type user: string | ||
|
||
:returns: True/False | ||
:rtype: boolean | ||
""" | ||
user_orgs = _get_action('organization_list_for_user', {'user': user}, {'user': user}) | ||
return any([i.get('capacity') == 'admin' for i in user_orgs]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{% extends 'package/snippets/package_form.html' %} | ||
|
||
{% block stages %} | ||
{% if form_style != 'edit' %} | ||
{% if not h.ed_is_admin(c.user) %} | ||
<div class="alert alert-warning" role="alert"> | ||
<p> | ||
{% trans %}<strong>Note:</strong> This dataset will be submited for an administrator approval!{% endtrans %} | ||
</p> | ||
</div> | ||
{% endif %} | ||
{{ super() }} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block save_button_text %} | ||
{% if form_style != 'edit' %} | ||
{{ super() }} | ||
{% else %} | ||
{{ _('Update Dataset') }} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block cancel_button %} | ||
{% if form_style != 'edit' %} | ||
{{ super() }} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block delete_button %} | ||
{% if form_style == 'edit' and h.check_access('package_delete', {'id': pkg_dict.id}) %} | ||
{{ super() }} | ||
{% endif %} | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{# | ||
Inserts a stepped progress indicator for the new package form. Each stage can | ||
have one of three states, "uncomplete", "complete" and "active". | ||
|
||
stages - A list of states for each of the three stages. Missing stages default | ||
to "uncomplete". | ||
|
||
Example: | ||
|
||
{% snippet 'package/snippets/stages.html', stages=['active'] %} | ||
{% snippet 'package/snippets/stages.html', stages=['complete', 'active'] %} | ||
{% snippet 'package/snippets/stages.html', stages=['active', 'complete'] %} | ||
|
||
#} | ||
{% set s1 = stages[0] or 'active' %} | ||
{% set s2 = stages[1] or 'uncomplete' %} | ||
{% if s1 != 'uncomplete' %}{% set class = 'stage-1' %}{% endif %} | ||
{% if s2 != 'uncomplete' %}{% set class = 'stage-2' %}{% endif %} | ||
|
||
<ol class="stages {{ class }}"> | ||
<li class="first {{ s1 }}"> | ||
{% if s1 != 'complete' %} | ||
{% if h.ed_is_admin(c.user) %} | ||
<span class="highlight">{{ _('Create dataset') }}</span> | ||
{% else %} | ||
<span class="highlight">{{ _('Request dataset') }}</span> | ||
{% endif %} | ||
{% else %} | ||
{% if h.ed_is_admin(c.user) %} | ||
<button class="highlight" name="save" value="go-dataset" type="submit">{{ _('Create dataset') }}</button> | ||
{% else %} | ||
<button class="highlight" name="save" value="go-dataset" type="submit">{{ _('Request dataset') }}</button> | ||
{% endif %} | ||
{% endif %} | ||
</li> | ||
<li class="last {{ s2 }}"> | ||
{% if s2 != 'complete' %} | ||
<span class="highlight">{{ _('Add data') }}</span> | ||
{% else %} | ||
{% if s1 == 'active' %} | ||
{# stage 1 #} | ||
<button class="highlight" name="save" value="go-resources" type="submit">{{ _('Add data') }}</button> | ||
{% else %} | ||
{% link_for _('Add data'), named_route='dataset.new', class_="highlight" %} | ||
{% endif %} | ||
{% endif %} | ||
</li> | ||
</ol> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done in the
IPackageController.before_search
hook. In general is best to avoid overriding actions if possibleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to rethink the whole way pending datasets will be handled on the search. Probably using
IPermissionLabels
, as we will need to search for pending datasets at some point. But let's go with this for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amercader so is this fine? Or refactor to use
before_search
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please. Use before_search
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8edd1ad