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


Python PopItPerson.create_from_popit方法代码示例

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


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

示例1: handle

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
    def handle(self, *args, **options):
        self.verbosity = int(options.get('verbosity', 1))
        api = create_popit_api_object()
        if len(args) != 2:
            raise CommandError("You must provide all two arguments")

        person_id, other_name = args

        person = PopItPerson.create_from_popit(api, person_id)

        person.other_names.append(
            {
                'name': other_name,
                'note': options['note'],
                'start_date': options['start_date'],
                'end_date': options['end_date']
            }
        )

        person.save_to_popit(api)
        person.invalidate_cache_entries()

        # FIXME: this should create a new version in the versions
        # array too, otherwise you manually have to edit on the
        # YourNextRepresentative site too to create a new version with
        # a change message.

        print "Successfully updated {0}".format(person_id)
开发者ID:andylolz,项目名称:yournextrepresentative,代码行数:30,代码来源:candidates_add_other_name.py

示例2: get_context_data

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
 def get_context_data(self, **kwargs):
     context = super(PhotoUploadSuccess, self).get_context_data(**kwargs)
     context['person'] = PopItPerson.create_from_popit(
         self.api,
         kwargs['popit_person_id']
     )
     return context
开发者ID:YoQuieroSaber,项目名称:yournextrepresentative,代码行数:9,代码来源:views.py

示例3: handle

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
    def handle(self, *args, **options):
        self.verbosity = int(options.get('verbosity', 1))
        api = create_popit_api_object()
        if len(args) != 3:
            raise CommandError("You must provide all three arguments")

        person_id, scheme, identifier = args

        person = PopItPerson.create_from_popit(api, person_id)

        person.identifiers.append(
            {
                'scheme': scheme,
                'identifier': identifier,
            }
        )

        person.save_to_popit(api)
        person.invalidate_cache_entries()

        # FIXME: this should create a new version in the versions
        # array too, otherwise you manually have to edit on YourNextMP
        # too to create a new version with a change message.

        print "Successfully updated {0}".format(person_id)
开发者ID:YoQuieroSaber,项目名称:yournextrepresentative,代码行数:27,代码来源:candidates_add_identifier.py

示例4: handle

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
 def handle(self, *args, **kwargs):
     if len(args) < 1:
         raise CommandError("You must provide one or more PopIt person ID")
     for person_id in args:
         person = PopItPerson.create_from_popit(
             create_popit_api_object(), person_id
         )
         person.delete_memberships()
         self.create_party_memberships(person_id, person.popit_data)
         self.create_candidate_list_memberships(person_id, person.popit_data)
开发者ID:tfgg,项目名称:yournextmp-popit,代码行数:12,代码来源:candidates_recreate_memberships.py

示例5: handle

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
    def handle(self, *args, **options):
        from candidates.models import PopItPerson
        from candidates.popit import create_popit_api_object

        self.verbosity = int(options.get('verbosity', 1))
        api = create_popit_api_object()
        if len(args) != 1:
            raise CommandError("You must provide a person.js URL")
        person_js_url = args[0]
        people_data = requests.get(person_js_url).json()
        for person_data in people_data['persons']:
            twfy_person = PopItPerson.create_from_dict(person_data)
            ynmp_id = twfy_person.get_identifier('yournextmp')
            if not ynmp_id:
                continue
            parlparse_id = twfy_person.id
            ynmp_person = PopItPerson.create_from_popit(api, ynmp_id)
            existing_parlparse_id = ynmp_person.get_identifier('uk.org.publicwhip')
            if existing_parlparse_id:
                if existing_parlparse_id == parlparse_id:
                    # That's fine, there's already the right parlparse ID
                    pass
                else:
                    # Otherwise there's a mismatch, which needs investigation
                    msg = "Warning: parlparse ID mismatch between YNMP {0} "
                    msg += "and TWFY {1} for YNMP person {2}\n"
                    self.stderr.write(
                        msg.format(
                            existing_parlparse_id,
                            parlparse_id,
                            ynmp_id,
                        )
                    )
                continue
            msg = "Updating the YourNextMP person {0} with parlparse_id {1}\n"
            self.stdout.write(msg.format(ynmp_id, parlparse_id))
            ynmp_person.set_identifier(
                'uk.org.publicwhip',
                parlparse_id,
            )
            change_metadata = get_change_metadata(
                None, "Fetched a new parlparse ID"
            )
            ynmp_person.record_version(change_metadata)
            ynmp_person.save_to_popit(api)
            ynmp_person.invalidate_cache_entries()
开发者ID:ConocimientoAbierto,项目名称:policrowd,代码行数:48,代码来源:candidates_add_new_parlparse_ids.py

示例6: handle

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
 def handle(self, *args, **kwargs):
     api = create_popit_api_object()
     if len(args) < 1:
         raise CommandError("You must provide one or more PopIt person ID")
     for person_id in args:
         invalidate_person(person_id)
         person = PopItPerson.create_from_popit(api, person_id)
         posts_to_invalidate = person.get_associated_posts()
         person.delete_memberships(api)
         # The memberships are recreated when you assign to
         # standing_in and party_memberships; this script assumes
         # these are correct and so re-setting these should
         # recreate the memberships correctly.
         person.standing_in = person.standing_in
         person.party_memberships = person.party_memberships
         person.save_to_popit(api)
         invalidate_posts(posts_to_invalidate)
         invalidate_person(person_id)
开发者ID:YoQuieroSaber,项目名称:yournextrepresentative,代码行数:20,代码来源:candidates_recreate_memberships.py

示例7: upload_photo

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
def upload_photo(request, popit_person_id):
    if request.method == 'POST':
        form = UploadPersonPhotoForm(request.POST, request.FILES)
        if form.is_valid():
            # Make sure that we save the user that made the upload
            queued_image = form.save(commit=False)
            queued_image.user = request.user
            queued_image.save()
            # Record that action:
            LoggedAction.objects.create(
                user=request.user,
                action_type='photo-upload',
                ip_address=get_client_ip(request),
                popit_person_new_version='',
                popit_person_id=popit_person_id,
                source=form.cleaned_data['justification_for_use'],
            )
            return HttpResponseRedirect(reverse(
                'photo-upload-success',
                kwargs={
                    'popit_person_id': form.cleaned_data['popit_person_id']
                }
            ))
    else:
        form = UploadPersonPhotoForm(
            initial={
                'popit_person_id': popit_person_id
            }
        )
    api = create_popit_api_object()
    return render(
        request,
        'moderation_queue/photo-upload-new.html',
        {'form': form,
         'queued_images': QueuedImage.objects.filter(
             popit_person_id=popit_person_id,
             decision='undecided',
         ).order_by('created'),
         'person': PopItPerson.create_from_popit(api, popit_person_id)}
    )
开发者ID:YoQuieroSaber,项目名称:yournextrepresentative,代码行数:42,代码来源:views.py

示例8: crop_and_upload_image_to_popit

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
 def crop_and_upload_image_to_popit(self, image_filename, crop_bounds, moderator_why_allowed, make_primary):
     original = Image.open(image_filename)
     # Some uploaded images are CYMK, which gives you an error when
     # you try to write them as PNG, so convert to RGBA (this is
     # RGBA rather than RGB so that any alpha channel (transparency)
     # is preserved).
     original = original.convert('RGBA')
     cropped = original.crop(crop_bounds)
     ntf = NamedTemporaryFile(delete=False)
     cropped.save(ntf.name, 'PNG')
     # Upload the image to PopIt...
     person_id = self.queued_image.popit_person_id
     person = PopItPerson.create_from_popit(self.api, person_id)
     image_upload_url = '{base}persons/{person_id}/image'.format(
         base=get_base_url(),
         person_id=person_id
     )
     data = {
         'md5sum': get_file_md5sum(ntf.name),
         'user_why_allowed': self.queued_image.why_allowed,
         'user_justification_for_use': self.queued_image.justification_for_use,
         'moderator_why_allowed': moderator_why_allowed,
         'mime_type': 'image/png',
         'notes': _('Approved from photo moderation queue'),
         'uploaded_by_user': self.queued_image.user.username,
         'created': None,
     }
     if make_primary:
         data['index'] = 'first'
     with open(ntf.name) as f:
         requests.post(
             image_upload_url,
             data=data,
             files={'image': f.read()},
             headers={'APIKey': self.api.api_key}
         )
     person.invalidate_cache_entries()
     # Remove the cropped temporary image file:
     os.remove(ntf.name)
开发者ID:andylolz,项目名称:yournextrepresentative,代码行数:41,代码来源:views.py

示例9: form_valid

# 需要导入模块: from candidates.models import PopItPerson [as 别名]
# 或者: from candidates.models.PopItPerson import create_from_popit [as 别名]
 def form_valid(self, form):
     decision = form.cleaned_data['decision']
     person = PopItPerson.create_from_popit(
         self.api,
         self.queued_image.popit_person_id
     )
     candidate_path = person.get_absolute_url()
     candidate_name = person.name
     candidate_link = u'<a href="{url}">{name}</a>'.format(
         url=candidate_path,
         name=candidate_name,
     )
     photo_review_url = self.request.build_absolute_uri(
         self.queued_image.get_absolute_url()
     )
     def flash(level, message):
         messages.add_message(
             self.request,
             level,
             message,
             extra_tags='safe photo-review'
         )
     if decision == 'approved':
         # Crop the image...
         crop_fields = ('x_min', 'y_min', 'x_max', 'y_max')
         self.crop_and_upload_image_to_popit(
             self.queued_image.image.path,
             [form.cleaned_data[e] for e in crop_fields],
             form.cleaned_data['moderator_why_allowed'],
             form.cleaned_data['make_primary'],
         )
         self.queued_image.decision = 'approved'
         for i, field in enumerate(crop_fields):
             setattr(
                 self.queued_image,
                 'crop_' + field,
                 form.cleaned_data[field]
             )
         self.queued_image.save()
         update_message = _(u'Approved a photo upload from '
             u'{uploading_user} who provided the message: '
             u'"{message}"').format(
             uploading_user=self.queued_image.user.username,
             message=self.queued_image.justification_for_use,
         )
         change_metadata = get_change_metadata(
             self.request,
             update_message
         )
         # We have to refetch the person from PopIt, otherwise
         # saving the new version will write back the images array
         # from before we uploaded the image:
         person = PopItPerson.create_from_popit(self.api, person.id)
         person.record_version(change_metadata)
         person.save_to_popit(self.api, self.request.user)
         LoggedAction.objects.create(
             user=self.request.user,
             action_type='photo-approve',
             ip_address=get_client_ip(self.request),
             popit_person_new_version=change_metadata['version_id'],
             popit_person_id=self.queued_image.popit_person_id,
             source=update_message,
         )
         self.send_mail(
             _('YourNextMP image upload approved'),
             render_to_string(
                 'moderation_queue/photo_approved_email.txt',
                 {'candidate_page_url':
                  person.get_absolute_url(self.request)}
             ),
         )
         flash(
             messages.SUCCESS,
             _(u'You approved a photo upload for %s') % candidate_link
         )
     elif decision == 'rejected':
         self.queued_image.decision = 'rejected'
         self.queued_image.save()
         update_message = _(u'Rejected a photo upload from '
             u'{uploading_user}').format(
             uploading_user=self.queued_image.user.username,
         )
         LoggedAction.objects.create(
             user=self.request.user,
             action_type='photo-reject',
             ip_address=get_client_ip(self.request),
             popit_person_new_version='',
             popit_person_id=self.queued_image.popit_person_id,
             source=update_message,
         )
         retry_upload_link = self.request.build_absolute_uri(
             reverse(
                 'photo-upload',
                 kwargs={'popit_person_id': self.queued_image.popit_person_id}
             )
         )
         self.send_mail(
             _('YourNextMP image moderation results'),
             render_to_string(
                 'moderation_queue/photo_rejected_email.txt',
#.........这里部分代码省略.........
开发者ID:YoQuieroSaber,项目名称:yournextrepresentative,代码行数:103,代码来源:views.py


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