本文整理汇总了Python中webui.models.Collection.from_request方法的典型用法代码示例。如果您正苦于以下问题:Python Collection.from_request方法的具体用法?Python Collection.from_request怎么用?Python Collection.from_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webui.models.Collection
的用法示例。
在下文中一共展示了Collection.from_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: csv_export
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def csv_export( request, repo, org, cid, model=None ):
"""
"""
if (not model) or (not (model in ['entity','file'])):
raise Http404
collection = Collection.from_request(request)
things = {'entity':'objects', 'file':'files'}
csv_path = settings.CSV_EXPORT_PATH[model] % collection.id
csv_filename = os.path.basename(csv_path)
if model == 'entity':
file_url = reverse('webui-collection-csv-entities', args=collection.idparts)
elif model == 'file':
file_url = reverse('webui-collection-csv-files', args=collection.idparts)
# do it
result = csv_export_model.apply_async( (collection.path,model), countdown=2)
# add celery task_id to session
celery_tasks = request.session.get(settings.CELERY_TASKS_SESSION_KEY, {})
# IMPORTANT: 'action' *must* match a message in webui.tasks.TASK_STATUS_MESSAGES.
task = {'task_id': result.task_id,
'action': 'webui-csv-export-model',
'collection_id': collection.id,
'collection_url': collection.absolute_url(),
'things': things[model],
'file_name': csv_filename,
'file_url': file_url,
'start': datetime.now().strftime(settings.TIMESTAMP_FORMAT),}
celery_tasks[result.task_id] = task
request.session[settings.CELERY_TASKS_SESSION_KEY] = celery_tasks
return HttpResponseRedirect(collection.absolute_url())
示例2: csv_download
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def csv_download( request, repo, org, cid, model=None ):
"""Offers CSV file in settings.CSV_TMPDIR for download.
File must actually exist in settings.CSV_EXPORT_PATH and be readable.
File must be readable by Python csv module.
If all that is true then it must be a legal CSV file.
"""
collection = Collection.from_request(request)
path = settings.CSV_EXPORT_PATH[model] % collection.id
filename = os.path.basename(path)
if not os.path.exists(path):
raise Http404
import csv
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
writer = csv.writer(
response,
delimiter=fileio.CSV_DELIMITER,
quotechar=fileio.CSV_QUOTECHAR,
quoting=fileio.CSV_QUOTING
)
with open(path, 'rb') as f:
reader = csv.reader(
f,
delimiter=fileio.CSV_DELIMITER,
quotechar=fileio.CSV_QUOTECHAR,
quoting=fileio.CSV_QUOTING
)
for row in reader:
writer.writerow(row)
return response
示例3: changelog
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def changelog( request, repo, org, cid ):
collection = Collection.from_request(request)
alert_if_conflicted(request, collection)
return render_to_response(
'webui/collections/changelog.html',
{'collection': collection,},
context_instance=RequestContext(request, processors=[])
)
示例4: newexpert
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def newexpert( request, repo, org, cid ):
"""Ask for Entity ID, then create new Entity.
"""
git_name = request.session.get('git_name')
git_mail = request.session.get('git_mail')
if not git_name and git_mail:
messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
collection = Collection.from_request(request)
if collection.locked():
messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
return HttpResponseRedirect(entity.absolute_url())
collection.repo_fetch()
if collection.repo_behind():
messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
return HttpResponseRedirect(entity.absolute_url())
if request.method == 'POST':
form = NewEntityForm(request.POST)
if form.is_valid():
# TODO replace with Identifier
entity_id = '-'.join([repo, org, str(cid), str(form.cleaned_data['eid'])])
entity_ids = [entity.id for entity in collection.entities(quick=True)]
is_legal = False
already_exists = False
if '-'.join([repo, org, str(cid)]) == collection.id:
is_legal = True
else:
messages.error(request, "Can only create objects in this collection. Try again.")
if entity_id in entity_ids:
already_exists = True
messages.error(request, "That object ID already exists. Try again.")
if entity_id and is_legal and not already_exists:
collection_entity_newexpert(
request,
collection, entity_id,
git_name, git_mail
)
return HttpResponseRedirect(reverse('webui-collection-children', args=collection.idparts))
else:
data = {
'repo':repo,
'org':org,
'cid':cid,
}
form = NewEntityForm(data)
return render_to_response(
'webui/entities/new.html',
{'repo': repo,
'org': org,
'cid': cid,
'collection': collection,
'form': form,
},
context_instance=RequestContext(request, processors=[])
)
示例5: merge
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def merge( request, repo, org, cid ):
"""
Decides how to merge the various files in a merge conflict.
Sends user around to different editors and things until everything is merged.
"""
collection = Collection.from_request(request)
repository = dvcs.repository(collection.path_abs)
task_id = collection.locked()
status = commands.status(collection)
ahead = collection.repo_ahead()
behind = collection.repo_behind()
diverged = collection.repo_diverged()
conflicted = collection.repo_conflicted()
unmerged = dvcs.list_conflicted(repository)
staged = dvcs.list_staged(repository)
if request.method == 'POST':
form = MergeCommitForm(request.POST)
if form.is_valid():
which = form.cleaned_data['which']
if which == 'merge':
dvcs.merge_commit(repository)
committed = 1
elif which == 'commit':
dvcs.diverge_commit(repository)
committed = 1
else:
committed = 0
if committed:
if task_id:
collection.unlock(task_id)
messages.error(request, 'Merge conflict has been resolved. Please sync to make your changes available to other users.')
return HttpResponseRedirect( reverse('webui-collection', args=[repo,org,cid]) )
return HttpResponseRedirect( reverse('webui-merge', args=[repo,org,cid]) )
else:
which = 'unknown'
if conflicted and not unmerged:
which = 'merge'
elif diverged and staged:
which = 'commit'
form = MergeCommitForm({'path':collection.path, 'which':which,})
return render_to_response(
'webui/merge/index.html',
{'repo': repo,
'org': org,
'cid': cid,
'collection_path': collection.path,
'collection': collection,
'status': status,
'conflicted': conflicted,
'ahead': ahead,
'behind': behind,
'unmerged': unmerged,
'diverged': diverged,
'staged': staged,
'form': form,},
context_instance=RequestContext(request, processors=[])
)
示例6: sync_status_ajax
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def sync_status_ajax( request, repo, org, cid ):
collection = Collection.from_request(request)
gitstatus = collection.gitstatus()
if gitstatus:
sync_status = gitstatus['sync_status']
if sync_status.get('timestamp',None):
sync_status['timestamp'] = sync_status['timestamp'].strftime(settings.TIMESTAMP_FORMAT)
return HttpResponse(json.dumps(sync_status), content_type="application/json")
raise Http404
示例7: detail
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def detail( request, repo, org, cid ):
collection = Collection.from_request(request)
collection.model_def_commits()
collection.model_def_fields()
alert_if_conflicted(request, collection)
return render_to_response(
'webui/collections/detail.html',
{'collection': collection,
'collection_unlock_url': collection.unlock_url(collection.locked()),},
context_instance=RequestContext(request, processors=[])
)
示例8: unlock
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def unlock( request, repo, org, cid, task_id ):
"""Provides a way to remove collection lockfile through the web UI.
"""
git_name = request.session.get('git_name')
git_mail = request.session.get('git_mail')
if not git_name and git_mail:
messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
collection = Collection.from_request(request)
if task_id and collection.locked() and (task_id == collection.locked()):
collection.unlock(task_id)
messages.success(request, 'Collection <b>%s</b> unlocked.' % collection.id)
return HttpResponseRedirect(collection.absolute_url())
示例9: git_status
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def git_status( request, repo, org, cid ):
collection = Collection.from_request(request)
alert_if_conflicted(request, collection)
gitstatus = collection.gitstatus()
remotes = dvcs.remotes(dvcs.repository(collection.path))
return render_to_response(
'webui/collections/git-status.html',
{'collection': collection,
'status': gitstatus.get('status', 'git-status unavailable'),
'astatus': gitstatus.get('annex_status', 'annex-status unavailable'),
'timestamp': gitstatus.get('timestamp'),
'remotes': remotes,
},
context_instance=RequestContext(request, processors=[])
)
示例10: children
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def children( request, repo, org, cid ):
collection = Collection.from_request(request)
alert_if_conflicted(request, collection)
objects = collection.children(quick=True)
# paginate
thispage = request.GET.get('page', 1)
paginator = Paginator(objects, settings.RESULTS_PER_PAGE)
page = paginator.page(thispage)
return render_to_response(
'webui/collections/entities.html',
{'collection': collection,
'paginator': paginator,
'page': page,
'thispage': thispage,},
context_instance=RequestContext(request, processors=[])
)
示例11: edit
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def edit( request, repo, org, cid ):
git_name = request.session.get('git_name')
git_mail = request.session.get('git_mail')
if not git_name and git_mail:
messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
collection = Collection.from_request(request)
module = collection.identifier.fields_module()
collection.model_def_commits()
collection.model_def_fields()
if collection.locked():
messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
return HttpResponseRedirect(collection.absolute_url())
collection.repo_fetch()
if collection.repo_behind():
messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
return HttpResponseRedirect(collection.absolute_url())
if request.method == 'POST':
form = DDRForm(request.POST, fields=module.FIELDS)
if form.is_valid():
collection.form_post(form)
collection.write_json()
collection.write_ead()
updated_files = [collection.json_path, collection.ead_path,]
# if inheritable fields selected, propagate changes to child objects
inheritables = collection.selected_inheritables(form.cleaned_data)
modified_ids,modified_files = collection.update_inheritables(inheritables, form.cleaned_data)
if modified_files:
updated_files = updated_files + modified_files
# commit files, delete cache, update search index, update git status
collection_edit(request, collection, updated_files, git_name, git_mail)
return HttpResponseRedirect(collection.absolute_url())
else:
form = DDRForm(collection.form_prep(), fields=module.FIELDS)
return render_to_response(
'webui/collections/edit-json.html',
{'collection': collection,
'form': form,
},
context_instance=RequestContext(request, processors=[])
)
示例12: edit_auto
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def edit_auto( request, repo, org, cid ):
git_name = request.session.get('git_name')
git_mail = request.session.get('git_mail')
if not git_name and git_mail:
messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
collection = Collection.from_request(request)
filename = request.GET.get('filename', None)
filepath = os.path.join(collection.path, filename)
with open(filepath, 'r') as f:
text = f.read()
merged = dvcs.automerge_conflicted(text, 'left')
with open(filepath, 'w') as f:
f.write(merged)
# TODO git add FILENAME
return HttpResponseRedirect(reverse('webui-merge', args=[repo,org,cid]))
示例13: sync
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def sync( request, repo, org, cid ):
try:
collection = Collection.from_request(request)
except:
raise Http404
git_name = request.session.get('git_name')
git_mail = request.session.get('git_mail')
if not git_name and git_mail:
messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
alert_if_conflicted(request, collection)
if collection.locked():
messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
return HttpResponseRedirect(collection.absolute_url())
if request.method == 'POST':
form = SyncConfirmForm(request.POST)
form_is_valid = form.is_valid()
if form.is_valid() and form.cleaned_data['confirmed']:
result = collection_sync.apply_async( (git_name,git_mail,collection.path), countdown=2)
lockstatus = collection.lock(result.task_id)
# add celery task_id to session
celery_tasks = request.session.get(settings.CELERY_TASKS_SESSION_KEY, {})
# IMPORTANT: 'action' *must* match a message in webui.tasks.TASK_STATUS_MESSAGES.
task = {'task_id': result.task_id,
'action': 'webui-collection-sync',
'collection_id': collection.id,
'collection_url': collection.absolute_url(),
'start': datetime.now().strftime(settings.TIMESTAMP_FORMAT),}
celery_tasks[result.task_id] = task
request.session[settings.CELERY_TASKS_SESSION_KEY] = celery_tasks
return HttpResponseRedirect(collection.absolute_url())
#else:
# assert False
else:
form = SyncConfirmForm()
return render_to_response(
'webui/collections/sync-confirm.html',
{'collection': collection,
'form': form,},
context_instance=RequestContext(request, processors=[])
)
示例14: edit_json
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def edit_json( request, repo, org, cid ):
"""
"""
collection = Collection.from_request(request)
repository = dvcs.repository(collection.path)
filename = ''
if request.method == 'POST':
filename = request.POST.get('filename', None)
elif request.method == 'GET':
filename = request.GET.get('filename', None)
fields = []
if filename:
path = os.path.join(collection.path, filename)
with open(path, 'r') as f:
txt = f.read()
fields = dvcs.conflicting_fields(txt)
if request.method == 'POST':
#form = MergeJSONForm(request.POST)
#if form.is_valid():
# text = form.cleaned_data['text']
# # TODO validate XML
# with open(filepath, 'w') as f:
# f.write(text)
# # git add file
# dvcs.merge_add(repository, filename)
assert False
elif request.method == 'GET':
form = MergeJSONForm(fields=fields)
return render_to_response(
'webui/merge/edit-json.html',
{'filename':filename,
'fields':fields,
'form':form,},
context_instance=RequestContext(request, processors=[])
)
return HttpResponseRedirect( reverse('webui-merge', args=[repo,org,cid]) )
示例15: edit_raw
# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_request [as 别名]
def edit_raw( request, repo, org, cid ):
"""
"""
git_name = request.session.get('git_name')
git_mail = request.session.get('git_mail')
if not git_name and git_mail:
messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
collection = Collection.from_request(request)
repository = dvcs.repository(collection.path)
filename = ''
if request.method == 'POST':
filename = request.POST.get('filename', None)
elif request.method == 'GET':
filename = request.GET.get('filename', None)
filepath = os.path.join(collection.path, filename)
if request.method == 'POST':
form = MergeRawForm(request.POST)
if form.is_valid():
text = form.cleaned_data['text']
# TODO validate XML
with open(filepath, 'w') as f:
f.write(text)
# git add file
dvcs.merge_add(repository, filename)
return HttpResponseRedirect( reverse('webui-merge', args=[repo,org,cid]) )
else:
with open(filepath, 'r') as f:
text = f.read()
form = MergeRawForm({'filename': filename, 'text': text,})
return render_to_response(
'webui/merge/edit-raw.html',
{'repo': repo,
'org': org,
'cid': cid,
'filename':filename,
'form': form,},
context_instance=RequestContext(request, processors=[])
)