def get_name(self, obj): if obj.user.profile.curator is None: return None change_ending = Petrovich() return (change_ending.firstname( value=obj.user.profile.curator.first_name, case=Case.DATIVE, # gender=user.profile.curator.gender, ) + " " + obj.user.profile.curator.last_name[0] + ".")
def _skloninefio(self): if self.fio_head: fio = self.fio_head.split(' ') if len(fio) == 3: p = Petrovich() surname = fio[0] name = fio[1] lastname = fio[2] self.fio_head_rod_pad = p.lastname( surname, Case.GENITIVE) + ' ' + p.firstname( name, Case.GENITIVE) + ' ' + p.middlename( lastname, Case.GENITIVE) self.fio_head_dat_pad = p.lastname( surname, Case.DATIVE) + ' ' + p.firstname( name, Case.DATIVE) + ' ' + p.middlename( lastname, Case.DATIVE)
def create_paper(aid_request: AidRequest): try: today = datetime.date.today() date = "{} {} {} г.".format(today.day, MONTH_RU[today.month], today.year) user = aid_request.applicant userprofile = user.userprofile student_info = userprofile.student_info sex = get_sex(user) if sex == 'female': student = "студентки" gender = Gender.FEMALE else: student = "студента" gender = Gender.MALE p = Petrovich() fst = p.firstname(student_info.first_name, Case.GENITIVE, gender) lst = p.firstname(student_info.last_name, Case.GENITIVE, gender) if userprofile.middlename: mdl = p.firstname(userprofile.middlename, Case.GENITIVE, gender) else: mdl = "" name = "{} {} {}".format(lst, fst, mdl) context = { "student": student, "group": str(student_info.group), "date": date, "name": name, "reason": aid_request.category.reason, } tpl = DocxTemplate(STATIC_ROOT + "/fin_aid/Obrazets_Zayavlenia_Na_Matpomosch.docx") tpl.render(context) path = MEDIA_ROOT + "/aid_docs/user_{}/".format(user_hash(user)) filename = "application-{}-{}-{}.docx".format(today.year, today.month, today.day) os.makedirs(path, exist_ok=True) tpl.save(path + filename) application = AidDocument(request=aid_request, is_application_paper=True) application.file.save(filename, File(open(path + filename, "rb")), save=True) return filename except Exception as e: logger.exception(e)
def convert_lastnames(self): json_data = json.load(codecs.open(self.lastnames_src, 'r', 'utf-8-sig')) p = Petrovich() for item in json_data: if item['PeoplesCount'] > 0 and item["PeoplesCount"] < 1000: m_data = { "id": item["ID"], "name": item["Surname"], "gender": item["Sex"], "count": item["PeoplesCount"] } f_data = { "id": item["ID"], "name": p.lastname(item["Surname"], Case.GENITIVE, Gender.MALE), "gender": item["Sex"], "count": item["PeoplesCount"] } m_file = "male_russian_lastnames.txt" f_file = "female_russian_lastnames.txt" self.dump_results(m_data, full_path(m_file)) self.dump_results(f_data, full_path(f_file))
def gen_name(self): lastname, firstname, middlename = self.sender.split() lastname = Petrovich().lastname(lastname, Case.GENITIVE).capitalize() return lastname + " " \ + firstname[0].upper() + "." \ + middlename[0].upper() + "."
def setUpClass(cls): cls.p = Petrovich()
from petrovich.enums import Case, Gender from petrovich.main import Petrovich if __name__ == '__main__': rows = [ ('Алексеев', 'Алексей', 'Давыдович', Gender.MALE), ('Торсунов', 'Андрей', 'Владимирович', Gender.MALE), ('Матвеев', 'Денис', 'Евгеньевич', Gender.MALE), ('Исламов', 'Марат', 'Рафаэлевич', Gender.MALE), ('Алимова', 'Алия', 'Маратовна', Gender.FEMALE), ('Ткач', 'Валентина', 'Петровна', Gender.FEMALE), ('Ткач', 'Валентин', 'Петрович', Gender.MALE), ] petro = Petrovich() for segments in rows: fname, iname, oname, gender = segments for case in Case.CASES: print(u'{} {} {}'.format( petro.lastname(fname, case, gender), petro.firstname(iname, case, gender), petro.middlename(oname, case, gender), ))
def write_surnames_initials(id_surname, id_name, id_patronymic): human_class = Petrovich() changed_surname = human_class.lastname(id_surname, Case.DATIVE) return str(changed_surname + ' ' + get_initials(id_name, id_patronymic) + '\n')
def dative_name(id): FI = DB.get_person(id)[1].split(' ') petr = Petrovich() name = petr.firstname(FI[1], Case.DATIVE) return FI[0] + ' ' + name