Пример #1
0
 def copy_translations_from_remote_app(self, remote_app):
     """
     Copies metadata translations from given RemoteApp
     and ensures that at least one translation exists at the end.
     """
     from .remoteapp import RemoteApp
     for language_code in remote_app.get_available_languages():
         # get the translation for current language_code
         remote_app = RemoteApp.objects.language(language_code).get(
             pk=remote_app.pk)
         # copy the translation to this App instance
         if language_code in self.get_available_languages():
             app = App.objects.language(language_code).get(pk=self.pk)
             app.summary = remote_app.summary
             app.description = clean(remote_app.description)
             app.save()
         else:
             self.translate(language_code)
             self.summary = remote_app.summary
             self.description = clean(remote_app.description)
             self.save()
     # ensure that at least one translation exists
     if len(self.get_available_languages()) == 0:
         self.default_translate()
         self.save()
Пример #2
0
 def render(self, name, value, attrs=None, renderer=None):
     self.attrs.update({'list': 'list__%s' % name})
     text_html = super().render(name, value, attrs, renderer)
     data_list = '<datalist id="list__%s">' % name
     for item in self._list:
         value = clean(str(item[0]))
         name = clean(str(item[1]))
         data_list += '<option value="%s">%s</option>' % (value, name)
     data_list += '</datalist>'
     return text_html + data_list
Пример #3
0
    def update_from_json(self, app):
        """
        Updates the data for this app and ensures that at least one translation exists.
        :param app: A JSON app object from the repository v1 index.
        :return: True if app changed, False otherwise
        """
        if 'lastUpdated' not in app:
            logging.warning("App %s is missing 'lastUpdated' in index")
            return False

        # don't update if app hasn't changed since last update
        last_update = datetime.datetime.fromtimestamp(
            app['lastUpdated'] / 1000, timezone.utc)
        if self.last_updated_date and self.last_updated_date >= last_update:
            logging.info("Skipping update of %s, because did not change.",
                         self)
            return False
        else:
            self.last_updated_date = last_update

        if 'name' not in app:
            logging.warning("App %s is missing 'name' in index")
            return False
        self.name = app['name']
        if 'summary' in app and not self._move_to_localized(app, 'summary'):
            self.summary_override = app['summary']
        if 'description' in app and not self._move_to_localized(
                app, 'description'):
            self.description_override = clean(app['description'])
        if 'authorName' in app:
            self.author_name = app['authorName']
        if 'webSite' in app:
            self.website = app['webSite']
        if 'categories' in app:
            self._update_categories(app['categories'])
        if 'added' in app:
            date_added = datetime.datetime.fromtimestamp(
                app['added'] / 1000, timezone.utc)
            if self.added_date > date_added:
                self.added_date = date_added
        self.save()
        if 'localized' in app:
            self._update_translations(app['localized'])
            self._update_screenshots(app['localized'])
        if len(self.get_available_languages()) == 0:
            # no localization available, translate in default language
            self.default_translate()
            self.save()
        # do the icon last, because we require the app to be saved, so a pk exists
        if 'icon' in app:
            # Schedule icon updating task, because it takes too long within this task
            # pylint: disable=unexpected-keyword-arg
            tasks.update_remote_app_icon(self.pk,
                                         app['icon'],
                                         priority=PRIORITY_REMOTE_APP_ICON)
        return True
Пример #4
0
 def apply_translation(self, original_language_code, translation):
     # textual metadata
     if 'summary' in translation:
         self.summary = translation['summary']
     if 'description' in translation:
         self.description = clean(translation['description'])
     # graphic assets
     url = self._get_base_url(original_language_code)
     if 'featureGraphic' in translation:
         self.feature_graphic_url = url + translation['featureGraphic']
     if 'icon' in translation:
         self.high_res_icon_url = url + translation['icon']
     if 'tvBanner' in translation:
         self.tv_banner_url = url + translation['tvBanner']
     self.save()
    def _update(self, repo_index, update_apps):
        """
        Updates this remote repository with the given index

        :param repo_index: The repository index v1 in JSON format
        :param update_apps: False if apps should not be updated as well
        """
        # bail out if the repo did not change since last update
        repo_change = datetime.datetime.fromtimestamp(
            repo_index['repo']['timestamp'] / 1000, timezone.utc)
        if self.last_change_date and self.last_change_date >= repo_change:
            logging.info(
                "Remote repo date for %s did not change, not updating.",
                str(self))
            return

        # update repository's metadata
        self.name = repo_index['repo']['name']
        self.description = clean(repo_index['repo']['description'])
        if 'mirrors' in repo_index['repo']:
            self.mirrors = json.dumps(repo_index['repo']['mirrors'])
        if update_apps:
            self.last_change_date = repo_change
        else:
            # apps will be updated asynchronously soon, so this allows the update to pass
            self.last_change_date = datetime.datetime.fromtimestamp(
                0, timezone.utc)
        if not self.public_key:
            self.public_key = repo_index['repo'][
                'pubkey']  # added by index.download_repo_index()

        # download and save repository icon
        try:
            self._update_icon(repo_index['repo']['icon'])
        except Exception as e:
            logging.warning("Could not download repository icon. %s", e)

        self.save()

        if update_apps:
            self._update_apps(repo_index['apps'], repo_index['packages'])
Пример #6
0
 def test_clean_empty_link(self):
     string = 'Link <a href="fdroid.app:org.torproject.android">Orbot</a> not supported'
     self.assertEqual('Link Orbot not supported', clean(string))
Пример #7
0
 def test_clean_only_empty_link(self):
     string = 'Link <a href="https://orbot.org">Orbot</a> is supported'
     self.assertEqual(string, clean(string))