Skip to content

Commit

Permalink
submit_mpfile: insert cid into output
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Jul 15, 2015
1 parent ab042d6 commit e7fb477
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
15 changes: 14 additions & 1 deletion mpcontribs/io/mpfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def from_string(data):
# strip comments from data string
lines, comments = [], OrderedDict()
for idx,line in enumerate(data.splitlines()):
idx_str, line = str(idx), line.encode('utf-8')
idx_str, line = str(idx), line#.encode('utf-8')
line_split = line.lstrip().split('#', 1)
lines.append(line_split[0])
if len(line_split) > 1:
Expand Down Expand Up @@ -100,6 +100,19 @@ def make_general_section(self):
mp_cat_id, (mp_level01_titles[0], general_section)
)

def insert_id(self, cid, mp_cat_id):
"""insert entry containing contribution ID for `mp_cat_id`"""
# only works for single section files like in `utils.submit_mpfile`
first_sub_key = self.document[mp_cat_id].keys()[0]
self.document[mp_cat_id].insert_before(first_sub_key, ('cid', str(cid)))
for idx_str in self.comments.keys():
comment = self.comments.pop(idx_str)
idx_str_split = idx_str.split('*')
idx = int(idx_str_split[0])+1
idx_str = str(idx)
if len(idx_str_split) > 1: idx_str += '*'
self.comments[idx_str] = comment

def get_string(self, with_comments=False):
"""Returns a string to be written as a file"""
lines = []
Expand Down
3 changes: 2 additions & 1 deletion mpcontribs/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def delete_contributions(self, crit):

def submit_contribution(self, mpfile, contributor_email, project=None):
"""submit a single contribution to `mpcontribs.contributions` collection"""
mp_cat_id, data = mpfile.document.popitem(last=False)
mp_cat_id = mpfile.document.keys()[0]
data = mpfile.document[mp_cat_id]
update, cid = False, ObjectId() # TODO: new vs update
cid_short = get_short_object_id(cid)
collaborators = [contributor_email]
Expand Down
7 changes: 4 additions & 3 deletions mpcontribs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ def submit_mpfile(path_or_mpfile, target=None):
cid_short = get_short_object_id(cid)
else:
doc = cma.submit_contribution(mpfile_single, contributor)
cid_short = get_short_object_id(doc['_id'])
cid = doc['_id']
cid_short = get_short_object_id(cid)
print '> submitted as #{}'.format(cid_short)
# TODO embed cid into mpfile
mpfile_single.insert_id(cid, mp_cat_id)
print '> build contribution #{} into {} ...'.format(cid_short, mp_cat_id)
if target is not None:
url = target.build_contribution(cid)
print '> built #{}, see {}/{}'.format(cid_short, SITE, url)
else:
mcb = MPContributionsBuilder(doc)
single_build_doc = mcb.build(contributor, doc['_id'])
single_build_doc = mcb.build(contributor, cid)
build_doc.rec_update(single_build_doc)
print '> built #{}'.format(cid_short)
if target is not None and \
Expand Down

0 comments on commit e7fb477

Please sign in to comment.