Esempio n. 1
0
    def save_settings(self, request):
        config.set_configuration(
            'CREATE_BOOK_VISIBLE', self.cleaned_data['create_book_visible'])

        config.set_configuration(
            'BOOK_TRACK_CHANGES', self.cleaned_data['track_changes'])

        license = self.cleaned_data.get('create_book_license')
        if license is not None:
            config.set_configuration(
                'CREATE_BOOK_LICENSE', license.abbrevation)
        else:
            config.set_configuration('CREATE_BOOK_LICENSE', '')

        lang = self.cleaned_data.get('create_book_language')
        if lang is not None:
            config.set_configuration(
                'CREATE_BOOK_LANGUAGE', lang.abbrevation)
        else:
            config.set_configuration('CREATE_BOOK_LANGUAGE', '')

        # let's save metadata fields to be used
        create_book_metadata = self.cleaned_data.get('create_book_metadata', [])
        config.set_configuration('CREATE_BOOK_METADATA', create_book_metadata)

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 2
0
    def save_settings(self, request):
        config.set_configuration('CREATE_BOOK_VISIBLE',
                                 self.cleaned_data['create_book_visible'])

        config.set_configuration('BOOK_TRACK_CHANGES',
                                 self.cleaned_data['track_changes'])

        license = self.cleaned_data.get('create_book_license')
        if license is not None:
            config.set_configuration('CREATE_BOOK_LICENSE',
                                     license.abbrevation)
        else:
            config.set_configuration('CREATE_BOOK_LICENSE', '')

        lang = self.cleaned_data.get('create_book_language')
        if lang is not None:
            config.set_configuration('CREATE_BOOK_LANGUAGE', lang.abbrevation)
        else:
            config.set_configuration('CREATE_BOOK_LANGUAGE', '')

        # let's save metadata fields to be used
        create_book_metadata = self.cleaned_data.get('create_book_metadata',
                                                     [])
        config.set_configuration('CREATE_BOOK_METADATA', create_book_metadata)

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 3
0
    def save_settings(self, request):
        from uuid import uuid4

        config.set_configuration(
            'BOOKTYPE_SITE_NAME', self.cleaned_data['title'])
        config.set_configuration(
            'BOOKTYPE_SITE_TAGLINE', self.cleaned_data['tagline'])

        if 'favicon' in self.files:
            # just check for any kind of silly error
            try:
                prev_favicon = config.get_configuration('BOOKTYPE_SITE_FAVICON', None)
                fh, fname = misc.save_uploaded_as_file(self.files['favicon'])
                rand_name = 'favicon.%s.ico' % uuid4().hex[:8]
                shutil.move(fname, '{}/{}'.format(settings.STATIC_ROOT, rand_name))

                config.set_configuration(
                    'BOOKTYPE_SITE_FAVICON',
                    '{}/static/{}'.format(settings.BOOKTYPE_URL, rand_name)
                )

                # delete prev icon to avoid garbage
                if prev_favicon:
                    try:
                        prev_name = prev_favicon.rsplit('/', 1)[-1]
                        os.remove('{}/{}'.format(settings.STATIC_ROOT, prev_name))
                    except Exception as err:
                        logger.exception("Unable to remove previous favicon. Msg: %s" % err)
            except:
                pass

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 4
0
    def handle(self, *args, **options):
        if not hasattr(settings, 'BOOKTYPE_CONFIG'):
            raise CommandError('Does not have BOOKTYPE_CONFIG in settings.py file.')

        if len(args) != 2:
            raise CommandError("You must specify variable name and value.")

        key = args[0]
        value = args[1]

        if options['integer']:
            try:
                value = int(value)
            except ValueError:
                raise CommandError("I don't think this %s is a number!" % value)

        if options['float']:
            try:
                value = float(value)
            except ValueError:
                raise CommandError("I don't think this %s is a number!" % value)
                

        if options['as_json']:
            try:
                value = json.loads(value)
            except ValueError:
                raise CommandError("Not a valid JSON string.")

        if options['append']:
            # ovo neshto ne radi sa as_jsonom
            lst = config.get_configuration(key, [])

            if type(lst) == type([]):
                lst.append(value)
                config.set_configuration(key, lst)
            else:
                raise CommandError("Can not append to something that is not a list")
        elif options['remove']:
            lst = config.get_configuration(key, [])

            if type(lst) == type([]):
                try:
                    lst.remove(value)
                except ValueError:
                    raise CommandError("I can't see it!")

                config.set_configuration(key, lst)
            else:
                raise CommandError("Can not append to something that is not a list")
        else:
            config.set_configuration(key, value)
            
        try:
            config.save_configuration()
        except config.ConfigurationError:
            raise CommandError("Could not save the file.")
Esempio n. 5
0
    def handle(self, *args, **options):
        if not hasattr(settings, 'BOOKTYPE_CONFIG'):
            raise CommandError('Does not have BOOKTYPE_CONFIG in settings.py file.')

        if len(options['<name> <value>']) != 2:
            raise CommandError("You must specify variable name and value.")

        key = options['<name> <value>'][0]
        value = options['<name> <value>'][1]

        if options['integer']:
            try:
                value = int(value)
            except ValueError:
                raise CommandError("I don't think this %s is a number!" % value)

        if options['float']:
            try:
                value = float(value)
            except ValueError:
                raise CommandError("I don't think this %s is a number!" % value)

        if options['as_json']:
            try:
                value = json.loads(value)
            except ValueError:
                raise CommandError("Not a valid JSON string.")

        if options['append']:
            # ovo neshto ne radi sa as_jsonom
            lst = config.get_configuration(key, [])

            if type(lst) == type([]):
                lst.append(value)
                config.set_configuration(key, lst)
            else:
                raise CommandError("Can not append to something that is not a list")
        elif options['remove']:
            lst = config.get_configuration(key, [])

            if type(lst) == type([]):
                try:
                    lst.remove(value)
                except ValueError:
                    raise CommandError("I can't see it!")

                config.set_configuration(key, lst)
            else:
                raise CommandError("Can not append to something that is not a list")
        else:
            config.set_configuration(key, value)

        try:
            config.save_configuration()
        except config.ConfigurationError:
            raise CommandError("Could not save the file.")
Esempio n. 6
0
    def save_settings(self, request):
        static_root = settings.BOOKTYPE_ROOT

        config.set_configuration('BOOKTYPE_FRONTPAGE_HISTORY',
                                 self.cleaned_data['show_changes'])
        config.set_configuration('BOOKTYPE_FRONTPAGE_USE_ANONYMOUS_PAGE',
                                 self.cleaned_data['use_anonymous_page'])
        config.set_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_MESSAGE',
                                 self.cleaned_data['anonymous_message'])
        config.set_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_EMAIL',
                                 self.cleaned_data['anonymous_email'])

        # anonymous page image
        destination_filename = 'anonymous_image.png'
        destination_dir = '{0}/portal/frontpage/'.format(settings.MEDIA_ROOT)
        destination_file_path = '{dir}{filename}'.format(
            dir=destination_dir, filename=destination_filename)

        if 'anonymous_image_remove' in request.POST:
            os.remove(destination_file_path)
            config.del_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE')
        elif 'anonymous_image' in self.files:
            try:
                fh, fname = misc.save_uploaded_as_file(
                    self.files['anonymous_image'])

                if not os.path.exists(destination_dir):
                    os.makedirs(destination_dir)

                shutil.move(fname, destination_file_path)
                config.set_configuration(
                    'BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE',
                    '{0}portal/frontpage/anonymous_image.png'.format(
                        settings.MEDIA_URL))
            except:
                pass

        # welcome message
        if not os.path.exists('%s/templates/portal/' % static_root):
            os.makedirs('%s/templates/portal/' % static_root)

        try:
            f = open('%s/templates/portal/welcome_message.html' % static_root,
                     'w')

            text_data = self.cleaned_data.get('description', '')
            for ch in ['{%', '%}', '{{', '}}']:
                text_data = text_data.replace(ch, '')

            f.write(text_data.encode('utf8'))
            f.close()
            config.save_configuration()
        except IOError as err:
            raise err
        except config.ConfigurationError as err:
            raise err
Esempio n. 7
0
    def save_settings(self, request):
        config.set_configuration('DEFAULT_ROLE_%s' % self.anonymous,
                                 self.cleaned_data[self.anonymous])
        config.set_configuration('DEFAULT_ROLE_%s' % self.registered,
                                 self.cleaned_data[self.registered])

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 8
0
    def save_settings(self, request):
        config.set_configuration('FREE_REGISTRATION',
                                 self.cleaned_data['user_register'])
        config.set_configuration('ADMIN_CREATE_BOOKS',
                                 self.cleaned_data['create_books'])
        config.set_configuration('ADMIN_IMPORT_BOOKS',
                                 self.cleaned_data['import_books'])

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 9
0
    def save_settings(self, request):
        opts = []
        for _opt in self.OPTIONS:
            if self.cleaned_data.get('publish_{0}'.format(_opt)):
                opts.append(_opt)

        config.set_configuration('PUBLISH_OPTIONS', opts)

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 10
0
    def save_settings(self, request):
        config.set_configuration(
            'FREE_REGISTRATION', self.cleaned_data['user_register'])
        config.set_configuration(
            'ADMIN_CREATE_BOOKS', self.cleaned_data['create_books'])
        config.set_configuration(
            'ADMIN_IMPORT_BOOKS', self.cleaned_data['import_books'])

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 11
0
    def save_settings(self, request):
        opts = []
        for _opt in self.OPTIONS:
            if self.cleaned_data.get('publish_{0}'.format(_opt)):
                opts.append(_opt)

        config.set_configuration('PUBLISH_OPTIONS', opts)

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 12
0
    def handle(self, *args, **options):
        if not hasattr(settings, 'BOOKTYPE_CONFIG'):
            raise CommandError('Does not have BOOKTYPE_CONFIG in settings.py file.')

        if len(args) != 1:
            raise CommandError("You must specify variable name")

        if not settings.BOOKTYPE_CONFIG.has_key(args[0]):
            raise CommandError("There is no such variable.")

        del settings.BOOKTYPE_CONFIG[args[0]]

        config.save_configuration()
Esempio n. 13
0
    def save_settings(self, request):
        config.set_configuration(
            'DEFAULT_ROLE_%s' % self.anonymous,
            self.cleaned_data[self.anonymous]
        )
        config.set_configuration(
            'DEFAULT_ROLE_%s' % self.registered,
            self.cleaned_data[self.registered]
        )

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 14
0
    def save_settings(self, request):
        static_root = settings.BOOKTYPE_ROOT

        config.set_configuration('BOOKTYPE_FRONTPAGE_HISTORY', self.cleaned_data['show_changes'])
        config.set_configuration('BOOKTYPE_FRONTPAGE_USE_ANONYMOUS_PAGE', self.cleaned_data['use_anonymous_page'])
        config.set_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_MESSAGE', self.cleaned_data['anonymous_message'])
        config.set_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_EMAIL', self.cleaned_data['anonymous_email'])

        # anonymous page image
        destination_filename = 'anonymous_image.png'
        destination_dir = '{0}/portal/frontpage/'.format(settings.MEDIA_ROOT)
        destination_file_path = '{dir}{filename}'.format(dir=destination_dir, filename=destination_filename)

        if 'anonymous_image_remove' in request.POST:
            os.remove(destination_file_path)
            config.del_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE')
        elif 'anonymous_image' in self.files:
            try:
                fh, fname = misc.save_uploaded_as_file(self.files['anonymous_image'])

                if not os.path.exists(destination_dir):
                    os.makedirs(destination_dir)

                shutil.move(fname, destination_file_path)
                config.set_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE',
                                         '{0}portal/frontpage/anonymous_image.png'.format(settings.MEDIA_URL))
            except:
                pass

        # welcome message
        if not os.path.exists('%s/templates/portal/' % static_root):
            os.makedirs('%s/templates/portal/' % static_root)

        try:
            f = open(
                '%s/templates/portal/welcome_message.html' % static_root, 'w')

            text_data = self.cleaned_data.get('description', '')
            for ch in ['{%', '%}', '{{', '}}']:
                text_data = text_data.replace(ch, '')

            f.write(text_data.encode('utf8'))
            f.close()
            config.save_configuration()
        except IOError as err:
            raise err
        except config.ConfigurationError as err:
            raise err
Esempio n. 15
0
    def save_settings(self, request):
        config.set_configuration('CREATE_BOOK_VISIBLE',
                                 self.cleaned_data['visible'])

        config.set_configuration('BOOK_TRACK_CHANGES',
                                 self.cleaned_data['track_changes'])

        if 'license' in self.cleaned_data:
            if self.cleaned_data['license'] is not None:
                config.set_configuration(
                    'CREATE_BOOK_LICENSE',
                    self.cleaned_data['license'].abbrevation)
            else:
                config.set_configuration('CREATE_BOOK_LICENSE', '')
        else:
            config.set_configuration('CREATE_BOOK_LICENSE', '')

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 16
0
    def save_settings(self, request):
        from uuid import uuid4

        config.set_configuration('BOOKTYPE_SITE_NAME',
                                 self.cleaned_data['title'])
        config.set_configuration('BOOKTYPE_SITE_TAGLINE',
                                 self.cleaned_data['tagline'])
        config.set_configuration('BOOKTYPE_FRONTPAGE_URL',
                                 self.cleaned_data['frontpage_url'])

        if 'favicon' in self.files:
            # just check for any kind of silly error
            try:
                prev_favicon = config.get_configuration(
                    'BOOKTYPE_SITE_FAVICON', None)
                fh, fname = misc.save_uploaded_as_file(self.files['favicon'])
                rand_name = 'favicon.%s.ico' % uuid4().hex[:8]
                shutil.move(fname, '{}/{}'.format(settings.STATIC_ROOT,
                                                  rand_name))

                config.set_configuration(
                    'BOOKTYPE_SITE_FAVICON',
                    '{}{}'.format(settings.STATIC_URL, rand_name))

                # delete prev icon to avoid garbage
                if prev_favicon:
                    try:
                        prev_name = prev_favicon.rsplit('/', 1)[-1]
                        os.remove('{}/{}'.format(settings.STATIC_ROOT,
                                                 prev_name))
                    except Exception as err:
                        logger.exception(
                            "Unable to remove previous favicon. Msg: %s" % err)
            except:
                pass

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 17
0
    def save_settings(self, request):
        config.set_configuration(
            'CREATE_BOOK_VISIBLE', self.cleaned_data['visible'])

        config.set_configuration(
            'BOOK_TRACK_CHANGES', self.cleaned_data['track_changes'])

        if 'license' in self.cleaned_data:
            if self.cleaned_data['license'] is not None:
                config.set_configuration(
                    'CREATE_BOOK_LICENSE',
                    self.cleaned_data['license'].abbrevation
                )
            else:
                config.set_configuration('CREATE_BOOK_LICENSE', '')
        else:
            config.set_configuration('CREATE_BOOK_LICENSE', '')

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 18
0
    def save_settings(self, request):
        data = self.__class__.initial_data()

        if self.cleaned_data['book_css'] != data['book_css']:
            config.set_configuration(
                'BOOKTYPE_CSS_BOOK', self.cleaned_data['book_css'])

        if self.cleaned_data['ebook_css'] != data['ebook_css']:
            config.set_configuration(
                'BOOKTYPE_CSS_EBOOK', self.cleaned_data['ebook_css'])

        if self.cleaned_data['pdf_css'] != data['pdf_css']:
            config.set_configuration(
                'BOOKTYPE_CSS_PDF', self.cleaned_data['pdf_css'])

        if self.cleaned_data['odt_css'] != data['odt_css']:
            config.set_configuration(
                'BOOKTYPE_CSS_ODT', self.cleaned_data['odt_css'])

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err
Esempio n. 19
0
    def save_settings(self, request):
        data = self.__class__.initial_data()

        if self.cleaned_data['book_css'] != data['book_css']:
            config.set_configuration('BOOKTYPE_CSS_BOOK',
                                     self.cleaned_data['book_css'])

        if self.cleaned_data['ebook_css'] != data['ebook_css']:
            config.set_configuration('BOOKTYPE_CSS_EBOOK',
                                     self.cleaned_data['ebook_css'])

        if self.cleaned_data['pdf_css'] != data['pdf_css']:
            config.set_configuration('BOOKTYPE_CSS_PDF',
                                     self.cleaned_data['pdf_css'])

        if self.cleaned_data['odt_css'] != data['odt_css']:
            config.set_configuration('BOOKTYPE_CSS_ODT',
                                     self.cleaned_data['odt_css'])

        try:
            config.save_configuration()
        except config.ConfigurationError as err:
            raise err