예제 #1
0
    def post(self, request, publisher_id):
        user_id = request.session['user_id']
        username = request.session['username']
        context = {}
        epublisher = PublisherForm(request.POST)

        if 'update-publisher' in request.POST:
            if epublisher.is_valid():
                p = Publisher()
                p.company_name = epublisher.cleaned_data['company_name']
                p.city = epublisher.cleaned_data['city']
                p.state_code = epublisher.cleaned_data['state_code']
                p.zip_code = epublisher.cleaned_data['zip_code']
                p.phone_number = epublisher.cleaned_data['phone_number']
                p.contact_name = epublisher.cleaned_data['contact_name']
                p.publisher_id = publisher_id
                self.pdao.update(p)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username']
            return redirect(
                reverse(('adminpublisherdetail'),
                        kwargs={'publisher_id': publisher_id}))

        if 'delete-publisher' in request.POST:
            self.pdao.delete(publisher_id)
            context['user_id'] = request.session['user_id'],
            context['username'] = request.session['username']
            return redirect(reverse('adminpublisherindex'))
예제 #2
0
    def get_byid(self, publisher_id):
        publisher = None
        try:
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            args = [publisher_id]
            cursor.callproc('getPublisherByPublisherID', args)
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for publisher_row in result.fetchall():
                    publisher = Publisher()
                    publisher.publisher_id = publisher_row[0]
                    publisher.company_name = publisher_row[1]
                    publisher.city = publisher_row[2]
                    publisher.state_code = publisher_row[3]
                    publisher.zip_code = publisher_row[4]
                    publisher.phone_number = publisher_row[5]
                    publisher.contact_name = publisher_row[6]

            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return publisher
예제 #3
0
    def get_all(self):
        publishers = []
        try:
            # Setup connection to the DB
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            # Calls the stored procedure
            cursor.callproc('getAllPublishers')

            # This loop iterates through the resultsets
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for publisher_row in result.fetchall():
                    publisher = Publisher()
                    publisher.publisher_id = publisher_row[0]
                    publisher.company_name = publisher_row[1]
                    publisher.city = publisher_row[2]
                    publisher.state_code = publisher_row[3]
                    publisher.zip_code = publisher_row[4]
                    publisher.phone_number = publisher_row[5]
                    publisher.contact_name = publisher_row[6]
                    publishers.append(publisher)

            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return publishers
예제 #4
0
 def post(self, request):
     user_id = request.session['user_id']
     username = request.session['username']
     context = {}
     apublisher = PublisherForm(request.POST)
     if 'create-publisher' in request.POST:
         if apublisher.is_valid():
             p = Publisher()
             p.company_name = apublisher.cleaned_data['company_name']
             p.city = apublisher.cleaned_data['city']
             p.state_code = apublisher.cleaned_data['state_code']
             p.zip_code = apublisher.cleaned_data['zip_code']
             p.phone_number = apublisher.cleaned_data['phone_number']
             p.contact_name = apublisher.cleaned_data['contact_name']
             self.pdao.create(p)
         context['user_id'] = request.session['user_id'],
         context['username'] = request.session['username']
         return redirect(reverse('adminpublisherindex'))
예제 #5
0
    def get_byname(self, company_name):
        publisher = Publisher()
        try:
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            args = (company_name, )
            cursor.callproc('getPublisherByName', args)
            # This gets the first resultset
            result = next(cursor.stored_results())
            # This gets the first row in the resultset
            publisher_row = result.fetchone()
            publisher.publisher_id = publisher_row[0]
            publisher.company_name = publisher_row[1]
            publisher.city = publisher_row[2]
            publisher.state_code = publisher_row[3]
            publisher.zip_code = publisher_row[4]
            publisher.phone_number = publisher_row[5]
            publisher.contact_name = publisher_row[6]
            leftover_rows = len(result.fetchall())
            # Probably don't need this since we should make the company name a UI
            if leftover_rows != 0:
                print(
                    str(leftover_rows) +
                    " more row(s) have the company name: " + "\"" +
                    company_name + "\"")

            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return publisher
    def post(self, request):
        context = {}
        self.get_dropdown_data()
        # Handle POST requests
        if 'create-book' in request.POST:
            sub_book_form = BookForm(request.POST,
                                     author_choices=self.authors,
                                     publisher_choices=self.publishers,
                                     genre_choices=self.genres)
            book = Book()
            if sub_book_form.is_valid():
                book.title = sub_book_form.cleaned_data['title']
                book.isbn10 = sub_book_form.cleaned_data['isbn10']
                book.isbn13 = sub_book_form.cleaned_data['isbn13']
                book.copyRightDate = sub_book_form.cleaned_data[
                    'copyright_date']
                book.edition = sub_book_form.cleaned_data['edition']
                book.numberOfPages = sub_book_form.cleaned_data['num_pages']
                book.type = sub_book_form.cleaned_data['book_type']
                author = Author()
                author.author_id = int(sub_book_form.cleaned_data['authors'])
                book.author = author
                publisher = Publisher()
                publisher.publisher_id = int(
                    sub_book_form.cleaned_data['publishers'])
                book.publisher = publisher
                genre = Genre()
                genre.genre_id = int(sub_book_form.cleaned_data['genres'])
                book.genre = genre
                book.inventory.quantity_on_hand = sub_book_form.cleaned_data[
                    'quantity_on_hand']
                book.inventory.cost = sub_book_form.cleaned_data['cost']
                book.inventory.retail_price = sub_book_form.cleaned_data[
                    'retail_price']

                self.book_dao.create(book)

                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username']

                context['notification'] = "Book saved successfully!"
                return redirect(reverse('adminbookindex'))
            else:
                context['notification'] = "Not a valid submission."

        elif 'create-publisher' in request.POST:
            sub_publisher_form = PublisherForm(request.POST)
            publisher = Publisher()
            if sub_publisher_form.is_valid():
                publisher.company_name = sub_publisher_form.cleaned_data[
                    'company_name']
                publisher.city = sub_publisher_form.cleaned_data['city']
                publisher.state_code = sub_publisher_form.cleaned_data[
                    'state_code']
                publisher.zip_code = sub_publisher_form.cleaned_data[
                    'zip_code']
                publisher.phone_number = sub_publisher_form.cleaned_data[
                    'phone_number']
                publisher.contact_name = sub_publisher_form.cleaned_data[
                    'contact_name']
                self.publisher_dao.create(publisher)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username']
                context['notification'] = "Publisher saved successfully!"
                return redirect(reverse('adminaddbook'))
            else:
                context['notification'] = "Not a valid submission."

        elif 'create-author' in request.POST:
            sub_author_form = AuthorForm(request.POST)
            author = Author()
            if sub_author_form.is_valid():
                author.first_name = sub_author_form.cleaned_data['first_name']
                author.last_name = sub_author_form.cleaned_data['last_name']

                self.author_dao.create(author)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username']
                context['notification'] = "Author saved successfully!"
                return redirect(reverse('adminaddbook'))
            else:
                context['notification'] = "Not a valid submission."

        elif 'create-genre' in request.POST:
            sub_genre_form = GenreForm(request.POST)
            genre = Genre()
            if sub_genre_form.is_valid():
                genre.genre = sub_genre_form.cleaned_data['genre']

                self.genre_dao.create(genre)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username']
                context['notification'] = "Genre saved successfully!"
                return redirect(reverse('adminaddbook'))
            else:
                context['notification'] = "Not a valid submission."
        else:
            return redirect(reverse('adminaddbook'))