Skip to content

Commit

Permalink
#861: fix FieldCollection.add method for choice field type
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Jun 3, 2024
1 parent 1318a11 commit 59774a3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
15 changes: 15 additions & 0 deletions examples/sharepoint/fields/create_choice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Demonstrates how to create lookup field
"""
from office365.sharepoint.client_context import ClientContext
from tests import create_unique_name, test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
lib = client.web.default_document_library()

field_name = create_unique_name("ChoiceField")

choices = ["Not Started", "In Progress", "Completed", "Deferred"]
field = lib.fields.add_choice_field(title=field_name, values=choices).execute_query()

field.delete_object().execute_query() # clean up
4 changes: 2 additions & 2 deletions office365/sharepoint/fields/choice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from office365.sharepoint.fields.field import Field
from office365.sharepoint.fields.multi_choice import FieldMultiChoice


class FieldChoice(Field):
class FieldChoice(FieldMultiChoice):
"""Represents a choice field control."""
4 changes: 1 addition & 3 deletions office365/sharepoint/fields/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ def add(self, field_create_information):
:type field_create_information: office365.sharepoint.fields.creation_information.FieldCreationInformation
"""
return_type = Field.create_field_from_type(
self.context, field_create_information
)
return_type = Field.create_field(self.context, field_create_information)
self.add_child(return_type)
qry = CreateEntityQuery(self, return_type, return_type)
self.context.add_query(qry)
Expand Down
7 changes: 5 additions & 2 deletions office365/sharepoint/fields/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ class Field(Entity):
def __init__(self, context, resource_path=None):
super(Field, self).__init__(context, resource_path)

def __str__(self):
return self.title or self.entity_type_name

def __repr__(self):
return self.internal_name or self.id
return self.internal_name or self.id or self.entity_type_name

@staticmethod
def resolve_field_type(type_id_or_name):
Expand Down Expand Up @@ -63,7 +66,7 @@ def resolve_field_type(type_id_or_name):
return Field

@staticmethod
def create_field_from_type(context, field_parameters):
def create_field(context, field_parameters):
"""
Creates a field based on its type
Expand Down

0 comments on commit 59774a3

Please sign in to comment.