|
a/Allura/allura/lib/helpers.py |
|
b/Allura/allura/lib/helpers.py |
|
... |
|
... |
234 |
break
|
234 |
break
|
235 |
return ago + ' ago'
|
235 |
return ago + ' ago'
|
236 |
|
236 |
|
237 |
def ago_ts(timestamp):
|
237 |
def ago_ts(timestamp):
|
238 |
return ago(datetime.utcfromtimestamp(timestamp))
|
238 |
return ago(datetime.utcfromtimestamp(timestamp))
|
239 |
|
|
|
240 |
def tag_artifact(artifact, user, tags):
|
|
|
241 |
from allura import model as M
|
|
|
242 |
aref = artifact.dump_ref()
|
|
|
243 |
when = datetime.utcnow()
|
|
|
244 |
# Get the UserTags object
|
|
|
245 |
ut = M.UserTags.upsert(user, aref)
|
|
|
246 |
# Determine which tags were added/removed
|
|
|
247 |
user_tags = set(tag.tag for tag in ut.tags)
|
|
|
248 |
tags = set(tags)
|
|
|
249 |
added_tags = list(tags - user_tags)
|
|
|
250 |
removed_tags = list(user_tags - tags)
|
|
|
251 |
# Create the TagEvent
|
|
|
252 |
evt = M.TagEvent(
|
|
|
253 |
when=when,
|
|
|
254 |
user_id=user._id,
|
|
|
255 |
artifact_ref=aref,
|
|
|
256 |
added_tags=added_tags,
|
|
|
257 |
removed_tags=removed_tags)
|
|
|
258 |
# Update the UserTags Object
|
|
|
259 |
ut.add_tags(when, added_tags)
|
|
|
260 |
ut.remove_tags(removed_tags)
|
|
|
261 |
# Update the artifact
|
|
|
262 |
artifact.add_tags(added_tags)
|
|
|
263 |
artifact.remove_tags(removed_tags)
|
|
|
264 |
# Update the Tag index
|
|
|
265 |
M.Tag.add(aref, user, added_tags)
|
|
|
266 |
M.Tag.remove(aref, user, removed_tags)
|
|
|
267 |
|
239 |
|
268 |
class DateTimeConverter(FancyValidator):
|
240 |
class DateTimeConverter(FancyValidator):
|
269 |
|
241 |
|
270 |
def _to_python(self, value, state):
|
242 |
def _to_python(self, value, state):
|
271 |
try:
|
243 |
try:
|