Beispiel #1
0
    def get_context_data(self, **kwargs):
        context = super(FrontPageView, self).get_context_data(**kwargs)

        if config.get_configuration('BOOKTYPE_FRONTPAGE_USE_ANONYMOUS_PAGE') and self.request.user.is_anonymous():
            self.template_name = "portal/anonymous_frontpage.html"
            context['anonymous_message'] = config.get_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_MESSAGE')
            context['anonymous_email'] = config.get_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_EMAIL')
            context['anonymous_image'] = config.get_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE')
            return context

        context['is_admin'] = self.request.user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(self.request.user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [p.key_name for p in default_role.permissions.all()]
        else:
            context['roles_permissions'] = []

        b_query = Book.objects.all()

        if not self.request.user.is_superuser:
            if self.request.user.is_authenticated():
                b_query = b_query.filter(Q(hidden=False) | Q(owner=self.request.user))
            else:
                b_query = b_query.filter(hidden=False)

        context['books_list'] = b_query.order_by('-created')[:10]
        context['user_list'] = User.objects.filter(is_active=True).order_by('-date_joined')[:12]
        booki_group5 = BookiGroup.objects.all().order_by('-created')[:6]

        context['group_list'] = [{
            'url_name': g.url_name,
            'name': g.name,
            'description': g.description,
            'num_members': g.members.count(),
            'num_books': g.book_set.count(),
            'small_group_image': g.get_group_image
            } for g in booki_group5]

        context['recent_activities'] = BookHistory.objects.filter(kind__in=[1, 10], book__hidden=False).order_by('-modified')[:5]

        if self.request.user.is_authenticated():
            context['is_book_limit'] = Book.objects.filter(owner=self.request.user).count() >= config.get_configuration('BOOKTYPE_BOOKS_PER_USER') != -1
        else:
            context['is_book_limit'] = True

        if self.request.user.is_superuser:
            context['can_create_book'] = True
            context['is_book_limit'] = False
        # if only admin create then deny user permission to create new books
        elif config.get_configuration('ADMIN_CREATE_BOOKS'):
            context['can_create_book'] = False
        # check if user can create more books
        elif context['is_book_limit']:
            context['can_create_book'] = False
        else:
            context['can_create_book'] = True

        return context
Beispiel #2
0
    def get_context_data(self, **kwargs):
        context = super(FrontPageView, self).get_context_data(**kwargs)

        if config.get_configuration('BOOKTYPE_FRONTPAGE_USE_ANONYMOUS_PAGE') and self.request.user.is_anonymous():
            self.template_name = "portal/anonymous_frontpage.html"
            context['anonymous_message'] = config.get_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_MESSAGE')
            context['anonymous_email'] = config.get_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_EMAIL')
            context['anonymous_image'] = config.get_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE')
            return context

        context['is_admin'] = self.request.user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(self.request.user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [p.key_name for p in default_role.permissions.all()]
        else:
            context['roles_permissions'] = []

        b_query = Book.objects.all()

        if not self.request.user.is_superuser:
            if self.request.user.is_authenticated():
                b_query = b_query.filter(Q(hidden=False) | Q(owner=self.request.user))
            else:
                b_query = b_query.filter(hidden=False)

        context['books_list'] = b_query.order_by('-created')[:4]
        context['user_list'] = User.objects.filter(is_active=True).order_by('-date_joined')[:2]
        booki_group5 = BookiGroup.objects.all().order_by('-created')[:5]

        context['group_list'] = [{
            'url_name': g.url_name,
            'name': g.name,
            'description': g.description,
            'num_members': g.members.count(),
            'num_books': g.book_set.count(),
            'small_group_image': g.get_group_image
            } for g in booki_group5]

        context['recent_activities'] = BookHistory.objects.filter(kind__in=[1, 10], book__hidden=False).order_by('-modified')[:5]

        if self.request.user.is_authenticated():
            context['is_book_limit'] = Book.objects.filter(owner=self.request.user).count() >= config.get_configuration('BOOKTYPE_BOOKS_PER_USER') != -1
        else:
            context['is_book_limit'] = True

        if self.request.user.is_superuser:
            context['can_create_book'] = True
            context['is_book_limit'] = False
        # if only admin create then deny user permission to create new books
        elif config.get_configuration('ADMIN_CREATE_BOOKS'):
            context['can_create_book'] = False
        # check if user can create more books
        elif context['is_book_limit']:
            context['can_create_book'] = False
        else:
            context['can_create_book'] = True

        return context
Beispiel #3
0
    def get_context_data(self, **kwargs):
        context = super(ForgotPasswordView, self).get_context_data(**kwargs)

        context['is_admin'] = self.request.user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(self.request.user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [p.key_name for p in default_role.permissions.all()]
        else:
            context['roles_permissions'] = []

        return context
Beispiel #4
0
    def get_context_data(self, **kwargs):
        context = super(ForgotPasswordView, self).get_context_data(**kwargs)

        context['is_admin'] = self.request.user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(self.request.user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [p.key_name for p in default_role.permissions.all()]
        else:
            context['roles_permissions'] = []

        return context
Beispiel #5
0
    def get_context_data(self, **kwargs):
        context = super(SignInView, self).get_context_data(**kwargs)
        try:
            context['invite_email'] = self.request.session['invite_data']['email']
        except KeyError:
            pass

        context['is_admin'] = self.request.user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(self.request.user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [p.key_name for p in default_role.permissions.all()]
        else:
            context['roles_permissions'] = []
        return context
Beispiel #6
0
    def get_context_data(self, **kwargs):
        context = super(SignInView, self).get_context_data(**kwargs)
        try:
            context['invite_email'] = self.request.session['invite_data']['email']
        except KeyError:
            pass

        context['is_admin'] = self.request.user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(self.request.user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [p.key_name for p in default_role.permissions.all()]
        else:
            context['roles_permissions'] = []
        return context
Beispiel #7
0
    def get_context_data(self, **kwargs):
        context = super(DashboardPageView, self).get_context_data(**kwargs)
        current_user = self.request.user

        context['is_admin'] = current_user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(current_user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [
                p.key_name for p in default_role.permissions.all()
            ]
        else:
            context['roles_permissions'] = []

        context['licenses'] = License.objects.all().order_by('name')
        context['languages'] = Language.objects.all()

        if self.is_current_user_dashboard:
            context['books'] = Book.objects.select_related('version').filter(
                owner=self.object).order_by('title')
        else:
            context['books'] = Book.objects.select_related('version').filter(
                owner=self.object, hidden=False).order_by('title')

        context['groups'] = BookiGroup.objects.filter(
            owner=self.object).order_by('name')

        context['participating_groups'] = BookiGroup.objects.filter(
            members=self.object).exclude(owner=self.object).order_by('name')

        # get books which user has collaborated on
        book_ids = set(
            BookHistory.objects.filter(user=self.object).values_list(
                'book', flat=True).distinct())

        # get books with user assigned by roles
        book_ids.update(
            BookRole.objects.filter(members=self.object).values_list(
                'book', flat=True).distinct())

        context['books_collaborating'] = Book.objects.filter(
            id__in=book_ids).exclude(owner=self.object).order_by('title')

        # get user recent activity
        context['recent_activity'] = BookHistory.objects.filter(
            user=self.object).order_by('-modified')[:3]

        context['can_upload_book'] = security.get_security(
            current_user).has_perm('account.can_upload_book')
        context['can_create_book'] = True

        # NOTE: base_books will be user's books for now, let's define with the rest of team
        # what should be a good logic to define existent books as skeletons
        form_kwargs = {'base_book_qs': context['books']}

        context['book_creation_form'] = BookCreationForm(initial={
            'language':
            config.get_configuration('CREATE_BOOK_LANGUAGE'),
            'license':
            config.get_configuration('CREATE_BOOK_LICENSE'),
            'visible_to_everyone':
            config.get_configuration('CREATE_BOOK_VISIBLE')
        },
                                                         **form_kwargs)

        # if only admin import then deny user permission to upload books
        if config.get_configuration('ADMIN_IMPORT_BOOKS'):
            if not current_user.is_superuser:
                context['can_upload_book'] = False

        # if only admin create then deny user permission to create new books
        if config.get_configuration('ADMIN_CREATE_BOOKS'):
            if not current_user.is_superuser:
                context['can_create_book'] = False

        # check if user can create/import more books
        if current_user.is_authenticated():
            book_p_user = config.get_configuration('BOOKTYPE_BOOKS_PER_USER')
            context['is_book_limit'] = Book.objects.filter(
                owner=current_user).count() >= book_p_user != -1
        else:
            context['is_book_limit'] = True

        if context['is_book_limit']:
            if not current_user.is_superuser:
                context['can_create_book'] = False
                context['can_upload_book'] = False
            else:
                context['is_book_limit'] = False

        # change title in case of not authenticated user
        if not current_user.is_authenticated() or \
           self.object != current_user:
            context['title'] = _('User profile')
            context['page_title'] = _('User profile')

        # Getting context variables for the form to invite users
        if current_user.is_authenticated():
            initial = {
                'message': getattr(settings, 'BOOKTYPE_DEFAULT_INVITE_MESSAGE',
                                   '')
            }
            context['invite_form'] = UserInviteForm(user=current_user,
                                                    initial=initial)

        return context
Beispiel #8
0
    def get_context_data(self, **kwargs):
        context = super(DashboardPageView, self).get_context_data(**kwargs)
        current_user = self.request.user

        context['is_admin'] = current_user.is_superuser
        # get all user permissions
        role_key = security.get_default_role_key(current_user)
        default_role = security.get_default_role(role_key)
        if default_role:
            context['roles_permissions'] = [p.key_name for p in default_role.permissions.all()]
        else:
            context['roles_permissions'] = []

        context['licenses'] = License.objects.all().order_by('name')
        context['languages'] = Language.objects.all()

        if self.is_current_user_dashboard:
            context['books'] = Book.objects.select_related('version').filter(
                owner=self.object).order_by('title')
        else:
            context['books'] = Book.objects.select_related('version').filter(
                owner=self.object, hidden=False).order_by('title')

        context['groups'] = BookiGroup.objects.filter(
            owner=self.object).order_by('name')

        context['participating_groups'] = BookiGroup.objects.filter(
            members=self.object).exclude(owner=self.object).order_by('name')

        # get books which user has collaborated on
        book_ids = set(BookHistory.objects.filter(user=self.object).values_list('book', flat=True).distinct())

        # get books with user assigned by roles
        book_ids.update(BookRole.objects.filter(members=self.object).values_list('book', flat=True).distinct())

        context['books_collaborating'] = Book.objects.filter(
            id__in=book_ids).exclude(owner=self.object).order_by('title')

        # get user recent activity
        context['recent_activity'] = BookHistory.objects.filter(
            user=self.object).order_by('-modified')[:3]

        context['can_upload_book'] = security.get_security(current_user).has_perm('account.can_upload_book')
        context['can_create_book'] = True

        # NOTE: base_books will be user's books for now, let's define with the rest of team
        # what should be a good logic to define existent books as skeletons
        form_kwargs = {'base_book_qs': context['books']}

        context['book_creation_form'] = BookCreationForm(
            initial={
                'language': config.get_configuration('CREATE_BOOK_LANGUAGE'),
                'license': config.get_configuration('CREATE_BOOK_LICENSE'),
                'visible_to_everyone': config.get_configuration('CREATE_BOOK_VISIBLE')
            }, **form_kwargs)

        # if only admin import then deny user permission to upload books
        if config.get_configuration('ADMIN_IMPORT_BOOKS'):
            if not current_user.is_superuser:
                context['can_upload_book'] = False

        # if only admin create then deny user permission to create new books
        if config.get_configuration('ADMIN_CREATE_BOOKS'):
            if not current_user.is_superuser:
                context['can_create_book'] = False

        # check if user can create/import more books
        if current_user.is_authenticated():
            book_p_user = config.get_configuration('BOOKTYPE_BOOKS_PER_USER')
            context['is_book_limit'] = Book.objects.filter(owner=current_user).count() >= book_p_user != -1
        else:
            context['is_book_limit'] = True

        if context['is_book_limit']:
            if not current_user.is_superuser:
                context['can_create_book'] = False
                context['can_upload_book'] = False
            else:
                context['is_book_limit'] = False

        # change title in case of not authenticated user
        if not current_user.is_authenticated() or \
           self.object != current_user:
            context['title'] = _('User profile')
            context['page_title'] = _('User profile')

        # Getting context variables for the form to invite users
        if current_user.is_authenticated():
            initial = {
                'message': getattr(settings, 'BOOKTYPE_DEFAULT_INVITE_MESSAGE', '')
            }
            context['invite_form'] = UserInviteForm(user=current_user, initial=initial)

        return context