Exemple #1
0
def create(request):
    if request.method == 'POST':
        form = NewsForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('administration_news_index'))
    else:
        form = NewsForm()

    return direct_to_template(request, 'news/administration/news_create.html',
                              {'form': form,
                               'active_module': 'news'})
Exemple #2
0
def savenews(request):
    if request.POST and ("pause" not in request.session):
        form = NewsForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            now = timezone.now()
            comment.article_date = now

            # comment.comments_article = Article.objects.get(id=article_id)
            form.save()
            # request.session.set_expiry(60)
            # request.session['pause'] = True
    return redirect('/news/')
Exemple #3
0
def edit(request, news_id):
    news = get_object_or_404(News, id=news_id)
    if request.method == 'POST':
        form = NewsForm(request.POST, instance=news)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('administration_news_index'))
    else:

        form = NewsForm(model_to_dict(news),instance=news)
    return direct_to_template(request, 'news/administration/news_edit.html',
                              {'form': form,
                               'news':news,
                               'active_module': 'news'})
Exemple #4
0
def create(request, template="news/create.html"):
    #if 
    def get_slug(text, numb=0):
        "Create unique slug"
        if numb:
            text += "_%d" % numb
        s = slugify(text)
        try:
            News.objects.get(slug=s)
            return get_slug(text, numb + 1)
        except News.DoesNotExist:
            pass
        return s
    u = request.user
    if request.POST:
        n = News(author=u, show=False, slug=get_slug(request.POST['title']))
        f = NewsForm(request.POST, instance=n)
        if f.is_valid():
            n = f.save()
            return HttpResponseRedirect(n.get_absolute_url() + "show/")
    else:
        f = NewsForm()
    return render_to_response(template, {
        "form": f,
        }, context_instance=RequestContext(request))
def add_news(request):
    if request.method == 'POST':
        news_form = NewsForm(request.POST, request.FILES)
        if news_form.is_valid():
            news_form.save()
            return HttpResponseRedirect('/admin_forms/')
        else:
            degree_values = Degree.objects.values('name').distinct()
            event_form = EventForm()
            directory_form = DirectoryForm()
            news = NewsArticle.objects.all()
            events = Event.objects.all()
            return render(request, 'admin_forms.html',
                          {'degree_values': degree_values, 'news_form': news_form, 'event_form': event_form,
                           'directory_form': directory_form, 'news_class': "active", 'all_news': news,
                           'all_events': events})
    else:
        return HttpResponseBadRequest("THE REQUESTED URL IS INVALID")
Exemple #6
0
def new_news(request):
    news_form = NewsForm()
    if request.method == 'POST':
        news_form = NewsForm(request.POST, request.FILES)
        if news_form.is_valid():
            news = news_form.save()
            return render_to_response(
                'news_saved.html',
                {'news': news}
            )
    return render_to_response(
        'edit_news.html',
        {'news_form': news_form}
    )
Exemple #7
0
def create_news(request):

    if request.method == 'POST':
        news_form = NewsForm(request.POST,prefix='news_form')

        news_content_forms = []
        for lang in settings.LANGUAGES:
            news_content_forms.append({
                'form':NewsContentForm(request.POST,prefix='news_content' + lang[0]),
                'lang':lang[0]
            })

        if news_form.is_valid():



            valid = False
            for news_content_form in news_content_forms:
                valid = news_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                news = news_form.save(commit=False)
                if 'news_form_avatar' in request.FILES:
                    try:
                        avatar_img_name = handle_uploaded_file(request.FILES['news_form_avatar'])
                    except IOError as e:
                        return HttpResponse(u'Возникла ошибка при загрузке аватарки:' + e.message)
                    news.avatar_img_name = avatar_img_name
                news.save()
                for news_content_form in news_content_forms:
                    news_content = news_content_form['form'].save(commit=False)
                    news_content.lang = news_content_form['lang']
                    news_content.news = news
                    news_content.save()
                return redirect('news:administration:news_list')
    else:
        news_form = NewsForm(prefix="news_form")
        news_content_forms = []
        for lang in settings.LANGUAGES:
            news_content_forms.append({
                'form':NewsContentForm(prefix='news_content' + lang[0]),
                'lang':lang[0]
            })

    return render(request, 'news/administration/create_news.html', {
        'news_form': news_form,
        'news_content_forms': news_content_forms,
        })
Exemple #8
0
def update_news(request, news_title):
    news = News.objects.get(title=news_title)
    news_form = NewsForm(instance=news)
    if request.method == 'POST':
        news_form = NewsForm(request.POST, request.FILES)
        if news_form.is_valid():
            news = news_form.save()
            return render_to_response(
                'news_saved.html',
                {'news': news}
            )
    return render_to_response(
        'edit_news.html',
        {'news_form': news_form}
    )
Exemple #9
0
def edit(request, slug, template="news/create.html"):
    n = get_object_or_404(News, slug=slug)
    u = request.user
    if not (u is n.author or u.has_perm("news.can_edit")):
        return HttpResponseRedirect(request.META['HTTP_REFERER'] or "/news/")
    if request.POST:
        f = NewsForm(request.POST, instance=n)
        if f.is_valid():
            n = f.save()
            return HttpResponseRedirect(n.get_absolute_url() + "show/")
    else:
        f = NewsForm(instance=n)
    return render_to_response(template, {
        "form": f,
        }, context_instance=RequestContext(request))
Exemple #10
0
def create_news(request):

    if request.method == 'POST':
        news_form = NewsForm(request.POST, prefix='news_form')

        news_content_forms = []
        for lang in settings.LANGUAGES:
            news_content_forms.append({
                'form':
                NewsContentForm(request.POST, prefix='news_content' + lang[0]),
                'lang':
                lang[0]
            })

        if news_form.is_valid():

            valid = False
            for news_content_form in news_content_forms:
                valid = news_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                news = news_form.save(commit=False)
                news.save()
                for news_content_form in news_content_forms:
                    news_content = news_content_form['form'].save(commit=False)
                    news_content.lang = news_content_form['lang']
                    news_content.news = news
                    news_content.save()
                return redirect('professionals_news:administration:news_list')
    else:
        news_form = NewsForm(prefix="news_form")
        news_content_forms = []
        for lang in settings.LANGUAGES:
            news_content_forms.append({
                'form':
                NewsContentForm(prefix='news_content' + lang[0]),
                'lang':
                lang[0]
            })

    return render(request,
                  'professionals_news/administration/create_news.html', {
                      'news_form': news_form,
                      'news_content_forms': news_content_forms,
                  })
Exemple #11
0
def create_news(request):

    if request.method == 'POST':
        news_form = NewsForm(request.POST,prefix='news_form')

        news_content_forms = []
        for lang in settings.LANGUAGES:
            news_content_forms.append({
                'form':NewsContentForm(request.POST,prefix='news_content' + lang[0]),
                'lang':lang[0]
            })

        if news_form.is_valid():



            valid = False
            for news_content_form in news_content_forms:
                valid = news_content_form['form'].is_valid()
                print valid
                if not valid:
                    break

            if valid:
                news = news_form.save(commit=False)
                news.save()
                for news_content_form in news_content_forms:
                    news_content = news_content_form['form'].save(commit=False)
                    news_content.lang = news_content_form['lang']
                    news_content.news = news
                    news_content.save()
                return redirect('professionals_news:administration:news_list')
    else:
        news_form = NewsForm(prefix="news_form")
        news_content_forms = []
        for lang in settings.LANGUAGES:
            news_content_forms.append({
                'form':NewsContentForm(prefix='news_content' + lang[0]),
                'lang':lang[0]
            })

    return render(request, 'professionals_news/administration/create_news.html', {
        'news_form': news_form,
        'news_content_forms': news_content_forms,
    })
Exemple #12
0
def create_news(request):

    if request.method == 'POST':
        news_form = NewsForm(request.POST,prefix='news_form')

        if news_form.is_valid():
                news = news_form.save(commit=False)
                if 'news_form_avatar' in request.FILES:
                    avatar_img_name = handle_uploaded_file(request.FILES['news_form_avatar'])
                    news.avatar_img_name = avatar_img_name
                news.save()
                if 'save_edit' in request.POST:
                    return redirect('news:administration:edit_news', news.id)
                else:
                    return redirect('news:administration:news_list')
    else:
        news_form = NewsForm(prefix="news_form")

    return render(request, 'news/administration/create_news.html', {
        'news_form': news_form,
        })
Exemple #13
0
def edit_news(request, id):
    news = get_object_or_404(News, id=id)
    if request.method == 'POST':
        news_form = NewsForm(request.POST,prefix='news_form', instance=news)

        if news_form.is_valid():
            news = news_form.save(commit=False)
            if 'news_form_avatar' in request.FILES:
                if news.avatar_img_name:
                    handle_uploaded_file(request.FILES['news_form_avatar'], news.avatar_img_name)
                else:
                    avatar_img_name = handle_uploaded_file(request.FILES['news_form_avatar'])
                    news.avatar_img_name = avatar_img_name
            news.save()
            if 'save_edit' in request.POST:
                return redirect('news:administration:edit_news', news.id)
            else:
                return redirect('news:administration:news_list')
    else:
        news_form = NewsForm(prefix="news_form", instance=news)
    return render(request, 'news/administration/edit_news.html', {
        'news_form': news_form,
        })
Exemple #14
0
def edit_news(request, id):
    news = get_object_or_404(News, id=id)
    news_contents = NewsContent.objects.filter(news=news)
    news_contents_langs = {}

    for lang in settings.LANGUAGES:
        news_contents_langs[lang] = None

    for news_content in news_contents:
        news_contents_langs[news_content.lang] = news_content

    if request.method == 'POST':
        news_form = NewsForm(request.POST, prefix='news_form', instance=news)

        if news_form.is_valid():
            news_form.save()
            news_content_forms = []
            for lang in settings.LANGUAGES:
                lang = lang[0]
                if lang in news_contents_langs:
                    news_content_forms.append({
                        'form':
                        NewsContentForm(request.POST,
                                        prefix='news_content_' + lang,
                                        instance=news_contents_langs[lang]),
                        'lang':
                        lang
                    })
                else:
                    news_content_forms.append({
                        'form':
                        NewsContentForm(request.POST,
                                        prefix='news_content_' + lang),
                        'lang':
                        lang
                    })

            valid = False
            for news_content_form in news_content_forms:
                valid = news_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                for news_content_form in news_content_forms:
                    news_content = news_content_form['form'].save(commit=False)
                    news_content.news = news
                    news_content.lang = news_content_form['lang']
                    news_content.save()
                return redirect('news:administration:news_list')
    else:
        news_form = NewsForm(prefix="news_form", instance=news)
        news_content_forms = []
        for lang in settings.LANGUAGES:
            lang = lang[0]
            if lang in news_contents_langs:
                news_content_forms.append({
                    'form':
                    NewsContentForm(prefix='news_content_' + lang,
                                    instance=news_contents_langs[lang]),
                    'lang':
                    lang
                })
            else:
                news_content_forms.append({
                    'form':
                    NewsContentForm(prefix='news_content_' + lang),
                    'lang':
                    lang
                })
    return render(request, 'news/administration/edit_news.html', {
        'news_form': news_form,
        'news_content_forms': news_content_forms,
    })
Exemple #15
0
def edit_news(request, id):
    news = get_object_or_404(News, id=id)
    news_contents = NewsContent.objects.filter(news=news)
    news_contents_langs = {}

    for lang in settings.LANGUAGES:
        news_contents_langs[lang] = None

    for news_content in news_contents:
        news_contents_langs[news_content.lang] = news_content

    if request.method == 'POST':
        news_form = NewsForm(request.POST,prefix='news_form', instance=news)

        if news_form.is_valid():
            news_form.save()
            news_content_forms = []
            for lang in settings.LANGUAGES:
                lang = lang[0]
                if lang in news_contents_langs:
                    news_content_forms.append({
                        'form':NewsContentForm(request.POST,prefix='news_content_' + lang, instance=news_contents_langs[lang]),
                        'lang':lang
                    })
                else:
                    news_content_forms.append({
                        'form':NewsContentForm(request.POST, prefix='news_content_' + lang),
                        'lang':lang
                    })


            valid = False
            for news_content_form in news_content_forms:
                valid = news_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                for news_content_form in news_content_forms:
                    news_content = news_content_form['form'].save(commit=False)
                    news_content.news = news
                    news_content.lang = news_content_form['lang']
                    news_content.save()
                return redirect('news:administration:news_list')
    else:
        news_form = NewsForm(prefix="news_form", instance=news)
        news_content_forms = []
        for lang in settings.LANGUAGES:
            lang = lang[0]
            if lang in news_contents_langs:
                news_content_forms.append({
                    'form':NewsContentForm(prefix='news_content_' + lang, instance=news_contents_langs[lang]),
                    'lang':lang
                })
            else:
                news_content_forms.append({
                    'form':NewsContentForm(prefix='news_content_' + lang),
                    'lang':lang
                })
    return render(request, 'news/administration/edit_news.html', {
        'news_form': news_form,
        'news_content_forms': news_content_forms,
        })