コード例 #1
0
ファイル: views.py プロジェクト: Tatiana92/task-app
def save_person(request):
    import os
    import time

    message = '<html><body><textarea>no files</textarea></body></html>'
    if len(request.FILES) != 0:
        response = {}
        upload_image = request.FILES.getlist('file')[0]
        try:
            file_name = '%s' % (str(time.time()).replace(
                '.', '')) + upload_image.name
            destination = open(MEDIA_ROOT + file_name, 'wb+')
            for chunk in upload_image.chunks():
                destination.write(chunk)
            destination.close()
            new_item = Persons()
            new_item.first_name = request.POST['first_name']
            new_item.last_name = request.POST['last_name']
            new_item.date_of_birth = request.POST['date_of_birth']
            new_item.photo = file_name
            new_item.votes = request.POST['votes']
            new_item.age = request.POST['age']
            new_item.save()
            message = '<html><body><textarea>ok</textarea></body></html>'
        except Exception, e:
            message = '<html><body><textarea>error: %s</textarea></body></html>' % (
                str(e))
        return HttpResponse(message)
コード例 #2
0
ファイル: app.py プロジェクト: lldenisll/api_activity
 def post(self):
     data = request.json
     person = Persons(name=data['name'],age=data['age'])
     person.save()
     response={
         'id': person.id,
         'name': person.name,
         'age': person.age,
     }
     return response
コード例 #3
0
ファイル: main.py プロジェクト: NDesprez001/Flask_practice
def register():

    json = request.get_json()
    info = Persons(username=json['first_name'], email=json['email'])
    db.session.add(info)
    db.session.commit()
    return 'user added'
コード例 #4
0
def RegisteredUserUsernamePassword():
    PersonUserName = request.form.get("UserName")
    if db.query(Persons).filter_by(PersonUserName=PersonUserName).first():
        return render_template("Login/LoginFailed.html",
                               message="Uporabnik s tem imenom že obstaja.",
                               Link="/RegisteredUser")
    else:
        PersonPassword = request.form.get("Password")
        PersonPasswordCofirm = request.form.get("PasswordConfirm")
        if PersonPassword == PersonPasswordCofirm:
            HashedPassword = hashlib.sha256(
                PersonPassword.encode()).hexdigest()
            person = Persons(PersonName=session["PersonName"],
                             PersonLastName=session["PersonLastName"],
                             PersonEMSO=session["PersonEMSO"],
                             PersonCountry=session["PersonCountry"],
                             PersonEmailAddress=session["PersonEmailAddress"],
                             DateInserted=datetime.now(),
                             PersonUserName=PersonUserName,
                             PersonPassword=HashedPassword,
                             PriorityType=2,
                             IsDeleted=0)
            db.add(person)
            db.commit()
            # Napiši funkcijo za pošljanje podatkov na mail.
            return render_template("Login/RegisteredUser.html",
                                   PersonUserName=PersonUserName,
                                   PersonPassword=PersonPassword)
        else:
            return render_template("Login/LoginFailed.html",
                                   message="Gesli se ne ujemata.",
                                   Link="/RegisteredUser")
コード例 #5
0
def LoginForm():
    if not db.query(Persons).filter_by(PersonUserName="******").first():
        admin = Persons(PersonUserName="******",
                        PersonPassword=str(
                            hashlib.sha256("admin".encode()).hexdigest()),
                        PriorityType=1,
                        IsDeleted=0)
        db.add(admin)
        db.commit()
    return render_template("Login/Login.html")
コード例 #6
0
    def main(self):

        print("Scraping data for all films...")
        all_films = self.session.query(Films)

        for film in all_films:
            try:
                film_page = self.redirect_to_film_page(film.wiki_href)
                film_data = self.scrape_film_infobox(film_page)
            except Exception as e:
                print(e)
                continue
                
            try:
                # 1. load films_wiki
                film_obj = FilmsWiki(

                    film = film,
                    title = film_data["Title"],
                    released = self.extract_date(film_data["Released"]),
                    running_time = self.extract_runtime(film_data["Running Time"]),
                    budget = self.extract_money(film_data["Budget"]),
                    box_office = self.extract_money(film_data["Box Office"]),
                    )
                
                self.session.add(film_obj)

                # 2. load persons and film_persons

                for role in self.person_roles:
                    if film_data[role]:
                        persons = film_data[role]
                        
                        # if single person, make list
                        if type(persons) != list: 
                            persons = [persons] 

                        for name in persons:
                            try:
                                existing_person = self.session.query(Persons).\
                                                filter_by(full_name=name).one()
                                person_obj = existing_person

                            except Exception:
                                try:
                                    person_obj = Persons(
                                        full_name = name
                                        )
                                    self.session.add(person_obj)
                                    self.session.flush()
                                
                                except Exception:
                                    self.session.rollback()
                                
                            try:
                                film_person_obj = FilmPersons(
                                    film = film_obj,
                                    person = person_obj,
                                    role = role
                                    )
                                self.session.add(film_person_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()


                # 3. load countries and film_counries
                if film_data["Country"]:
                    countries = film_data["Country"]
                    
                    # if single country, make list
                    if type(countries) != list:
                        countries = [countries]

                    for country in countries:
                        try:
                            existing_country = self.session.query(Countries).\
                                            filter_by(country=country).one()
                            country_obj = existing_country

                        except Exception:
                            try:
                                country_obj = Countries(
                                    country = country
                                    )
                                self.session.add(country_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()

                        try:       
                            film_country_obj = FilmCountries(
                                film = film_obj,
                                country = country_obj
                                )
                            self.session.add(film_country_obj)
                            self.session.flush()
                        except Exception:
                            self.session.rollback()

                # 4. load companies and film_companies
                for role in self.company_roles:
                    if film_data[role]:
                        companies = film_data[role]

                        # if single company, make list
                        if type(companies) != list:
                            companies = [companies]

                        for company in companies:
                            try:
                                existing_company = self.session.query(Companies).\
                                                filter_by(company=company).one()
                                company_obj = existing_company
                            
                            except Exception:
                                try:
                                    company_obj = Companies(
                                        company = company
                                        )
                                    self.session.add(company_obj)
                                    self.session.flush()

                                except Exception:
                                    self.session.rollback()
                            try:
                                film_company_obj = FilmCompanies(
                                    film = film_obj,
                                    company = company_obj,
                                    role = role
                                    )
                                self.session.add(film_company_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()

                # 5. load languages and film_languages
                if film_data["Language"]:
                    languages = film_data["Language"]
                    
                    # if single language, make list
                    if type(languages) != list:
                        languages = [languages]

                    for language in languages:
                        try:
                            existing_language = self.session.query(Languages).\
                                                filter_by(language=language).one()
                            language_obj = existing_language

                        except Exception:
                            try:
                                language_obj = Languages(
                                    language = language
                                    )
                                self.session.add(language_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()

                        try:
                            film_language_obj = FilmLanguages(
                                film = film_obj,
                                language = language_obj
                                )
                            self.session.add(film_language_obj)
                            self.session.flush()
                        except Exception:
                            self.session.rollback()

                    print("Collected data for {}".format(film.title))
                    self.session.commit()
            
            except Exception as e:
                print(e)
                continue
コード例 #7
0
def insert_person():
    person = Persons(name='Denis', age='27')
    print(person)
    person.save()