def edit_or_create_contest_block(request, contest=None): is_success = False if request.method == 'POST' and 'Insert' not in request.POST: form = ContestEditForm(request.POST) if form.is_valid(): if contest is None: if not os.path.exists( os.path.dirname(form.cleaned_data["path"])): raise NoDirectoryException("There is no such directory!") if os.path.exists(form.cleaned_data["path"]): raise ContestExistsException("This contest already exists") contest = Contest() contest.path = form.cleaned_data["path"] command_create_contest(form.cleaned_data["path"][:-8], []) contest.name = form.cleaned_data["name"] contest.id_method = form.cleaned_data["id_method"] contest.statement_name = form.cleaned_data["statement_name"] contest.statement_location = form.cleaned_data[ "statement_location"] contest.statement_date = form.cleaned_data["statement_date"] contest.statement_template = form.cleaned_data[ "statement_template"] contest.save() export_from_database(contest) is_success = True else: if contest is None: form = ContestEditForm() else: form = ContestEditForm( initial={ 'path': contest.path, 'name': contest.name, 'id_method': contest.id_method, 'statement_name': contest.statement_name, 'statement_location': contest.statement_location, 'statement_date': contest.statement_date, 'statement_template': contest.statement_template, }) return { 'form': form, 'is_success': is_success, }
def edit_or_create_contest_block(request, contest=None): is_success = False if request.method == 'POST' and 'Insert' not in request.POST: form = ContestEditForm(request.POST) if form.is_valid(): if contest is None: if not os.path.exists(os.path.dirname(form.cleaned_data["path"])): raise NoDirectoryException("There is no such directory!") if os.path.exists(form.cleaned_data["path"]): raise ContestExistsException("This contest already exists") contest = Contest() contest.path = form.cleaned_data["path"] command_create_contest(form.cleaned_data["path"][:-8], []) contest.name = form.cleaned_data["name"] contest.id_method = form.cleaned_data["id_method"] contest.statement_name = form.cleaned_data["statement_name"] contest.statement_location = form.cleaned_data["statement_location"] contest.statement_date = form.cleaned_data["statement_date"] contest.statement_template = form.cleaned_data["statement_template"] contest.save() export_from_database(contest) is_success = True else: if contest is None: form = ContestEditForm() else: form = ContestEditForm(initial={ 'path': contest.path, 'name': contest.name, 'id_method': contest.id_method, 'statement_name': contest.statement_name, 'statement_location': contest.statement_location, 'statement_date': contest.statement_date, 'statement_template': contest.statement_template, }) return { 'form': form, 'is_success': is_success, }
def wrapped_function(request, id, *args, **kwargs): contest_was_deleted = False if read: try: contest = Contest.objects.get(id=id) except Contest.DoesNotExist: contest = None contest_path = contest.path if contest else None if contest: contest = synchronization.import_to_database(contest) if contest: contest.save() else: contest_was_deleted = True if not contest_was_deleted: response = function(request, id, *args, **kwargs) if write: synchronization.export_from_database(Contest.objects.get(id=id)) return response else: return render_to_response("contest/deleted_contest.html", {"path": contest_path})
def wrapped_function(request, id, *args, **kwargs): contest_was_deleted = False if read: try: contest = Contest.objects.get(id=id) except Contest.DoesNotExist: contest = None contest_path = contest.path if contest else None if contest: contest = synchronization.import_to_database(contest) if contest: contest.save() else: contest_was_deleted = True if not contest_was_deleted: response = function(request, id, *args, **kwargs) if write: synchronization.export_from_database( Contest.objects.get(id=id)) return response else: return render_to_response('contest/deleted_contest.html', {"path": contest_path})