Пример #1
0
def main():
    build = Building("Math Building", 25)
    build2 = Building("Science Building", 17)
    camp = Campus()
    build.get_info()
    build2.get_info()
    camp.add_building(build)
    camp.add_building(build2)
    camp.get_info()
Пример #2
0
def main():
    mb = Building('"Math Building"', 25)
    sb = Building('"Science Building"', 17)
    mb.get_info()
    sb.get_info()

    campus_total = Campus('"Math Building"', 1, 25)
    campus_total.add_building('"Science Building"', 1, 17)
    campus_total.get_info()
    campus_total.name_b()
Пример #3
0
 def get_campus(self, campus_id):
     with dbapi2.connect(self.dbfile) as connection:
         cursor = connection.cursor()
         query = "select * from campus where (id = %s)"
         cursor.execute(query, (campus_id, ))
         if (cursor.rowcount == 0):
             return None
     campus_ = Campus(*cursor.fetchone()[:])  # Inline unpacking of a tuple
     return campus_
Пример #4
0
 def save(form, image):
     print('HETYHEYHE', image)
     file_name = secure_filename(image.filename)
     # or ByteIO, whatever you like
     bin_file = image.read()
     campus = Campus(0, form.name.data, form.address.data, form.city.data,
                     form.size.data, form.foundation_date.data,
                     form.phone_number.data, file_name, image)
     validate_image(image)
Пример #5
0
def main():
    math_building = Building("Math Building", 25)
    math_building.get_info()

    science_building = Building("Science Building", 17)
    science_building.get_info()

    my_campus = Campus()
    my_campus.add_building(math_building)
    my_campus.add_building(science_building)
    my_campus.get_info()
Пример #6
0
 def get_campuses(self):
     campuses = []
     with dbapi2.connect(self.dbfile) as connection:
         cursor = connection.cursor()
         query = "select * from campus order by id asc"
         cursor.execute(query)
         print('Cursor.rowcount', cursor.rowcount)
         for row in cursor:
             campus = Campus(*row[:])
             campuses.append((campus.id, campus))
     return campuses
Пример #7
0
Файл: main.py Проект: NOdoff/OOP
def main():
    b = Building("Math Building", 25)
    c = Campus()
    n = Building("Science Building", 17)
    b.get_info()
    n.get_info()
    c.add_building(b)
    c.add_building(n)
    c.get_info()
Пример #8
0
def campus():
    if (current_user.is_admin):
        db = current_app.config["db"]
        campuses = db.get_campuses()
        campus = {}
        form = add_campus_form()
        error = ''
        if request.method == "POST" and 'delete_campus_flag' in request.form:
            campus_id = request.form['delete_campus_flag']

            try:
                db.delete_campus(campus_id)
                return redirect(url_for('campus'))
            except Error as e:
                error = type(e).__name__ + '----' + str(e)
                if isinstance(e, errors.ForeignKeyViolation):
                    str_e = str(e)
                    if 'faculty' in str_e:
                        error = "There are faculties in this campus! It can not be deleted!"
                pass
            context = {
                # 'form': form,
                'campuses': campuses,
                'form': form,
                'error': error
            }
            return render_template('/campuses/campus.html', context=context)
        elif request.method == "POST" and 'add_campus_form' in request.form:
            if (form.validate()):
                image = request.files['image']
                filename = secure_filename(image.filename)
                file_extension = filename.split(".")[-1]
                filename = filename.split(".")[0]
                if (validate_image(file_extension)):
                    img_data = request.files['image'].read()
                else:
                    filename = ""
                    file_extension = "NO_IMAGE"
                    img_data = b''
                campus = Campus(0, form.name.data, form.address.data,
                                form.city.data, form.size.data,
                                form.foundation_date.data,
                                form.phone_number.data, file_extension,
                                img_data)
                try:
                    db.add_campus(campus)
                    return redirect(url_for('campus'))
                except Error as e:
                    error = tidy_error(e)
                print(error)
                return redirect(url_for('campus'))
            else:
                error = form.errors
                context = {
                    # 'form': form,
                    'campuses': campuses,
                    'form': form,
                    'error': error
                }
                return render_template('/campuses/campus.html',
                                       context=context)
        elif request.method == "POST" and "redirect_edit_page" in request.form:
            campus_form_id = request.form['redirect_edit_page']
            return redirect(
                url_for('campus_detailed', campus_id=campus_form_id))
        context = {
            # 'form': form,
            'campuses': campuses,
            'form': form,
            'error': error
        }
        return render_template('/campuses/campus.html', context=context)
Пример #9
0
def campus_detailed(campus_id):
    if (current_user.is_admin):
        db = current_app.config["db"]
        campus = db.get_campus(campus_id)
        edit_campus_form = add_campus_form()
        add_faculty = add_faculty_form()
        if (campus.img_data is None):
            image = ""
            image_extension = ""
        elif (campus.img_extension != "NO_IMAGE"):
            image = b64encode(campus.img_data)
            image = image.decode('utf-8')
            image_extension = campus.img_extension
        else:
            image = ""
            image_extension = ""
        faculties = db.get_faculties_from_campus(campus.id)

        if request.method == "POST" and 'change_picture' in request.form:
            image = request.files['image']
            filename = secure_filename(image.filename)
            file_extension = filename.split(".")[-1]
            filename = filename.split(".")[0]
            img_data = b''
            error = ''
            if (validate_image(file_extension)):
                img_data = request.files['image'].read()
            updated_campus = Campus(campus_id, campus.name, campus.address,
                                    campus.city, campus.size,
                                    campus.foundation_date,
                                    campus.phone_number, file_extension,
                                    img_data)
            try:
                db.update_campus(updated_campus)
                return redirect(url_for('campus_detailed',
                                        campus_id=campus_id))
            except Error as e:
                error = tidy_error(e)
                pass
            context = {
                'Campus': campus,
                'edit_campus_form': edit_campus_form,
                'campus_image': image,
                'campus_image_extension': image_extension,
                'add_faculty_form': add_faculty,
                'faculties': faculties,
                'image_added': True,
                'error': error
            }
            return render_template('/campuses/campus_detailed.html',
                                   context=context)
        elif request.method == "POST" and "delete_image" in request.form:
            file_extension = ""
            img_data = b""
            updated_campus = Campus(campus_id, campus.name, campus.address,
                                    campus.city, campus.size,
                                    campus.foundation_date,
                                    campus.phone_number, file_extension,
                                    img_data)
            error = ''
            try:
                db.update_campus(updated_campus)
                return redirect(url_for('campus_detailed',
                                        campus_id=campus_id))
            except Error as e:
                error = tidy_error(e)
                pass
            context = {
                'Campus': campus,
                'edit_campus_form': edit_campus_form,
                'campus_image': image,
                'campus_image_extension': image_extension,
                'add_faculty_form': add_faculty,
                'faculties': faculties,
                'image_added': True,
                'error': error
            }
            return render_template('/campuses/campus_detailed.html',
                                   context=context)
        elif request.method == "POST" and 'add_faculty_form' in request.form:
            error = ''
            if (add_faculty.validate()):
                faculty = Faculty(0, request.form['add_faculty_form'],
                                  add_faculty.name.data,
                                  add_faculty.shortened_name.data,
                                  add_faculty.address.data,
                                  add_faculty.foundation_date.data,
                                  add_faculty.phone_number.data)
                try:
                    db.add_faculty(faculty)
                    return redirect(
                        url_for('campus_detailed', campus_id=campus.id))
                except Error as e:
                    error = tidy_error(e)
                    pass

            context = {
                'Campus': campus,
                'edit_campus_form': edit_campus_form,
                'campus_image': image,
                'campus_image_extension': image_extension,
                'add_faculty_form': add_faculty,
                'faculties': faculties,
                'image_added': True,
                'error': error
            }
            return render_template('/campuses/campus_detailed.html',
                                   context=context)
        elif request.method == "POST" and 'edit_campus_form' in request.form:
            campus_id = campus.id
            updated_campus = Campus(campus_id, edit_campus_form.name.data,
                                    edit_campus_form.address.data,
                                    edit_campus_form.city.data,
                                    edit_campus_form.size.data,
                                    edit_campus_form.foundation_date.data,
                                    edit_campus_form.phone_number.data,
                                    campus.img_extension, campus.img_data)
            error = ''
            if (edit_campus_form.validate()):
                try:
                    db.update_campus(updated_campus)
                    return redirect(
                        url_for('campus_detailed', campus_id=campus.id))
                except Error as e:
                    error = tidy_error(e)
                    pass
                add_faculty = add_faculty_form()
                edit_campus_form = add_campus_form()
            else:
                error = edit_campus_form.errors
            context = {
                'Campus': campus,
                'edit_campus_form': edit_campus_form,
                'campus_image': image,
                'campus_image_extension': image_extension,
                'add_faculty_form': add_faculty,
                'faculties': faculties,
                'image_added': True,
                'error': error,
                'update_error': error
            }
            return render_template('/campuses/campus_detailed.html',
                                   context=context)
        elif request.method == "POST" and 'delete_faculty_flag' in request.form:
            faculty_delete_id = request.form['delete_faculty_flag']
            error = ''
            try:
                db.delete_faculty(faculty_delete_id)
                return redirect(url_for('campus_detailed',
                                        campus_id=campus.id))
            except Error as e:
                error = type(e).__name__ + '----' + str(e)
                if isinstance(e, errors.ForeignKeyViolation):
                    str_e = str(e)
                    if 'department' in str_e:
                        remove_error = "There are departments in this faculty! It can not be deleted!"
                pass
            context = {
                'Campus': campus,
                'edit_campus_form': edit_campus_form,
                'campus_image': image,
                'campus_image_extension': image_extension,
                'add_faculty_form': add_faculty,
                'faculties': faculties,
                'image_added': True,
                'remove_error': remove_error
            }
            return render_template('/campuses/campus_detailed.html',
                                   context=context)
        elif request.method == "POST" and 'redirect_edit_page' in request.form:
            faculty_form_id = request.form['redirect_edit_page']
            return redirect(
                url_for('faculty_detailed', faculty_id=faculty_form_id))

        context = {
            # 'add_faculty_form': add_facultyForm,
            'Campus': campus,
            'edit_campus_form': edit_campus_form,
            'campus_image': image,
            'campus_image_extension': image_extension,
            'add_faculty_form': add_faculty,
            'faculties': faculties,
            'image_added': True,
        }
        return render_template('/campuses/campus_detailed.html',
                               context=context)
Пример #10
0
#! /usr/bin/env python3
from campus import Campus
from student import Student
import os
from orm import ORM

DIR = os.path.dirname(__file__)
DBNAME = 'school.db'
DBPATH = os.path.join(DIR, 'data', DBNAME)

ORM.dbpath = DBPATH
bk = Campus(city="city")
bk.load_text()
# bkm = Word(word_count='word count')
# bkm.makeword(word)
Пример #11
0
from building import Building
from campus import Campus

if __name__ == '__main__':
    bd = Building("Math Building", 25)
    bd2 = Building("Science Building", 17)
    bd.get_info()
    bd2.get_info()
    cp = Campus()
    cp.add_building(bd)
    cp.add_building(bd2)
    cp.get_info()
Пример #12
0
from building import Building
from campus import Campus

if __name__ == "__main__":
    buildings = (Building("MathBuilding", 25), Building("ScienceBuilding", 17))
    campus = Campus()
    for building in buildings:
        campus.add_building(building)
        building.get_info()
    campus.get_info()



Пример #13
0
 def jsonToCampus(self, data):
     type = data['type']
     id = data['id']
     name = data['name'].encode('utf-8')
     campus = Campus(type, id, name)
     return campus
Пример #14
0
from building import Building
from campus import Campus

obj = Campus()

mathb = Building("MATH BUILDING", 300)
mathb.get_info()

sci = Building("Science BUILDING", 700)
sci.get_info()

obj.add_building(mathb)
obj.get_info()

obj.add_building(sci)
obj.get_info()
Пример #15
0
def seed(dbpath=DBPATH):
    ORM.dbpath = dbpath

    NewYork = Campus(city='New York', state='New York')
    NewYork.save()