10000 Decouple Organization object from BaseAccount · pythonthings/github3.py@ffa06ad · GitHub
[go: up one dir, main page]

Skip to content

Commit ffa06ad

Browse files
omgjlksigmavirus24
authored andcommitted
Decouple Organization object from BaseAccount
Alter how we import models as well, and fix a missing attribute on a call. Signed-off-by: Jesse Keating <jkeating@j2solutions.net>
1 parent 5fb0817 commit ffa06ad

File tree

1 file changed

+63
-9
lines changed

1 file changed

+63
-9
lines changed

github3/orgs.py

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77

88
from uritemplate import URITemplate
99

10-
from . import users
10+
from . import users, models
1111

1212
from .decorators import requires_auth
1313
from .events import Event
14-
from .models import BaseAccount, GitHubCore
1514
from .projects import Project
1615
from .repos import Repository
1716

1817

19-
class Team(GitHubCore):
18+
class Team(models.GitHubCore):
2019

2120
"""The :class:`Team <Team>` object.
2221
@@ -230,7 +229,7 @@ def remove_repository(self, repository):
230229
return self._boolean(self._delete(url), 204, 404)
231230

232231

233-
class Organization(BaseAccount):
232+
class Organization(models.GitHubCore):
234233

235234
"""The :class:`Organization <Organization>` object.
236235
@@ -248,13 +247,65 @@ class Organization(BaseAccount):
248247
members_roles = frozenset(['all', 'admin', 'member'])
249248

250249
def _update_attributes(self, org):
251-
super(Organization, self)._update_attributes(org)
252-
self.type = self.type or 'Organization'
250+
# Set the type of object
251+
self.type = self._get_attribute(org, 'type')
252+
if not self.type:
253+
self.type = 'Organization'
254+
255+
self._api = self._get_attribute(org, 'url')
256+
257+
#: URL of the avatar at gravatar
258+
self.avatar_url = self._get_attribute(org, 'avatar_url')
259+
260+
#: URL of the blog
261+
self.blog = self._get_attribute(org, 'blog')
262+
263+
#: Name of the company
264+
self.company = self._get_attribute(org, 'company')
265+
266+
#: datetime object representing the date the account was created
267+
self.created_at = self._strptime_attribute(org, 'created_at')
268+
269+
#: E-mail address of the org
270+
self.email = self._get_attribute(org, 'email')
271+
272+
# The number of people following this org
273+
#: Number of followers
274+
self.followers_count = self._get_attribute(org, 'followers')
275+
276+
# The number of people this org follows
277+
#: Number of people the org is following
278+
self.following_count = self._get_attribute(org, 'following')
279+
280+
#: Unique ID of the account
281+
self.id = self._get_attribute(org, 'id')
282+
283+
#: Location of the org
284+
self.location = self._get_attribute(org, 'location')
285+
286+
#: Name of the organization
287+
self.login = self._get_attribute(org, 'login')
288+
289+
# e.g. first_name last_name
290+
#: Real name of the org
291+
self.name = self._get_attribute(org, 'name')
292+
293+
# The number of public_repos
294+
#: Number of public repos owned by the org
295+
self.public_repos_count = self._get_attribute(org, 'public_repos')
296+
297+
# e.g. https://github.com/self._login
298+
#: URL of the org's profile
299+
self.html_url = self._get_attribute(org, 'html_url')
300+
301+
#: Description of the org
302+
self.description = self._get_attribute(org, 'description')
253303

254304
#: Events url (not a template)
255305
self.events_url = self._get_attribute(org, 'events_url')
306+
256307
#: Number of private repositories.
257-
self.private_repos = self._get_attribute(org, 'private_repos')
308+
self.private_repos = self._get_attribute(org, 'owned_private_repos')
258309

259310
#: Public Members URL Template. Expands with ``member``
260311
self.public_members_urlt = self._class_attribute(
@@ -266,6 +317,9 @@ def _update_attributes(self, org):
266317
#: Repositories url (not a template)
267318
self.repos_url = self._get_attribute(org, 'repos_url')
268319

320+
def _repr(self):
321+
return '<Organization [{s.login}:{s.name}]>'.format(s=self)
322+
269323
@requires_auth
270324
def add_member(self, username, team_id):
271325
"""Add ``username`` to ``team`` and thereby to this organization.
@@ -652,7 +706,7 @@ def team(self, team_id):
652706
return self._instance_or_null(Team, json)
653707

654708

655-
class Membership(GitHubCore):
709+
class Membership(models.GitHubCore):
656710

657711
"""The wrapper for information about Team and Organization memberships."""
658712

@@ -689,7 +743,7 @@ def edit(self, state):
689743
"""
690744
if state and state.lower() == 'active':
691745
data = dumps({'state': state.lower()})
692-
json = self._json(self._patch(self._api, data=data))
746+
json = self._json(self._patch(self._api, data=data), 200)
693747
self._update_attributes(json)
694748
return True
695749
return False

0 commit comments

Comments
 (0)
0