本文整理汇总了Python中oc_platform.APIUtilities.success方法的典型用法代码示例。如果您正苦于以下问题:Python APIUtilities.success方法的具体用法?Python APIUtilities.success怎么用?Python APIUtilities.success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oc_platform.APIUtilities
的用法示例。
在下文中一共展示了APIUtilities.success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_mapping
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def create_mapping(request):
from_id = request.POST.get('from', None)
to_id = request.POST.get('to', None)
standards_category = TagCategory.objects.get(title='Standards')
try:
from_node = Tag.objects.get(pk=from_id, category=standards_category)
to_node = Tag.objects.get(pk=to_id, category=standards_category)
except:
return APIUtilities._api_not_found()
from meta.models import TagMapping
mapping = TagMapping(from_node=from_node, to_node=to_node)
mapping.save()
serialize_mapping = {
'id': mapping.id,
'from_id': from_node.id,
'from_title': from_node.title,
'to_id': to_node.id,
'to_title': to_node.title,
}
return APIUtilities.success(serialize_mapping)
示例2: events_around
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def events_around(request, around_date):
import datetime
import dateutil.parser
around = dateutil.parser.parse(around_date)
a_month = datetime.timedelta(days=31)
a_month_ago = around - a_month
after_one_month = around + a_month
from django.utils import timezone
now = timezone.now()
if (now > around):
events = Event.objects.filter(user=request.user, start__range=(
a_month_ago, around)).order_by('start')
else:
events = Event.objects.filter(user=request.user, start__range=(
around, after_one_month)).order_by('start')
serialized_events = {}
for event in events:
serialized_event = _serialize_event(event)
date = event.start.strftime('%Y-%m-%d')
if date in serialized_events:
serialized_events[date].append(serialized_event)
else:
serialized_events[date] = [serialized_event]
return APIUtilities.success(serialized_events)
示例3: autocomplete_standard
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def autocomplete_standard(request, query):
standards = Tag.objects.filter(
title__icontains=query, category=TagCategory.objects.get(title='Standards'))
limit = request.GET.get('limit', None)
result_set = []
def append_standard(standard_id, standard_title):
try:
next(
serialized_standard for serialized_standard in result_set if serialized_standard['id'] == standard_id)
except:
result_set.append({
'id': standard.id,
'title': standard.title,
})
if limit:
for standard in standards[:int(limit)]:
append_standard(standard.id, standard.title)
else:
for standard in standards:
append_standard(standard.id, standard.title)
return APIUtilities.success(result_set)
示例4: link_objective_to_standard
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def link_objective_to_standard(request):
objective_id = request.POST.get('objective_id', None)
standard_id = request.POST.get('standard_id', None)
remove_objective_id = request.POST.get('remove_objective_id', None)
standards_categories = TagCategory.objects.filter(title__in=['Standards', 'Objectives'])
try:
from curriculum.models import Objective
objective = Objective.objects.get(pk=objective_id)
previous_objective = Objective.objects.get(pk=remove_objective_id)
standard = Tag.objects.get(pk=standard_id, category__in=standards_categories)
except:
return APIUtilities._api_not_found()
if objective.parent:
return APIUtilities.failure({
'standard_id': objective.parent.id,
'standard_title': objective.parent.title
})
else:
previous_objective.parent = None
previous_objective.save()
objective.parent = standard
objective.save()
objective.parent = standard
objective.save()
return APIUtilities.success()
示例5: create_section
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def create_section(request):
parent_id = request.POST.get('parent_id', None)
is_unit = request.POST.get('is_unit', None)
title = request.POST.get('title', None)
section_type = request.POST.get('section_type', None)
position = request.POST.get('position', None)
settings = {
'type': section_type
}
try:
if is_unit:
parent = Unit.objects.get(pk=parent_id)
else:
parent = StandardCategory.objects.get(pk=parent_id)
except:
return APIUtilities._api_not_found()
new_section = Section(position=position, title=title, settings=settings)
new_section.save()
parent.sections.add(new_section)
context = {
'id': new_section.id
}
return APIUtilities.success(context)
示例6: add_url_to_section_item_resources
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def add_url_to_section_item_resources(request):
section_item_resources_id = request.POST.get('section_item_resources_id', None)
try:
section_item_resources = SectionItemResources.objects.get(pk=section_item_resources_id)
except:
section_item_resources = create_resource_set(request, section_item_resources)
if not section_item_resources:
return APIUtilities._api_not_found()
from oer.views import new_url_from_form
new_resource = new_url_from_form(
request.user, request.POST.get('title', None),
request.POST.get('url', None))
new_objective_resource = Resource(resource=new_resource)
new_objective_resource.save()
section_item_resources.resources.add(new_objective_resource)
context = {
'resource': {
'id': new_objective_resource.id,
'url': new_resource.revision.content.url,
'title': new_resource.title,
'thumbnail': settings.MEDIA_URL + new_resource.image.name if new_resource.image else '',
}
}
return APIUtilities.success(context)
示例7: get_sections
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def get_sections(request, unit_id):
try:
unit = Unit.objects.get(pk=unit_id)
except:
return APIUtilities._api_not_found()
return APIUtilities.success(get_serialized_sections(unit))
示例8: get_standard
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def get_standard(request, standard_id):
try:
standard = StandardCategory.objects.get(pk=standard_id)
except:
return APIUtilities._api_not_found()
return APIUtilities.success(get_serialized_sections(standard))
示例9: _get_daily_events
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def _get_daily_events(request, date, now):
from django.core.urlresolvers import reverse
import datetime
end = now + datetime.timedelta(days=1)
events = Event.objects.filter(
user=request.user,
start__gte=now,
end__lte=end,
).order_by('start')
serialized_events = []
for event in events:
serialized_event = {
'id': event.id,
'start': event.start.isoformat(),
'end': event.end.isoformat(),
'date': date,
'title': event.title,
'all_day': event.all_day,
'url': reverse(
'planner:event', kwargs={
'event_id': event.id,
}
)
}
serialized_events.append(serialized_event)
return APIUtilities.success(serialized_events)
示例10: reposition_sections
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def reposition_sections(request):
for section_id, section_position in request.POST.items():
section = Section.objects.get(pk=section_id)
section.position = int(section_position)
section.save()
return APIUtilities.success()
示例11: reposition_items
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def reposition_items(request):
for item_id, item_position in request.POST.items():
item = SectionItem.objects.get(pk=item_id)
item.position = int(item_position)
item.save()
return APIUtilities.success()
示例12: get_mappings
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def get_mappings(request, standard_id):
from meta.models import TagMapping
standards_category = TagCategory.objects.get(title='Standards')
try:
standard = Tag.objects.get(pk=standard_id, category=standards_category)
except:
return APIUtilities._api_not_found()
tag_mappings = TagMapping.objects.filter(from_node=standard)
serialized_tag_mappings = []
for tag_mapping in tag_mappings:
serialized_tag_mappings.append({
'id': tag_mapping.id,
'standard': tag_mapping.to_node.id,
'standardTitle': tag_mapping.to_node.title,
'notes': tag_mapping.deviation,
})
context = {
'mappings': serialized_tag_mappings
}
return APIUtilities.success(context)
示例13: push_changes
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def push_changes(request, curriculum_id):
import datetime
now = datetime.datetime.now().isoformat()
from curriculum.tasks import push_changes as push_changes_task
push_changes_task.delay(now, curriculum_id)
return APIUtilities.success({'lastPushed': now})
示例14: update_item
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def update_item(request):
item_id = request.POST.get('id', None)
description = request.POST.get('description', None)
try:
item = SectionItem.objects.get(pk=item_id)
except:
return APIUtilities._api_not_found()
try:
if description:
item.description = description
item.save()
context = { 'item': {
'id': item.id,
'description': item.description
}}
else:
new_metas = []
import re
for post_key, post_value in request.POST.items():
if 'meta' in post_key:
# Loop through the json objects.
match = re.match('meta\[(?P<num>\d+)\]\[(?P<key>.+)\]', post_key)
try:
new_metas[int(match.group('num'))][match.group('key')] = post_value
except:
new_metas.append({match.group('key'): post_value})
for new_meta in new_metas:
# If the meta object exists, update it.
try:
next(meta_item for meta_item in item.meta if meta_item['slug'] == new_meta['slug'])['body'] = new_meta['body']
except:
# If not, create it.
if not item.meta:
item.meta = []
item.meta.append({
'slug': new_meta['slug'],
'body': new_meta['body'],
'title': new_meta['title'],
'position': new_meta['position']
})
item.save()
context = {
'id': item.id,
'meta': item.meta
}
return APIUtilities.success(context)
except:
return APIUtilities._api_failure()
示例15: create_unit
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import success [as 别名]
def create_unit(request):
title = request.POST.get('title', None)
textbook_id = request.POST.get('textbook_id', None)
curriculum_id = request.POST.get('curriculum_id', None)
# Period properties.
period_type = request.POST.get('type', None)
unit = request.POST.get('unit', None)
begin = request.POST.get('begin', None)
end = request.POST.get('end', None)
period_from = request.POST.get('from', None)
period_to = request.POST.get('to', None)
position = request.POST.get('position', None)
parent = request.POST.get('parent', None)
if begin:
period = {
'type': period_type,
'unit': unit,
'begin': int(begin),
'end': int(end),
'from': period_from,
'to': period_to
}
else:
period = {
'type': period_type,
'unit': unit,
'position': int(position),
'parent': int(parent)
}
try:
curriculum = Curriculum.objects.get(pk=curriculum_id)
except:
return APIUtilities._api_not_found()
if textbook_id:
try:
textbook = Textbook.objects.get(pk=textbook_id)
except:
return APIUtilities._api_not_found()
else:
textbook = None
new_unit = Unit(title=title, period=period)
new_unit.save()
if textbook:
textbook.units.add(new_unit)
curriculum.units.add(new_unit)
context = {
'id': new_unit.id
}
return APIUtilities.success(context)