def test_add_author(self):
     # Add another author on the fly
     author = Author()
     author.first_name = 'George'
     author.last_name = 'Orwell'
     self.db.session.add(author)
     self.db.session.commit()
 def test_add_author(self):
     # Add another author on the fly
     author = Author()
     author.first_name = 'George'
     author.last_name = 'Orwell'
     self.db.session.add(author)
     self.db.session.commit()
    def setUp(self):
        # Make sure that the user defined setUp method runs after the fixtures
        # setup function (i.e., the database should be setup already)
        assert Author.query.count() == 1
        assert Book.query.count() == 3

        # Add another author on the fly
        author = Author()
        author.first_name = 'George'
        author.last_name = 'Orwell'
        self.db.session.add(author)
        self.db.session.commit()
    def setUp(self):
        # Make sure that the user defined setUp method runs after the fixtures
        # setup function (i.e., the database should be setup already)
        assert Author.query.count() == 1
        assert Book.query.count() == 3

        # Add another author on the fly
        author = Author()
        author.first_name = 'George'
        author.last_name = 'Orwell'
        self.db.session.add(author)
        self.db.session.commit()
Exemple #5
0
        def test_two(self):
            print "Inside test_two"
            # Add another author on the fly
            author = Author()
            author.first_name = 'Aldous'
            author.last_name = 'Huxley'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "Brave New World"
            book.published_date = datetime.datetime(1932, 5, 12)
            self.db.session.add(book)

            self.db.session.commit()
Exemple #6
0
        def test_one(self):
            print "Inside test_one"
            # Add another author on the fly
            author = Author()
            author.first_name = 'George'
            author.last_name = 'Orwell'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "1984"
            book.published_date = datetime.datetime(1949, 6, 8)
            self.db.session.add(book)

            self.db.session.commit()
        def test_two(self):
            print("Inside test_two")
            # Add another author on the fly
            author = Author()
            author.first_name = 'Aldous'
            author.last_name = 'Huxley'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "Brave New World"
            book.published_date = datetime.datetime(1932, 5, 12)
            self.db.session.add(book)

            self.db.session.commit()
        def test_one(self):
            print("Inside test_one")
            # Add another author on the fly
            author = Author()
            author.first_name = 'George'
            author.last_name = 'Orwell'
            self.db.session.add(author)

            # Add another book for the new author
            book = Book()
            book.title = "1984"
            book.published_date = datetime.datetime(1949, 6, 8)
            self.db.session.add(book)

            self.db.session.commit()
Exemple #9
0
def addauthor(request):
	if request.GET:
 
		author = Author()
		author.AuthorID = request.GET['AuthorID']
		author.Name = request.GET['Name']
		author.Age = request.GET['Age']
		author.Country = request.GET['Country']
		author.save()
		return render_to_response('add_finish.html')
	else:
		return render_to_response('addauthor.html')
Exemple #10
0
def register(request):
    if request.method == 'POST':
        f = CustomUserCreationForm(request.POST)
        if f.is_valid():
            # send email verification now
            activation_key = helpers.generate_activation_key(
                username=request.POST['username'])

            subject = "TheGreatDjangoBlog Account Verification"

            message = '''\nPlease visit the following link to verify your account
						\n\n{0}://{1}/cadmin/activate/account/?key={2}''' \
               .format(request.scheme, request.get_host(), activation_key)

            error = False

            try:
                send_mail(subject, message, settings.SERVER_EMAIL,
                          [request.POST['email']])
                messages.add_message(
                    request, messages.INFO,
                    'Account created! Click on the link sent to your email to activate the account'
                )

            except:
                error = True
                messages.add_message(
                    request, messages.INFO,
                    'Unable to send email verification. Please try again')

            if not error:
                u = User.objects.create_user(request.POST['username'],
                                             request.POST['email'],
                                             request.POST['password1'],
                                             is_active=0,
                                             is_staff=True)

                author = Author()
                author.activation_key = activation_key
                author.user = u
                author.save()

            return redirect('register')
    else:
        f = CustomUserCreationForm()

    return render(request, 'cadmin/register.html', {'form': f})
Exemple #11
0
import json
from myapp.models import Author, Book
from bpmappers.djangomodel import ModelMapper


class AuthorMapper(ModelMapper):
    class Meta:
        model = Author


class BookMapper(ModelMapper):
    class Meta:
        model = Book


author = Author(name="tokibito", company="BeProud")
book = Book(title="Spam", price=500, author=author)
# マッピングとJSON変換
print("author:", json.dumps(AuthorMapper(author).as_dict(), indent=2))
print("book:", json.dumps(BookMapper(book).as_dict(), indent=2))