当前位置: 首页>>代码示例>>Python>>正文


Python Contact.save方法代码示例

本文整理汇总了Python中models.Contact.save方法的典型用法代码示例。如果您正苦于以下问题:Python Contact.save方法的具体用法?Python Contact.save怎么用?Python Contact.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Contact的用法示例。


在下文中一共展示了Contact.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_contacts

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
def upload_contacts(request):
  if not request.user.is_authenticated():
    return HttpResponse('You are not logged in')
  if request.FILES.__contains__('csv'):
    rows = csv.reader(request.FILES['csv'])
    count = 0
    for row in rows:
      if count > 0 and len(row) == 11:
        contactExists = Contact.objects.filter(email=row[4]).count()
        if not contactExists:
          contact = Contact(
            first_name = row[0],
            last_name = row[1],
            phone = row[2],
            mobile = row[3],
            email = row[4],
            address = row[5],
            colony = row[6],
            city = row[7],
            zip_code = row[8],
            birth_date = row[10] if row[10] != '' else '1988-11-16',
            amount = '',
            period = '',
            payment = '',
            tax_info = ''
          )
          contact.save()
          if len(row[9]) > 0:
            for group in Group.objects.filter(id__in=row[9].split(' ')):
              contact.group.add(group)
          contact.save()
      count+=1
    return HttpResponseRedirect('/admin/impulso/contact/')
  return render('admin/upload.html', {}, context_instance = RequestContext(request))
开发者ID:jcebXD,项目名称:impulso,代码行数:36,代码来源:views.py

示例2: contact_add

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
def contact_add(request):
    """
    Handle normal request to add a contact.
    """
    if request.method != 'POST':
        raise Http404
    
    form = ContactAddForm(request.POST)
    if form.is_valid():
        contact_email = form.cleaned_data['contact_email']
        
        contact = Contact()
        contact.user_email = form.cleaned_data['user_email']
        contact.contact_email = contact_email
        contact.contact_name = form.cleaned_data['contact_name']
        contact.note = form.cleaned_data['note']
        contact.save()
            
        messages.success(request, _(u"Successfully adding %s to contacts.") % contact_email)
    else:
        messages.error(request, _('Failed to add an contact.'))
    
    referer = request.META.get('HTTP_REFERER', None)
    if not referer:
        referer = SITE_ROOT
    return HttpResponseRedirect(referer)
开发者ID:hilerchyn,项目名称:seahub,代码行数:28,代码来源:views.py

示例3: test_encoding_is_proper

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
 def test_encoding_is_proper(self):
     # test_str = unicode("✄", "utf-8")
     test_str = u"✄"
     name = Contact(first_name=test_str)
     name.save()
     name2 = Contact.objects.get(first_name=test_str)
     self.assertEqual(name.first_name, name2.first_name)
开发者ID:whorst,项目名称:Capstone,代码行数:9,代码来源:tests.py

示例4: send_invitation

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
def send_invitation(invitation):
  """
  """
  try:
    user = User.objects.get(email=invitation.email)
    message = "{0} added you to his contacts".format(
        invitation.sender.username)
    contact = Contact(owner=invitation.sender, user=user)
    contact.save()
    invitation.delete()
    return HttpResponseRedirect(contact.get_absolute_url())
  except User.DoesNotExist:
    message = """
{0} Invites you to join his contacts.
You can register on http://{1}/user/create_account/ \
if you want to accept his invitation""".format(
        invitation.sender.username,
        Site.objects.get_current().domain
        )
  send_mail('An invitation sent to you',
             message,
             invitation.sender,
             [invitation.email],
             fail_silently=False
             )
  return HttpResponseRedirect(invitation.get_absolute_url())
开发者ID:bilougit,项目名称:agenda,代码行数:28,代码来源:views.py

示例5: create

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
def create():
    form = ContactForm()
    if form.validate_on_submit():
        new_contact = Contact()
        new_name = Name()
        new_contact.email = form.email.data
        new_name.first_name = form.first_name.data
        new_name.last_name = form.last_name.data
        new_contact.name = new_name
        new_contact.group = form.group.data
        for language in form.languages.data:
            if language:
                new_contact.tags.append(language)
        other_tags = form.other_tags.data.replace(", ", ",").split(",")
        for tag in other_tags:
            new_contact.tags.append(tag)
        try:
            new_contact.save()
            print new_contact.name.first_name, new_contact.name.last_name
            flash_string = '<a href="/{}">{} {}</a> was added to the database.'
            print flash_string
            flash_string = flash_string.format(
                new_contact.email, new_contact.name.first_name, new_contact.name.last_name
            )
            flash(Markup(flash_string))
            return redirect(url_for("index"))
        except Exception as e:
            print "Errors in the form"
            flash("There were errors in the form.  Specifically, " + e.message)

    return render_template("create_contact.html", form=form)
开发者ID:skatingskull,项目名称:based,代码行数:33,代码来源:views.py

示例6: test_signal_processor

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
    def test_signal_processor(self):
        contact = Contact(
            first_name='Igor_test',
            last_name='Kucher_test',
            birth_date='1990-01-10',
            email='[email protected]',
            jabber='[email protected]',
            skype='skype_test',
            other_contacts='other_test',
            bio='bio_test'
        )
        contact.save()

        contact_object_name = ContentType.objects.get_for_model(contact).model

        log_entry = ModelsChangeLog.objects.latest()
        self.assertEqual(log_entry.model, contact_object_name.title())
        self.assertEqual(log_entry.action, ModelsChangeLog.CREATE)
        self.assertEqual(log_entry.object_id, contact.pk)

        contact.first_name = 'Igor_test_edit'
        contact.save()
        log_entry = ModelsChangeLog.objects.latest()
        self.assertEqual(log_entry.model, contact_object_name.title())
        self.assertEqual(log_entry.action, ModelsChangeLog.EDIT)
        self.assertEqual(log_entry.object_id, contact.pk)

        contact_pk = contact.pk
        contact.delete()
        log_entry = ModelsChangeLog.objects.latest('created')
        self.assertEqual(log_entry.model, contact_object_name.title())
        self.assertEqual(log_entry.action, ModelsChangeLog.DELETE)
        self.assertEqual(log_entry.object_id, contact_pk)
开发者ID:crash-843,项目名称:test42,代码行数:35,代码来源:tests.py

示例7: create

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
def create():
    form = ContactForm()
    if form.validate_on_submit():
        new_contact = Contact()
        new_name = Name()
        new_contact.email = form.email.data
        new_name.first_name = form.first_name.data
        new_name.last_name = form.last_name.data
        new_contact.name = new_name
        new_contact.group = form.group.data
        new_contact.known_from = form.known_from.data
        new_contact.general_comment = form.general_note.data
        new_contact.current_status = form.status.data
        for language in form.languages.data:
            if language:
                new_contact.tags.append(language)
        other_tags = form.other_tags.data.replace(', ', ',').split(',')
        for tag in other_tags:
            new_contact.tags.append(tag)
        try:
            new_contact.save()
            flash_string = '<a href=\"/{}\">{} {}</a> was added to the database.'
            flash_string = flash_string.format(new_contact.email, new_contact.name.first_name,
                                               new_contact.name.last_name)
            flash(Markup(flash_string))
            update_p_dict()
            return redirect(url_for('index'))
        except NotUniqueError:
            msg = "That email address is already in use.  <a href=\"/" + form.email.data + "\">View Entry.</a>"
            form.email.errors.append(Markup(msg))
        except Exception as e:
            flash("There were database-raised errors in the form.  Specifically, " + e.message)

    return render_template('create_contact.html', form=form)
开发者ID:deecewan,项目名称:based,代码行数:36,代码来源:views.py

示例8: test_contact_attributes

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
    def test_contact_attributes(self):
        source = Source.objects.get(slug="test")

        attributes = {
                'procedure' : 'test',
                'procedures_long' : 'long',
                'contact_by' : 'June 12',
                'best_call_time' : '12am',
                'hear_about_us' : 'magazine',
                'date_contacted' : 'july 1',
                'call_message' : 'hey there',
                'location' : 'none'
            }

        contact_params = {
                'name' : 'test',
                'address' : '123 fake st.',
                'city' : 'test city',
                'state' : 'state',
                'zip_code' : 'zip_code',
                'phone' : 'phone',
                'email' : 'email',
                'message' : 'test',
                'source' : source,
                'attributes' : simplejson.dumps(attributes)
                }

        contact = Contact(**contact_params)
        contact.save()


        assert contact.json_attributes == attributes, True

        assert contact.get_attribute("procedure") == "test", True
        assert contact.get_attribute("procedures_long") == "long", True
开发者ID:capacitr,项目名称:cap-contact-form,代码行数:37,代码来源:tests.py

示例9: new

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
 def new(self, name, phone=None, fax=None):
     contact = Contact(
         name=name,
         phone=phone,
         fax=fax
     )
     contact.save()
     return serialize(contact, excludes=[re.compile(r'^datetime_'),])
开发者ID:Digitalxero,项目名称:simpleapi,代码行数:10,代码来源:handlers.py

示例10: setUp

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
 def setUp(self):
     u = User(username='phil',email_address='[email protected]')
     u.save()
     ct = Contact(first_name='tom',last_name='salfield',organisation='the-hub',email_address='[email protected]',location='islington',apply_msg='about me', find_out='through the grapevine',invited_by=u)
     ct.save()
     self.u = u
     self.ct = ct
     return
开发者ID:GunioRobot,项目名称:hubplus,代码行数:10,代码来源:tests.py

示例11: test_model_contact

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
 def test_model_contact(self):
     """Test Contact model"""
     type = ContactType(name='Test', slug='test')
     type.save()
     obj = Contact(name='Test', contact_type=type)
     obj.save()
     self.assertEquals('Test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:11,代码来源:tests.py

示例12: contacts

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
def contacts(request):
	if request.method == "GET":
		contacts = Contact.objects.all()
		return HttpResponse(format_contacts(contacts), mimetype="application/json")
	elif request.method == "POST":
		contact = Contact()
		data = json.loads(request.raw_post_data)
		contact.fromRaw(data)
		contact.save()
		return HttpResponse(format_contacts([contact]), mimetype="application/json")
开发者ID:Lovestruck,项目名称:Contacts,代码行数:12,代码来源:views-django.py

示例13: done

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
    def done(self, form_list, **kwargs):

        new = Contact()
        #new.user = self.request.user
        for form in form_list:
            for k, v in form.cleaned_data.iteritems():
                setattr(new, k, v)
        new.save()

        return redirect('/users/')
开发者ID:liushu2000,项目名称:django-crispy-formwizard,代码行数:12,代码来源:views.py

示例14: parse_contacts

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
    def parse_contacts(self, contacts):
        "Break down CSV file into fields"

        for row in contacts:

            # Tidy up keys (iterkeys strip())

            try:
                type = row['type']
            except Exception:
                pass  # Set type to default type

            try:
                name = row['name']
            except Exception:
                try:
                    firstname = row['firstname']
                    surname = row['surname']
                    name = firstname + " " + surname
                except Exception:
                    continue

            contact_type = ContactType.objects.filter(name=type)
            if contact_type:
                contact_type = contact_type[0]

            # Create a new contact if it doesn't exist
            contact_exists = Contact.objects.filter(
                name=name, contact_type__name=type, trash=False)

            # TODO: If one does exist then append the data on that contact

            if not contact_exists:

                contact = Contact()
                contact.name = name
                contact.contact_type = contact_type
                contact.auto_notify = False
                contact.save()

                fields = contact_type.fields.filter(trash=False)

                for field in fields:
                    if field.name in row:
                        x = row[field.name]
                        if field.field_type == 'email':
                            x = self.verify_email(x)
                        if field.field_type == 'url':
                            x = self.verify_url(x)
                        if x:
                            contact_value = ContactValue()
                            contact_value.field = field
                            contact_value.contact = contact
                            contact_value.value = x
                            contact_value.save()
开发者ID:tovmeod,项目名称:anaf,代码行数:57,代码来源:csvapi.py

示例15: TnycntTestCase

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import save [as 别名]
class TnycntTestCase(TestCase):
    """
    Create a sample contact form
    """
    def setUp(self):
        self.sample_user = User.objects.create_user(username='u', password='p',
                           email='[email protected]')
        self.sample_contact_form = Contact(title='Sample Form',
                                      description='Sample description',
                                      is_active=True,
                                      user=self.sample_user,)
        self.sample_contact_form.save()                              
        self.client.login(username='u', password='p')
开发者ID:brianmacdonald,项目名称:tnycnt,代码行数:15,代码来源:tests.py


注:本文中的models.Contact.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。