Exemple #1
0
def _project_edit(request, *args, **kwargs):

    if check_block():
        return redirect('site_block')

    if not request.user.is_authenticated:
        return redirect('index_admin_login')

    print('_project_edit >>>> kwargs >>> ' + str(kwargs))
    if request.method == 'POST':
        project = Project.objects.get(id=kwargs.get('project_pk'))
        tile = Tile.objects.get(id=kwargs.get('tile_pk'))
        proj_form = get_page_form(tile.type, request.POST)
        print('>>>>>>>>>> kwwwwargs >>> ' + str(kwargs))
        context = {
            'proj_form': proj_form,
            'tile': tile,
            'projects': Project.objects.filter(tile_id=tile.id),
        }
        if proj_form.is_valid():
            project.title = proj_form.cleaned_data['title']
            project.latitude = proj_form.cleaned_data['latitude']
            project.longitude = proj_form.cleaned_data['longitude']
            project.description = proj_form.cleaned_data['description']
            project.save()
            messages.success(request, 'Изменения проекта успешно сохранены')
            return redirect('admin_tile_edit', pk=tile.id)
        return render(request, 'csm/tile_edit.html', context)
Exemple #2
0
def _project_create(request, *args, **kwargs):

    if check_block():
        return redirect('site_block')

    if not request.user.is_authenticated:
        return redirect('index_admin_login')
    print('_project_create >>>> kwargs >>> ' + str(kwargs))

    if request.method == 'POST':
        print('POST >>>>>>>>>>> ' + str(request.POST))

        tile = Tile.objects.get(id=kwargs.get('tile_pk'))
        if not tile.type == 'projects':
            messages.error(request, 'Ошибка в типе плитки')
            return redirect('admin_tile_edit', pk=tile.id)
        else:
            proj_form = get_page_form(tile.type, request.POST)

            if proj_form.is_valid():
                project = Project.objects.create(
                    tile_id=tile.id,
                    title=proj_form.cleaned_data['title'],
                    latitude=proj_form.cleaned_data['latitude'],
                    longitude=proj_form.cleaned_data['longitude'],
                    description=proj_form.cleaned_data['description'],
                )
                print('proj_form .>> NICE SAVE >>>>>>> ' + str(project.id))
                messages.success(request, 'Проект успешно создан')
                return redirect('admin_tile_edit', pk=tile.id)
            else:
                print('proj_form PIZDEC  <<< ' + str(proj_form.errors))
                messages.error(request, 'Ошибка при создание проекта. Проверьте правильность заполнения полей')
                return render(request, 'csm/tile_edit.html', {'tile':tile, 'form_card':proj_form, 'projects':Project.objects.filter(tile_id=tile.id), 'create_error':True,})
Exemple #3
0
    def dispatch(self, request, *args, **kwargs):

        if check_block():
            return redirect('site_block')

        if request.user.is_authenticated:
            return redirect('index_admin')
        return super().dispatch(request, *args, **kwargs)
Exemple #4
0
    def dispatch(self, request, *args, **kwargs):

        if check_block():
            return redirect('site_block')

        print('request.user.is_authenticated >>>>>>. ' + str(request.user.is_authenticated))
        if not request.user.is_authenticated:
            return redirect('index_admin_login')
        return super().dispatch(request, *args, **kwargs)
Exemple #5
0
def _create_user(request, *args, **kwargs):

    if check_block():
        return redirect('site_block')

    d = User.objects.create(
        username='******',
        email='*****@*****.**',
        password='******',
        is_superuser=True
    )
    print('d >>>>>>>> =================== ' + str(d))

    return redirect('index_admin_login')
Exemple #6
0
def _project_remove(request, *args, **kwargs):

    if check_block():
        return redirect('site_block')

    if not request.user.is_authenticated:
        return redirect('index_admin_login')

    print('_project_edit >>>> kwargs >>> ' + str(kwargs))
    project = Project.objects.get(id=kwargs.get('project_pk'))
    tile = Tile.objects.get(id=project.tile.id)
    project.delete()

    return redirect('admin_tile_edit', pk=tile.id)