New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to clone a contribution #3207

Merged
merged 2 commits into from Jan 26, 2018

Conversation

Projects
None yet
2 participants
@mic4ael
Member

mic4ael commented Jan 17, 2018

No description provided.

self._synchronize_friendly_id(new_event)
db.session.flush()
return {'contrib_map': self._contrib_map, 'subcontrib_map': self._subcontrib_map}
def _clone_contribs(self, new_event):
def _create_new_contribution(self, event, contribution, excluded_attrs=None):

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

I think keeping it named old_contrib is clearer, since then you have <new|old>_contrib instead of new_contrib and contribution.

class RHCloneContribution(RHManageContributionBase):
def _process(self):
clone_contribution(self.event, self.contrib, False)

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

I would use a kwarg for the last one, or just omit it and set a default value of False.

def _process(self):
clone_contribution(self.event, self.contrib, False)
db.session.commit()
return jsonify_data(html=self.list_generator.render_list()['html'])

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

What about using the same way like we do for all the other endpoints?

return jsonify_data(**self.list_generator.render_list())

Not sure if there's anything besides html but if it's used to update the contribution list it'd probably break if we ever added something else since here that would then be missing.

}
if preserve_session:
shared_data['sessions']['session_map'][contribution.session] = contribution.session

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

You could always populate this above; no harm in having it even when the session is not used.

def clone_contribution(event, contribution, preserve_session):
shared_data = {
'event_persons': {'person_map': {person: person for person in event.persons}},

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

You could actually do this: dict(zip(event.persons, event.persons))

The literals you used are also quite clear, just mentioning that this would work too :p

shared_data['sessions']['session_block_map'][contribution.session_block] = contribution.session_block
cloner = ContributionCloner(event, contribution=contribution, preserve_session=preserve_session)
cloner.run(event, [], shared_data)

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

the 2nd argument is usually a set. so maybe passing an empty set() is safer

.first())
def _process(self):
clone_contribution(self.event, self.contribution, True)

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

kwarg style for the last arg

def _process(self):
clone_contribution(self.event, self.contribution, True)
db.session.commit()

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

why are you committing here? db.session.flush() is all you need if you just need to populate the id and default args

class RHCloneContribution(RHManageContributionBase):
def _process(self):
clone_contribution(self.event, self.contrib, False)
db.session.commit()

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 17, 2018

Member

why are you committing here? db.session.flush() is all you need if you just need to populate the id and default args

@mic4ael mic4ael force-pushed the mic4ael:cloning-contributions branch from cc14f2c to 936bf93 Jan 22, 2018

new_contrib.acl_entries = clone_principals(ContributionPrincipal, old_contrib.acl_entries)
new_contrib.references = list(self._clone_references(ContributionReference, old_contrib.references))
new_contrib.person_links = list(self._clone_person_links(ContributionPersonLink,
old_contrib.person_links))

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 24, 2018

Member

I think this now fits in one line

if self.preserve_session:
entry = schedule_contribution(new_contribution, self.contribution.timetable_entry.start_dt,
session_block=new_contribution.session_block)
self.old_event.timetable_entries.append(entry)

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 24, 2018

Member

I really dislike the idea of using old_event for any operation that creates something new. When cloning something within the event, the new event should be the same as old_event anyway, but by not using the old event you remove the risk of code actually messing with the old event during normal event cloning.

This comment has been minimized.

@mic4ael

mic4ael Jan 24, 2018

Member

Good point.

self._clone_contrib()
else:
self._clone_contribs(new_event)
self._synchronize_friendly_id(new_event)

This comment has been minimized.

@ThiefMaster

ThiefMaster Jan 24, 2018

Member

This shouldn't run when cloning a single contribution.

@mic4ael mic4ael force-pushed the mic4ael:cloning-contributions branch 6 times, most recently from 9330c58 to 643aa54 Jan 24, 2018

@ThiefMaster ThiefMaster force-pushed the mic4ael:cloning-contributions branch from c9abe22 to db83e62 Jan 26, 2018

Simplify same-event contribution cloning logic
Also:

- add a changelog entry
- fix timetable balloon behavior when clicking the clone button

@ThiefMaster ThiefMaster force-pushed the mic4ael:cloning-contributions branch from db83e62 to 1dfd5a9 Jan 26, 2018

@ThiefMaster ThiefMaster merged commit 1dfd5a9 into indico:master Jan 26, 2018

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@mic4ael mic4ael deleted the mic4ael:cloning-contributions branch Jan 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment