Exemple #1
0
class MainArticles(View):
    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(
        group_required(
            'admin',
            HttpResponse(MessageManager().getMessage(
                message='no_privileg_to_reach_this_page'))))
    def get(self, request, *args, **kwargs):
        main_articles = readJson(
            'configuration/json/webconfig.json')['main_articles']
        print(main_articles)
        return HttpResponse(json.dumps(main_articles),
                            content_type='application/json')

    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(
        group_required(
            'admin',
            HttpResponse(MessageManager().getMessage(
                message='no_privileg_to_reach_this_page'))))
    def post(self, request, *args, **kwargs):
        web_config = readJson('configuration/json/webconfig.json')
        web_config['main_articles']['first'] = request.POST['first']
        web_config['main_articles']['list'] = re.sub(
            r"[^\w]", " ", request.POST['list']).split()
        write_to_file = writeJson('configuration/json/webconfig.json',
                                  web_config)
        if write_to_file:
            MessageManager().makeMessage(request, message='success_edited')
            return redirect(request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request, message='problem_with_save')
        return redirect(request.META.get('HTTP_REFERER'))
class CreateArticle(TemplateView):
    template_name = 'article/stuff/create_article.html'

    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def get(self, request, *args, **kwargs):
        self.form = ArticleCreateForm()
        self.article_language_code = kwargs['language']
        self.initialarticle = InitialArticle.objects.get(
            keywords=kwargs['keywords'])
        return super(CreateArticle, self).get(request, *args, **kwargs)

    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def post(self, request, *args, **kwargs):
        initial_article = InitialArticle.objects.get(
            keywords=kwargs['keywords'])
        self.form = ArticleCreateForm(request.POST, request.FILES)
        if self.form.is_valid():
            article_ = self.form.save_(initial_article, kwargs['language'])
            return redirect('/' + 'article/get/' + article_.language + '/' +
                            str(article_.initial))
        MessageManager().makeMessage(request, message='form_is_not_valid')
        return redirect('x')  #request.META.get('HTTP_REFERER'))

    def get_context_data(self, **kwargs):
        context = super(CreateArticle, self).get_context_data(**kwargs)
        context['article_create_form'] = self.form
        context['article_language_code'] = self.article_language_code
        context['initialarticle'] = self.initialarticle
        return context
Exemple #3
0
class MixedArticles(View):
    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(
        group_required(
            'admin',
            HttpResponse(MessageManager().getMessage(
                message='no_privileg_to_reach_this_page'))))
    def get(self, request, *args, **kwargs):
        mixed_articles = readJson(
            'configuration/json/webconfig.json')['mixed_articles']
        return HttpResponse(json.dumps(mixed_articles),
                            content_type='application/json')

    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(
        group_required(
            'admin',
            HttpResponse(MessageManager().getMessage(
                message='no_privileg_to_reach_this_page'))))
    def post(self, request, *args, **kwargs):
        if request.FILES['mixed_articles'].name[-5:] == '.json':
            data = getMemoryJsonData(request.FILES['mixed_articles'])
            web_config = readJson('configuration/json/webconfig.json')
            web_config['mixed_articles'] = data
            write_to_file = writeJson('configuration/json/webconfig.json',
                                      web_config)
            if write_to_file:
                MessageManager().makeMessage(request, message='success_edited')
                return redirect(request.META.get('HTTP_REFERER'))
            MessageManager().makeMessage(request, message='problem_with_save')
            return redirect(request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request, message='unsupported_file_type')
        return redirect(request.META.get('HTTP_REFERER'))
class EditArticleCategory(TemplateView):
    template_name = 'articlecategory/edit_article_category.html'

    @method_decorator(login_required(login_url='/login'))
    @method_decorator(group_required('moderator', redirect_to='/moderator'))
    def get(self, request, *args, **kwargs):
        article_category = ArticleCategory.objects.get(
            pk=kwargs['article_category_pk'])
        self.form = ArticleCategoryModelForm(instance=article_category)
        return super(EditArticleCategory, self).get(request, *args, **kwargs)

    @method_decorator(login_required(login_url='/login'))
    @method_decorator(group_required('moderator', redirect_to='/moderator'))
    def post(self, request, *args, **kwargs):
        article_category = ArticleCategory.objects.get(
            pk=kwargs['article_category_pk'])
        edited_article_category = ArticleCategoryModelForm(
            request.POST, instance=article_category)
        if edited_article_category.is_valid():
            edited_article_category.save()
            MessageManager().makeMessage(request, message='success_edited')
            return redirect(request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request, message='problem_with_save')
        return redirect(str(request.path))

    def get_context_data(self, **kwargs):
        context = super(EditArticleCategory, self).get_context_data(**kwargs)
        context['article_category_form'] = self.form
        return context
class CreateInitialArticle(TemplateView):
    template_name = 'initialarticle/create_initial_article.html'

    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def get(self, request, *args, **kwargs):
        self.form = InitialArticleCreateForm(request=request)
        return super(CreateInitialArticle, self).get(request, *args, **kwargs)

    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def post(self, request, *args, **kwargs):
        self.form = InitialArticleCreateForm(request.POST, request=request)
        if self.form.is_valid():
            initial_article = self.form.save(request.user)
            if initial_article:
                return redirect('/article/stuff/create/' +
                                request.LANGUAGE_CODE + '/' +
                                str(initial_article.keywords))
            MessageManager().makeMessage(request, message='keywords_exists')
            return redirect(request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request, message='form_is_not_valid')
        return redirect(request.META.get('HTTP_REFERER'))

    def get_context_data(self, **kwargs):
        context = super(CreateInitialArticle, self).get_context_data(**kwargs)
        context['create_initial_article_fileds'] = self.form
        return context
class EditArticle(TemplateView):
    template_name = 'article/stuff/edit_article.html'

    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def get(self, request, *args, **kwargs):
        article = Article.objects.get_article(keywords=kwargs['keywords'],
                                              language=kwargs['language'])
        if Article.objects.article_owner_is_requester(request, article):
            self.form = ArticleEditForm(instance=article)
            self.article_language_code = kwargs['language']
            self.initialarticle = InitialArticle.objects.get(
                keywords=kwargs['keywords'])
            return super(EditArticle, self).get(request, *args, **kwargs)
        MessageManager().makeMessage(request,
                                     message='no_privileg_to_reach_this_page')
        return redirect(request.META.get('HTTP_REFERER'))

    @method_decorator(exception_redirect)
    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def post(self, request, *args, **kwargs):
        article = Article.objects.get_article(keywords=kwargs['keywords'],
                                              language=kwargs['language'])
        if Article.objects.article_owner_is_requester(request, article):
            self.form = ArticleEditForm(request.POST,
                                        request.FILES,
                                        instance=article)
            if self.form.is_valid():
                article = self.form.edit(article)
                return redirect('/article/get/' + article.language + '/' +
                                article.initial.keywords)
            MessageManager().makeMessage(request, message='form_is_not_valid')
            return redirect('x')  #request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request,
                                     message='no_privileg_to_reach_this_page')
        return redirect(request.META.get('HTTP_REFERER'))

    def get_context_data(self, **kwargs):
        context = super(EditArticle, self).get_context_data(**kwargs)
        context['article_edit_form'] = self.form
        context['article_language_code'] = self.article_language_code
        context['initialarticle'] = self.initialarticle
        return context
class EditInitialArticle(TemplateView):
    template_name = 'initialarticle/edit_initial_article.html'

    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def get(self, request, *args, **kwargs):
        initial_article = InitialArticle.objects.get_by_keywords(
            keywords=kwargs['keywords'])
        if InitialArticle.objects.initial_article_owner_is_requester(
                request, initial_article):
            self.form = InitialArticleEditForm(instance=initial_article,
                                               request=request)
            return super(EditInitialArticle, self).get(request, *args,
                                                       **kwargs)
        MessageManager().makeMessage(request,
                                     message='no_privileg_to_reach_this_page')
        return redirect(request.META.get('HTTP_REFERER'))

    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def post(self, request, *args, **kwargs):
        initial_article = InitialArticle.objects.get_by_keywords(
            keywords=kwargs['keywords'])
        if InitialArticle.objects.initial_article_owner_is_requester(
                request, initial_article):
            self.form = InitialArticleEditForm(request.POST,
                                               instance=initial_article,
                                               request=request)
            if self.form.is_valid():
                self.form.save_(article_keywords_object=initial_article,
                                user=request.user)
                return redirect('/initialarticle/userarticles')
            MessageManager().makeMessage(request, message='form_is_not_valid')
            return redirect(request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request,
                                     message='no_privileg_to_reach_this_page')
        return redirect(request.META.get('HTTP_REFERER'))

    def get_context_data(self, **kwargs):
        context = super(EditInitialArticle, self).get_context_data(**kwargs)
        context['edit_initial_article_fileds'] = self.form
        return context
Exemple #8
0
class RemoveUserFromGroup(View):
    @method_decorator(login_required(login_url='login'))
    @method_decorator(group_required('admin', redirect_to='/'))
    def get(self, request, *args, **kwargs):
        user = get_user_model().objects.get(pk=kwargs['user_pk'])
        groups = Group.objects.exclude(name='admin')
        for group in groups:
            if group.name == kwargs['group']:
                group.user_set.remove(user)
                return redirect(request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request, message='group_not_exist')
        return redirect(request.META.get('HTTP_REFERER'))
Exemple #9
0
class GetUsers(TemplateView):
    template_name = 'manage/manage_users.html'

    @method_decorator(login_required(login_url='login'))
    @method_decorator(group_required('admin', redirect_to='/'))
    def get(self, request, *args, **kwargs):
        self.users = get_user_model().objects.exclude(groups__name='admin')
        return super(GetUsers, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(GetUsers, self).get_context_data(**kwargs)
        context['users'] = self.users
        return context
class GetArticleCategories(TemplateView):
    template_name = 'articlecategory/get_article_categories.html'

    @method_decorator(login_required(login_url='/login'))
    @method_decorator(group_required('moderator', redirect_to='/moderator'))
    def get(self, request, *args, **kwargs):
        self.article_categoies = ArticleCategory.objects.all()
        return super(GetArticleCategories, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(GetArticleCategories, self).get_context_data(**kwargs)
        context['article_categories'] = self.article_categoies
        return context
class RequesterInitialarticles(TemplateView):
    template_name = 'initialarticle/requester_initilarticles.html'

    @method_decorator(login_required)
    @method_decorator(group_required('stuff'))
    def get(self, request, *args, **kwargs):
        self.initialarticles = InitialArticle.objects.filter(by=request.user)
        return super(RequesterInitialarticles,
                     self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(RequesterInitialarticles,
                        self).get_context_data(**kwargs)
        context['initialarticles'] = self.initialarticles
        return context
            request.POST, instance=article_category)
        if edited_article_category.is_valid():
            edited_article_category.save()
            MessageManager().makeMessage(request, message='success_edited')
            return redirect(request.META.get('HTTP_REFERER'))
        MessageManager().makeMessage(request, message='problem_with_save')
        return redirect(str(request.path))

    def get_context_data(self, **kwargs):
        context = super(EditArticleCategory, self).get_context_data(**kwargs)
        context['article_category_form'] = self.form
        return context


@method_decorator(login_required(login_url='/login'))
@method_decorator(group_required('moderator', redirect_to='/moderator'))
def removeArticleCategory(request, *args, **kwargs):
    if request.method == 'POST':
        article_category = ArticleCategory.objects.get(
            pk=kwargs['article_category_pk'])
        article_category.delete()
        return redirect(str(request.path))


class GetArticleCategories(TemplateView):
    template_name = 'articlecategory/get_article_categories.html'

    @method_decorator(login_required(login_url='/login'))
    @method_decorator(group_required('moderator', redirect_to='/moderator'))
    def get(self, request, *args, **kwargs):
        self.article_categoies = ArticleCategory.objects.all()