本文整理匯總了Python中django.contrib.admin.models.ADDITION屬性的典型用法代碼示例。如果您正苦於以下問題:Python models.ADDITION屬性的具體用法?Python models.ADDITION怎麽用?Python models.ADDITION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.contrib.admin.models
的用法示例。
在下文中一共展示了models.ADDITION屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: clone
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def clone(self, user):
clone = copy(self)
clone.name = self.__get_clone_name()
clone._state.adding = True
clone.pk = None
# avoid cloned templates to be flagged as default
# to avoid potential unwanted duplications in
# newly registrated devices
clone.default = False
clone.full_clean()
clone.save()
ct = ContentType.objects.get(model='template')
LogEntry.objects.log_action(
user_id=user.id,
content_type_id=ct.pk,
object_id=clone.pk,
object_repr=clone.name,
action_flag=ADDITION,
)
return clone
示例2: test_log_actions
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def test_log_actions(self):
ma = ModelAdmin(Band, self.site)
mock_request = MockRequest()
mock_request.user = User.objects.create(username='bill')
content_type = get_content_type_for_model(self.band)
tests = (
(ma.log_addition, ADDITION, {'added': {}}),
(ma.log_change, CHANGE, {'changed': {'fields': ['name', 'bio']}}),
(ma.log_deletion, DELETION, str(self.band)),
)
for method, flag, message in tests:
with self.subTest(name=method.__name__):
created = method(mock_request, self.band, message)
fetched = LogEntry.objects.filter(action_flag=flag).latest('id')
self.assertEqual(created, fetched)
self.assertEqual(fetched.action_flag, flag)
self.assertEqual(fetched.content_type, content_type)
self.assertEqual(fetched.object_id, str(self.band.pk))
self.assertEqual(fetched.user, mock_request.user)
if flag == DELETION:
self.assertEqual(fetched.change_message, '')
self.assertEqual(fetched.object_repr, message)
else:
self.assertEqual(fetched.change_message, str(message))
self.assertEqual(fetched.object_repr, str(self.band))
示例3: lookups
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def lookups(self, request, model_admin):
return (
(admin_models.ADDITION, 'Added'),
(admin_models.CHANGE, 'Changed'),
(admin_models.DELETION, 'Deleted'),
)
示例4: addition
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def addition(request, object):
"""
Log that an object has been successfully added.
"""
models.LogEntry.objects.log_action(
user_id=request.user.pk,
content_type_id=ContentType.objects.get_for_model(object).pk,
object_id=object.pk,
object_repr=force_str(object),
action_flag=models.ADDITION,
)
示例5: log_addition
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def log_addition(self, request, object, message):
"""
Log that an object has been successfully added.
The default implementation creates an admin LogEntry object.
"""
from django.contrib.admin.models import LogEntry, ADDITION
return LogEntry.objects.log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(object).pk,
object_id=object.pk,
object_repr=str(object),
action_flag=ADDITION,
change_message=message,
)
示例6: log_addition
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def log_addition(self, request, object, message):
"""
Log that an object has been successfully added.
The default implementation creates an admin LogEntry object.
"""
from django.contrib.admin.models import LogEntry, ADDITION
return LogEntry.objects.log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(object).pk,
object_id=object.pk,
object_repr=force_text(object),
action_flag=ADDITION,
change_message=message,
)
示例7: post
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def post(request):
u"""Method responsible for saving new offer.
:param request: WSGIRequest instance
"""
form = CreateOfferForm(request.POST)
if form.is_valid():
offer = form.save()
offer.create_new()
offer.save()
save_history(request, offer, action=ADDITION)
send_mail(
request,
'offer_creation',
['administrators@volontuloapp.org'],
{'offer': offer}
)
messages.success(request, u"Dziękujemy za dodanie oferty.")
return redirect(
'offers_view',
slug=slugify(offer.title),
id_=offer.id,
)
messages.error(
request,
u"Formularz zawiera niepoprawnie wypełnione pola <br />{0}".format(
'<br />'.join(form.errors)),
)
return render(
request,
'offers/offer_form.html',
{
'form': form,
'offer': Offer(),
'organizations': request.user.userprofile.organizations.all(),
}
)
示例8: log_addition
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def log_addition(self, request, object, message):
"""
Log that an object has been successfully added.
The default implementation creates an admin LogEntry object.
"""
from django.contrib.admin.models import LogEntry, ADDITION
LogEntry.objects.log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(object).pk,
object_id=object.pk,
object_repr=force_text(object),
action_flag=ADDITION,
change_message=message,
)
示例9: test_logentry_unicode
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def test_logentry_unicode(self):
log_entry = LogEntry()
log_entry.action_flag = ADDITION
self.assertTrue(str(log_entry).startswith('Added '))
log_entry.action_flag = CHANGE
self.assertTrue(str(log_entry).startswith('Changed '))
log_entry.action_flag = DELETION
self.assertTrue(str(log_entry).startswith('Deleted '))
# Make sure custom action_flags works
log_entry.action_flag = 4
self.assertEqual(str(log_entry), 'LogEntry Object')
示例10: test_proxy_model_content_type_is_used_for_log_entries
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def test_proxy_model_content_type_is_used_for_log_entries(self):
"""
Log entries for proxy models should have the proxy model's contenttype
(#21084).
"""
proxy_content_type = ContentType.objects.get_for_model(ArticleProxy, for_concrete_model=False)
post_data = {
'site': self.site.pk, 'title': "Foo", 'hist': "Bar",
'created_0': '2015-12-25', 'created_1': '00:00',
}
changelist_url = reverse('admin:admin_utils_articleproxy_changelist')
# add
proxy_add_url = reverse('admin:admin_utils_articleproxy_add')
response = self.client.post(proxy_add_url, post_data)
self.assertRedirects(response, changelist_url)
proxy_addition_log = LogEntry.objects.latest('id')
self.assertEqual(proxy_addition_log.action_flag, ADDITION)
self.assertEqual(proxy_addition_log.content_type, proxy_content_type)
# change
article_id = proxy_addition_log.object_id
proxy_change_url = reverse('admin:admin_utils_articleproxy_change', args=(article_id,))
post_data['title'] = 'New'
response = self.client.post(proxy_change_url, post_data)
self.assertRedirects(response, changelist_url)
proxy_change_log = LogEntry.objects.latest('id')
self.assertEqual(proxy_change_log.action_flag, CHANGE)
self.assertEqual(proxy_change_log.content_type, proxy_content_type)
# delete
proxy_delete_url = reverse('admin:admin_utils_articleproxy_delete', args=(article_id,))
response = self.client.post(proxy_delete_url, {'post': 'yes'})
self.assertRedirects(response, changelist_url)
proxy_delete_log = LogEntry.objects.latest('id')
self.assertEqual(proxy_delete_log.action_flag, DELETION)
self.assertEqual(proxy_delete_log.content_type, proxy_content_type)
示例11: post
# 需要導入模塊: from django.contrib.admin import models [as 別名]
# 或者: from django.contrib.admin.models import ADDITION [as 別名]
def post(self, request, *args, **kwargs):
"""
Perform the actual import action (after the user has confirmed he
wishes to import)
"""
resource = self.get_import_resource_class()(**self.get_import_resource_kwargs(request, *args, **kwargs))
confirm_form = ConfirmImportForm(request.POST)
if confirm_form.is_valid():
import_formats = self.get_import_formats()
input_format = import_formats[
int(confirm_form.cleaned_data['input_format'])
]()
tmp_storage = self.get_tmp_storage_class()(name=confirm_form.cleaned_data['import_file_name'])
data = tmp_storage.read(input_format.get_read_mode())
if not input_format.is_binary() and self.from_encoding:
data = force_text(data, self.from_encoding)
dataset = input_format.create_dataset(data)
result = resource.import_data(dataset, dry_run=False,
raise_errors=True,
file_name=confirm_form.cleaned_data['original_file_name'],
user=request.user)
if not self.get_skip_admin_log():
# Add imported objects to LogEntry
logentry_map = {
RowResult.IMPORT_TYPE_NEW: ADDITION,
RowResult.IMPORT_TYPE_UPDATE: CHANGE,
RowResult.IMPORT_TYPE_DELETE: DELETION,
}
content_type_id = ContentType.objects.get_for_model(self.model).pk
for row in result:
if row.import_type != row.IMPORT_TYPE_ERROR and row.import_type != row.IMPORT_TYPE_SKIP:
LogEntry.objects.log_action(
user_id=request.user.pk,
content_type_id=content_type_id,
object_id=row.object_id,
object_repr=row.object_repr,
action_flag=logentry_map[row.import_type],
change_message="%s through import_export" % row.import_type,
)
success_message = str(_(u'Import finished')) + ' , ' + str(_(u'Add')) + ' : %d' % result.totals[
RowResult.IMPORT_TYPE_NEW] + ' , ' + str(_(u'Update')) + ' : %d' % result.totals[
RowResult.IMPORT_TYPE_UPDATE]
messages.success(request, success_message)
tmp_storage.remove()
post_import.send(sender=None, model=self.model)
model_info = (self.opts.app_label, self.opts.model_name)
url = reverse('xadmin:%s_%s_changelist' % model_info,
current_app=self.admin_site.name)
return HttpResponseRedirect(url)