def create(): if not check_permission(current_user, 'article'): flash('你没有权限') return redirect(url_for('Common.index')) form = CreateForm(request.form) form.category_id.choices = [(c.id, c.category_name) for c in Category.query.all()] if request.method == 'POST' and form.validate(): title = form.title.data html_content = form.html_content.data raw_content = form.raw_content.data category_id = form.category_id.data brief = raw_content[:100] article = Article(current_user.id, title, brief, raw_content, html_content, category_id) f = request.files['cover'] if f: try: article.cover = save_file(f) except Exception, e: pass article.save() return redirect(url_for('Common.index'))
def new(): form = CreateForm() if form.validate_on_submit(): todo = TodoModel(title=form.title.data, remarks=form.remarks.data) todo.save_to_db() return redirect(url_for('view.home')) return render_template('create.html', form=form)
def create(): form = CreateForm() if form.validate_on_submit(): newuser = form.username.data password = crypt.crypt(form.password.data,salt()) user = User(nickname=newuser, password=sha256_crypt.encrypt(form.password.data), email=form.email.data, role=ROLE_USER) db.session.add(user) db.session.commit() os.system("sudo mkdir " + settings.WORKING_DIR + newuser) os.system("sudo mkdir " + settings.REMOTE_DIR + newuser) os.system("sudo mkdir " + settings.WORKING_DIR + newuser + "/myRepo") os.system("sudo chmod 777 " + settings.REMOTE_DIR + newuser) os.system("sudo chmod 777 " + settings.WORKING_DIR + newuser) repo = Repo.init_bare(settings.REMOTE_DIR + newuser + "/") newrepo = Rpstry(repourl="/myRepo/", owner=user) db.session.add(newrepo) db.session.commit() working_repo = repo.clone(settings.WORKING_DIR + newuser + newrepo.repourl, False, False, "origin") p = subprocess.Popen(["sudo", "git", "remote", "add", "origin", "file:///" + settings.REMOTE_DIR + newuser + "/"], cwd=settings.WORKING_DIR + newuser + "/myRepo/") p.wait() open(settings.REMOTE_DIR + newuser + "/.htpasswd", 'a').writelines(newuser + ":" + password + "\n") s = get_serializer() payload = s.dumps(user.id) url = url_for('activate_user', payload=payload, _external=True) msg = Message('Confirm Email Address', sender = ADMINS[0], recipients = [user.email]) msg.body = "Follow this link to activate account: " + url mail.send(msg) flash("User created and activation email sent") return redirect(url_for('login')) return render_template('createAccount.html', title = 'Create New Account', form = form)
def create(): form = CreateForm() if request.method == 'POST' and form.validate_on_submit(): file = request.files['userfile'] if file: filename = secure_filename(file.filename) if not (check_file_extension(file.filename)): flash(('red', 'Неподдерживаемый формат файла')) view_log.error('Неподдерживаемый формат файла') view_log.error(filename) return redirect(url_for('create')) view_log.info('check new article ' + request.form['article_name'] + 'by ' + request.form['author_name']) article = articles(article_name = request.form['article_name'],\ author_name = request.form['author_name'],\ article_file = filename,\ email = request.form['email']) flash(save_article(article, file, filename)) #add email notification about add new article return render_template('create.html',\ form=form) else: flash(('red', 'Прикрепите файл')) return redirect(url_for('create')) return render_template("create.html",\ form=form)
def create(): """ Page to create a new project account """ form = CreateForm(request.form) if form.validate_on_submit(): # On submit, grab form information project_name = form.project_name.data email = form.email.data password = form.password.data hashed_password = generate_password_hash(password) description = form.description.data # Create the account db = DB() resp = db.create(project_name, password, hashed_password, description=description, email=email) if resp['status']: flash(u'Project successfully created!') return redirect( url_for('admin_home', admin_id=g.admin['project_id'])) else: flash(resp['message']) return render_template('create.html', form=form)
def update(article_id): article = Article.query.get(article_id) form = CreateForm(request.form) form.category_id.choices = [(c.id, c.category_name) for c in Category.query.all()] if form.validate(): title = form.title.data html_content = form.html_content.data raw_content = form.raw_content.data category_id = form.category_id.data brief = raw_content[:100] category_id = form.category_id.data article.title = title article.brief = brief article.raw_content = raw_content article.html_content = html_content article.category_id = category_id f = request.files['cover'] if f: try: article.cover = save_file(f) except Exception, e: pass article.update() return redirect(url_for('Article.retrieve', article_id=article.id))
def create(): form = CreateForm() if request.method == 'POST' and form.validate_on_submit(): file = request.files['userfile'] if file: filename = secure_filename(file.filename) if not(check_file_extension(file.filename)): flash(('red','Неподдерживаемый формат файла')) view_log.error('Неподдерживаемый формат файла') view_log.error(filename) return redirect(url_for('create')) view_log.info('check new article ' + request.form['article_name'] + 'by '+ request.form['author_name']) article = articles(article_name = request.form['article_name'],\ author_name = request.form['author_name'],\ article_file = filename,\ email = request.form['email']) flash(save_article(article, file, filename)) #add email notification about add new article return render_template('create.html',\ form=form) else: flash(('red','Прикрепите файл')) return redirect(url_for('create')) return render_template("create.html",\ form=form)
def create(): form = CreateForm() if form.validate_on_submit(): page = pm.save_new_page(form.title.data, content=form.body.data, tags=form.tags.data) flash(_('Page created.'), 'success') return redirect(url_for('show', id=page.id)) return render_template("editor.html", form=form, title=_('create a new page'), flag='Create', highlight=True)
def create_board(request): bingo_board = _get_user_bingo_board(request) game = bingo_board.game if bingo_board is not None else None user = request.user if bingo_board: Game.objects.filter(id=bingo_board.game.id).update( last_used=times.now()) return redirect(reverse(bingo, kwargs={ 'board_id': bingo_board.board_id})) elif request.POST: create_form = CreateForm( request.POST, prefix="create", game=game) if create_form.is_valid(): with transaction.atomic(): ip = request.META['REMOTE_ADDR'] password = create_form.cleaned_data.get('password') game_description = create_form.cleaned_data.get( 'description', '') game = get_game( site=get_current_site(request), description=game_description, create=True) Game.objects.filter(id=game.id).update( last_used=times.now()) # if the user is logged in, associate the board with # the user, and ignore the password # (so no other user can claim the board) user = user if user.is_authenticated() else None if user: password = None bingo_board = BingoBoard( game=game, user=user, ip=ip, password=password) bingo_board.save() if USE_SSE: _publish_num_users(game.site.id, game.num_users(), game.num_active_users()) return redirect(reverse(bingo, kwargs={ 'board_id': bingo_board.board_id})) else: reclaim_form = ReclaimForm(prefix="reclaim") return render( request, "bingo/reclaim_board.html", { 'reclaim_form': reclaim_form, 'create_form': create_form, } ) else: return redirect(reverse(main))
def __init__(self, session, login_session, client_id=None): """ Args: session: sqlalchemy session object. login_session: flask session object. client_id: client_id. """ self.session = session self.login_session = login_session self.client_id = client_id self.form = CreateForm()
def create(): """ Creates a new organization belonging to the currently signed in user :return: """ form = CreateForm(request.form) if form.validate_on_submit(): org, membership = utils.organization.create_organization(form.name.data, g.user.id) return redirect('/organization/' + str(org.id)) return render_template('main/create.html', form=CreateForm())
def save(): my_form = CreateForm(csrf_enabled=False) my_post = None if not my_form.post_id.data and my_form.validate_on_submit(): my_post = Post(my_form.title.data, my_form.text.data) db.session.add(my_post) if my_form.post_id.data and my_form.validate_on_submit(): my_post = Post.query.get(my_form.post_id.data) my_post.title = my_form.title.data my_post.text = my_form.text.data db.session.commit() return redirect(url_for('view', post_id=my_post.post_id))
def customer_create(): form = CreateForm() if request.method == 'POST': if form.validate() == False: return render_template('signup.htm', form=form) else: newclient = Customer(form.clientid.data, form.firstname.data, form.lastname.data, form.email.data) db.session.add(newclient) db.session.commit() return "ALL OK" elif request.method == 'GET': return render_template('create.htm', form=form)
def create_project(request): if request.method == "POST": form = CreateForm(request.POST) if form.is_valid(): name = form.cleaned_data["project_name"] lat_lng = form.cleaned_data["location"] pnt = Point(lat_lng["lng"], lat_lng["lat"]) model_proj = Project.objects.create(name=name, starting_point=pnt, owner=request.user) return HttpResponseRedirect('/project/%s/' % model_proj.id) else: form = CreateForm() return render_to_response('create_project.html', {"form": form, "user": request.user}, context_instance=RequestContext(request))
def create_board(request): bingo_board = _get_user_bingo_board(request) game = bingo_board.game if bingo_board is not None else None user = request.user if bingo_board: Game.objects.filter(id=bingo_board.game.id).update( last_used=times.now()) return redirect( reverse(bingo, kwargs={'board_id': bingo_board.board_id})) elif request.POST: create_form = CreateForm(request.POST, prefix="create", game=game) if create_form.is_valid(): with transaction.atomic(): ip = request.META['REMOTE_ADDR'] password = create_form.cleaned_data.get('password') game_description = create_form.cleaned_data.get( 'description', '') game = get_game(site=get_current_site(request), description=game_description, create=True) Game.objects.filter(id=game.id).update(last_used=times.now()) # if the user is logged in, associate the board with # the user, and ignore the password # (so no other user can claim the board) user = user if user.is_authenticated() else None if user: password = None bingo_board = BingoBoard(game=game, user=user, ip=ip, password=password) bingo_board.save() if USE_SSE: _publish_num_users(game.site.id, game.num_users(), game.num_active_users()) return redirect( reverse(bingo, kwargs={'board_id': bingo_board.board_id})) else: reclaim_form = ReclaimForm(prefix="reclaim") return render(request, "bingo/reclaim_board.html", { 'reclaim_form': reclaim_form, 'create_form': create_form, }) else: return redirect(reverse(main))
def create_witness(): form = CreateForm(request.form) if request.method == 'POST' and form.validate(): name = form.name.data age = form.age.data comment = form.comment.data # トランザクション with db.session.begin(subtransactions=True): new_person = Person(name, age, comment) db.session.add(new_person) db.session.commit() return redirect(url_for('witness_list')) return render_template('create_witness.html', form=form)
def create_member(): form = CreateForm(request.form) if request.method == 'POST' and form.validate(): name = form.name.data age = form.age.data comment = form.comment.data with db.session.begin(subtransactions=True): new_member = Member(name, age, comment) db.session.add(new_member) db.session.commit() return redirect(url_for('member_list')) return render_template('create_member.html', form=form)
def add(): form = CreateForm() nick = session['profile']['name'] if form.validate_on_submit(): data = { 'author': form.author.data, 'title': form.title.data, 'year': form.year.data } response = requests.post('http://service/publications', headers={"Authorization": nick + ":password"}, data=data) redis.publish(nick, 'There is new publication!') return redirect(url_for('publications')) return render_template('create.html', form=form)
def get(self, request): create_form = CreateForm() context = {'form': create_form} return render(request, 'users/new.html', context)
def create(request): try: data = { 'msg': '', 'index': 'project', 'form': CreateForm(request.POST) } if request.method == 'POST': name = request.POST.get('name', '') description = request.POST.get('description', '') try: price = float(request.POST.get('price', 0)) except: price = 0 try: total = int(request.POST.get('total', 0)) except: total = 0 if not name: data['msg'] = '项目名称不能为空' else: project = Projects(name=name, price=price, total=total, description=description, status=1) project.save() data['msg'] = '项目创建成功' except: utils.debug() return utils.ErrResp(errors.FuncFailed) return render(request, 'backend/project/create.html', data)
def index(): # inisialisasi form = CreateForm() output = [] vhost = [] USER = "******" HOST = "pcxma.com" # Ports are handled in ~/.ssh/config since we use OpenSSH COMMAND = "ls /etc/nginx/vhost" ssh = subprocess.Popen(["ssh", "%s@%s" % (USER, HOST), COMMAND], stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = ssh.communicate() if result[0] != "": output.append(result[0]) # get all vhost vhost = result[0].split('.conf\n') vhost.pop() vhost.insert(0, 'wpuser') else: output.append("ERROR: " + result[1]) vhost.append('wpuser') return render_template("index.html", form=form, output=output, vhost=vhost)
def create(): # creates a drink recipe and enters into recipes collection form = CreateForm(request.form) if form.validate_on_submit(): # set the collection recipes_db = mongo.db.recipes # insert the new recipe recipes_db.insert_one({ 'name': request.form['name'], 'user': session['username'], 'image': request.form['image'], 'ingredients': request.form['ingredients'], 'instructions': request.form['instructions'] }) return redirect(url_for('home', title='New Drink Created')) return render_template('create.html', title='Create a Drink', form=form)
def reclaim_board(request): ip = request.META['REMOTE_ADDR'] game = get_game(site=get_current_site(request), create=False) if game is not None: Game.objects.filter(id=game.id).update(last_used=times.now()) bingo_board = _get_user_bingo_board(request) if not bingo_board is None: return redirect( reverse(bingo, kwargs={'board_id': bingo_board.board_id})) if request.POST: reclaim_form = ReclaimForm(request.POST, game=game, prefix="reclaim") if reclaim_form.is_valid(): bingo_board = reclaim_form.cleaned_data['bingo_board'] request.session['board_id'] = bingo_board.id bingo_board.ip = ip bingo_board.save() return redirect( reverse(bingo, kwargs={'board_id': bingo_board.board_id})) else: reclaim_form = ReclaimForm(prefix="reclaim") create_form = CreateForm(prefix="create", game=game) return render(request, "bingo/reclaim_board.html", { 'reclaim_form': reclaim_form, 'create_form': create_form, })
def main(request, reclaim_form=None, create_form=None): game = get_game(site=get_current_site(request), create=False) bingo_board = _get_user_bingo_board(request) create_form = CreateForm(prefix="create", game=game) reclaim_form = ReclaimForm(prefix="reclaim") boards = BingoBoard.objects.filter(game=game) old_games = Game.objects.filter(site=get_current_site(request)).exclude( # games without any boards created bingoboard=None).exclude( # games without game_id are hidden game_id=None).order_by("-created") if game is not None: old_games = old_games.exclude(id=game.id) return render( request, "bingo/main.html", { 'my_board': bingo_board, 'create_form': create_form, 'reclaim_form': reclaim_form, 'boards': boards, 'current_game': game, 'old_games': old_games, 'can_start_game': not GAME_START_DISABLED, })
def create(): form = CreateForm() if form.validate_on_submit(): eventOwner = Users.query.filter_by(id=int(session['user'])).first() new_event = Events(sport=form.sport.data, starttime=form.starttime.data, endtime=form.endtime.data, date=form.date.data, place=form.place.data, n_ppl=form.n_ppl.data, eventOwner=eventOwner) db.session.add(new_event) db.session.commit() flash('Event successfully created by ' + new_event.eventOwner.firstname) return redirect('/index') return render_template('create.html', title='Create', form=form)
def Contact_Create(request): if request.POST: form = CreateForm(request.POST) if form.is_valid(): a = form.save() messages.add_message(request, messages.SUCCESS, "You Data was added") return HttpResponseRedirect('/users/all') else: form = CreateForm() args = {} args.update(csrf(request)) args['form'] = form return render_to_response('create_list.html', args)
def post(self, request): create_form = CreateForm(request.POST) if not create_form.is_valid(): msg = 'Please fill the form correctly and try again!' context = {'form': create_form, 'msg': msg, 'color': 'yellow'} return render(request, 'users/new.html', context) else: if not (create_form.cleaned_data['password1'] and create_form.cleaned_data['password2'] and (create_form.cleaned_data['password2'] == create_form.cleaned_data['password1'])): context = { 'form': create_form, 'msg': "Password fields do not match!", 'color': 'yellow' } return render(request, 'users/new.html', context) pre_saved_user = create_form.save(commit=False) pre_saved_user.set_password(create_form.cleaned_data['password2']) pre_saved_user.save() new_wallet = Wallet.objects.create(user=pre_saved_user) new_wallet.save() pre_saved_user.wallet_address = new_wallet.wallet_address pre_saved_user.save() request.session.flush() return redirect('/users/login/')
def create(request, tid): template = get_object_or_404(Template, id=tid) fields = template.fields.all() form = CreateForm() if request.method == "POST": form = CreateForm(request.POST) if form.is_valid(): graph = form.save(commit=False) graph.template = template graph.owner = Member.objects.get(user=request.user) graph.save() for field in fields: onto = request.POST.get(field.fname, "") mapping = Mapping.objects.create(field=field, onto=onto) graph.mappings.add(mapping) graph.save() return HttpResponseRedirect("/graph/result/%d" % graph.id) return render(request, "create_graph.html", {"form": form, "fields": fields})
def create(request): try: data = { 'msg': '', 'index': 'admin', 'form': CreateForm(request.POST) } if request.method == 'POST': username = request.POST.get('username', '') password = request.POST.get('password', '') email = request.POST.get('email', '') first_name = request.POST.get('first_name', '') reg_code = request.POST.get('reg_code', '') bank_code = request.POST.get('bank_code', '') bank_card = request.POST.get('bank_card', '') if not username or not password or not email: data['msg'] = '账号及密码、邮箱不能为空' elif len(password) < 10: data['msg'] = '密码长度至少为10' else: u_exists = Auth_user.objects.filter(username=username).exists() if u_exists: data['msg'] = '账号已存在' else: u = Auth_user.objects \ .create_user(username, email, password) u.first_name = first_name u.is_superuser = 1 u.is_staff = 1 u.save() uinfo = UserInfo( user=u, reg_time=datetime.now(), reg_ip=get_ip(request), bank_code=bank_code, bank_card=bank_card ) if reg_code: code_exists = InviteCode.objects \ .filter(code=reg_code).filter(status=0) if not code_exists: uinfo.reg_code = reg_code uinfo.reg_type = 2 else: uinfo.reg_type = 1 uinfo.save() data['msg'] = '账号创建成功' except: utils.debug() return utils.ErrResp(errors.FuncFailed) return render(request, 'backend/admin/create.html', data)
class CreateItemView(MethodView): """Handles GET, POST request for '/catalog/category/<int:category_id>/create'""" def __init__(self, session, login_session, client_id=None): """ Args: session: sqlalchemy session object. login_session: flask session object. client_id: client_id. """ self.session = session self.login_session = login_session self.client_id = client_id self.form = CreateForm() def get(self, category_id): context = { "user": self.login_session, "error": False, "client_id": self.client_id } if self.login_session.get("user_id"): try: category = self.session.query( Category).filter_by(id=category_id).one() pre_select_category = category.name self.form.categories.data = [pre_select_category] context["category_id"] = category_id context["form"] = self.form except Exception as e: context["error"] = True context["msg"] = e return render_template("error.html", context=context) return render_template("create.html", context=context) else: return redirect(url_for("mainView")) def post(self, category_id): if self.login_session.get("user_id"): if self.form.validate(): createMovie(self.form, self.session, self.login_session) return redirect( url_for("CategoryView", category_id=category_id)) else: return self.get(category_id) else: response = make_response( json.dumps("Unauthorized access denied."), 401 ) response.headers["Content-Type"] = "application/json" return response
def create_account(): form = CreateForm() if form.validate_on_submit(): name = form.name.data password = form.password.data if form.balance.data > 0: balance = form.balance.data else: balance = 0 new_account = Account(name, password, balance) db.session.add(new_account) db.session.commit() new_transaction = Transaction('deposit', 'account opening', new_account.id, balance) db.session.add(new_transaction) db.session.commit() session['username'] = new_account.name return redirect(url_for('my_account')) return render_template('create_account.html', form=form)
def post(self, request): userinstance = stories(author=request.user) form = CreateForm( request.POST or None, request.FILES, instance=userinstance, ) if form.is_valid(): form.save(commit=True) title = form.cleaned_data['title'] '''description = form.cleaned_data['description'] content = form.cleaned_data['content']''' send_mail( subject="blog created!!", message="congrats your post: " + title + " has been published successfully", from_email="*****@*****.**", recipient_list=[request.user.email], fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD, ) return redirect('/stories/')
def create(): """ Page to create a new project account """ form = CreateForm(request.form) if form.validate_on_submit(): # On submit, grab form information project_name = form.project_name.data email = form.email.data password = form.password.data hashed_password = generate_password_hash(password) description = form.description.data # Create the account db = DB() resp = db.create(project_name, password, hashed_password, description=description, email=email) if resp['status']: flash(u'Project successfully created!') return redirect(url_for('admin_home', admin_id=g.admin['project_id'])) else: flash(resp['message']) return render_template('create.html', form=form)
def create(): if 'username' not in session: return redirect('/login') form = CreateForm() community_name = form.title.data bio = form.bio.data existence = '' if not community_name in [tuply[1] for tuply in community_model.get_all()]\ and not (community_name is None) and not (bio is None): community_model.insert(community_name, bio, session['user_id']) user_model.follow(session['user_id'], community_model.get_name(community_name)[0]) return redirect(('/community/{}').format(community_name)) elif not (community_name is None) and not (bio is None): existence = 'This name is taken' return render_template('create.html', form=form, existence=existence)
def game(request, game_id): bingo_board = _get_user_bingo_board(request) create_form = CreateForm(prefix="create", game=game) reclaim_form = ReclaimForm(prefix="reclaim") return render( request, "bingo/game.html", { 'game': get_object_or_404( Game, site=get_current_site(request), game_id=game_id), 'my_board': bingo_board, 'create_form': create_form, 'reclaim_form': reclaim_form, "twittercard_account": TWITTERCARD_ACCOUNT, })
def create(request): try: data = {'msg': '', 'index': 'news', 'form': CreateForm(request.POST)} if request.method == 'POST': title = request.POST.get('title', '') content = request.POST.get('content', '') try: category = int(request.POST.get('category', 0)) except: category = 0 if not title: data['msg'] = '标题不能为空' elif not category: data['msg'] = '分类不能为空' else: cate = News(title=title, content=content, category_id=category) cate.save() data['msg'] = '创建成功' except: utils.debug() return utils.ErrResp(errors.FuncFailed) return render(request, 'backend/news/create.html', data)
def create(request, tid): template = get_object_or_404(Template, id=tid) fields = template.fields.all() form = CreateForm() if request.method == 'POST': form = CreateForm(request.POST) if form.is_valid(): graph = form.save(commit=False) graph.template = template graph.owner = Member.objects.get(user=request.user) graph.save() for field in fields: onto = request.POST.get(field.fname, '') mapping = Mapping.objects.create(field=field, onto=onto) graph.mappings.add(mapping) graph.save() return HttpResponseRedirect('/graph/result/%d' % graph.id) return render(request, 'create_graph.html', {'form': form, 'fields': fields})
def post(self, request): if not request.user.is_authenticated(): return render(request, 'unauthorised.html') form = CreateForm(request.POST) if form.is_valid(): this = form.cleaned_data q_con = Contest.objects.filter(code=this.get('contest')) q_user = User.objects.filter(username=this.get('to')) if len(q_con) == 0: return render( request, 'create_challenge.html', { 'form': form, 'error': 'Contest Code is incorrect,Please make sure the contest is still active' }) if len(q_user) == 0: return render( request, 'create_challenge.html', { 'form': CreateForm(), 'error': 'No User with that username found.' }) try: con = q_con[0] ch = Challenge.objects.create(frm=request.user.username, to=this.get('to'), contest=con.code, expire=con.end, time=datetime.now()) except (InternalError, IntegrityError): return render( request, 'create_challenge.html', { 'form': form, 'error': 'Internal Server Error 500, Please try again.' }) #Create a New Notification try: notif = Notification.objects.create( user=this.get('to'), title='You have been challenged by ' + request.user.username) except (InternalError): return render( request, 'create_challenge.html', { 'form': form, 'error': 'Internal Server Error 500, Please try again.' }) return render(request, 'created_challenge.html', { 'challenge': ch, 'contest': con }) else: return render(request, 'create_challenge.html', { 'form': CreateForm(), 'error': 'Invalid Form Data' })
def create(request): if request.method == 'POST': form = CreateForm(request.POST) if form.is_valid() : startYear = form.cleaned_data['startYear'] startMonth = form.cleaned_data['startMonth'] startDay = form.cleaned_data['startDay'] startHour = form.cleaned_data['startHour'] startMinute = form.cleaned_data['startMinute'] toursNumber = form.cleaned_data['toursNumber'] lenWriteWords = form.cleaned_data['lenWriteWords'] lenWatchResult = form.cleaned_data['lenWatchResult'] lenChecking = form.cleaned_data['lenChecking'] lenWaitWords = form.cleaned_data['lenWaitWords'] lenCountStatisticsWords = 10 lenCountResult = 10 lenGame = lenWriteWords + lenWaitWords + lenCountStatisticsWords + lenChecking + lenCountResult + lenWatchResult info = form.cleaned_data['info'] start = datetime.datetime(startYear, startMonth, startDay, startHour, startMinute) newGame = DataGame(start = start, toursNumber = toursNumber, lenWriteWords = lenWriteWords, lenWatchResult = lenWatchResult, lenChecking = lenChecking, lenWaitWords = lenWaitWords) newGame.save() delta = datetime.timedelta(minutes=info) action = Tasks(taskTime = start - delta, action = "info", gameID = newGame, tourID = -1) action.save() listToChain = [] for i in range(toursNumber): delta = datetime.timedelta(seconds = i*(lenGame)) countdownTime = start + delta - datetime.datetime.today() - datetime.timedelta(seconds = 1) task_choice_titles.apply_async((Tasks(gameID = newGame, tourID = i),), countdown = countdownTime.seconds) #listToChain.append(task_choice_titles.subtask((Tasks(gameID = newGame, tourID = i),), countdown = countdownTime.seconds)) action = Tasks(taskTime = start + delta, action = "tour", gameID = newGame, tourID = i) action.save() delta = datetime.timedelta(seconds = i*(lenGame) + lenWriteWords) action = Tasks(taskTime = start + delta, action = "sendWords", gameID = newGame, tourID = i) action.save() delta = datetime.timedelta(seconds = i*(lenGame) + lenWriteWords + lenWaitWords) countdownTime = start + delta - datetime.datetime.today() task_count_statistics_words.apply_async((Tasks(gameID = newGame, tourID = i),), countdown = countdownTime.seconds) action = Tasks(taskTime = start + delta, action = "countStatisticsWords", gameID = newGame, tourID = i) action.save() delta = datetime.timedelta(seconds = i*(lenGame) + lenWriteWords + lenWaitWords + lenCountStatisticsWords) action = Tasks(taskTime = start + delta, action = "check", gameID = newGame, tourID = i) action.save() delta = datetime.timedelta(seconds = i*(lenGame) + lenWriteWords + lenWaitWords + lenCountStatisticsWords + lenChecking) countdownTime = start + delta - datetime.datetime.today() task_count_result.apply_async((Tasks(gameID = newGame, tourID = i),), countdown = countdownTime.seconds) action = Tasks(taskTime = start + delta, action = "countResult", gameID = newGame, tourID = i) action.save() delta = datetime.timedelta(seconds = i*(lenGame) + lenWriteWords + lenWaitWords + lenCountStatisticsWords +lenChecking + lenCountResult) action = Tasks(taskTime = start + delta, action = "watchResult", gameID = newGame, tourID = i) action.save() delta = datetime.timedelta(seconds = toursNumber*(lenGame)) countdownTime = start + delta - datetime.datetime.today() - datetime.timedelta(seconds = 1) task_count_final_result.apply_async((Tasks(gameID = newGame, tourID = toursNumber),), countdown = countdownTime.seconds) action = Tasks(taskTime = start + delta, action = "endGame", gameID = newGame, tourID = toursNumber) action.save() return render_to_response('ok_create.html', locals(), context_instance=RequestContext(request)) error = u"Не удалось создать игру. Произошла ошибка." return render_to_response('error.html', locals(), context_instance=RequestContext(request))