Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export and merge functions #17

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2dbc7cf
Amending project attributes for use in eclipse development enviroment
ajparsons Feb 3, 2017
2014840
Split collections and item classes into separate files and out of bas…
ajparsons Feb 3, 2017
16373b7
Changed Collection subclassing to use class attribute
ajparsons Feb 3, 2017
b12f3c6
Collection objects are permanent parts of Popolo object
ajparsons Feb 3, 2017
c7f0caf
Amend PopoloObject to prepare for read/write data objects
ajparsons Feb 3, 2017
bc36884
PopoloObject subclasses moved to new attribute system
ajparsons Feb 3, 2017
2cbccd5
Created 'twitter' setter for Person object.
ajparsons Feb 3, 2017
82a95a5
Changed defaults for date properties to use .PAST or .FUTURE
ajparsons Feb 3, 2017
240d637
Added export functionality
ajparsons Feb 3, 2017
72c2801
Added 'merge' function
ajparsons Feb 3, 2017
d6c7d73
Amended handling of default settings.
ajparsons Feb 6, 2017
d5366c5
Date attributes will now accept datetime objects being 'set'
ajparsons Feb 6, 2017
400691f
Add safeguards to prevent objects sharing attributes.
ajparsons Feb 6, 2017
7b6166a
Added test suite with tests for property setting and file saving.
ajparsons Feb 6, 2017
2520cfd
Assigning a null contact_detail will now delete the row rather than a…
ajparsons Feb 6, 2017
461cedf
Removed unused ability to specify which field is used to match Relate…
ajparsons Feb 6, 2017
63a87e9
Added processing for handling of saving vague-dates and date ranges.
ajparsons Feb 6, 2017
270f68a
Python 3 Compatibility changes.
ajparsons Feb 6, 2017
04a8729
Created effective_start_date and effective_end_date properties
ajparsons Jan 30, 2018
c4a39a5
Add get_identfier function
ajparsons Jan 30, 2018
ba755f7
Updated hash id system for memberships
ajparsons Jan 30, 2018
6df1ea7
Fix to merge function
ajparsons Jan 30, 2018
7db9f3c
Allowed source as an attribute of membership
ajparsons Jan 22, 2020
ccbd20d
changed default loading to uft-8 encoding
ajparsons Jan 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 11 additions & 32 deletions popolo_data/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

class PopoloCollection(object):

def __init__(self, data_list, object_class, all_popolo):
object_class = None

def __init__(self, data_list , all_popolo):
self.all_popolo = all_popolo
self.object_class = object_class
self.object_class = self.__class__.object_class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this line is actually necessary, is it? self.foo falls back to trying to find a class variable foo, e.g.:

In [1]: class Thing(object):
   ...:     foo = 'class foo'
   ...:     bar = 'class bar'
   ...:     def __init__(self):
   ...:         self.foo = 'instance foo'
   ...:     def print_stuff(self):
   ...:         print self.foo
   ...:         print self.bar
   ...:         

In [2]: Thing().print_stuff()
instance foo
class bar

self.object_list = \
[self.object_class(data, all_popolo) for data in data_list]
self.lookup_from_key = {}
Expand Down Expand Up @@ -49,46 +51,23 @@ def get(self, **kwargs):


class PersonCollection(PopoloCollection):

def __init__(self, persons_data, all_popolo):
super(PersonCollection, self).__init__(
persons_data, Person, all_popolo)

object_class = Person

class OrganizationCollection(PopoloCollection):

def __init__(self, organizations_data, all_popolo):
super(OrganizationCollection, self).__init__(
organizations_data, Organization, all_popolo)

object_class = Organization

class MembershipCollection(PopoloCollection):

def __init__(self, memberships_data, all_popolo):
super(MembershipCollection, self).__init__(
memberships_data, Membership, all_popolo)

object_class = Membership

class AreaCollection(PopoloCollection):

def __init__(self, areas_data, all_popolo):
super(AreaCollection, self).__init__(
areas_data, Area, all_popolo)

object_class = Area

class PostCollection(PopoloCollection):

def __init__(self, posts_data, all_popolo):
super(PostCollection, self).__init__(
posts_data, Post, all_popolo)

object_class = Post

class EventCollection(PopoloCollection):

def __init__(self, events_data, all_popolo):
super(EventCollection, self).__init__(
events_data, Event, all_popolo)

object_class = Event

@property
def elections(self):
elections_list = self.filter(classification='general election')
Expand Down