"""Subclass of clsSource, which is generated by wxFormBuilder.""" import wx from odmtools.view.clsCreateSource import clsSource from odmtools.odmdata import Source # Implementing clsSource class frmCreateSource(clsSource): def __init__(self, parent, service_man, prev_src): clsSource.__init__(self, parent) self.service_man = service_man self.prev = prev_src self.source = None self.series_service = self.service_man.get_series_service() self.populate_meta() def populate_meta(self): self.meta_list = {} metas = self.series_service.get_iso_metadata() if metas is not None: self.meta_list = {(x.title, x.id) for x in metas} # {(key, value) for (key, value) in zip(key_list, value_list)} self.meta_list["None"] = 0 self.chMeta.AppendItems(self.meta_list.keys()) self.chMeta.SetSelection(0) def getSource(self): return self.source # Handlers for dlgCreateSource events. def onOkClick(self, event): self.source = self.createSource() if self.all_fields_full(): self.EndModal(wx.ID_OK) else: wx.MessageDialog(None, "All required source fields must be completed.", " ", wx.OK).ShowModal() def all_fields_full(self): return (self.txtOrg.GetValue() != '') and \ (self.txtDescrip.GetValue() != '') and \ (self.txtName.GetValue() != '') and \ (self.txtPhone.GetValue() != '') and \ (self.txtEmail.GetValue() != '') and \ (self.txtAddress.GetValue() != '') and \ (self.txtCity.GetValue() != '') and \ (self.txtState.GetValue() != '') and \ (self.txtZip.GetValue() != '') and \ (self.txtCitation.GetValue() != '') def createSource(self): s = Source() s.organization = self.txtOrg.GetValue() if self.txtOrg.GetValue() != u'' else None s.description = self.txtDescrip.GetValue() if self.txtDescrip.GetValue() != u'' else None s.link = self.txtLink.GetValue() if self.txtLink.GetValue() != u'' else None s.contact_name = self.txtName.GetValue() if self.txtName.GetValue() != u'' else None s.phone = self.txtPhone.GetValue() if self.txtPhone.GetValue() != u'' else None s.email = self.txtEmail.GetValue() if self.txtEmail.GetValue() != u'' else None s.address = self.txtAddress.GetValue() if self.txtAddress.GetValue() != u'' else None s.city = self.txtCity.GetValue() if self.txtCity.GetValue() != u'' else None s.state = self.txtState.GetValue() if self.txtState.GetValue() != u'' else None s.zip_code = self.txtZip.GetValue() if self.txtZip.GetValue() != u'' else None s.citation = self.txtCitation.GetValue() if self.txtCitation.GetValue() != u'' else None s.iso_metadata_id = self.meta_list[self.chMeta.GetItems()[self.chMeta.GetSelection()]] # s.iso_metadata_id = 0 return s def onCancelClick(self, event): # TODO: Implement onCancelClick self.EndModal(wx.ID_CANCEL)