本文整理汇总了Python中reversion.set_user方法的典型用法代码示例。如果您正苦于以下问题:Python reversion.set_user方法的具体用法?Python reversion.set_user怎么用?Python reversion.set_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reversion
的用法示例。
在下文中一共展示了reversion.set_user方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _save_as_revision
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def _save_as_revision(self, object_list, user, comment):
for object in object_list:
object.save()
reversion.set_user(user=user)
reversion.set_comment(comment=comment)
示例2: event_undelete
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def event_undelete(request, event_id):
request.user.is_authenticated() and reversion.set_user(request.user)
try:
deleted_version = Version.objects. \
get_deleted(Event).get(object_id=event_id)
except Version.DoesNotExist:
raise Http404
# TODO ask the user for a reason for the undeletion
deleted_revision = deleted_version.revision
revisioninfos = deleted_revision.revisioninfo_set.all()
# a revision should have only one revisioninfo (design constraint)
# TODO check this constranint with a post_save signal in revisioninfo
assert len( revisioninfos ) == 1
revisioninfo = revisioninfos[0]
# we check if there is an event with the same name and start date
# TODO test when there is one
as_text = revisioninfo.as_text
simple_fields = Event.get_fields( as_text )[0]
title = simple_fields['title']
start = simple_fields['start']
try:
equal = Event.objects.get( title = title,
dates__eventdate_name = start )
except Event.DoesNotExist:
deleted_revision.revert()
reversion.add_meta( RevisionInfo, as_text = as_text )
equal = False
if not equal:
messages.info( request, _('Event has been successfully undeleted.') )
return HttpResponseRedirect( reverse(
'event_show_all', kwargs = {'event_id': event_id} ) )
messages.error( request, _( 'Undelete operation not possible' ) )
templates = {
'title': _( "undelete event %(event_nr)s" ) % \
{'event_nr': deleted_version.object_id,},
'as_text': as_text,
'event_id': event_id,
'title': title,
'start': start,
'equal': equal,}
return render(request, 'event_undelete_error.html', templates)
示例3: update_from_korben
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def update_from_korben(self):
"""Update the model fields from Korben.
:return the new instance
"""
with reversion.create_revision():
korben_data = self._convert_model_to_korben_format()
korben_response = self.korben_connector.get(data=korben_data)
self._map_korben_response_to_model_instance(korben_response)
self.save(as_korben=True)
reversion.set_user(get_korben_user())
reversion.set_comment('Updated by Korben')
return self
示例4: testCanAddMetaToRevision
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def testCanAddMetaToRevision(self):
# Create a revision with lots of meta data.
with reversion.create_revision():
self.test11.save()
reversion.set_comment("Foo bar")
self.assertEqual(reversion.get_comment(), "Foo bar")
reversion.set_user(self.user)
self.assertEqual(reversion.get_user(), self.user)
reversion.add_meta(RevisionMeta, age=5)
# Test the revision data.
revision = reversion.get_for_object(self.test11)[0].revision
self.assertEqual(revision.user, self.user)
self.assertEqual(revision.comment, "Foo bar")
self.assertEqual(revision.revisionmeta.age, 5)
示例5: generate_pairings_view
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def generate_pairings_view(self, request, object_id):
round_ = get_object_or_404(Round, pk=object_id)
if not request.user.has_perm('tournament.generate_pairings', round_.season.league):
raise PermissionDenied
if request.method == 'POST':
form = forms.GeneratePairingsForm(request.POST)
if form.is_valid():
try:
if form.cleaned_data['run_in_background']:
signals.do_generate_pairings.send(sender=self.__class__, round_id=round_.pk, overwrite=form.cleaned_data['overwrite_existing'])
self.message_user(request, 'Generating pairings in background.', messages.INFO)
return redirect('admin:review_pairings', object_id)
else:
pairinggen.generate_pairings(round_, overwrite=form.cleaned_data['overwrite_existing'])
with reversion.create_revision():
reversion.set_user(request.user)
reversion.set_comment('Generated pairings.')
round_.publish_pairings = False
round_.save()
self.message_user(request, 'Pairings generated.', messages.INFO)
return redirect('admin:review_pairings', object_id)
except pairinggen.PairingsExistException:
if not round_.publish_pairings:
self.message_user(request, 'Unpublished pairings already exist.', messages.WARNING)
return redirect('admin:review_pairings', object_id)
self.message_user(request, 'Pairings already exist for the selected round.', messages.ERROR)
except pairinggen.PairingHasResultException:
self.message_user(request, 'Pairings with results can\'t be overwritten.', messages.ERROR)
except pairinggen.PairingGenerationException as e:
self.message_user(request, 'Error generating pairings. %s' % e.message, messages.ERROR)
return redirect('admin:generate_pairings', object_id=round_.pk)
else:
form = forms.GeneratePairingsForm()
context = {
'has_permission': True,
'opts': self.model._meta,
'site_url': '/',
'original': round_,
'title': 'Generate pairings',
'form': form
}
return render(request, 'tournament/admin/generate_pairings.html', context)
示例6: reject_registration
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def reject_registration(self, request, object_id):
reg = get_object_or_404(Registration, pk=object_id)
if not request.user.has_perm('tournament.change_registration', reg.season.league):
raise PermissionDenied
if reg.status != 'pending':
return redirect('admin:review_registration', object_id)
if request.method == 'POST':
changelist_filters = request.POST.get('_changelist_filters', '')
form = forms.RejectRegistrationForm(request.POST, registration=reg)
if form.is_valid():
if 'confirm' in form.data:
with reversion.create_revision():
reversion.set_user(request.user)
reversion.set_comment('Rejected registration.')
reg.status = 'rejected'
reg.status_changed_by = request.user.username
reg.status_changed_date = timezone.now()
reg.save()
self.message_user(request, 'Registration for "%s" rejected.' % reg.lichess_username, messages.INFO)
return redirect_with_params('admin:tournament_registration_changelist', params='?' + changelist_filters)
else:
return redirect('admin:review_registration', object_id)
return redirect_with_params('admin:review_registration', object_id, params='?_changelist_filters=' + urlquote(changelist_filters))
else:
changelist_filters = request.GET.get('_changelist_filters', '')
form = forms.RejectRegistrationForm(registration=reg)
context = {
'has_permission': True,
'opts': self.model._meta,
'site_url': '/',
'original': reg,
'title': 'Confirm rejection',
'form': form,
'changelist_filters': changelist_filters
}
return render(request, 'tournament/admin/reject_registration.html', context)
示例7: run
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def run(self, complete_round=False, complete_season=False, update_board_order=False, generate_pairings=False, background=False, user=None):
msg_list = []
round_to_close = self.round_to_close
round_to_open = self.round_to_open
season_to_close = self.season_to_close
with transaction.atomic():
if complete_round and round_to_close is not None:
with reversion.create_revision():
reversion.set_user(user)
reversion.set_comment('Closed round.')
round_to_close.is_completed = True
round_to_close.save()
msg_list.append(('Round %d set as completed.' % round_to_close.number, messages.INFO))
if complete_season and season_to_close is not None and (round_to_close is None or round_to_close.is_completed):
with reversion.create_revision():
reversion.set_user(user)
reversion.set_comment('Closed season.')
season_to_close.is_completed = True
season_to_close.save()
msg_list.append(('%s set as completed.' % season_to_close.name, messages.INFO))
if update_board_order and round_to_open is not None and self.season.league.competitor_type == 'team':
try:
UpdateBoardOrderWorkflow(self.season).run(alternates_only=False)
msg_list.append(('Board order updated.', messages.INFO))
except IndexError:
msg_list.append(('Error updating board order.', messages.ERROR))
return msg_list
if generate_pairings and round_to_open is not None:
if background:
signals.do_generate_pairings.send(sender=self.__class__, round_id=round_to_open.pk)
msg_list.append(('Generating pairings in background.', messages.INFO))
else:
try:
pairinggen.generate_pairings(round_to_open, overwrite=False)
with reversion.create_revision():
reversion.set_user(user)
reversion.set_comment('Generated pairings.')
round_to_open.publish_pairings = False
round_to_open.save()
msg_list.append(('Pairings generated.', messages.INFO))
except pairinggen.PairingsExistException:
msg_list.append(('Unpublished pairings already exist.', messages.WARNING))
except pairinggen.PairingHasResultException:
msg_list.append(('Pairings with results can\'t be overwritten.', messages.ERROR))
except pairinggen.PairingGenerationException as e:
msg_list.append(('Error generating pairings. %s' % e.message, messages.ERROR))
return msg_list
示例8: _change_recurrences
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_user [as 别名]
def _change_recurrences( user, event, events ): # {{{1
""" modifies the events in ``events`` with the data of ``event`` except for
``start`` and ``end``, and including urls changes also. """
if not events:
return
for rec in events:
assert rec.recurring.master == event.recurring.master
something_changed = False
with reversion.create_revision():
user.is_authenticated() and reversion.set_user(user)
for field in Event.get_simple_fields():
if field in ['startdate', 'enddate']:
continue
if getattr(rec, field) != getattr(event, field):
setattr( rec, field, getattr( event, field ) )
something_changed = True
if rec.description != event.description:
rec.description = event.description
something_changed = True
rec_urls = rec.urls.all()
event_urls = event.urls.all()
for i in range( max( len(rec_urls), len(event_urls) ) ):
if i < len( rec_urls ) and i < len( event_urls ):
url_changed = False
if rec_urls[i].url_name != event_urls[i].url_name:
rec_urls[i].url_name = event_urls[i].url_name
url_changed = True
if rec_urls[i].url != event_urls[i].url:
rec_urls[i].url = event_urls[i].url
url_changed = True
if url_changed:
rec_urls[i].save()
something_changed = True
elif i >= len( event_urls ):
rec_urls[i].delete()
something_changed = True
else:
assert i >= len( rec_urls )
EventUrl.objects.create(
event = rec,
url_name = event_urls[i].url_name,
url = event_urls[i].url )
something_changed = True
if something_changed:
rec.version = rec.version + 1
rec.save()
reversion.add_meta( RevisionInfo,
as_text = smart_unicode( rec.as_text() ) )
# def event_new_raw( request, template_event_id = None ): {{{1