コード例 #1
0
    def handle(self, *args, **options):
        mongodb.MongoDbConnect()
        self.stdout.write("::::Fill Country And City in DB")

        for file_name in os.listdir(CLIST_DIR):
            f = open(CLIST_DIR + file_name)
            country_obj = eval(f.read())
            f.close()
            country_name = file_name.replace(".clist", "")

            self.stdout.write("::::Creating " + country_name)
            #
            #   Create country mongodb object
            #
            country = models.Country(name=country_name,
                                     code=country_obj['code'])
            country.save()
            for c in country_obj['city_list']:
                self.stdout.write("::::Creating for " + country_name +
                                  " city " + c['name'])
                city = models.City(name=c['name'], location=c['coordinates'])
                city.save()
                country.city_list.append(city)
            country.save()

        self.stdout.write("::::END")
コード例 #2
0
    def handle(self, *args, **options):
        mongodb.MongoDbConnect()
        models.Translation.objects().delete()

        def collect_from_dir(d):
            listdir = os.listdir(d)
            for path in listdir:
                filepath = os.path.join(d, path)
                ext = os.path.splitext(filepath)[-1]
                if ext in FILE_TYPES.keys() and path not in SKIP_FILE:
                    tr = FILE_TYPES[ext](filepath)
                    tr.find_tr()
                    self.add_tr(tr.tr, filepath)
                if path in FILE_TYPES.keys():
                    tr = FILE_TYPES[path](filepath)
                    tr.find_tr()
                    self.add_tr(tr.tr, filepath)

                if os.path.isdir(
                        filepath) and path[0] != '.' and path not in SKIP_DIR:
                    collect_from_dir(filepath)

        collect_from_dir(settings.BASE_DIR)

        for t in STRING_TO_TRANSLATE.keys():
            tr = models.Translation.objects(line=t)
            if not tr:
                tr = models.Translation(line=t,
                                        occurance=STRING_TO_TRANSLATE[t])
                tr.save()
            self.stdout.write("}}}}}}}}}}}}}}}" + repr(t))
            self.stdout.write(repr(STRING_TO_TRANSLATE[t]))

        self.stdout.write("::::END")
コード例 #3
0
ファイル: InitValue.py プロジェクト: ganap/so
    def handle(self, *args, **options):
        mongodb.MongoDbConnect()
        self.stdout.write("::::Create Moderator queue...")

        mq = mongoapp_models.ModeratorQueue.objects(name="main")
        if not mq:
            mq = mongoapp_models.ModeratorQueue(name="main")
            mq.save()
        self.stdout.write("::::Create Site preferences...")
        sp = models.SitePreferences.objects.all()
        if not sp:
            models.SitePreferences.objects.create()

        self.stdout.write("::::END")
コード例 #4
0
ファイル: RegenerateCCListMongo.py プロジェクト: ganap/so
    def handle(self, *args, **options):
        mongodb.MongoDbConnect()
        self.stdout.write(
            "::::Regenerate Country And City list files in /static/gen/L18n/country-city/"
        )
        locales = models.Locales.objects()
        locale_suffixes = []
        for locale in locales:
            locale_suffixes.append(locale.alias)
        #
        #   Get all countries and save them to files
        #

        countries_locales = {}
        for s in locale_suffixes:
            countries_locales[s] = {
                #   '3489284jdsjII293jJ': 'France',
                #   ...
            }

        for country in models.Country.objects():
            pk = str(country.pk)
            for locale in locale_suffixes:
                names = country.name_locale
                name = names.get(locale, None)
                if name:
                    countries_locales[locale][pk] = name
                else:
                    countries_locales[locale][pk] = country.name

        for locale in locale_suffixes:
            file_path = AUTO_GEN_DIR + "L18n/country-city/country-list."\
                + locale + ".json"
            f = open(file_path, "w")
            data = repr(countries_locales[locale])
            data = rm_spaces(data)
            f.write(data)
            f.close()
            gz_compress_file(file_path)

        self.stdout.write("::::County list      [DONE]")
        #
        #   Get all City from country and save them
        #   in folder with Country.oid
        #
        for country in models.Country.objects():
            pk = str(country.pk)
            country_dir = AUTO_GEN_DIR + "L18n/country-city/" + pk + "/"
            if not os.path.isdir(country_dir):
                os.mkdir(country_dir)
            for locale in locale_suffixes:
                city_dict = {}
                for city in country.city_list:
                    city_pk = str(city.pk)
                    names = city.name_locale
                    name = names.get(locale, None)
                    if name:
                        city_dict[city_pk] = name
                    else:
                        city_dict[city_pk] = city.name

                file_path = country_dir + "city-list." + locale + ".json"
                f = open(file_path, "w")
                data = rm_spaces(repr(city_dict))
                f.write(data)
                f.close()
                gz_compress_file(file_path)
            self.stdout.write("::::City list for " + country.name +
                              "         [DONE]")

        self.stdout.write("::::END")
コード例 #5
0
    def handle(self, *args, **options):
        mongodb.MongoDbConnect()
        self.stdout.write(
            "::::Regenerate Country And City list files in /static/gen/L18n/country-city/"
        )
        locales = models.Locales.objects()
        locale_suffixes = []
        for locale in locales:
            locale_suffixes.append(locale.alias)
        #
        #   Get all countries and save them to files
        #

        countries_locales = {}
        for s in locale_suffixes:
            countries_locales[s] = {
                #   1: 'France',
                #   ...
            }

        for country in models.DjCountry.objects.all():
            pk = str(country.pk)
            for locale in locale_suffixes:
                names = country.name_locale

                name = names.get(locale, None)
                if name:
                    countries_locales[locale][pk] = {
                        'n': name,
                        'c': country.code
                    }
                else:
                    countries_locales[locale][pk] = {
                        'n': country.name,
                        'c': country.code
                    }

        for locale in locale_suffixes:
            file_path = AUTO_GEN_DIR + "L18n/country-city/country-list."\
                + locale + ".json"
            f = open(file_path, "w")
            data = json.dumps(countries_locales[locale])
            data = rm_spaces(data)
            f.write(data)
            f.close()
            gz_compress_file(file_path)

        self.stdout.write("::::County list      [DONE]")
        #
        #   Get all City from country and save them
        #   in folder with Country.pk
        #
        for country in models.DjCountry.objects.all():
            pk = str(country.pk)
            country_dir = AUTO_GEN_DIR + "L18n/country-city/" + pk + "/"
            if not os.path.isdir(country_dir):
                os.mkdir(country_dir)
            for locale in locale_suffixes:
                city_list_export = []
                city_list = models.DjCity.objects.filter(country=country)
                for city in city_list:
                    city_pk = city.pk
                    names = city.name_locale
                    name = names.get(locale, None)
                    if name:
                        city_list_export.append({"p": city_pk, "n": name})
                    else:
                        city_list_export.append({"p": city_pk, "n": city.name})

                self.stdout.write(repr(city_list_export))
                file_path = country_dir + "city-list." + locale + ".json"
                f = open(file_path, "w")
                data = rm_spaces(json.dumps(city_list_export))
                f.write(data)
                f.close()
                gz_compress_file(file_path)
            self.stdout.write("::::City list for " + country.name +
                              "         [DONE]")

        timestamp = helpers.timestamp()
        f = open(AUTO_GEN_DIR + "L18n/country-city/autogen.timestamp", "w")
        f.write(str(timestamp))
        f.close()
        self.stdout.write("::::END")