示例#1
0
 def put(self, id=None):
     data = ApiContact.parser.parse_args()
     contact = Contact.find_by_id(data['id'])
     if contact is None:
         contact = Contact(data['name'], data['email'])
     else:
         contact.name = data['name']
         contact.email = data['email']
     contact.save_to_db()
     return contact.json()
示例#2
0
    def _get_fields_from_edit_(self):
        wd = self.app.wd
        contact = Contact()
        # GET main fields
        contact.id = self._get_field_value_(By.NAME, "id")
        contact.first_name = self._get_field_value_(By.NAME, "firstname")
        contact.middle_name = self._get_field_value_(By.NAME, "middlename")
        contact.last_name = self._get_field_value_(By.NAME, "lastname")
        contact.nickname = self._get_field_value_(By.NAME, "nickname")

        # GET companies fields
        contact.company = self._get_field_value_(By.NAME, "company")
        contact.title = self._get_field_value_(By.NAME, "title")
        contact.address = self._get_field_value_(By.NAME, "address")

        # GET phones fields
        contact.home_phone = self._get_field_value_(By.NAME, "home")
        contact.mobile_phone = self._get_field_value_(By.NAME, "mobile")
        contact.work_phone = self._get_field_value_(By.NAME, "work")
        contact.fax_phone = self._get_field_value_(By.NAME, "fax")

        # GET email fields
        contact.email = self._get_field_value_(By.NAME, "email")
        contact.email2 = self._get_field_value_(By.NAME, "email2")
        contact.email3 = self._get_field_value_(By.NAME, "email3")
        contact.homepage = self._get_field_value_(By.NAME, "homepage")

        # TODO do some stuff for get value of selector
        # GET birthday date field
        # if contact.birth_date is not date.min and contact.birth_date is not None:
        #     b_day = contact.birth_date.day.__str__()
        #     b_month = contact.birth_date.strftime("%B")
        #     b_year = contact.birth_date.year.__int__()
        # else:
        #     b_day = None
        #     b_month = None
        #     = None
        # self._set_select_value_(By.XPATH, "//div[@id='content']/form/select[1]", b_day)
        # self._set_select_value_(By.XPATH, "//div[@id='content']/form/select[2]", b_month)
        # b_year = self._get_field_value_(By.NAME, "byear", b_year)
        # contact.birth_date = date(b_year,b_month,b_day)

        # GET anniversary date field
        # if contact.anniversary_date is not date.min and contact.anniversary_date is not None:
        #     a_day = contact.anniversary_date.day.__str__()
        #     a_month = contact.anniversary_date.strftime("%B")
        #     a_year = contact.anniversary_date.year.__int__()
        # else:
        #     a_day = None
        #     a_month = None
        #     a_year = None
        # self._set_select_value_(By.XPATH, "//div[@id='content']/form/select[3]", a_day)
        # self._set_select_value_(By.XPATH, "//div[@id='content']/form/select[4]", a_month)
        # a_year = self._get_field_value_(By.NAME, "ayear")
        # contact.birth_date = date(a_year, a_month, a_day)

        # GET address fields
        contact.address2 = self._get_field_value_(By.NAME, "address2")
        contact.phone2 = self._get_field_value_(By.NAME, "phone2")
        contact.notes = self._get_field_value_(By.NAME, "notes")
        # Return founded fields
        return contact