|
a/Allura/allura/model/artifact.py |
|
b/Allura/allura/model/artifact.py |
|
... |
|
... |
8 |
from datetime import datetime
|
8 |
from datetime import datetime
|
9 |
import Image
|
9 |
import Image
|
10 |
|
10 |
|
11 |
import bson
|
11 |
import bson
|
12 |
import pymongo
|
12 |
import pymongo
|
13 |
from pylons import c, g
|
13 |
from pylons import c, g, request
|
14 |
from ming import Document, Session, Field
|
14 |
from ming import Document, Session, Field
|
15 |
from ming import schema as S
|
15 |
from ming import schema as S
|
16 |
from ming import orm
|
16 |
from ming import orm
|
17 |
from ming.orm import mapper, state, session
|
17 |
from ming.orm import mapper, state, session
|
18 |
from ming.orm.mapped_class import MappedClass, MappedClassMeta
|
18 |
from ming.orm.mapped_class import MappedClass, MappedClassMeta
|
|
... |
|
... |
494 |
artifact_class = FieldProperty(str)
|
494 |
artifact_class = FieldProperty(str)
|
495 |
version = FieldProperty(S.Int, if_missing=0)
|
495 |
version = FieldProperty(S.Int, if_missing=0)
|
496 |
author = FieldProperty(dict(
|
496 |
author = FieldProperty(dict(
|
497 |
id=S.ObjectId,
|
497 |
id=S.ObjectId,
|
498 |
username=str,
|
498 |
username=str,
|
499 |
display_name=str))
|
499 |
display_name=str,
|
|
|
500 |
logged_ip=str))
|
500 |
timestamp = FieldProperty(datetime)
|
501 |
timestamp = FieldProperty(datetime)
|
501 |
data = FieldProperty(None)
|
502 |
data = FieldProperty(None)
|
502 |
|
503 |
|
503 |
def index(self):
|
504 |
def index(self):
|
504 |
result = Artifact.index(self)
|
505 |
result = Artifact.index(self)
|
|
... |
|
... |
532 |
import_id = FieldProperty(S.ObjectId, if_missing=None)
|
533 |
import_id = FieldProperty(S.ObjectId, if_missing=None)
|
533 |
|
534 |
|
534 |
def commit(self):
|
535 |
def commit(self):
|
535 |
'''Save off a snapshot of the artifact and increment the version #'''
|
536 |
'''Save off a snapshot of the artifact and increment the version #'''
|
536 |
self.version += 1
|
537 |
self.version += 1
|
|
|
538 |
try:
|
|
|
539 |
ip_address = request.headers.get('X_FORWARDED_FOR', request.remote_addr)
|
|
|
540 |
ip_address = ip_address.split(',')[0].strip()
|
|
|
541 |
except:
|
|
|
542 |
ip_address = '0.0.0.0'
|
537 |
data = dict(
|
543 |
data = dict(
|
538 |
artifact_id=self._id,
|
544 |
artifact_id=self._id,
|
539 |
artifact_class='%s.%s' % (
|
545 |
artifact_class='%s.%s' % (
|
540 |
self.__class__.__module__,
|
546 |
self.__class__.__module__,
|
541 |
self.__class__.__name__),
|
547 |
self.__class__.__name__),
|
542 |
version=self.version,
|
548 |
version=self.version,
|
543 |
author=dict(
|
549 |
author=dict(
|
544 |
id=c.user._id,
|
550 |
id=c.user._id,
|
545 |
username=c.user.username,
|
551 |
username=c.user.username,
|
546 |
display_name=c.user.display_name),
|
552 |
display_name=c.user.display_name,
|
|
|
553 |
logged_ip=ip_address),
|
547 |
timestamp=datetime.utcnow(),
|
554 |
timestamp=datetime.utcnow(),
|
548 |
data=state(self).document.deinstrumented_clone())
|
555 |
data=state(self).document.deinstrumented_clone())
|
549 |
ss = self.__mongometa__.history_class(**data)
|
556 |
ss = self.__mongometa__.history_class(**data)
|
550 |
session(ss).insert_now(ss, state(ss))
|
557 |
session(ss).insert_now(ss, state(ss))
|
551 |
log.info('Snapshot version %s of %s',
|
558 |
log.info('Snapshot version %s of %s',
|