class MoodChangeDatasetMixin(object): recorded_start = Field(header='recorded start') recorded = Field(header='recorded end') def __init__(self, *args, **kwargs): moods = Mood.objects.all().order_by('name').values_list('name', flat=True) mood_fields = [] for (mood, time) in product(moods, ('in', 'out')): field_name = '%s_%s' % (str(mood).replace(' ', '_'), time) header_name = '%s (%s)' % (mood, time) self.base_fields[field_name] = Field(header=header_name) mood_fields.append(field_name) self._meta.field_order += tuple(mood_fields) super(MoodChangeDatasetMixin, self).__init__(*args, **kwargs) class Meta: model = MoodChange fields = [ 'recorded_start', 'recorded', ] field_order = ( 'recorded_start', 'recorded', )
class LookingGoodDatasetMixin(object): total_participants = Field(header='total participants') total_tags = Field(header='total tags') items_tagged = Field(header='items tagged') class Meta: model = LookingGoodEvent fields = [ 'total_participants', 'total_tags', 'items_tagged', ]
def __init__(self, *args, **kwargs): units = system_distance_units(kwargs.get('measurement_system', None)) # Add bed dimensions self.base_fields.update({ 'bed_length': Field(attribute='bed_length_%s' % units, header='bed length (%s)' % units), 'bed_width': Field(attribute='bed_width_%s' % units, header='bed width (%s)' % units) }) self._meta.field_order += ('bed_width', 'bed_length',) super(CropcountDatasetMixin, self).__init__(*args, **kwargs)
class RecipeTallyDatasetMixin(object): recorded = Field(header='recorded end') recipes_count = Field(header='# of recipes') class Meta: model = RecipeTally fields = [ 'recorded', 'recipes_count', ] field_order = ( 'recorded', 'recipes_count', )
class HarvestcountDatasetMixin(object): gardener = Field(header='gardener') crop = Field(header='crop') crop_variety = Field(header='crop variety') plants = Field(header='plants') area = Field(header='area') def __init__(self, **kwargs): units = system_weight_units(kwargs.get('measurement_system', None)) self.base_fields.update({ 'weight': Field(attribute='weight_%s' % units, header='weight (%s)' % units) }) self._meta.fields = [ 'weight', ] + self._meta.fields if self._meta.field_order: self._meta.field_order = ('weight', ) + self._meta.field_order else: self._meta.field_order = ('weight', ) super(HarvestcountDatasetMixin, self).__init__(**kwargs) class Meta: model = Harvest fields = [ 'recorded', 'gardener', 'crop', 'crop_variety', 'plants', 'area', ] field_order = ( 'recorded', 'gardener', 'crop', 'crop_variety', 'plants', 'area', )
class YumYuckDatasetMixin(object): recorded = Field(header='recorded') crop = Field(header='crop') yum_before = Field(header='yum before') yuck_before = Field(header='yuck before') yum_after = Field(header='yum after') yuck_after = Field(header='yuck after') class Meta: model = YumYuck fields = [ 'recorded', 'crop', 'yum_before', 'yuck_before', 'yum_after', 'yuck_after', ] field_order = ( 'recorded', 'crop', 'yum_before', 'yuck_before', 'yum_after', 'yuck_after', )
class HoursByGeographyDatasetMixin(object): recorded_start = Field(header='recorded start') recorded = Field(header='recorded end') in_half = Field(header='1/2-hour pins "IN"') in_whole = Field(header='1-hour pins "IN"') out_half = Field(header='1/2-hour pins "OUT"') out_whole = Field(header='1-hour pins "OUT"') class Meta: model = HoursByGeography fields = [ 'recorded_start', 'recorded', 'in_half', 'in_whole', 'out_half', 'out_whole', ] field_order = ( 'recorded_start', 'recorded', 'in_half', 'in_whole', 'out_half', 'out_whole', )
class HoursByTaskDatasetMixin(object): recorded_start = Field(header='recorded start') recorded = Field(header='recorded end') def __init__(self, *args, **kwargs): tasks = Task.objects.all().order_by('name') task_fields = [] def attrify(task): """ Get an attr string for the task that will work on an HoursByTask object. """ return 'task_%d' % task.pk # Add all potential tasks for task in tasks: field_name = attrify(task) self.base_fields[field_name] = Field(header=task.name) task_fields.append(field_name) self._meta.field_order += tuple(task_fields) # Add task_other self.base_fields['task_other'] = Field(header='other tasks examples') self._meta.field_order += ('task_other', ) super(HoursByTaskDatasetMixin, self).__init__(*args, **kwargs) class Meta: model = HoursByTask fields = [ 'recorded_start', 'recorded', ] field_order = ( 'recorded_start', 'recorded', )
class RainwaterHarvestDatasetMixin(object): recorded_start = Field(header='recorded start') recorded = Field(header='recorded end') roof_length = Field(header='roof length (feet)') roof_width = Field(header='roof width (feet)') volume = Field(header='volume (gallons)') class Meta: model = RainwaterHarvest fields = [ 'recorded_start', 'recorded', 'roof_length', 'roof_width', 'volume', ] field_order = ( 'recorded_start', 'recorded', 'roof_length', 'roof_width', 'volume', )
def __init__(self, **kwargs): units = system_weight_units(kwargs.get('measurement_system', None)) self.base_fields.update({ 'weight': Field(attribute='weight_%s' % units, header='weight (%s)' % units) }) self._meta.fields = [ 'weight', ] + self._meta.fields if self._meta.field_order: self._meta.field_order = ('weight', ) + self._meta.field_order else: self._meta.field_order = ('weight', ) super(WeightDatasetMixin, self).__init__(**kwargs)
def __init__(self, *args, **kwargs): # Add project self.base_fields['project'] = Field(header='project') self._meta.field_order += ('project', ) garden = kwargs.get('gardens', [])[0] gardeners = garden.gardener_set.all().order_by('name') gardener_fields = [] def attrify(gardener): """ Get an attr string for the gardener that will work on an HoursByProject object. """ return 'gardener_%d' % gardener.pk # Add all potential gardeners for gardener in gardeners: field_name = attrify(gardener) self.base_fields[field_name] = Field(header=gardener.name) gardener_fields.append(field_name) self._meta.field_order += tuple(gardener_fields) super(HoursByProjectDataset, self).__init__(*args, **kwargs)
def __init__(self, filters=None, **kwargs): # Save filters for later self.filters = filters # Update available base fields # XXX Not really anonymized here, garden_pk needs obfuscation before # being exported (eg, in the view) self.base_fields.update( {'garden_pk': Field(attribute='garden_pk', header='garden')}) self.base_fields.update({ 'garden_state': Field(attribute='garden_state', header='garden state') }) self.base_fields.update({ 'garden_zip': Field(attribute='garden_zip', header='garden zip code') }) self.base_fields.update({ 'garden_name': Field(attribute='garden_public_name', header='garden name') }) self.base_fields.update({ 'garden_latitude': Field(attribute='garden_public_latitude', header='garden latitude') }) self.base_fields.update({ 'garden_longitude': Field(attribute='garden_public_longitude', header='garden longitude') }) # Update fields to be exported self._meta.fields = [ 'recorded', 'garden_pk', 'garden_state', 'garden_zip', 'garden_name', 'garden_latitude', 'garden_longitude', ] + self._meta.fields self._meta.field_order += ( 'recorded', 'garden_pk', 'garden_state', 'garden_zip', 'garden_name', 'garden_latitude', 'garden_longitude', ) super(PublicMetricDatasetMixin, self).__init__()
def __init__(self, gardens=None, start=None, end=None, **kwargs): self.gardens = gardens self.start = start self.end = end self._meta.fields = ['recorded', 'added_by_display',] + self._meta.fields if self._meta.field_order: self._meta.field_order = ('recorded', 'added_by_display',) + self._meta.field_order else: self._meta.field_order = ('recorded', 'added_by_display',) if 'garden' in self._meta.fields: self._meta.field_order = ('garden',) + self._meta.field_order self.base_fields.update({ 'added_by_display': Field(attribute='added_by_display', header='added by') }) super(MetricDatasetMixin, self).__init__()
class DonationDatasetMixin(object): produce_name = Field(header='produce name') def __init__(self, **kwargs): units = system_weight_units(kwargs.get('measurement_system', None)) self.base_fields.update({ 'weight': Field(attribute='weight_%s' % units, header='weight (%s)' % units) }) self._meta.fields = [ 'weight', ] + self._meta.fields if self._meta.field_order: self._meta.field_order = ('weight', ) + self._meta.field_order else: self._meta.field_order = ('weight', ) super(DonationDatasetMixin, self).__init__(**kwargs) class Meta: model = Donation
def __init__(self, *args, **kwargs): included = [field.name for field in self.model._meta.fields] if self._meta.fields: included = filter(lambda x: x in self._meta.fields, included) if self._meta.exclude: included = filter(lambda x: x not in self._meta.exclude, included) self.fields = {field: Field() for field in included} self.fields.update(deepcopy(self.base_fields)) fields = [ field.attribute or name for name, field in self.fields.items() ] header_dict = { field.header or name: field.attribute or name for name, field in self.fields.items() } header_list = header_dict.keys() self.attr_list = fields self.header_dict = header_dict self.header_list = header_list super(ModelDataset, self).__init__(*args, **kwargs)
class CropcountDatasetMixin(object): recorded = Field(header='recorded') box = Field(header='bed') crop = Field(header='crop') crop_variety = Field(header='crop variety') quantity = Field(header='quantity') units = Field(header='units') def __init__(self, *args, **kwargs): units = system_distance_units(kwargs.get('measurement_system', None)) # Add bed dimensions self.base_fields.update({ 'bed_length': Field(attribute='bed_length_%s' % units, header='bed length (%s)' % units), 'bed_width': Field(attribute='bed_width_%s' % units, header='bed width (%s)' % units) }) self._meta.field_order += ('bed_width', 'bed_length',) super(CropcountDatasetMixin, self).__init__(*args, **kwargs) class Meta: model = Patch fields = [ 'recorded', 'box', 'crop', 'crop_variety', 'quantity', 'units', ] field_order = ( 'recorded', 'box', 'crop', 'crop_variety', 'quantity', 'units', )
class SmartsAndSkillsDatasetMixin(object): participants = Field(header='number of participants') skills_shared = Field(header='# of skills shared') skills_shared_examples = Field(header='examples of skills shared') concepts_shared = Field(header='# of concepts shared') concepts_shared_examples = Field(header='examples of concepts shared') projects_proposed = Field(header='# of projects proposed') projects_proposed_examples = Field(header='examples of projects proposed') ideas_to_learn = Field(header='# of ideas to learn') ideas_to_learn_examples = Field(header='examples of ideas to learn') intentions_to_collaborate = Field(header='# of intentions to collaborate') intentions_to_collaborate_examples = Field( header='examples of intentions to collaborate') class Meta: model = SmartsAndSkills fields = [ 'recorded', 'added_by_display', 'participants', 'skills_shared', 'skills_shared_examples', 'concepts_shared', 'concepts_shared_examples', 'projects_proposed', 'projects_proposed_examples', 'ideas_to_learn', 'ideas_to_learn_examples', 'intentions_to_collaborate', 'intentions_to_collaborate_examples', ]
def __init__(self, *args, **kwargs): # Add name self.base_fields['name'] = Field(header='name') self._meta.field_order += ('name', ) super(ProgramReachDataset, self).__init__(*args, **kwargs)
class ProgramReachDatasetMixin(object): recorded_start = Field(header='recorded start') recorded = Field(header='recorded end') hours_each_day = Field(header='hours each day') collaborated_with_organization = Field( header='collaborated with organization') collaboration_first = Field(header='first collaboration with organization') age_10 = Field(header='# under 10') age_10_14 = Field(header='# 10 to 14') age_15_19 = Field(header='# 15 to 19') age_20_24 = Field(header='# 20 to 24') age_25_34 = Field(header='# 25 to 34') age_35_44 = Field(header='# 35 to 44') age_45_54 = Field(header='# 45 to 54') age_55_64 = Field(header='# 55 to 64') age_65 = Field(header='# 65 and older') gender_male = Field(header='# male') gender_female = Field(header='# female') gender_other = Field(header='# other gender') zipcode_inside = Field(header='# within garden zipcode') zipcode_outside = Field(header='# outside garden zipcode') other_features = Field(header='other features') def __init__(self, *args, **kwargs): # Add features_display self.base_fields['features_display'] = Field(header='features') self._meta.field_order += ('features_display', ) super(ProgramReachDatasetMixin, self).__init__(*args, **kwargs) class Meta: model = ProgramReach fields = [ 'recorded_start', 'recorded', 'hours_each_day', 'collaborated_with_organization', 'collaboration_first', 'age_10', 'age_10_14', 'age_15_19', 'age_20_24', 'age_25_34', 'age_35_44', 'age_45_54', 'age_55_64', 'age_65', 'gender_male', 'gender_female', 'gender_other', 'zipcode_inside', 'zipcode_outside', 'other_features', ] field_order = ( 'recorded_start', 'recorded', 'hours_each_day', 'collaborated_with_organization', 'collaboration_first', 'age_10', 'age_10_14', 'age_15_19', 'age_20_24', 'age_25_34', 'age_35_44', 'age_45_54', 'age_55_64', 'age_65', 'gender_male', 'gender_female', 'gender_other', 'zipcode_inside', 'zipcode_outside', 'other_features', )
def __init__(self, *args, **kwargs): # Add features_display self.base_fields['features_display'] = Field(header='features') self._meta.field_order += ('features_display', ) super(ProgramReachDatasetMixin, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Add total_hours self.base_fields['total_hours'] = Field(header='total hours') self._meta.field_order += ('total_hours', ) super(PublicHoursByProjectDataset, self).__init__(*args, **kwargs)
class GardenDataset(dataset_cls): garden = Field(header='garden') def __init__(self, *args, **kwargs): self._meta.fields = ['garden',] + super(GardenDataset, self)._meta.fields # garden will be made first in MetricDatasetMixin super(GardenDataset, self).__init__(*args, **kwargs)
class TestModelDataset(ModelDataset): field1 = Field(header='Field 1') field2 = Field(attribute='field1') class Meta: model = TestModel