def migrate_to_country_code(apps, schema_editor):
    Country = apps.get_model('tracker', 'Country')
    Donor = apps.get_model('tracker', 'Donor')
    PayPalIPN = apps.get_model('ipn', 'PayPalIPN')
    for d in Donor.objects.all():
        foundCountry = Country.objects.none()
        if d.migrateaddresscountry:
            foundCountry = Country.objects.filter(name=d.migrateaddresscountry)
            if not foundCountry.exists():
                foundCountry = Country.objects.filter(alpha2=d.migrateaddresscountry)
            if not foundCountry.exists():
                foundCountry = Country.objects.filter(alpha3=d.migrateaddresscountry)
            if not foundCountry.exists():
                if util.try_parse_int(d.migrateaddresscountry) != None:
                    foundCountry = Country.objects.filter(
                        numeric=d.migrateaddresscountry)
        # As a last resort, search through this user's most recent IPN for
        # country data
        if not foundCountry.exists() and d.paypalemail:
            foundIPNs = PayPalIPN.objects.filter(
                payer_email=d.email).order_by('-payment_date')
            if foundIPNs.exists():
                foundIPN = foundIPNs[0]
                foundCountry = Country.objects.filter(
                    alpha2=foundIPN.address_country_code)
        if foundCountry.exists():
            d.addresscountry = foundCountry[0]
            d.save()
Esempio n. 2
0
def migrate_to_country_code(apps, schema_editor):
    Country = apps.get_model('tracker', 'Country')
    Donor = apps.get_model('tracker', 'Donor')
    PayPalIPN = apps.get_model('ipn', 'PayPalIPN')
    for d in Donor.objects.all():
        foundCountry = Country.objects.none()
        if d.migrateaddresscountry:
            foundCountry = Country.objects.filter(name=d.migrateaddresscountry)
            if not foundCountry.exists():
                foundCountry = Country.objects.filter(alpha2=d.migrateaddresscountry)
            if not foundCountry.exists():
                foundCountry = Country.objects.filter(alpha3=d.migrateaddresscountry)
            if not foundCountry.exists():
                if util.try_parse_int(d.migrateaddresscountry) != None:
                    foundCountry = Country.objects.filter(
                        numeric=d.migrateaddresscountry)
        # As a last resort, search through this user's most recent IPN for
        # country data
        if not foundCountry.exists() and d.paypalemail:
            foundIPNs = PayPalIPN.objects.filter(
                payer_email=d.email).order_by('-payment_date')
            if foundIPNs.exists():
                foundIPN = foundIPNs[0]
                foundCountry = Country.objects.filter(
                    alpha2=foundIPN.address_country_code)
        if foundCountry.exists():
            d.addresscountry = foundCountry[0]
            d.save()
Esempio n. 3
0
    def process_search(self, run, cleanedRunName, searchResults):
        exactMatches = []
        potentialMatches = []
        for response in searchResults:
            if response['name'].lower() == cleanedRunName.lower():
                self.message("Found exact match {0}".format(response['name']),
                             2)
                exactMatches.append(response)
            else:
                potentialMatches.append(response)

        # If we find any exact matches, prefer those over any potential matches
        if len(exactMatches) > 0:
            potentialMatches = exactMatches

        # If we find any matches with release dates, prefer those over any matches without release dates
        filterNoDate = self.filter_none_dates(potentialMatches)
        if len(filterNoDate) > 0:
            potentialMatches = filterNoDate

        if len(potentialMatches) == 0:
            self.message("No matches found for {0}".format(cleanedRunName))
        elif len(potentialMatches) > 1:
            if self.interactive:
                self.message(
                    "Multiple matches found for {0}, please select one:".
                    format(cleanedRunName), 0)
                self.message("Possibilities:", 3)
                self.message("{0}".format(potentialMatches), 3)
                numMatches = len(potentialMatches)
                for i in range(0, numMatches):
                    parsed = self.parse_query_results(potentialMatches[i])
                    self.message(
                        "{0}) {1} ({2}) for {3}".format(
                            i + 1, parsed['name'], parsed['release_year'],
                            ', '.join(parsed['platforms'] or ['(Unknown)'])),
                        0)
                val = None
                while not isinstance(val, int) or (val < 1
                                                   or val > numMatches):
                    self.message(
                        "Please select a value between 1 and {0} (enter a blank line to skip)"
                        .format(numMatches), 0)
                    input = input(' -> ')
                    if input == '':
                        val = None
                        break
                    val = util.try_parse_int(input)
                if val != None and val >= 1 and val <= numMatches:
                    self.process_query(run, potentialMatches[val - 1])
                else:
                    self.foundAmbigiousSearched = True
            else:
                self.message(
                    "Multiple matches found for {0}, skipping for now".format(
                        cleanedRunName))
                self.foundAmbigiousSearched = True
        else:
            self.process_query(run, potentialMatches[0])
    def process_search(self, run, cleanedRunName, searchResults):
        exactMatches = []
        potentialMatches = []
        for response in searchResults:
            if response['name'].lower() == cleanedRunName.lower():
                self.message(u"Found exact match {0}".format(
                    response['name']), 2)
                exactMatches.append(response)
            else:
                potentialMatches.append(response)

        # If we find any exact matches, prefer those over any potential matches
        if len(exactMatches) > 0:
            potentialMatches = exactMatches

        # If we find any matches with release dates, prefer those over any matches without release dates
        filterNoDate = self.filter_none_dates(potentialMatches)
        if len(filterNoDate) > 0:
            potentialMatches = filterNoDate

        if len(potentialMatches) == 0:
            self.message(u"No matches found for {0}".format(cleanedRunName))
        elif len(potentialMatches) > 1:
            if self.interactive:
                self.message(u"Multiple matches found for {0}, please select one:".format(
                    cleanedRunName), 0)
                self.message(u"Possibilities:", 3)
                self.message(u"{0}".format(potentialMatches), 3)
                numMatches = len(potentialMatches)
                for i in range(0, numMatches):
                    parsed = self.parse_query_results(potentialMatches[i])
                    self.message(u"{0}) {1} ({2}) for {3}".format(
                        i+1, parsed['name'], parsed['release_year'], ', '.join(parsed['platforms'] or ['(Unknown)'])), 0)
                val = None
                while not isinstance(val, int) or (val < 1 or val > numMatches):
                    self.message(
                        u"Please select a value between 1 and {0} (enter a blank line to skip)".format(numMatches), 0)
                    input = raw_input(' -> ')
                    if input == '':
                        val = None
                        break
                    val = util.try_parse_int(input)
                if val != None and val >= 1 and val <= numMatches:
                    self.process_query(run, potentialMatches[val-1])
                else:
                    self.foundAmbigiousSearched = True
            else:
                self.message(
                    u"Multiple matches found for {0}, skipping for now".format(cleanedRunName))
                self.foundAmbigiousSearched = True
        else:
            self.process_query(run, potentialMatches[0])
Esempio n. 5
0
    def process_query(self, run, searchResult):
        parsed = self.parse_query_results(searchResult)

        if run.name != parsed['name']:
            self.message(
                "Setting run {0} name to {1}".format(run.name, parsed['name']),
                2)
            if self.compiledCleaningExpression.search(run.name):
                self.message(
                    'Detected run name {0} (id={1}) may have category information embedded in it.'
                    .format(run.name, run.id), 0 if self.interactive else 1)
                if self.interactive:
                    self.message(
                        'Please set a category for this run (hit enter to leave as {0})'
                        .format(run.category), 0)
                    input = input(' -> ')
                    if input != '':
                        run.category = input
            run.name = parsed['name']

        if run.giantbomb_id != parsed['giantbomb_id']:
            self.message(
                "Setting run {0} giantbomb_id to {1}".format(
                    run.name, parsed['giantbomb_id']), 2)
            run.giantbomb_id = parsed['giantbomb_id']

        if parsed['release_year'] == None:
            if self.interactive:
                self.message("No release date found for {0}".format(run.name),
                             0)
                val = None
                while not isinstance(val, int):
                    self.message(
                        "Enter the release year (leave blank to leave as is): ",
                        0)
                    input = input(' -> ')
                    if input == '':
                        break
                    val = util.try_parse_int(input)
                if val != None:
                    run.release_year = val
            else:
                self.message(
                    "No release date info found for {0} (id={1}), you will need to fix this manually."
                    .format(run.name, run.id))
        elif run.release_year != parsed['release_year']:
            self.message(
                "Setting run {0} release_year to {1}".format(
                    run.name, parsed['release_year']), 2)
            run.release_year = parsed['release_year']

        platformCount = len(parsed['platforms'])
        if run.console in parsed['platforms']:
            self.message(
                "Console already set for {0} to {1}.".format(
                    run.name, run.console), 0)
        elif platformCount != 1:
            if platformCount == 0:
                self.message("No platforms found for {0}".format(run.name), 0)
            else:
                self.message(
                    "Multiple platforms found for {0}".format(run.name), 0)
            self.message("Currently : {0}".format(run.console or "<unset>"), 0)
            if self.interactive:
                val = None
                if platformCount == 0:
                    self.message(
                        "Select a console, or enter a name manually (leave blank to keep as is):"
                    )
                else:
                    self.message(
                        "Enter a console name (leave blank to keep as is):")
                    i = 1
                    for platform in parsed['platforms']:
                        self.message("{0}) {1}".format(i, platform), 0)
                        i += 1
                    input = input(' -> ')
                    if input != '':
                        val = util.try_parse_int(input)
                        if val != None and val >= 1 and val <= platformCount:
                            run.console = parsed['platforms'][val - 1]
                        else:
                            run.console = input
            elif not run.console:
                self.message(
                    "Multiple platforms found for {0}, leaving as is for now.".
                    format(run.name), 0)
        else:
            platform = parsed['platforms'][0]
            if run.console != platform:
                self.message(
                    "Setting console for {0} to {1}".format(
                        run.name, platform), 0)
                run.console = platform

        run.save()
    def process_query(self, run, searchResult):
        parsed = self.parse_query_results(searchResult)
        
        if run.name != parsed['name']:
            self.message(u"Setting run {0} name to {1}".format(run.name, parsed['name']), 2)
            if self.compiledCleaningExpression.search(run.name):
                self.message(u'Detected run name {0} (id={1}) may have category information embedded in it.'.format(run.name, run.id), 0 if self.interactive else 1)
                if self.interactive:
                    self.message(u'Please set a category for this run (hit enter to leave as {0})'.format(run.category), 0)
                    input = raw_input(' -> ')
                    if input != '':
                        run.category = input
            run.name = parsed['name']

        if run.giantbomb_id != parsed['giantbomb_id']:
            self.message(u"Setting run {0} giantbomb_id to {1}".format(run.name, parsed['giantbomb_id']), 2)
            run.giantbomb_id = parsed['giantbomb_id']
        
        if parsed['release_year'] == None:
            if self.interactive:
                self.message(u"No release date found for {0}".format(run.name), 0)
                val = None
                while not isinstance(val, int):
                    self.message(u"Enter the release year (leave blank to leave as is): ", 0)
                    input = raw_input(' -> ')
                    if input == '':
                        break
                    val = util.try_parse_int(input)
                if val != None:
                    run.release_year = val
            else:
                self.message(u"No release date info found for {0} (id={1}), you will need to fix this manually.".format(run.name, run.id))
        elif run.release_year != parsed['release_year']:
            self.message(u"Setting run {0} release_year to {1}".format(run.name, parsed['release_year']), 2)
            run.release_year = parsed['release_year']

        platformCount = len(parsed['platforms'])
        if run.console in parsed['platforms']:
            self.message(u"Console already set for {0} to {1}.".format(run.name, run.console), 0)
        elif platformCount != 1:
            if platformCount == 0:
                self.message(u"No platforms found for {0}".format(run.name), 0)
            else:
                self.message(u"Multiple platforms found for {0}".format(run.name), 0)
            self.message(u"Currently : {0}".format(run.console or "<unset>"), 0)
            if self.interactive:
                val = None
                if platformCount == 0:
                    self.message(u"Select a console, or enter a name manually (leave blank to keep as is):")
                else:
                    self.message(u"Enter a console name (leave blank to keep as is):")
                    i = 1
                    for platform in parsed['platforms']:
                        self.message("{0}) {1}".format(i, platform), 0)
                        i += 1
                    input = raw_input(' -> ')
                    if input != '':
                        val = util.try_parse_int(input)
                        if val != None and val >= 1 and val <= platformCount:
                            run.console = parsed['platforms'][val-1]
                        else:
                            run.console = input
            elif not run.console:
                    self.message(u"Multiple platforms found for {0}, leaving as is for now.".format(run.name), 0)
        else:
            platform = parsed['platforms'][0]
            if run.console != platform:
                self.message(u"Setting console for {0} to {1}".format(run.name, platform), 0)
                run.console = platform 
            
        run.save()