def set_data_for(self, group_id=None, search=None): if search: self.data = [("", tel.contact.name) for tel in PhoneNumber.filter().group_by('contact') if search.contact == tel.contact] else: self.data = [("", contact.name) for contact in Contact.all()] if group_id: if group_id == ALL_CONTACTS: qs = ContactGroup.filter().group_by('contact') else: qs = ContactGroup.filter(group__id=group_id) self.data = [("", contact_gp.contact.name) for contact_gp in qs]
def isvalid(self): self.list_phone_num = [(i.contact.number) for i in ContactGroup.filter(group__id=self.group.id)] if self.list_phone_num == []: self.send_butt.setEnabled(False) self.send_butt.setToolTip(u"""Ce groupe n'a pas le numéro de téléphone.""")
def save_form(self): if not self.iscomplet(): return full_name = unicode(self.full_name.text()) phone_number = int(self.phone_number.text().replace('.', '')) try: Contact(number=phone_number, name=full_name).save() except: self.msg_e_or_c.setText(u"Ce numéro existe déjà") self.msg_e_or_c.setStyleSheet("color: red") return grp = unicode(self.list_grp[self.combo_grp.currentIndex()]) if not grp == "Aucun": grp = Group.select().where(Group.name == grp).get() contact = Contact.select().where( Contact.number == phone_number).get() ContactGroup(group=grp.id, contact=contact).save() self.full_name.setText("") self.phone_number.setText("") self.msg_e_or_c.setText( u"Le numéro (<b>{}</b>) à éte bien enregistré".format( phone_number))
def addressbook_contactlist(group_id): try: group_id = int(group_id) except: group_id = ALL_CONTACTS if group_id == ALL_CONTACTS: qs = ContactGroup.filter().group_by('contact') group_dict = {'id': -1, 'name': u"Tous"} else: qs = ContactGroup.filter(group__id=group_id) group_dict = Group.get(id=group_id).to_dict() data = {'contacts': [contact_group.contact.to_dict() for contact_group in qs], 'group': group_dict} return json.dumps(data)
def save(self): data = self.data data['owner'] = current_identity.id group = ContactGroup(**data) db.session.add(group) db.session.flush() db.session.commit() return ContactGroup.query.filter_by(id=group.id).first()
def isvalid(self): self.list_phone_num = [ (i.contact.number) for i in ContactGroup.filter(group__id=self.group.id) ] if self.list_phone_num == []: self.send_butt.setEnabled(False) self.send_butt.setToolTip(u"""Ce groupe n'a pas le numéro de téléphone.""")
def set_data_for(self, group_id=None, search=None): if isinstance(group_id, int): qs = ContactGroup.select().where(ContactGroup.group == Group.get(Group.id == group_id)) self.data = [("", contact_gp.contact.name, contact_gp.contact.number) for contact_gp in qs] else: qs = Contact.select() if search: print(search) qs = qs.where(Contact.number.contains(search) | Contact.name.contains(search)) print(qs) self.data = [("", contact.name, contact.number) for contact in qs]
def addressbook_add_contact_to_group(group_id, contact_id): contact = Contact.get(id=int(contact_id)) group = Group.get(id=int(group_id)) data = {'contact': contact.to_dict(), 'group': group.to_dict()} subst = {'contact': contact.display_name(), 'group': group.display_name()} if ContactGroup.filter(contact=contact, group=group).count(): dict_return(data, INFO, u"%(contact)s fait déjà parti du groupe %(group)s." % subst, message_html=u"<strong>%(contact)s</strong> fait déjà " u"parti du groupe " u"<strong>%(group)s</strong>." % subst) else: cg = ContactGroup(contact=contact, group=group) try: cg.save() dict_return(data, SUCCESS, u"%(contact)s a été ajouté au groupe %(group)s." % subst, message_html=u"<strong>%(contact)s</strong> a été " u"ajouté au groupe " u"<strong>%(group)s</strong>." % subst) except Exception as e: subst.update({'err': e.message}) dict_return(data, ERROR, u"Impossible d'ajouter %(contact)s au groupe " u"%(group)s: %(err)r" % subst, message_html=u"Impossible d'ajouter " u"<strong>%(contact)s</strong> au " u"groupe <strong>%(group)s</strong>:<br />" u"<em>%(err)r</em>" % subst) return json.dumps(data)
def popup(self, pos): row = self.selectionModel().selection().indexes()[0].row() if (len(self.data) - 1) < row: return False self.contact = Contact.get(Contact.number == int(self.data[row][2])) menu = QMenu() menu.addAction(QIcon("{}transfer.png".format(Config.img_media)), u"Faire un envoi", lambda: self.send_money(self.contact)) menu.addAction(QIcon("{}edit_contact.png".format(Config.img_media)), u"modifier le contact", lambda: self.edit_contacts(self.contact)) addgroup = menu.addMenu(u"Ajouter au groupe") delgroup = menu.addMenu(u"Enlever du groupe") # # Enlever du groupe no_select = ContactGroup.filter(contact__number=int(self.data[row][2])) [delgroup.addAction(u"{}".format(grp_ct.group.name), lambda grp_ct=grp_ct: self.del_grp( grp_ct)) for grp_ct in no_select] # # Ajout au groupe lt_grp_select = [(i.group.name) for i in no_select] [addgroup.addAction(u"{}".format(grp.name), lambda grp=grp: self.add_grp(grp)) for grp in Group.select() if not grp.name in lt_grp_select] self.action = menu.exec_(self.mapToGlobal(pos)) self.refresh()
def addressbook_delete_group(group_id): data = {} subst = {} try: group = Group.get(id=int(group_id)) contact_groups = ContactGroup.filter(group__id=int(group_id)) except Group.DoesNotExist as e: subst.update({'err': e.message, 'group': group_id}) dict_return(data, ERROR, u"Le groupe #%(group)s n'existe pas : %(err)r" % subst, message_html=u"Le groupe " u"<strong>%(group)s</strong> n'existe pas.<br />" u"<em>%(err)r</em>" % subst) return json.dumps(data) subst.update({'group': group.display_name()}) try: [cg.delete_instance() for cg in contact_groups] group.delete_instance() dict_return(data, SUCCESS, u"%(group)s a été supprimé avec succès." % subst, message_html=u"<strong>%(group)s</strong> " u"a été supprimé avec succès." % subst) except Exception as e: subst.update({'err': e.message}) dict_return(data, ERROR, u"Impossible de supprimer le groupe %(group)s : %(err)r" % subst, message_html=u"Impossible de supprimer le groupe " u"<strong>%(group)s</strong><br />" u"<em>%(err)r</em>" % subst) return json.dumps(data)
def add_grp(self, grpname): group = Group.get(Group.name == grpname.name) ContactGroup.get_or_create(group=group, contact=self.contact) self.refresh()
def del_grp(self, grp_ct): group = Group.get(Group.name == grp_ct.group.name) contactgrp = ContactGroup.select().where(ContactGroup.group == group, ContactGroup.contact == self.contact).get() contactgrp.delete_instance() self.refresh()