fnp
/
redakcja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
c6b7810
)
Naprawienie poważnego błędu w update, który mylił klienta o stanie
author
Łukasz Rekucki
<lrekucki@gmail.com>
Mon, 19 Oct 2009 08:54:24 +0000
(10:54 +0200)
committer
Łukasz Rekucki
<lrekucki@gmail.com>
Mon, 19 Oct 2009 08:54:24 +0000
(10:54 +0200)
apps/api/handlers/library_handlers.py
patch
|
blob
|
history
apps/api/handlers/manage_handlers.py
patch
|
blob
|
history
lib/wlrepo/__init__.py
patch
|
blob
|
history
lib/wlrepo/mercurial_backend/__init__.py
patch
|
blob
|
history
lib/wlrepo/mercurial_backend/document.py
patch
|
blob
|
history
platforma/static/js/views/gallery.js
patch
|
blob
|
history
diff --git
a/apps/api/handlers/library_handlers.py
b/apps/api/handlers/library_handlers.py
index
6ac0ba1
..
0635861
100644
(file)
--- a/
apps/api/handlers/library_handlers.py
+++ b/
apps/api/handlers/library_handlers.py
@@
-29,7
+29,7
@@
from explorer.models import GalleryForDocument
import api.forms as forms
import api.response as response
from api.utils import validate_form, hglibrary, natural_order
import api.forms as forms
import api.response as response
from api.utils import validate_form, hglibrary, natural_order
-from api.models import PartCache
+from api.models import PartCache
, PullRequest
#
import settings
#
import settings
@@
-38,6
+38,12
@@
import settings
def is_prq(username):
return username.startswith('$prq-')
def is_prq(username):
return username.startswith('$prq-')
+def prq_for_user(username):
+ try:
+ return PullRequest.objects.get(id=int(username[5:]))
+ except:
+ return None
+
def check_user(request, user):
log.info("user: %r, perm: %r" % (request.user, request.user.get_all_permissions()) )
#pull request
def check_user(request, user):
log.info("user: %r, perm: %r" % (request.user, request.user.get_all_permissions()) )
#pull request
@@
-140,7
+146,6
@@
class LibraryHandler(BaseHandler):
log.info("DOCID %s", docid)
doc = lib.document_create(docid)
# document created, but no content yet
log.info("DOCID %s", docid)
doc = lib.document_create(docid)
# document created, but no content yet
-
try:
doc = doc.quickwrite('xml', data.encode('utf-8'),
'$AUTO$ XML data uploaded.', user=request.user.username)
try:
doc = doc.quickwrite('xml', data.encode('utf-8'),
'$AUTO$ XML data uploaded.', user=request.user.username)
@@
-229,28
+234,28
@@
class DocumentHandler(BaseHandler):
# the user doesn't have this document checked out
# or some other weird error occured
# try to do the checkout
# the user doesn't have this document checked out
# or some other weird error occured
# try to do the checkout
-
if is_prq(user) or (user == request.user.username)
:
-
try
:
+
try
:
+
if user == request.user.username
:
mdoc = lib.document(docid)
doc = mdoc.take(user)
mdoc = lib.document(docid)
doc = mdoc.take(user)
-
- if is_prq(user):
- # source revision, should probably change
- # but there are no changes yet, so...
- pass
-
- except RevisionNotFound, e:
+ elif is_prq(user):
+ prq = prq_for_user(user)
+ # commiter's document
+ prq_doc = lib.document_for_rev(prq.source_revision)
+ doc = prq_doc.take(user)
+ else:
return response.EntityNotFound().django_response({
'reason': 'document-not-found',
'message': e.message,
return response.EntityNotFound().django_response({
'reason': 'document-not-found',
'message': e.message,
- 'docid': docid
+ 'docid': docid,
+ 'user': user,
})
})
- e
ls
e:
+ e
xcept RevisionNotFound,
e:
return response.EntityNotFound().django_response({
'reason': 'document-not-found',
'message': e.message,
'docid': docid,
return response.EntityNotFound().django_response({
'reason': 'document-not-found',
'message': e.message,
'docid': docid,
- 'user': user
,
+ 'user': user
})
return {
})
return {
@@
-623,13
+628,7
@@
class MergeHandler(BaseHandler):
if form.cleaned_data['type'] == 'update':
# update is always performed from the file branch
# to the user branch
if form.cleaned_data['type'] == 'update':
# update is always performed from the file branch
# to the user branch
- changed, clean = base_doc.update(request.user.username)
-
- # update user document
- if changed:
- user_doc_new = user_doc.latest()
- else:
- user_doc_new = user_doc
+ user_doc_new = base_doc.update(request.user.username)
# shared document is the same
doc_new = doc
# shared document is the same
doc_new = doc
@@
-699,8
+698,8
@@
class MergeHandler(BaseHandler):
"revision": user_doc_new.revision,
'timestamp': user_doc_new.revision.timestamp,
"revision": user_doc_new.revision,
'timestamp': user_doc_new.revision.timestamp,
- "parent_revision": user_doc
_new
.revision,
- "parent_timestamp": user_doc
_new
.revision.timestamp,
+ "parent_revision": user_doc.revision,
+ "parent_timestamp": user_doc.revision.timestamp,
"shared_revision": doc_new.revision,
"shared_timestamp": doc_new.revision.timestamp,
"shared_revision": doc_new.revision,
"shared_timestamp": doc_new.revision.timestamp,
diff --git
a/apps/api/handlers/manage_handlers.py
b/apps/api/handlers/manage_handlers.py
index
df32b8b
..
b94ca72
100644
(file)
--- a/
apps/api/handlers/manage_handlers.py
+++ b/
apps/api/handlers/manage_handlers.py
@@
-8,11
+8,12
@@
__date__ = "$2009-09-25 15:49:50$"
__doc__ = "Module documentation."
from piston.handler import BaseHandler
__doc__ = "Module documentation."
from piston.handler import BaseHandler
+from wlrepo import UpdateException
from api.utils import hglibrary
from api.models import PullRequest
from api.response import *
from api.utils import hglibrary
from api.models import PullRequest
from api.response import *
-
from datetime
import datetime
+import datetime
class PullRequestListHandler(BaseHandler):
allowed_methods = ('GET',)
class PullRequestListHandler(BaseHandler):
allowed_methods = ('GET',)
@@
-59,7
+60,7
@@
class PullRequestHandler(BaseHandler):
'message': "This pull request is alredy resolved. Can't accept."
})
'message': "This pull request is alredy resolved. Can't accept."
})
- src_doc = lib.document( prq.source_revision )
+ src_doc = lib.document
_for_rev
( prq.source_revision )
lock = lib.lock()
try:
lock = lib.lock()
try:
@@
-69,30
+70,28
@@
class PullRequestHandler(BaseHandler):
#
# Q: where to put the updated revision ?
# A: create a special user branch named prq-#prqid
#
# Q: where to put the updated revision ?
# A: create a special user branch named prq-#prqid
- prq_doc = src_doc.take("$prq-%d" % pr
d
.id)
+ prq_doc = src_doc.take("$prq-%d" % pr
q
.id)
# This could be not the first time we try this,
# so the prq_doc could already be there
# and up to date
# This could be not the first time we try this,
# so the prq_doc could already be there
# and up to date
- success, changed = prq_doc.update(user.username)
- prq.status = 'E'
-
- if not success:
- prq.save()
+ try:
+ prq_doc = prq_doc.update(user.username)
+ prq.source_revision = str(prq_doc.revision)
+ src_doc = prq_doc
+ except UpdateException, e:
# this can happen only if the merge program
# is misconfigured - try returning an entity conflict
# TODO: put some useful infor here
# this can happen only if the merge program
# is misconfigured - try returning an entity conflict
# TODO: put some useful infor here
- return EntityConflict().django_response()
-
- if changed:
- prq_doc = prq_doc.latest()
-
- prq.source_revision = str(prq_doc.revision)
- src_doc = prq_doc
+ prq.status = 'E'
+ prq.save()
+ return EntityConflict().django_response({
+ 'reason': 'update-failed',
+ 'message': e.message })
# check if there are conflicts
# check if there are conflicts
- if
prq
_doc.has_conflict_marks():
+ if
src
_doc.has_conflict_marks():
prq.status = 'E'
prq.save()
# Now, the user must resolve the conflict
prq.status = 'E'
prq.save()
# Now, the user must resolve the conflict
@@
-111,7
+110,7
@@
class PullRequestHandler(BaseHandler):
# sync state with repository
prq.status = 'A'
prq.merged_revision = str(src_doc.shared().revision)
# sync state with repository
prq.status = 'A'
prq.merged_revision = str(src_doc.shared().revision)
- prq.merged_timestamp = datetime()
+ prq.merged_timestamp = datetime
.now
()
prq.save()
return SuccessAllOk().django_response({
prq.save()
return SuccessAllOk().django_response({
diff --git
a/lib/wlrepo/__init__.py
b/lib/wlrepo/__init__.py
index
9de75a0
..
0f373d4
100644
(file)
--- a/
lib/wlrepo/__init__.py
+++ b/
lib/wlrepo/__init__.py
@@
-105,6
+105,9
@@
class LibraryException(Exception):
Exception.__init__(self, msg)
self.cause = cause
Exception.__init__(self, msg)
self.cause = cause
+class UpdateException(LibraryException):
+ pass
+
class RevisionNotFound(LibraryException):
def __init__(self, rev):
LibraryException.__init__(self, "Revision %r not found." % rev)
class RevisionNotFound(LibraryException):
def __init__(self, rev):
LibraryException.__init__(self, "Revision %r not found." % rev)
diff --git
a/lib/wlrepo/mercurial_backend/__init__.py
b/lib/wlrepo/mercurial_backend/__init__.py
index
536d08c
..
22a9d52
100644
(file)
--- a/
lib/wlrepo/mercurial_backend/__init__.py
+++ b/
lib/wlrepo/mercurial_backend/__init__.py
@@
-89,9
+89,9
@@
class MercurialRevision(wlrepo.Revision):
status = self._library._merge(other._changectx.node())
if status.isclean():
self._library._commit(user=user, message=message)
status = self._library._merge(other._changectx.node())
if status.isclean():
self._library._commit(user=user, message=message)
- return
(True, True)
+ return
True
else:
else:
- return
(False, False)
+ return
False
finally:
lock.release()
finally:
lock.release()
diff --git
a/lib/wlrepo/mercurial_backend/document.py
b/lib/wlrepo/mercurial_backend/document.py
index
0883d99
..
3911d04
100644
(file)
--- a/
lib/wlrepo/mercurial_backend/document.py
+++ b/
lib/wlrepo/mercurial_backend/document.py
@@
-116,23
+116,24
@@
class MercurialDocument(wlrepo.Document):
try:
if self.ismain():
# main revision of the document
try:
if self.ismain():
# main revision of the document
- return
(True, False)
+ return
self
- if self._revision.has_children():
- log.info('Update failed: has children.')
- # can't update non-latest revision
- return (False, False)
+ if self._revision.has_children():
+ raise UpdateException("Revision has children.")
sv = self.shared()
if self.parentof(sv):
sv = self.shared()
if self.parentof(sv):
- return
(True, False)
+ return
self
if sv.ancestorof(self):
if sv.ancestorof(self):
- return
(True, False)
+ return
self
- return self._revision.merge_with(sv._revision, user=user,
- message="$AUTO$ Personal branch update.")
+ if self._revision.merge_with(sv._revision, user=user,\
+ message="$AUTO$ Personal branch update."):
+ return self.latest()
+ else:
+ raise UpdateException("Merge failed.")
finally:
lock.release()
finally:
lock.release()
diff --git
a/platforma/static/js/views/gallery.js
b/platforma/static/js/views/gallery.js
index
e0e3dc7
..
176b0ab
100644
(file)
--- a/
platforma/static/js/views/gallery.js
+++ b/
platforma/static/js/views/gallery.js
@@
-182,7
+182,11
@@
var ImageGalleryView = View.extend({
offset.y = vp_height-MARGIN;
$page.css({left: offset.x, top: offset.y});
offset.y = vp_height-MARGIN;
$page.css({left: offset.x, top: offset.y});
- },
+ },
+
+ reload: function() {
+ this.model.load(true);
+ },
renderImage: function(target)
{
renderImage: function(target)
{