def test_author_slug_for_multiple_unique_author_name(self): author_name = 'Author Name Author Name Author Name Author Name Author Name' author1 = Author(name=author_name) author2 = Author(name=author_name + ' ') author3 = Author(name=author_name + '. ') author1.save() author2.save() author3.save() assert Author.objects.get(name=author_name).slug == 'author-name-author-name-author-name-author-name-au' assert Author.objects.get(name=author_name + ' ').slug == 'author-name-author-name-author-name-author-name-a1' assert Author.objects.get(name=author_name + '. ').slug == 'author-name-author-name-author-name-author-name-a2'
def createAuthor(request): if request.method == 'POST': form = CreateAuthorForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] birthDate = form.cleaned_data['birthDate'] deathDate = form.cleaned_data['deathDate'] nationality = form.cleaned_data['nationality'] auteur = Author(name=name, birthDate=birthDate, deathDate=deathDate, nationality=nationality) auteur.save() messages.add_message(request, messages.INFO, 'L\'auteur à été créé') return redirect('author-list', ) else: pass else: form = CreateAuthorForm() return render(request, "author/create.html", { 'form': form, })
def setup(): form = SetupForm() error = '' if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author( form.fullname.data, form.email.data, form.username.data, hashed_password, #bcrypt hashed True ) # send to db db.session.add(author) # needs to match "admin = ...db.ForeignKey('author.id'))" in models.py db.session.flush() # sqlalchemy simulates record being written to db = check if author.id: blog = Blog( form.name.data, author.id ) db.session.add(blog) db.session.flush() else: db.session.rollback() error = 'Error creating user' if author.id and blog.id: db.session.commit() flash('Blog created') return redirect(url_for('index')) else: db.session.rollback() error = 'Error creating blog' return render_template('blog/setup.html', form=form, error=error)
def add_user(): form = RegisterForm() blog = Blog.query.all() if request.method == 'POST': if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data.encode('utf8'), salt) fullname = form.fullname.data email = form.email.data username = form.username.data password = hashed_password is_author = True is_admin = form.is_admin.data is_active = True author = Author(fullname, email, username, password, is_author, is_admin, is_active) db.session.add(author) db.session.commit() flash('User added successfully') return redirect(url_for('admin_app.admin')) return render_template('/author/register.html', form=form, blog=blog)
def setup(): error = None form = SetupForm() if form.validate_on_submit(): author = Author(form.fullname.data, form.email.data, form.username.data, form.password.data, True) db.session.add(author) db.session.flush() if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error creating user" if author.id and blog.id: db.session.commit() flash("Blog created") return redirect(url_for('admin')) else: db.session.rollback() error = "Error creating blog" return render_template('blog/setup.html', form=form)
def setup(): error = '' form = SetupForm() if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_pwd = bcrypt.hashpw(form.password.data.encode('utf-8'), salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_pwd, True) db.session.add(author) db.session.flush() if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = 'err. creatin user' if author.id and blog.id: db.session.commit() else: db.session.rollback() error = 'err.creatin blog' flash('blog created') redirect(url_for('admin')) return render_template('blog/setup.html', form=form, error=error)
def setup(): form = SetupForm() error = "" if form.validate_on_submit(): author = Author( form.fullname.data, form.email.data, form.username.data, bcrypt.generate_password_hash(form.password.data), True ) db.session.add(author) db.session.flush() if author.id: blog = Blog( form.name.data, author.id ) db.session.add(blog) db.session.flush() if author.id and blog.id: db.session.commit() flash("Blog created") return redirect(url_for("index")) else: error = "Error creating blog" db.session.rollback() else: error = "Error creating author" db.session.rollback() return render_template("blog/setup.html", form=form, error=error)
def setup(): form = SetupForm() error = "" # taking data from form and adding that data it to the table if form.validate_on_submit(): salt = bcrypt.gensalt() # generating salt hashed_password = bcrypt.hashpw(form.password.data.encode('utf8'), salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, True) db.session.add(author) db.session() db.session.flush() if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error Creating user" if author.id and blog.id: db.session.commit() flash("Blog Created") return redirect(url_for('admin')) else: db.session.rollback() error = "Error Creating Blog" return render_template('blog/setup.html', form=form)
def setup(): form = SetupForm() error = "" if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, True) db.session.add(author) # this will flush data, but not commit, and this gives us an author.id db.session.flush() if author.id: # have author id, so record does not already exit in author table # now build blog record blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error creating user" if author.id and blog.id: db.session.commit() flash("Blog created") return redirect(url_for('index')) else: db.session.rollback() error = "Error creating blog" return render_template('blog/setup.html', form=form, error=error)
def setup(): form = SetupForm() error = None if form.validate_on_submit(): # Encrypt password data salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) # Create Author entitiy author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, True) db.session.add(author) db.session.flush() # Check author entity for errors, create Blog entity if none if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error creating user" # Check Blog entity for errors if author.id and blog.id: db.session.commit() flash("Blog Created") return redirect(url_for('admin')) else: db.session.rollback() error = "Error creating blog" return render_template('blog/setup.html', form=form)
def setup(): blogs = Blog.query.count() if blogs(): return redirect(url_for('admin')) form = SetupForm() if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author( form.fullname.data, form.email.data, form.username.data, hashed_password, True ) db.session.add(author) db.session.flush() if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error Creating User" if author.id and blog.id: db.session.commit() else: db.session.rollback() error = "Error Creating Blog" flash('Blog Created') return redirect('/admin') return render_template('blog/setup.html', form=form)
def setup(): form = SetupForm() error = "" if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, True) db.session.add(author) db.session.flush() if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error creating user" if author.id and blog.id: db.session.commit() flash("Blog created") return redirect(url_for('index')) else: db.session.rollback() error = "Error creating blog" return render_template('blog/setup.html', form=form, error=error)
def twitter_auth(): oauth_verifier = request.args.get('oauth_verifier') access_token = get_access_token(session['request_token'], oauth_verifier) print(access_token['screen_name']) user = Author.query.filter_by( username=access_token['screen_name'], ).first() if user: session['username'] = user.username session['is_author'] = user.is_author session['user_id'] = user.id if 'next' in session: next = session.get('next') session.pop('next') return redirect(next) else: return redirect(url_for('index')) if not user: salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw("password", salt) author = Author(access_token['screen_name'], access_token['screen_name'] + "@defaultemail.com", access_token['screen_name'], hashed_password, True) db.session.add(author) db.session.flush() db.session.commit() return redirect(url_for('success')) abort(403)
def setup(): form = SetupForm() if request.method == 'POST': if form.validate_on_submit(): blog_name = form.blog_name.data author_name = form.author_name.data email = form.email.data username = form.username.data password = form.password.data is_author = True author = Author(author_name, email, username, password, is_author) db.session.add(author) db.session.flush() if author.id: blog = Blog(blog_name, author.id) db.session.add(blog) db.session.commit() return redirect(url_for('login')) else: db.session.rollback() return 'Form set up Failed' return 'Form Set Up Done!!' return render_template('author/setup.html', form = form)
def create_author_object_based_on_book_dict_and_save_in_db(book_dict): authors_list = book_dict["authors"] for author in authors_list: try: object_allready_in_db = Author.objects.get(authorName=author) return object_allready_in_db except Author.DoesNotExist: new_author_object = Author(authorName=author) new_author_object.save() return new_author_object
def register(): form = RegisterForm() if form.validate_on_submit(): hashed_password = generate_password_hash(form.password.data) author = Author(form.full_name.data, form.email.data, hashed_password) db.session.add(author) db.session.commit() flash("You have successfully registered", "success") return render_template("author/login.html", form=form) return render_template("author/register.html", form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): hashed_password = generate_password_hash(form.password.data) author = Author(form.full_name.data, form.email.data, hashed_password) db.session.add(author) db.session.commit() flash('You are now registered, please login') return redirect(url_for('.login')) return render_template('/author/register.html', form=form)
def setUp(self): """ Create a user object to be used by the tests """ time_mock = datetime.datetime(2017, 4, 10, 12, 00, tzinfo=pytz.utc) with mock.patch('django.utils.timezone.now') as mock_time: mock_time.return_value = time_mock self.user = CustomUser(id=111, email='*****@*****.**', password='******', first_name='fname', middle_name='mname', last_name='lname') self.user.save() self.user_free = CustomUser(id=222, email='*****@*****.**', password='******', first_name='2fname', middle_name='2mname', last_name='2lname') self.user_free.save() self.author1 = Author(id=101, name="author1", surname="s1", patronymic="p1") self.author1.save() self.author2 = Author(id=102, name="author2", surname="s2", patronymic="p2") self.author2.save() self.book1 = Book(id=101, name="book1", description="description1", count=1) self.book1.save() self.book1.authors.add(self.author1) self.book1.save() self.book2 = Book(id=102, name="book2", description="description2") self.book2.save() self.book2.authors.add(self.author2) self.book2.save() self.book3 = Book(id=103, name="book3", description="description3") self.book3.save() self.book3.authors.add(self.author1) self.book3.authors.add(self.author2) self.book3.save() self.order1 = Order(id=101, user=self.user, book=self.book1, plated_end_at=TEST_DATE) self.order1.save() self.order2 = Order(id=102, user=self.user, book=self.book2, plated_end_at=TEST_DATE) self.order2.save() self.order3 = Order(id=103, user=self.user, book=self.book3, end_at=TEST_DATE_END, plated_end_at=TEST_DATE) self.order3.save()
def register(): form = RegisterForm() if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, False) db.session.add(author) db.session.commit() return redirect('/success') return render_template('author/register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): hashed_password = generate_password_hash( form.password.data) # сохраним пароль в хешированном виде author = Author(form.full_name.data, form.email.data, hashed_password) db.session.add(author) db.session.commit() flash('Подзравляем, Вы зарегестрировались! Можете войти на форум.') return redirect(url_for('author_app.login')) return render_template('author/register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): author = Author(form.full_name.data, form.email.data, password=Password.generate_password_hash( form.password.data)) db.session.add(author) db.session.commit() flash(constants.REGISTRATION_SUCCESSFUL) return url_secure_redirect("author_app.login") return render_template('author/register.html', form=form)
def register(cls, user_data): User = get_user_model() logger.info('Creating user model.') new_user = User.objects.create_user( email=user_data.get('email'), first_name=user_data.get('first_name'), last_name=user_data.get('last_name'), password=user_data.get('password'), is_staff=True) logger.info('Creating authentication token for user.') token, created = Token.objects.get_or_create(user=new_user) logger.info('Creating author profile for new user.') author = Author(skills=user_data.get('skills')) return token, new_user, author
def handle(self, *args, **options): try: authors_list = [] with open(options["csvpath"]) as csvfile: reader = csv.DictReader(csvfile) for row in reader: authors_list.append(Author(name=row["name"])) break_size = len(authors_list) / 2 Author.objects.bulk_create(authors_list, ignore_conflicts=True, batch_size=break_size) print("All data have been imported to database") except Exception as e: logger.error(e)
def register(): form = RegisterForm() error = None #get_flashed_messages() if form.validate_on_submit(): author = Author(form.fullname.data, form.email.data, form.username.data, form.password.data, True) error = flush_commit(author) if error: return render_template('author/register.html', form=form, error=error) else: return redirect(url_for('success')) else: return render_template('author/register.html', form=form, error=error)
def create(request): topics = Topic.objects.all() if request.user.id == None: return HttpResponse('please login') if request.method == 'POST': requestpost = request.POST.getlist('choice') # returns topic id requestweight = request.POST.getlist( 'weight') # returns a list of weights form = ChallengeForm(request.POST) if form.is_valid(): challenge = form.save(commit=False) exist = Challenge.objects.filter(name=challenge.name) if not exist.exists(): challenge.save() a = Author() a.user = request.user a.challenge = challenge a.timestamp = datetime.datetime.now() a.save() for i in range(0, len(requestpost)): idx = int(requestpost[i]) topicweight = 0 for j in range(0, len(requestweight)): if requestweight[j] != '': topicweight = requestweight[j] requestweight[j] = '' break ct = ChallengeTopic() ct.challenge = challenge ct.topic = Topic.objects.get(pk=idx) ct.weight = float(topicweight) ct.save() return redirect('thanks/') else: return HttpResponse('Challenge Name exists') else: form = ChallengeForm() return render(request, 'challenge/create.html', { 'form': form, 'topics': topics })
def blog_setup(): blogs = Blog.query.count() #if blogs: #return redirect(url_for('blog_admin')) form = SetupForm() #SetupForm().validate_username(form.username.data) if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, True) db.session.add(author) db.session.flush() if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error creating user" if author.id and blog.id: db.session.commit() subject = "Confirm your email" token = security.ts.dumps("*****@*****.**", salt='email-confirm-key') confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('email/activate.html', confirm_url=confirm_url) send = send_mail.Message("TELEPORT", form.email.data, "subject", html) send.send_message() else: db.session.rollback() error = "Error creating blog" flash('Blog created') return render_template('blog/blog_setup.html', form=form)
def setup(): form = SetupForm() error = "" if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) if request.method == "POST": print("method is post") else: print("method is not post") #image = request.files.get('image') image = request.files.get('image') print("Image: ", image) filename = None try: filename = uploaded_images.save(image) print("Try filename") print("File Name: ", filename) except: flash("The image was not uploaded.") print("The image was not uploaded.") author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, True, form.bio.data, filename) db.session.add(author) db.session.flush() if author.id: blog = Blog(form.name.data, author.id) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error creating user" if author.id and blog.id: db.session.commit() flash("Blog created") return redirect(url_for('index')) else: db.session.rollback() error = "Error creating blog" return render_template('blog/setup.html', form=form, error=error, action="new")
def setup(): form = SetupForm() error = None error2 = None #, blogs_from_author if form.validate_on_submit(): #More secure passwords salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, True) error = flush_obj(author) if error: db.session.rollback() db.session.close() flash("Error registering admin user") return render_template('blog/setup.html', form=form, error=error) else: blog = Blog(form.name.data, author.id) #TODO: Create view with author's blog, verify if name matches one of them using #blogs_from_author = Blog.query.filter_by().join etc #Throw error if author have blog with same name, else continue # blogs_from_author = db.query.filter_by(admin=author.id) # for blg in blogs_from_author: # if blg.name==blog.name: # error2="Blog and user already exists" # db.sesssion.rollback() # db.session.close() # flash(error2) # return render_template('blog/setup.html', form=form, error=error2) error2 = flush_commit(blog) if error2: flash("Unexpected Database Error registering Blog") return render_template('blog/setup.html', form=form, error=error2) else: session['username'] = form.username.data flash("Blog created") return redirect(url_for('admin')) return render_template('blog/setup.html', form=form, error=error)
def register(): form = RegisterForm() error = None if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) author = Author(form.fullname.data, form.email.data, form.username.data, hashed_password, form.is_author.data) db.session.add(author) db.session.flush() if author.id: db.session.commit() flash("User created successfully!") return redirect(url_for('success')) else: db.session.rollback() error = "Error creating user" return render_template('author/register.html', form=form)
def setup(): form = SetupForm() data = request.form error = "" blog_name = data.get('name') username = data.get('username') password = data.get('password') fullname = data.get('fullname') email = data.get('email') print("form.validate_on_submit(): {}".format(form.validate_on_submit())) print("data: {}".format(data)) if form.validate_on_submit(): author = Author(password=password, email=email, fullname=fullname, username=username, is_author=True) db.session.add(author) db.session.flush() if author.id: blog = Blog(admin=author.id, name=blog_name) db.session.add(blog) db.session.flush() else: db.session.rollback() error = "Error creating Author" if author.id and blog.id: db.session.commit() flash("Blog created") return redirect(url_for("admin")) else: db.session.rollback() error = "Error creating Blog" return render_template('blog/setup.html', form=form, error=error)