Skip to content

Commit

Permalink
Merge branch 'master' into feature-1669-publisher-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Feb 8, 2012
2 parents cd8405a + f9fc4f1 commit 61eab28
Show file tree
Hide file tree
Showing 35 changed files with 130 additions and 69 deletions.
2 changes: 0 additions & 2 deletions ckan/controllers/user.py
Expand Up @@ -103,8 +103,6 @@ def read(self, id=None):
c.about_formatted = self._format_about(user_dict['about'])
c.user_activity_stream = user_activity_list_html(context,
{'id':c.user_dict['id']})

c.created_formatted = h.date_str_to_datetime(user_dict['created']).strftime('%b %d, %Y')
return render('user/read.html')

def me(self):
Expand Down
14 changes: 13 additions & 1 deletion ckan/lib/base.py
Expand Up @@ -87,6 +87,18 @@ def __before__(self, action, **params):
i18n.handle_request(request, c)

def _identify_user(self):
'''
Identifies the user using two methods:
a) If he has logged into the web interface then repoze.who will
set REMOTE_USER.
b) For API calls he may set a header with his API key.
If the user is identified then:
c.user = user name (unicode)
c.author = user name
otherwise:
c.user = None
c.author = user\'s IP address (unicode)
'''
# see if it was proxied first
c.remote_addr = request.environ.get('HTTP_X_FORWARDED_FOR', '')
if not c.remote_addr:
Expand All @@ -98,7 +110,7 @@ def _identify_user(self):
c.user = c.user.decode('utf8')
c.userobj = model.User.by_name(c.user)
if c.userobj is None:
# This occurs when you are logged in with openid, clean db
# This occurs when you are logged in, clean db
# and then restart i.e. only really for testers. There is no
# user object, so even though repoze thinks you are logged in
# and your cookie has ckan_display_name, we need to force user
Expand Down
12 changes: 8 additions & 4 deletions ckan/lib/dictization/model_save.py
Expand Up @@ -286,10 +286,14 @@ def package_dict_save(pkg_dict, context):
package_tag_list_save(pkg_dict.get("tags", []), pkg, context)
package_membership_list_save(pkg_dict.get("groups", []), pkg, context)

subjects = pkg_dict.get('relationships_as_subject', [])
relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
objects = pkg_dict.get('relationships_as_object', [])
relationship_list_save(subjects, pkg, 'relationships_as_object', context)
# relationships are not considered 'part' of the package, so only
# process this if the key is provided
if 'relationships_as_subject' in pkg_dict:
subjects = pkg_dict.get('relationships_as_subject', [])
relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
if 'relationships_as_object' in pkg_dict:
objects = pkg_dict.get('relationships_as_object', [])
relationship_list_save(objects, pkg, 'relationships_as_object', context)

extras = package_extras_save(pkg_dict.get("extras", []), pkg, context)

Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/hash.py
Expand Up @@ -12,7 +12,7 @@ def get_message_hash(value):
# avoid getting config value at module scope since config may
# not be read in yet
secret = config['beaker.session.secret']
return hmac.new(secret, value, hashlib.sha1).hexdigest()
return hmac.new(secret, value.encode('utf8'), hashlib.sha1).hexdigest()

def get_redirect():
'''Checks the return_to value against the hash, and if it
Expand Down
6 changes: 5 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -281,11 +281,15 @@ def pager(self, *args, **kwargs):
)
return super(Page, self).pager(*args, **kwargs)

def render_datetime(datetime_, date_format='%Y-%m-%d %H:%M'):
def render_datetime(datetime_, date_format=None, with_hours=False):
'''Render a datetime object or timestamp string as a pretty string
(Y-m-d H:m).
If timestamp is badly formatted, then a blank string is returned.
'''
if not date_format:
date_format = '%b %d, %Y'
if with_hours:
date_format += ', %H:%M'
if isinstance(datetime_, datetime.datetime):
return datetime_.strftime(date_format)
elif isinstance(datetime_, basestring):
Expand Down
17 changes: 11 additions & 6 deletions ckan/logic/validators.py
@@ -1,5 +1,6 @@
import re
import datetime
from itertools import count
import re
from pylons.i18n import _, ungettext, N_, gettext
from ckan.lib.navl.dictization_functions import Invalid, Missing, missing, unflatten
from ckan.authz import Authorizer
Expand Down Expand Up @@ -268,13 +269,17 @@ def tag_string_convert(key, data, errors, context):
'''Takes a list of tags that is a comma-separated string (in data[key])
and parses tag names. These are added to the data dict, enumerated. They
are also validated.'''
tag_string = data[key]

tags = [tag.strip() \
for tag in tag_string.split(',') \
if tag.strip()]
if isinstance(data[key], basestring):
tags = [tag.strip() \
for tag in data[key].split(',') \
if tag.strip()]
else:
tags = data[key]

current_index = max( [int(k[1]) for k in data.keys() if len(k) == 3 and k[0] == 'tags'] + [-1] )

for num, tag in enumerate(tags):
for num, tag in zip(count(current_index+1), tags):
data[('tags', num, 'name')] = tag

for tag in tags:
Expand Down
14 changes: 7 additions & 7 deletions ckan/public/css/style.css
Expand Up @@ -1527,30 +1527,30 @@ body.authz form button {
/* = Activity Streams = */
/* ==================== */

.activity-stream-activity {
.activity-stream .activity {
padding-bottom:1em;

}
.activity-stream-activity a {
.activity-stream .activity a {
font-weight:bold;

}
.activity-stream-activity .actor {
.activity-stream .activity .actor {

}
.activity-stream-activity .verb {
.activity-stream .activity .verb {
background-color:PapayaWhip;
padding:.25em;
margin:.25em;

}
.activity-stream-activity .object {
.activity-stream .activity .object {

}
.activity-stream-activity .target {
.activity-stream .activity .target {

}
.activity-stream-activity .date {
.activity-stream .activity .date {
color:#999;

}
8 changes: 4 additions & 4 deletions ckan/templates/_util.html
Expand Up @@ -384,7 +384,7 @@
</div>
</py:if>
</td>
<td>${h.render_datetime(revision.timestamp)}</td>
<td>${h.render_datetime(revision.timestamp, with_hours=True)}</td>
<td>${h.linked_user(revision.author)}</td>
<td>
<py:for each="pkg in revision.packages">
Expand Down Expand Up @@ -451,8 +451,8 @@
</tr>
</table>

<div py:def="activity_stream_activity(actor, verb, object=None, target=None)"
class="activity-stream-activity">
<div py:def="activity_div(actor, verb, object=None, target=None)"
class="activity">
<span class="actor">
${actor}
</span>
Expand All @@ -474,7 +474,7 @@
</py:otherwise>
</py:choose>
<span class="date">
${h.render_datetime(activity.timestamp, '%B %d %Y')}
${h.render_datetime(activity.timestamp)}
</span>
</div>

Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/added_tag.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='added',
object="the tag "+h.tag_link(detail.data.tag),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_group.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated',
object="the group "+h.group_link(activity.data.group),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_package.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated',
object="the dataset "+h.dataset_link(activity.data.package),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_package_extra.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='changed',
object='the extra "'+detail.data.package_extra.key+'"',
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_resource.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated',
object='the resource '+h.resource_link(detail.data.resource,
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/changed_user.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='updated their profile.',
activity=activity
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/activity_streams/deleted_group.html
Expand Up @@ -6,10 +6,10 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object="the group "+h.group_link(activity.data.group),
object="the group "+activity.data.group.name,
activity=activity
)}
</html>
4 changes: 2 additions & 2 deletions ckan/templates/activity_streams/deleted_package.html
Expand Up @@ -6,9 +6,9 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object="the dataset "+h.dataset_link(activity.data.package),
object="the dataset "+h.dataset_display_name(activity.data.package),
activity=activity)}
</html>
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/deleted_package_extra.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object='the extra "'+detail.data.package_extra.key+'"',
Expand Down
5 changes: 2 additions & 3 deletions ckan/templates/activity_streams/deleted_resource.html
Expand Up @@ -6,11 +6,10 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='deleted',
object='the resource '+h.resource_link(detail.data.resource,
activity.data.package.id),
object='the resource '+h.resource_display_name(detail.data.resource),
target='from the dataset '+h.dataset_link(activity.data.package),
activity=activity
)}
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_group.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='created',
object="the group "+h.group_link(activity.data.group),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_package.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='created',
object="the dataset "+h.dataset_link(activity.data.package),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_package_extra.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='added',
object='the extra "'+detail.data.package_extra.key+'"',
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_resource.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='added',
object='the resource '+h.resource_link(detail.data.resource,
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/new_user.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='signed up.',
activity=activity
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/activity_streams/removed_tag.html
Expand Up @@ -6,7 +6,7 @@
py:strip=""
>
<xi:include href="../_util.html" />
${activity_stream_activity(
${activity_div(
actor=h.linked_user(activity.user_id),
verb='removed',
object="the tag "+h.tag_link(detail.data.tag),
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/history.html
Expand Up @@ -47,7 +47,7 @@ <h3 py:if="c.error" class="form-errors">
<a href="${h.url_for(controller='revision',action='read',id=rev['id'])}">${rev['id'][:4]}&#8230;</a>
</td>
<td>
<a href="${h.url_for(controller='package',action='read',id='%s@%s' % (c.pkg_dict['name'], rev['timestamp']))}" title="${'Read dataset as of %s' % rev['timestamp']}">${h.render_datetime(rev['timestamp'])}</a></td>
<a href="${h.url_for(controller='package',action='read',id='%s@%s' % (c.pkg_dict['name'], rev['timestamp']))}" title="${'Read dataset as of %s' % rev['timestamp']}">${h.render_datetime(rev['timestamp'], with_hours=True)}</a></td>
<td>${h.linked_user(rev['author'])}</td>
<td>${rev['message']}</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/package/read.html
Expand Up @@ -84,8 +84,8 @@ <h3>Related Datasets</h3>
<div py:match="content">
<py:if test="c.pkg_revision_id">
<div id="revision" class="widget-container">
<p py:if="c.pkg_revision_not_latest">This is an old revision of this dataset, as edited <!--!by ${h.linked_user(rev.author)}-->at ${h.render_datetime(c.pkg_revision_timestamp)}. It may differ significantly from the <a href="${url(controller='package', action='read', id=c.pkg.name)}">current revision</a>.</p>
<p py:if="not c.pkg_revision_not_latest">This is the current revision of this dataset, as edited <!--!by ${h.linked_user(rev.author)}-->at ${h.render_datetime(c.pkg_revision_timestamp)}.</p>
<p py:if="c.pkg_revision_not_latest">This is an old revision of this dataset, as edited <!--!by ${h.linked_user(rev.author)}-->at ${h.render_datetime(c.pkg_revision_timestamp, with_hours=True)}. It may differ significantly from the <a href="${url(controller='package', action='read', id=c.pkg.name)}">current revision</a>.</p>
<p py:if="not c.pkg_revision_not_latest">This is the current revision of this dataset, as edited <!--!by ${h.linked_user(rev.author)}-->at ${h.render_datetime(c.pkg_revision_timestamp, with_hours=True)}.</p>
</div>
</py:if>

Expand Down
8 changes: 5 additions & 3 deletions ckan/templates/user/read.html
Expand Up @@ -31,8 +31,8 @@
</py:if>
</dd>
<dt>Member since</dt>
<dd>${c.created_formatted}</dd>
<py:if test="c.about_formatted">
<dd>${h.render_datetime(c.user_dict['created'])}</dd>
<py:if test="unicode(c.about_formatted)">
<dt>About</dt>
<dd>${c.about_formatted}</dd>
</py:if>
Expand Down Expand Up @@ -69,7 +69,9 @@ <h2>Datasets</h2>
</div>
<div class="changes span-12 last">
<h2>Public Activity</h2>
${c.user_activity_stream}
<div class="activity-stream">
${c.user_activity_stream}
</div>
</div>
</div>
</div>
Expand Down
7 changes: 0 additions & 7 deletions ckan/tests/functional/api/base.py
Expand Up @@ -278,13 +278,6 @@ def _ref_group(cls, group):
assert cls.ref_group_by in ['id', 'name']
return getattr(group, cls.ref_group_by)

@classmethod
def _list_package_refs(cls, packages):
return [getattr(p, cls.ref_package_by) for p in packages]

@classmethod
def _list_group_refs(cls, groups):
return [getattr(p, cls.ref_group_by) for p in groups]

class Api1TestCase(Api1and2TestCase):

Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/functional/test_activity.py
Expand Up @@ -201,5 +201,5 @@ def test_activity(self):
# By now we've created >15 activities, but only the latest 15 should
# appear on the page.
result = self.app.get(offset, status=200)
assert result.body.count('<div class="activity-stream-activity">') \
assert result.body.count('<div class="activity">') \
== 15

0 comments on commit 61eab28

Please sign in to comment.