Example #1
0
def pages_list(request, library_code, parent=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if parent:
        parent = get_object_or_404(Page, id=parent, library=library)

    pages_page = get_page(request, Page.objects.filter(parent=parent, library=library))
    pages_page.object_list = list(pages_page.object_list)
    contents = list(Content.objects.filter(page__in=pages_page.object_list, lang=get_language()[:2]))

    pages_dict = {}
    for page in pages_page.object_list:
        pages_dict[page.id] = {'page': page}

    for content in contents:
        pages_dict[content.page_id]['page'].content = content

    # pages = [page['page'] for page in pages_dict.values()]


    return render(request, 'participant_pages/administration/pages_list.html', {
        'library': library,
        'parent': parent,
        'pages': pages_page.object_list,
        'pages_page': pages_page,
    })
Example #2
0
def edit_news_image(request, library_code, id, image_id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    news_image = get_object_or_404(NewsImage, news_id=id, id=image_id)

    if request.method == 'POST':
        form = forms.NewsImageForm(request.POST,
                                   request.FILES,
                                   instance=news_image)
        if form.is_valid():
            form.save()
            return redirect('participant_news:administration:news_images',
                            library_code=library_code,
                            id=news_image.news_id)
    else:
        form = forms.NewsImageForm(instance=news_image)

    return render(
        request, 'participant_news/administration/edit_news_image.html', {
            'news': news_image.news,
            'news_image': news_image,
            'library': library,
            'form': form
        })
Example #3
0
def create_item(request, menu_id, library_code, parent=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    menu = get_object_or_404(Menu, id=menu_id)

    if not parent:
        parent = menu.root_item
    else:
        parent = get_object_or_404(MenuItem, id=parent)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST, prefix='item_form')

        if item_form.is_valid():

            item = item_form.save(commit=False)
            item.parent = parent
            item.show = parent.show
            item.save()
            return redirect('participant_menu:administration:menu_detail', menu_id=menu.id, library_code=library_code)
    else:
        item_form = MenuItemForm(prefix="item_form")

    return render(request, 'participant_menu/administration/create_item.html', {
        'library': library,
        'item_form': item_form,
        'menu': menu
    })
Example #4
0
def edit_info(request, library_code, managed_libraries=[]):
    error = ''
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponse(u'Вы должны быть сотрудником организации', status=403)

    try:
        avatar = models.LibraryAvatar.objects.get(library=library)
    except models.LibraryAvatar.DoesNotExist:
        avatar = None

    if request.method == 'POST':
        avatar_from = forms.AvatarForm(request.POST, request.FILES, prefix='avatar_from', instance=avatar)
        library_form = forms.LibraryInfoForm(request.POST, prefix='library_form', instance=library)
        if avatar_from.is_valid() and library_form.is_valid():
            avatar = avatar_from.save(commit=False)
            avatar.library = library
            try:
                avatar.save()
            except IOError as e:
                error = u'Ошибка при сохранении изображения %s' % e.message
            library_form.save()
    else:
        avatar_from = forms.AvatarForm(prefix='avatar_from', instance=avatar)
        library_form = forms.LibraryInfoForm(prefix='library_form', instance=library)
    return render(request, 'participant_site/administration/edit_info.html', {
        'avatar_from': avatar_from,
        'library_form': library_form,
        'library': library,
        'error': error
    })
Example #5
0
def create_menu(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if request.method == 'POST':

        menu_form = MenuForm(request.POST, prefix='menu_form')
        if menu_form.is_valid():
            menu = menu_form.save(commit=False)
            menu.library = library
            root_item = MenuItem()
            root_item.save()
            menu.root_item = root_item
            menu.save()
            return redirect('participant_menu:administration:menu_list',
                            library_code=library_code)
    else:
        menu_form = MenuForm(prefix='menu_form')

    return render(request, 'participant_menu/administration/create_menu.html',
                  {
                      'library': library,
                      'menu_form': menu_form
                  })
Example #6
0
def polls_list(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_photopolls'):
        return HttpResponseForbidden()
    polls_page = get_page(
        request,
        Poll.objects.filter(library=library).order_by('-create_date'), 10)

    poll_contents = list(
        PollContent.objects.filter(poll__in=list(polls_page.object_list),
                                   lang=get_language()[:2]))

    t_dict = {}
    for poll in polls_page.object_list:
        t_dict[poll.id] = {'poll': poll}

    for poll_content in poll_contents:
        t_dict[poll_content.poll_id]['poll'].poll_content = poll_content

    return render(
        request, 'participant_photopolls/administration/polls_list.html', {
            'library': library,
            'polls_list': polls_page.object_list,
            'polls_page': polls_page,
        })
Example #7
0
def events_list(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_events'):
        return HttpResponseForbidden(u'У вас нет прав для доступа к разделу')

    events_page = get_page(
        request,
        Event.objects.filter(library=library).order_by('-create_date'), 10)

    event_contents = list(
        EventContent.objects.filter(event__in=list(events_page.object_list),
                                    lang=get_language()[:2]))

    t_dict = {}
    for event in events_page.object_list:
        t_dict[event.id] = {'event': event}

    for event_content in event_contents:
        t_dict[event_content.event_id]['event'].event_content = event_content

    return render(
        request, 'participant_events/administration/events_list.html', {
            'library': library,
            'events_list': events_page.object_list,
            'events_page': events_page,
        })
Example #8
0
def menu_list(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_menu'):
        return HttpResponseForbidden()


    for lang in settings.LANGUAGES:
        try:
            menu = Menu.objects.get(slug='main_menu', library=library, lang=lang[0])
        except Menu.DoesNotExist:
            root_item = MenuItem()
            root_item.save()
            menu = Menu(
                slug='main_menu',
                library=library,
                lang=lang[0],
                root_item=root_item,
                title=u'Главное меню'
            )
            menu.save()

    menu_list = Menu.objects.filter(library=library).order_by('slug', 'lang')

    return render(request, 'participant_menu/administration/menus_list.html', {
        'library': library,
        'menu_list': menu_list,
    })
Example #9
0
def menu_list(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_menu'):
        return HttpResponseForbidden()

    for lang in settings.LANGUAGES:
        try:
            menu = Menu.objects.get(slug='main_menu',
                                    library=library,
                                    lang=lang[0])
        except Menu.DoesNotExist:
            root_item = MenuItem()
            root_item.save()
            menu = Menu(slug='main_menu',
                        library=library,
                        lang=lang[0],
                        root_item=root_item,
                        title=u'Главное меню')
            menu.save()

    menu_list = Menu.objects.filter(library=library).order_by('slug', 'lang')

    return render(request, 'participant_menu/administration/menus_list.html', {
        'library': library,
        'menu_list': menu_list,
    })
Example #10
0
def pages_list(request, library_code, parent=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if parent:
        parent = get_object_or_404(Page, id=parent, library=library)

    pages_page = get_page(request,
                          Page.objects.filter(parent=parent, library=library))
    pages_page.object_list = list(pages_page.object_list)
    contents = list(
        Content.objects.filter(page__in=pages_page.object_list,
                               lang=get_language()[:2]))

    pages_dict = {}
    for page in pages_page.object_list:
        pages_dict[page.id] = {'page': page}

    for content in contents:
        pages_dict[content.page_id]['page'].content = content

    # pages = [page['page'] for page in pages_dict.values()]

    return render(
        request, 'participant_pages/administration/pages_list.html', {
            'library': library,
            'parent': parent,
            'pages': pages_page.object_list,
            'pages_page': pages_page,
        })
Example #11
0
def create_news(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

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

        if 'news_form_avatar' in request.FILES:
            avatar_img_name, avatar_img_extension = os.path.splitext(request.FILES['news_form_avatar'].name.lower())
            if avatar_img_extension.lstrip('.') not in IMAGE_EXTENSIONS:
                news_form.add_error("show_avatar", u'Картинка должна быть в формате JPEG, PNG или BMP')

        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.library = library
            news.save()
            if 'save_edit' in request.POST:
                return redirect('participant_news:administration:edit_news', library_code=library_code, id=news.id)
            else:
                return redirect('participant_news:administration:news_list', library_code=library_code)
    else:
        news_form = forms.NewsForm(prefix="news_form")

    return render(request, 'participant_news/administration/create_news.html', {
        'library': library,
        'news_form': news_form,
    })
Example #12
0
def create_page_content(request, library_code, page_id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    page = get_object_or_404(Page, id=page_id)
    if request.method == 'POST':
        content_form = ContentForm(request.POST, prefix='content_form')

        if content_form.is_valid():
            content = content_form.save(commit=False)
            content.page = page
            content.save()

            save = request.POST.get('save', u'save_edit')
            if save == u'save':
                return redirect('participant_pages:administration:edit_page', library_code=library_code, id=page_id)
            else:
                return redirect('participant_pages:administration:edit_page_content', library_code=library_code,
                                page_id=page_id, lang=content.lang)
    else:
        content_form = ContentForm(prefix='content_form')
    return render(request, 'participant_pages/administration/create_page_content.html', {
        'library': library,
        'page': page,
        'content_form': content_form,
        'content_type': 'participant_pages',
        'content_id': str(library.id) + '_' + page.url_path.replace('/', '_')
    })
Example #13
0
def item_edit(request, id, library_code, menu_id=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    menu = get_object_or_404(Menu, id=menu_id)
    item = get_object_or_404(MenuItem, id=id)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST,
                                 prefix='item_form',
                                 instance=item)
        if item_form.is_valid():
            item_form.save()
            return redirect('participant_menu:administration:menu_detail',
                            menu_id=menu_id,
                            library_code=library_code)

    else:
        item_form = MenuItemForm(prefix="item_form", instance=item)
    return render(request, 'participant_menu/administration/edit_item.html', {
        'library': library,
        'item': item,
        'item_form': item_form,
        'menu': menu
    })
Example #14
0
def create_news(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

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

        if "news_form_avatar" in request.FILES:
            avatar_img_name, avatar_img_extension = os.path.splitext(request.FILES["news_form_avatar"].name.lower())
            if avatar_img_extension not in IMAGE_EXTENSIONS:
                news_form.add_error("show_avatar", u"Картинка должна быть в формате JPEG, PNG или BMP")

        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.library = library
            news.save()
            if "save_edit" in request.POST:
                return redirect("participant_news:administration:edit_news", library_code=library_code, id=news.id)
            else:
                return redirect("participant_news:administration:news_list", library_code=library_code)
    else:
        news_form = forms.NewsForm(prefix="news_form")

    return render(
        request, "participant_news/administration/create_news.html", {"library": library, "news_form": news_form}
    )
Example #15
0
def edit(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    banner = get_object_or_404(models.Banner,
                               id=id,
                               library_creator=library.id)
    if request.method == 'POST':
        banner_form = forms.BannerForm(request.POST,
                                       request.FILES,
                                       instance=banner)
        if banner_form.is_valid():
            banner = banner_form.save(commit=False)
            banner.save()
            return redirect('participant_banners:administration:index',
                            library_code=library_code,
                            lang=banner.lang)
    else:
        banner_form = forms.BannerForm(instance=banner)

    return render(request,
                  'participant_banners/administration/edit_banner.html', {
                      'library': library,
                      'banner': banner,
                      'banner_form': banner_form
                  })
Example #16
0
def index(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    return redirect('participant_pages:administration:pages_list',
                    library_code=library_code)
Example #17
0
def item_down(request, menu_id, id, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    item = get_object_or_404(MenuItem, id=id)
    item.down()
    return redirect('participant_menu:administration:menu_detail', menu_id=menu_id, library_code=library_code)
Example #18
0
def index(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_photopolls'):
        return HttpResponseForbidden()
    return redirect('participant_photopolls:administration:polls_list', library_code=library_code)
Example #19
0
def delete_poll(request, id, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    poll = get_object_or_404(Poll, id=id, library=library)
    poll.delete()
    return redirect('participant_photopolls:administration:polls_list', library_code=library_code)
Example #20
0
def delete_news_image(request, library_code, id, image_id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    news_image = get_object_or_404(NewsImage, news_id=id, id=image_id)
    news_image.delete()
    return redirect("participant_news:administration:news_images", library_code=library_code, id=id)
Example #21
0
def delete_menu(request, id, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    menu = get_object_or_404(Menu, id=id)
    menu.delete()
    return redirect('participant_menu:administration:menus_list', library_code=library_code)
Example #22
0
def delete(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    banner = get_object_or_404(models.Banner, id=id, library_creator=library.id)
    banner.delete()
    return redirect("participant_banners:administration:index", library_code=library_code, lang=banner.lang)
Example #23
0
def delete_news_image(request, library_code, id, image_id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    news_image = get_object_or_404(NewsImage, news_id=id, id=image_id)
    news_image.delete()
    return redirect('participant_news:administration:news_images', library_code=library_code, id=id)
Example #24
0
def create_event(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if request.method == 'POST':
        event_form = EventForm(request.POST,
                               request.FILES,
                               prefix='event_form')

        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form':
                EventContentForm(request.POST,
                                 prefix='event_content' + lang[0]),
                'lang':
                lang[0]
            })
        if event_form.is_valid():
            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                event = event_form.save(commit=False)
                event.library = library
                event.save()
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(
                        commit=False)
                    event_content.lang = event_content_form['lang']
                    event_content.event = event
                    event_content.save()
                event_form.save_m2m()
                return redirect(
                    'participant_events:administration:events_list',
                    library_code=library_code)
    else:
        event_form = EventForm(prefix="event_form")
        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form':
                EventContentForm(prefix='event_content' + lang[0]),
                'lang':
                lang[0]
            })

    return render(
        request, 'participant_events/administration/create_event.html', {
            'library': library,
            'event_form': event_form,
            'event_content_forms': event_content_forms,
        })
Example #25
0
def index(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_events'):
        return HttpResponseForbidden(u'У вас нет прав для доступа к разделу')

    return redirect('participant_events:administration:events_list', library_code=library_code)
Example #26
0
def index(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_news'):
        return HttpResponseForbidden(u'У вас нет доступа к разделу')

    return redirect('participant_news:administration:news_list', library_code=library_code)
Example #27
0
def delete_news(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    news = get_object_or_404(News, library=library, id=id)
    news.delete()
    delete_avatar(news.avatar_img_name)
    return redirect("participant_news:administration:news_list", library_code=library_code)
Example #28
0
def delete_news(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    news = get_object_or_404(News, library=library, id=id)
    news.delete()
    delete_avatar(news.avatar_img_name)
    return redirect('participant_news:administration:news_list', library_code=library_code)
Example #29
0
def index(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    if not request.user.has_module_perms("participant_news"):
        return HttpResponseForbidden(u"У вас нет доступа к разделу")

    return redirect("participant_news:administration:news_list", library_code=library_code)
Example #30
0
def delete_poll(request, id, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    poll = get_object_or_404(Poll, id=id, library=library)
    poll.delete()
    return redirect('participant_photopolls:administration:polls_list',
                    library_code=library_code)
Example #31
0
def index(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponse(u'Вы должны быть сотрудником организации', status=403)

    # branches = library.get_descendants()
    return render(request, 'participant_site/administration/backend_base.html', {
        'library': library,
        'managed_libraries': managed_libraries
    })
Example #32
0
def delete_page(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    page = get_object_or_404(Page, id=id)
    page.delete()
    if page.parent_id:
        return redirect('participant_pages:administration:pages_list', library_code=library_code, parent=page.parent_id)
    return redirect('participant_pages:administration:pages_list', library_code=library_code)
Example #33
0
def delete_event(request, id, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    event = get_object_or_404(Event, id=id)
    event.delete()
    return redirect('participant_events:administration:events_list',
                    library_code=library_code)
Example #34
0
def create_poll(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if request.method == 'POST':
        poll_form = PollForm(request.POST, request.FILES, prefix='poll_form')

        poll_content_forms = []
        for lang in settings.LANGUAGES:
            poll_content_forms.append({
                'form':
                PollContentForm(request.POST, prefix='poll_content' + lang[0]),
                'lang':
                lang[0]
            })
        if poll_form.is_valid():
            valid = False
            for poll_content_form in poll_content_forms:
                valid = poll_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                poll = poll_form.save(commit=False)
                poll.library = library
                poll.save()
                for poll_content_form in poll_content_forms:
                    poll_content = poll_content_form['form'].save(commit=False)
                    poll_content.lang = poll_content_form['lang']
                    poll_content.poll = poll
                    poll_content.save()
                poll_form.save_m2m()
                return redirect(
                    'participant_photopolls:administration:polls_list',
                    library_code=library_code)
    else:
        poll_form = PollForm(prefix="poll_form")
        poll_content_forms = []
        for lang in settings.LANGUAGES:
            poll_content_forms.append({
                'form':
                PollContentForm(prefix='poll_content' + lang[0]),
                'lang':
                lang[0]
            })

    return render(
        request, 'participant_photopolls/administration/create_poll.html', {
            'library': library,
            'poll_form': poll_form,
            'poll_content_forms': poll_content_forms,
        })
Example #35
0
def item_down(request, menu_id, id, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    item = get_object_or_404(MenuItem, id=id)
    item.down()
    return redirect('participant_menu:administration:menu_detail',
                    menu_id=menu_id,
                    library_code=library_code)
Example #36
0
def news_images(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    news = get_object_or_404(News, library=library, id=id)
    news_images = NewsImage.objects.filter(news=news)
    return render(request, 'participant_news/administration/news_images.html', {
        'news_images': news_images,
        'news': news,
        'library': library
    })
Example #37
0
def unbind_to_children_orgs(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    banner = get_object_or_404(models.Banner, id=id, library_creator=library.id)

    for descedant in library.get_descendants():
        banner.libraries.remove(descedant)
    banner.in_descendants = False
    banner.save()
    return redirect("participant_banners:administration:index", library_code=library_code, lang=banner.lang)
Example #38
0
def news_images(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    news = get_object_or_404(News, library=library, id=id)
    news_images = NewsImage.objects.filter(news=news)
    return render(
        request,
        "participant_news/administration/news_images.html",
        {"news_images": news_images, "news": news, "library": library},
    )
Example #39
0
def edit_page_content(request,
                      library_code,
                      page_id,
                      lang,
                      managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    lang_form = LanguageForm({'lang': lang})
    if not lang_form.is_valid():
        return HttpResponse(
            _(u'Language is not registered in system.') +
            _(u" Language code: ") + lang)

    page = get_object_or_404(Page, id=page_id)

    try:
        content = Content.objects.get(page=page_id, lang=lang)
    except Content.DoesNotExist:
        content = Content(page=page, lang=lang)

    ContentForm = get_content_form(('page', 'lang'))

    if request.method == 'POST':
        content_form = ContentForm(request.POST,
                                   prefix='content_form',
                                   instance=content)

        if content_form.is_valid():
            content = content_form.save(commit=False)
            content.page = page
            content.save()

        save = request.POST.get('save', u'save_edit')
        if save == u'save':
            return redirect('participant_pages:administration:edit_page',
                            library_code=library_code,
                            id=page_id)

    else:
        content_form = ContentForm(prefix='content_form', instance=content)
    return render(
        request, 'participant_pages/administration/edit_page_content.html', {
            'library': library,
            'page': page,
            'content': content,
            'content_form': content_form,
            'content_type': 'participant_pages',
            'content_id':
            str(library.id) + '_' + page.url_path.replace('/', '_')
        })
Example #40
0
def index(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponse(u'Вы должны быть сотрудником организации',
                            status=403)

    # branches = library.get_descendants()
    return render(request, 'participant_site/administration/backend_base.html',
                  {
                      'library': library,
                      'managed_libraries': managed_libraries
                  })
Example #41
0
def delete(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    banner = get_object_or_404(models.Banner,
                               id=id,
                               library_creator=library.id)
    banner.delete()
    return redirect('participant_banners:administration:index',
                    library_code=library_code,
                    lang=banner.lang)
Example #42
0
def delete_page(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    page = get_object_or_404(Page, id=id)
    page.delete()
    if page.parent_id:
        return redirect('participant_pages:administration:pages_list',
                        library_code=library_code,
                        parent=page.parent_id)
    return redirect('participant_pages:administration:pages_list',
                    library_code=library_code)
Example #43
0
def poll_detail(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_photopolls'):
        return HttpResponseForbidden()
    poll = get_object_or_404(Poll, id=id)
    images = PollImage.objects.filter(poll=poll)
    return render(request, 'participant_photopolls/administration/poll_detail.html', {
        'library': library,
        'poll': poll,
        'images': images
        })
Example #44
0
def menu_detail(request, library_code, menu_id, managed_libraries=[]):
    if not request.user.has_module_perms('participant_menu'):
        return HttpResponseForbidden()

    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')
    menu = get_object_or_404(Menu, id=menu_id)
    nodes = list(menu.root_item.get_descendants())
    return render(request, 'participant_menu/administration/menu_detail.html', {
        'menu': menu,
        'nodes': nodes,
        'library': library
    })
Example #45
0
def news_list(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_news'):
        return HttpResponseForbidden(u'У вас нет доступа к разделу')

    news_page = get_page(request, News.objects.filter(library=library).order_by('-order', '-create_date'))
    return render(request, 'participant_news/administration/news_list.html', {
        'library': library,
        'news_list': news_page.object_list,
        'news_page': news_page,
    })
Example #46
0
def assign_page_permissions(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    obj = get_object_or_404(Page, id=id)

    if request.method == 'POST':
        GroupsForm = get_groups_form(Group.objects.all())
        groups_form = GroupsForm(request.POST)
        if groups_form.is_valid():
            assign_permission(groups_form.cleaned_data['groups'], [obj], VIEW_PAGE_PERMISSION)
            assign_permission(groups_form.cleaned_data['groups'], obj.get_descendants(), VIEW_PAGE_PERMISSION)
    return HttpResponse(u'{"status":"ok"}')
Example #47
0
def news_list(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    if not request.user.has_module_perms("participant_news"):
        return HttpResponseForbidden(u"У вас нет доступа к разделу")

    news_page = get_page(request, News.objects.filter(library=library).order_by("-order", "-create_date"))
    return render(
        request,
        "participant_news/administration/news_list.html",
        {"library": library, "news_list": news_page.object_list, "news_page": news_page},
    )
Example #48
0
def page_permissions(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    obj = get_object_or_404(Page, id=id)

    GroupsForm = get_groups_form(Group.objects.all(), initial=list(get_groups_with_perms(obj)))
    groups_form = GroupsForm()

    return render(request, 'participant_pages/administration/permissions.html', {
        'library': library,
        'page': obj,
        'groups_form': groups_form,
    })
Example #49
0
def create_poll_image(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    poll = get_object_or_404(Poll, id=id, library=library)
    if request.method == 'POST':
        poll_image_form = PollImageForm(request.POST,request.FILES, prefix='poll_image_form')

        poll_image_content_forms = []
        for lang in settings.LANGUAGES:
            poll_image_content_forms.append({
                'form':PollImageContentForm(request.POST,prefix='poll_image_content' + lang[0]),
                'lang':lang[0]
            })
        if poll_image_form.is_valid():
            valid = False
            for poll_image_content_form in poll_image_content_forms:
                valid = poll_image_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                poll_image = poll_image_form.save(commit=False)
                poll_image.poll = poll
                poll_image.save()
                for poll_image_content_form in poll_image_content_forms:
                    poll_image_content = poll_image_content_form['form'].save(commit=False)
                    poll_image_content.lang = poll_image_content_form['lang']
                    poll_image_content.poll_image = poll_image
                    poll_image_content.save()
                poll_image_form.save_m2m()
                return redirect('participant_photopolls:administration:poll_detail', library_code=library_code, id=id)
    else:
        poll_image_form = PollImageForm(prefix="poll_image_form")
        poll_image_content_forms = []
        for lang in settings.LANGUAGES:
            poll_image_content_forms.append({
                'form': PollImageContentForm(prefix='poll_image_content' + lang[0]),
                'lang': lang[0]
            })

    return render(request, 'participant_photopolls/administration/create_poll_image.html', {
        'library': library,
        'poll': poll,
        'poll_image_form': poll_image_form,
        'poll_image_content_forms': poll_image_content_forms,
    })
Example #50
0
def menu_detail(request, library_code, menu_id, managed_libraries=[]):
    if not request.user.has_module_perms('participant_menu'):
        return HttpResponseForbidden()

    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')
    menu = get_object_or_404(Menu, id=menu_id)
    nodes = list(menu.root_item.get_descendants())
    return render(request, 'participant_menu/administration/menu_detail.html',
                  {
                      'menu': menu,
                      'nodes': nodes,
                      'library': library
                  })
Example #51
0
def poll_detail(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if not request.user.has_module_perms('participant_photopolls'):
        return HttpResponseForbidden()
    poll = get_object_or_404(Poll, id=id)
    images = PollImage.objects.filter(poll=poll)
    return render(request,
                  'participant_photopolls/administration/poll_detail.html', {
                      'library': library,
                      'poll': poll,
                      'images': images
                  })
Example #52
0
def assign_page_permissions(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    obj = get_object_or_404(Page, id=id)

    if request.method == 'POST':
        GroupsForm = get_groups_form(Group.objects.all())
        groups_form = GroupsForm(request.POST)
        if groups_form.is_valid():
            assign_permission(groups_form.cleaned_data['groups'], [obj],
                              VIEW_PAGE_PERMISSION)
            assign_permission(groups_form.cleaned_data['groups'],
                              obj.get_descendants(), VIEW_PAGE_PERMISSION)
    return HttpResponse(u'{"status":"ok"}')
Example #53
0
def unbind_to_children_orgs(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    banner = get_object_or_404(models.Banner,
                               id=id,
                               library_creator=library.id)

    for descedant in library.get_descendants():
        banner.libraries.remove(descedant)
    banner.in_descendants = False
    banner.save()
    return redirect('participant_banners:administration:index',
                    library_code=library_code,
                    lang=banner.lang)
Example #54
0
def create_event(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if request.method == 'POST':
        event_form = EventForm(request.POST, request.FILES, prefix='event_form')

        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form': EventContentForm(request.POST, prefix='event_content' + lang[0]),
                'lang': lang[0]
            })
        if event_form.is_valid():
            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                event = event_form.save(commit=False)
                event.library = library
                event.save()
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(commit=False)
                    event_content.lang = event_content_form['lang']
                    event_content.event = event
                    event_content.save()
                event_form.save_m2m()
                return redirect('participant_events:administration:events_list', library_code=library_code)
    else:
        event_form = EventForm(prefix="event_form")
        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form': EventContentForm(prefix='event_content' + lang[0]),
                'lang': lang[0]
            })

    return render(request, 'participant_events/administration/create_event.html', {
        'library': library,
        'event_form': event_form,
        'event_content_forms': event_content_forms,
    })
Example #55
0
def create_page(request, library_code, parent=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if parent:
        parent = get_object_or_404(Page, id=parent, library=library)

    PageForm = get_page_form(library, parent)
    if request.method == 'POST':
        page_form = PageForm(request.POST, prefix='page_form')

        if page_form.is_valid():
            page = page_form.save(commit=False)
            if parent:
                page.parent = parent

            if not request.user.has_perm('participant_pages.public_page'):
                page.public = False
            page.library = library
            page.save()
            if parent:
                # наследование прав от родителя
                copy_perms_for_groups(parent, page)
            else:
                try:
                    users_group = Group.objects.get(name='users')
                    assign_permission([users_group], [page],
                                      VIEW_PAGE_PERMISSION)
                except Group.DoesNotExist:
                    pass
            return redirect(
                'participant_pages:administration:create_page_content',
                library_code=library_code,
                page_id=page.id)
    else:
        page_form = PageForm(prefix='page_form')

    return render(request, 'participant_pages/administration/create_page.html',
                  {
                      'library': library,
                      'parent': parent,
                      'page_form': page_form,
                  })
Example #56
0
def page_permissions(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    obj = get_object_or_404(Page, id=id)

    GroupsForm = get_groups_form(Group.objects.all(),
                                 initial=list(get_groups_with_perms(obj)))
    groups_form = GroupsForm()

    return render(request, 'participant_pages/administration/permissions.html',
                  {
                      'library': library,
                      'page': obj,
                      'groups_form': groups_form,
                  })
Example #57
0
def create(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    if request.method == "POST":
        banner_form = forms.BannerForm(request.POST, request.FILES)
        if banner_form.is_valid():
            banner = banner_form.save(commit=False)
            banner.library_creator = library
            banner.save()
            banner.libraries.add(library)
            return redirect("participant_banners:administration:index", library_code=library_code, lang=banner.lang)
    else:
        banner_form = forms.BannerForm()
    return render(
        request,
        "participant_banners/administration/create_banner.html",
        {"library": library, "banner_form": banner_form},
    )
Example #58
0
def edit(request, library_code, id, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u"Вы должны быть сотрудником этой организации")

    banner = get_object_or_404(models.Banner, id=id, library_creator=library.id)
    if request.method == "POST":
        banner_form = forms.BannerForm(request.POST, request.FILES, instance=banner)
        if banner_form.is_valid():
            banner = banner_form.save(commit=False)
            banner.save()
            return redirect("participant_banners:administration:index", library_code=library_code, lang=banner.lang)
    else:
        banner_form = forms.BannerForm(instance=banner)

    return render(
        request,
        "participant_banners/administration/edit_banner.html",
        {"library": library, "banner": banner, "banner_form": banner_form},
    )