def save(self, commit=True): instance = super(OrgForm, self).save(commit=False) if 'issues' in self.fields: old_issues = instance.issues.all() new_issues = self.cleaned_data['issues'] to_delete = set(old_issues) - set(new_issues) to_create = set(new_issues) - set(old_issues) OrgIssueRelationship.objects.filter(org=instance, issue__in=to_delete).delete() for issue in to_create: relationship = OrgIssueRelationship(org=instance, issue=issue) try: relationship.full_clean() relationship.save() except ValidationError, e: pass del(self.cleaned_data['issues'])
def save(self, commit=True): instance = super(OrgForm, self).save(commit=False) if 'issues' in self.fields: old_issues = instance.issues.all() new_issues = self.cleaned_data['issues'] to_delete = set(old_issues) - set(new_issues) to_create = set(new_issues) - set(old_issues) OrgIssueRelationship.objects.filter(org=instance, issue__in=to_delete).delete() for issue in to_create: relationship = OrgIssueRelationship(org=instance, issue=issue) try: relationship.full_clean() relationship.save() except ValidationError, e: pass del (self.cleaned_data['issues'])
original.parentorg.add(Org.objects.get(id=o)) for o in original.parentorg.all(): if o.id not in org['child_orgs']: original.parentorg.remove(Org.objects.get(id=o.id)) # this probably needs to change down the road because i can't imagine this is very sustainable. for i in org['tags']['context']: iss = Issue.objects.get(name__iexact=i['name']) try: r = OrgIssueRelationship.objects.get(issue=iss, org=original) r.rank = i['tag_rank'] r.date_updated = datetime.datetime.now() r.save() except: r = OrgIssueRelationship() r.issue = iss r.org = original r.date_created = datetime.datetime.now() r.date_updated = datetime.datetime.now() r.rank = i['tag_rank'] r.save() ''' {u'locality': u'New York', u'region': u'Brooklyn', u'longitude': u'-73.948883', u'country_name': u'United States', u'postal_code': u'', u'address': u'', u'latitude': u'40.655071', u'type': u'County', u'raw_geodata': {u'lang': u'en-US', u'popRank': u'0', u'name': u'Brooklyn', u'woeid': u'12589335', u'uri': u'http://where.yahooapis.com/v1/place/12589335', u'admin1': {u'content': u'New York', u'code': u'US-NY', u'type': u'State'}, u'admin3': None, u'admin2': {u'content': u'Brooklyn', u'code': u'', u'type': u'County'}, u'centroid': {u'latitude': u'40.655071', u'longitude': u'-73.948883'}, u'locality1': {u'content': u'New York', u'type': u'Town'}, u'locality2': None, u'country': {u'content': u'United States', u'code': u'US', u'type': u'Country'}, u'boundingBox': {u'northEast': {u'latitude': u'40.739471', u'longitude': u'-73.833359'}, u'southWest': {u'latitude': u'40.570679', u'longitude': u'-74.042068'}}, u'areaRank': u'5', u'postal': None, u'placeTypeName': {u'content': u'County', u'code': u'9'}}} ''' if 'location' in org and org['location']: loc = org['location'] raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance( loc.get("raw_geodata"), dict) else loc.get("raw_geodata") #Until we fix duplicate locations we have to do the following...lame.
original.parentorg.add(Org.objects.get(id = o)) for o in original.parentorg.all(): if o.id not in org['child_orgs']: original.parentorg.remove(Org.objects.get(id = o.id)) # this probably needs to change down the road because i can't imagine this is very sustainable. for i in org['tags']['context']: iss = Issue.objects.get(name__iexact = i['name']) try: r = OrgIssueRelationship.objects.get(issue = iss, org = original) r.rank = i['tag_rank'] r.date_updated = datetime.datetime.now() r.save() except: r = OrgIssueRelationship() r.issue = iss r.org = original r.date_created = datetime.datetime.now() r.date_updated = datetime.datetime.now() r.rank = i['tag_rank'] r.save() ''' {u'locality': u'New York', u'region': u'Brooklyn', u'longitude': u'-73.948883', u'country_name': u'United States', u'postal_code': u'', u'address': u'', u'latitude': u'40.655071', u'type': u'County', u'raw_geodata': {u'lang': u'en-US', u'popRank': u'0', u'name': u'Brooklyn', u'woeid': u'12589335', u'uri': u'http://where.yahooapis.com/v1/place/12589335', u'admin1': {u'content': u'New York', u'code': u'US-NY', u'type': u'State'}, u'admin3': None, u'admin2': {u'content': u'Brooklyn', u'code': u'', u'type': u'County'}, u'centroid': {u'latitude': u'40.655071', u'longitude': u'-73.948883'}, u'locality1': {u'content': u'New York', u'type': u'Town'}, u'locality2': None, u'country': {u'content': u'United States', u'code': u'US', u'type': u'Country'}, u'boundingBox': {u'northEast': {u'latitude': u'40.739471', u'longitude': u'-73.833359'}, u'southWest': {u'latitude': u'40.570679', u'longitude': u'-74.042068'}}, u'areaRank': u'5', u'postal': None, u'placeTypeName': {u'content': u'County', u'code': u'9'}}} ''' if 'location' in org and org['location']: loc = org['location'] raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance(loc.get("raw_geodata"), dict) else loc.get("raw_geodata") #Until we fix duplicate locations we have to do the following...lame.