Esempio n. 1
0
def index():
    form = ContactForm()
    if request.method == 'POST' and form.validate_on_submit():
        contact = Contact()
        form.populate_obj(contact)
        if form.latitude.data and form.longitude.data:
            contact.geo = ndb.GeoPt(form.latitude.data, form.longitude.data)
        contact.put()
        return redirect(url_for('contacts.admin.index'))
    contacts = Contact.query().order(-Contact.order_id)
    return render_template(
        'contacts/admin/index.html',
        form=form,
        contacts=contacts
    )
Esempio n. 2
0
def edit(key_id):
    contact = Contact.retrieve_by_id(key_id)
    if not contact:
        return redirect(url_for('contacts.admin.index'))
    if request.method == 'POST' and 'delete_contact' in request.form:
        contact.key.delete()
        return redirect(url_for('contacts.admin.index'))

    form = ContactForm(obj=contact)
    if contact.geo:
        form.latitude.data = contact.geo.lat
        form.longitude.data = contact.geo.lon
    if request.method == 'POST' and form.validate_on_submit():
        form.populate_obj(contact)
        if form.latitude.data and form.longitude.data:
            contact.geo = ndb.GeoPt(form.latitude.data, form.longitude.data)
        else:
            contact.geo = None
        contact.put()
        return redirect(url_for('contacts.admin.index'))
    return render_template(
        'contacts/admin/edit.html',
        form=form,
        contact=contact
    )
Esempio n. 3
0
def index():
    from main import FeedbackForm
    form = FeedbackForm()
    if form.validate_on_submit():
        feedback_email = model.Config.get_master_db().feedback_email
        try:
            if feedback_email:
                mail.send_mail(
                    sender=feedback_email,
                    to=feedback_email,
                    subject=u'[%s] - cообщение от %s' % (
                        model.Config.get_master_db().brand_name,
                        form.name.data,
                      ),
                    reply_to=form.email.data or feedback_email,
                    body=u'%s\n\n%s\n%s' % (form.feedback.data, form.email.data, form.contact.data)
                )
        except:
            pass
        flash(u'Спасибо за сообщение! Мы свяжемся с Вами в ближайшее время.', category='success')
        return redirect(url_for('contacts.index'))
    if not form.errors and auth.current_user_id() > 0:
        form.email.data = auth.current_user_db().email
    contacts = Contact.query(Contact.is_public == True).order(Contact.order_id)
    return render_template(
        'contacts/index.html',
        html_class='contacts_page',
        contacts=contacts,
        form=form
    )
Esempio n. 4
0
def create_contact(sh, row, govt):
    '''
    put agency name and note together as its name
    '''
    try:
        agency_name = sh.cell(row, 0).value.strip()
        #note = sh.cell(row, 1).value.strip()
        #agency_name = agency_name + '/' + note
        name = sh.cell(row, 1).value.strip().split(' ')
        fname, middle, lname = ('', '', '')
        if len(name) == 1:
            fname = name[0]
        elif len(name) == 2:
            fname = name[0]
            lname = name[1]
        elif len(name) > 2:
            fname = name[0]
            middle = name[1]
            lname = name[2]
        title = sh.cell(row, 2).value.strip()
    except Exception as e:
        print e
        import pdb;pdb.set_trace()
    
    email = sh.cell(row, 10).value.strip().split('mailto:')

    agency, created = Agency.objects.get_or_create(name=agency_name, government=govt)
    #i wish each contact had an agency field because this is a good way to associate the wrong contact with an agency
    #contact, created = Contact.objects.get_or_create(first_name=fname, middle_name=middle,
    #    last_name=lname)
    contact = Contact(first_name=fname, middle_name=middle, last_name=lname)
    logger.info('created %s %s %s' % (fname, middle, lname))
    contact.save()
    agency.contacts.add(contact)
    #contact.add_note(note)
    contact.add_title(title)
    #contact.add_address(address)
    #contact.add_phone(phone)
    if len(email) > 1:
        mail = email[1]
    else:
        mail = email[0]
    contact.add_email(mail)
    try:
        tags = str(sh.cell(row, 13).value).split(',')
        for tag in tags:
            tag = tag.strip()
            if tag != '':
                print 'tag added %s' % tag
                agency.tags.add(tag)
    except Exception as e:
        print '%s' % (e)
Esempio n. 5
0
 def obj_create(self, bundle, **kwargs):
     try:
         data = bundle.data
         user = bundle.request.user
         if user.is_anonymous():
             user = None
         if len(contact_is_valid(bundle)) > 0:
             raise BadRequest(contact_is_valid(bundle))
         print "user2 %s" % user
         data['dob'] = data['dob'] or None if 'dob' in data.keys() else None # Empty string no good
         agencyId = data['agencyId']
         del data['agencyId']
         emails = [EmailAddress.get_or_create(email)[0] for email in data['emails'] if email]
         map(lambda x: x.save(), emails)
         notes = [Note(content = data['notes'], user = user)]
         del data['notes']
         map(lambda x: x.save(), notes)
         titles = [Title(content = title) for title in data['titles'] if title]
         del data['titles']
         map(lambda x: x.save(), titles)
         del data['emails']
         phone_numbers = [Phone(content = phone) for phone in data['phone_numbers'] if phone]
         del data['phone_numbers']
         map(lambda x: x.save(), phone_numbers)
         addresses = [Address(content = address) for address in data['addresses'] if address]
         map(lambda x: x.save(), addresses)
         del data['addresses']
         agency = Agency.objects.get(id=agencyId)
         thecontact = Contact(**data)
         thecontact.save()
         thecontact.titles = titles
         thecontact.emails = emails
         thecontact.phone_numbers = phone_numbers
         thecontact.addresses = addresses
         thecontact.notes = notes
         thecontact.agency_related_contacts = [agency]
         thecontact.creator = user
         thecontact.save()
         agency.save()
         bundle.obj = thecontact
         return bundle
     except Exception as e:
         logger.exception(e)
         raise BadRequest (str(e))
Esempio n. 6
0
 def obj_create(self, bundle, **kwargs):
     try:
         data = bundle.data
         user = bundle.request.user
         if user.is_anonymous():
             user = None
         if len(contact_is_valid(bundle)) > 0:
             raise BadRequest(contact_is_valid(bundle))
         print "user2 %s" % user
         data['dob'] = data['dob'] or None if 'dob' in data.keys(
         ) else None  # Empty string no good
         agencyId = data['agencyId']
         del data['agencyId']
         emails = [
             EmailAddress.get_or_create(email)[0]
             for email in data['emails'] if email
         ]
         map(lambda x: x.save(), emails)
         notes = [Note(content=data['notes'], user=user)]
         del data['notes']
         map(lambda x: x.save(), notes)
         titles = [
             Title(content=title) for title in data['titles'] if title
         ]
         del data['titles']
         map(lambda x: x.save(), titles)
         del data['emails']
         phone_numbers = [
             Phone(content=phone) for phone in data['phone_numbers']
             if phone
         ]
         del data['phone_numbers']
         map(lambda x: x.save(), phone_numbers)
         addresses = [
             Address(content=address) for address in data['addresses']
             if address
         ]
         map(lambda x: x.save(), addresses)
         del data['addresses']
         agency = Agency.objects.get(id=agencyId)
         thecontact = Contact(**data)
         thecontact.save()
         thecontact.titles = titles
         thecontact.emails = emails
         thecontact.phone_numbers = phone_numbers
         thecontact.addresses = addresses
         thecontact.notes = notes
         thecontact.agency_related_contacts = [agency]
         thecontact.creator = user
         thecontact.save()
         agency.save()
         bundle.obj = thecontact
         return bundle
     except Exception as e:
         logger.exception(e)
         raise BadRequest(str(e))