def write_campaign(self, campaign_data):
        """
        Write the campaign data to the DB, and return a key.
        """

        date_start = datetime.datetime.strptime(campaign_data['startDate'], '%Y-%m-%dT%H:%M:%S.%fZ')
        date_end = datetime.datetime.strptime(campaign_data['endDate'], '%Y-%m-%dT%H:%M:%S.%fZ')

        # check if the campaign already exists
        campaigns = Campaign.objects.filter(date_start=date_start,
                                            short_name=campaign_data['title'])

        if campaigns.count() > 0:
            print "Campaign %s already exists." % campaigns[0].short_name
            return campaigns[0].id

        campaign = Campaign(short_name=campaign_data['title'][:100],
                            date_start=date_start,
                            date_end=date_end,
                            associated_researchers='',
                            associated_publications='',
                            associated_research_grant='',
                            contact_person=campaign_data['primaryContact'])
        campaign.save()
        authorization.make_campaign_public(campaign)

        return campaign.id
    def write_campaign(self, campaign_data):
        """
        Write the campaign data to the DB, and return a key.
        """

        # check if the campaign already exists
        campaigns = Campaign.objects.filter(date_start=campaign_data['date_start'], short_name=campaign_data['short_name'])

        if campaigns.count() > 0:
            print "Campaign %s already exists." % campaigns[0].short_name
            return campaigns[0].id

        campaign = Campaign(**campaign_data)
        campaign.save()
        authorization.make_campaign_public(campaign)

        return campaign.id