本文整理汇总了Python中oc_platform.APIUtilities._api_not_found方法的典型用法代码示例。如果您正苦于以下问题:Python APIUtilities._api_not_found方法的具体用法?Python APIUtilities._api_not_found怎么用?Python APIUtilities._api_not_found使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oc_platform.APIUtilities
的用法示例。
在下文中一共展示了APIUtilities._api_not_found方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_unit
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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)
示例2: add_url_to_section_item_resources
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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)
示例3: asynchronous_view
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [as 别名]
def asynchronous_view(request, resource_id):
from oer.views import render_resource
try:
resource = Resource.objects.get(pk=resource_id)
except:
return APIUtilities._api_not_found()
(resource, resource_type, revision) = render_resource(resource.resource.id)
from django.template import Template, Context
template = Template(open(
settings.TEMPLATE_DIR + '/templates/partials/resource-body.html', 'r').read())
context = Context({
'MEDIA_URL': settings.MEDIA_URL,
'STATIC_URL': settings.STATIC_URL,
'debug': settings.DEBUG,
'resource': resource
})
template_html = template.render(context)
from django.http import HttpResponse
return HttpResponse(
template_html, 200,
content_type="text/html"
)
示例4: get_standard
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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))
示例5: get_sections
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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))
示例6: create_section
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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)
示例7: delete_comment
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [as 别名]
def delete_comment(request, comment_id):
try:
comment = Comment.objects.get(pk=comment_id)
# TODO(Varun): Same logic as duplicated from template generation to show
# delete button
from interactions.CommentUtilities import CommentUtilities
(host_type, host, root) = CommentUtilities.get_comment_root(comment)
if host_type.name == 'project':
if request.user == comment.user or request.user in host.admins.all():
# Delete all descendant elements of this comment.
delete_comment_tree(comment)
return APIUtilities._api_success()
else:
return APIUtilities._api_unauthorized_failure()
elif host_type.name == 'resource':
if request.user == comment.user or (
request.user in host.collaborators.all() or
request.user == host.creator):
delete_comment_tree(comment)
return APIUtilities._api_success()
return APIUtilities._api_failure()
except Comment.DoesNotExist:
return APIUtilities._api_not_found()
示例8: link_objective_to_standard
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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()
示例9: get_resource_vote_count
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [as 别名]
def get_resource_vote_count(request, resource_id):
try:
from oer.models import Resource
resource = Resource.objects.get(pk=resource_id)
except:
return APIUtilities._api_not_found()
try:
from django.contrib.contenttypes.models import ContentType
resource_ct = ContentType.objects.get_for_model(Resource)
upvotes = Vote.objects.filter(
parent_id=resource.id, parent_type=resource_ct, positive=1)
downvotes = Vote.objects.filter(
parent_id=resource.id, parent_type=resource_ct, positive=0)
user_upvoted = False
user_downvoted = False
if (request.user.is_authenticated()):
if upvotes.filter(user=request.user).count() > 0:
user_upvoted = True
if downvotes.filter(user=request.user).count() > 0:
user_downvoted = True
context = {
'upvote_count': upvotes.count(),
'downvote_count': downvotes.count(),
'user_upvoted': 'true' if user_upvoted else 'false',
'user_downvoted': 'true' if user_downvoted else 'false'
}
return APIUtilities._api_success(context)
except:
return APIUtilities._api_failure()
示例10: create_mapping
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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)
示例11: get_mappings
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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)
示例12: favorite
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [as 别名]
def favorite(request, resource_id):
try:
resource = Resource.objects.get(pk=resource_id)
except:
return APIUtilities._api_not_found()
from interactions.views import favorite_resource
return favorite_resource(request, 'resource', resource.resource.id)
示例13: update_item
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [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()
示例14: get_curriculum
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [as 别名]
def get_curriculum(request, curriculum_id):
try:
curriculum = Curriculum.objects.get(pk=curriculum_id)
except:
return APIUtilities._api_not_found()
def get_serialized_standard_children(standard):
sub_standards = []
for sub_standard in standard.standard_categories.all():
sub_standards.append(
get_serialized_standard_children(sub_standard))
return {
'id': standard.id,
'title': standard.title,
'standards': sub_standards
}
serialized_textbooks = []
serialized_units = []
serialized_standards = []
for textbook in curriculum.textbooks.all():
serialized_textbook_units = []
for unit in curriculum.units.all():
if unit in textbook.units.all():
serialized_textbook_units.append({
'id': unit.id,
'textbook_id': textbook.id
})
serialized_textbooks.append({
'id': textbook.id,
'title': textbook.title,
'description': textbook.description,
'thumbnail': settings.MEDIA_URL + textbook.thumbnail.name,
'units': serialized_textbook_units
})
for unit in curriculum.units.all():
serialized_units.append({
'id': unit.id,
'title': unit.title,
'period': unit.period
})
for standard_category in curriculum.standard_categories.all():
serialized_standards.append(
get_serialized_standard_children(standard_category))
return APIUtilities.success({
'textbooks': serialized_textbooks,
'units': serialized_units,
'standards': serialized_standards
})
示例15: delete_event
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_not_found [as 别名]
def delete_event(request, event_id):
try:
event = Event.objects.get(pk=event_id)
except:
return APIUtilities._api_not_found()
if request.user != event.user:
return APIUtilities._api_unauthorized_failure()
event.delete()
return APIUtilities.success()