Exemplo n.º 1
0
def edit_entry(request, id):
    entry = get_object_or_404(Entry, id=id)
    user = request.user
    user_groups = [t[0] for t in user.groups.values_list('name')]
    if not (user.preplock and entry.preplock) \
            and (not entry.authors.exists() or user.is_superuser
                 or 'editors' in user_groups or 'admins' in user_groups
                 or user in entry.authors.all()):
        pass
    else:
        return redirect(entry.get_absolute_url())

    choices = {
        'author': viewmodels.editAuthors,
        'entry_status': viewmodels.editStatuses,
        'gender': viewmodels.editGenders,
        'onym': viewmodels.editOnyms,
        'part_of_speech': viewmodels._choices(
                            models.PART_OF_SPEECH_CHOICES),
        'participle_type': viewmodels.editParticiples,
        'substantivus_type': viewmodels.editSubstantivusTypes,
        'tantum': viewmodels.editTantum,
    }
    labels = {
        'author': dict(viewmodels.AUTHOR_CHOICES),  # sic! viewmodels
        'entry_status': dict(models.STATUS_CHOICES),
        'gender': dict(models.GENDER_CHOICES),
        'onym': dict(models.ONYM_CHOICES),
        'part_of_speech': dict(models.PART_OF_SPEECH_CHOICES),
        'participle_type': dict(models.PARTICIPLE_CHOICES),
        'substantivus_type': dict(models.SUBSTANTIVUS_TYPE_CHOICES),
        'tantum': dict(models.TANTUM_CHOICES)
    }
    slugs = {
        'onym': models.ONYM_MAP,
        'part_of_speech': models.PART_OF_SPEECH_MAP,
    }
    context = {
        'entry': viewmodels.entry_json(id),
        'choices': viewmodels._json(choices),
        'labels': viewmodels._json(labels),
        'slugs': viewmodels._json(slugs),
        'entryURL': Entry.objects.get(pk=id).get_absolute_url(),
        'PARTS_OF_SPEECH': models.PART_OF_SPEECH_CHOICES,
        'GENDERS': models.GENDER_CHOICES,
        'STATUSES': models.STATUS_CHOICES,
        'GREEK_EQ_STATUSES': models.Example.GREEK_EQ_STATUS,
        'SUBSTANTIVUS_TYPES': models.SUBSTANTIVUS_TYPE_CHOICES,
        'MAX_LENGTHS': models.MAX_LENGTHS,
    }
    return render_to_response('single_entry_edit.html', context,
                              RequestContext(request))
Exemplo n.º 2
0
def edit_entry(request, id):
    choices = {
        'author': viewmodels.editAuthors,
        'entry_status': viewmodels.editStatuses,
        'gender': viewmodels.editGenders,
        'onym': viewmodels.editOnyms,
        'part_of_speech': viewmodels._choices(
                            models.PART_OF_SPEECH_CHOICES),
        'participle_type': viewmodels.editParticiples,
        'substantivus_type': viewmodels.editSubstantivusTypes,
        'tantum': viewmodels.editTantum,
    }
    labels = {
        'author': dict(viewmodels.AUTHOR_CHOICES),  # sic! viewmodels
        'entry_status': dict(models.STATUS_CHOICES),
        'gender': dict(models.GENDER_CHOICES),
        'onym': dict(models.ONYM_CHOICES),
        'part_of_speech': dict(models.PART_OF_SPEECH_CHOICES),
        'participle_type': dict(models.PARTICIPLE_CHOICES),
        'substantivus_type': dict(models.SUBSTANTIVUS_TYPE_CHOICES),
        'tantum': dict(models.TANTUM_CHOICES)
    }
    slugs = {
        'onym': models.ONYM_MAP,
        'part_of_speech': models.PART_OF_SPEECH_MAP,
    }
    context = {
        'entry': viewmodels.entry_json(id),
        'choices': viewmodels._json(choices),
        'labels': viewmodels._json(labels),
        'slugs': viewmodels._json(slugs),
        'entryURL': Entry.objects.get(pk=id).get_absolute_url(),
        'PARTS_OF_SPEECH': models.PART_OF_SPEECH_CHOICES,
        'GENDERS': models.GENDER_CHOICES,
        'STATUSES': models.STATUS_CHOICES,
        'GREEK_EQ_STATUSES': models.Example.GREEK_EQ_STATUS,
        'SUBSTANTIVUS_TYPES': models.SUBSTANTIVUS_TYPE_CHOICES,
        'MAX_LENGTHS': models.MAX_LENGTHS,
    }
    return render_to_response('single_entry_edit.html', context,
                              RequestContext(request))
Exemplo n.º 3
0
def hellinist_workbench(request):
    for key in ('hwPrfx', 'hwAddress', 'hwExample'):
        if key in request.COOKIES:
            request.COOKIES[key] = base64 \
                .standard_b64decode(request.COOKIES[key]) \
                .decode('utf8')

    if request.method == 'POST':
        data = request.POST
    else:
        data = FilterExamplesForm.default_data
        data.update(request.COOKIES)

    form = FilterExamplesForm(data)
    if not form.is_valid():
        message = u'Форма FilterExamplesForm заполнена неправильно.'
        if request.method == 'POST':
            raise RuntimeError(message)
        else:
            # Кидаем исключение для обработки в мидлваре и стирания всех кук.
            raise InvalidCookieError(message)
    examples = filters.get_examples(form.cleaned_data)
    if request.user.preplock:
        examples = [ex for ex in examples if not ex.host_entry.preplock]

    paginator = Paginator(examples, per_page=4, orphans=2)
    if request.method == 'POST':
        pagenum = 1
    else:
        try:
            pagenum = int(request.GET.get('page', 1))
        except ValueError:
            pagenum = 1
    try:
        page = paginator.page(pagenum)
    except (EmptyPage, InvalidPage):
        page = paginator.page(paginator.num_pages)

    vM_examples = [
    {
        'id': e.id,
        'triplet': e.context_ucs,
        'antconc': e.context.strip() or e.example,
        'example': e.example,
        'address': e.address_text,
        'status': e.greek_eq_status,
        'audited': e.audited_time and e.audited,
        'comment': e.additional_info,
        'greqs': [
            {
                'unitext': greq.unitext,
                'initial_form': greq.initial_form,
                'id': greq.id,
                'additional_info': greq.additional_info
            }
            for greq in e.greek_equivs]
    }
    for e in page.object_list]

    context = {
        'examples': page.object_list,
        'form': form,
        'jsonExamples': viewmodels._json(vM_examples),
        'number_of_examples': paginator.count,
        'indicators': {
            'urgent': Example.objects.filter(greek_eq_status=u'U').count(),
            'meaning': Example.objects.filter(greek_eq_status=u'M').count(),
            },
        'page': page,
        'statusList': models.Example.GREEK_EQ_STATUS,
        'title': u'Греческий кабинет',
        'viewmodel': {
            'authors': viewmodels.jsonAuthors,
            'statuses': viewmodels.jsonGreqStatuses,
            'sortdir': viewmodels.jsonSortdir,
            'sortbase': viewmodels.jsonGreqSortbase,
            },
        'MAX_LENGTHS': models.MAX_LENGTHS,
        }
    response = render_to_response('hellinist_workbench.html', context,
                                  RequestContext(request))
    if request.method == 'POST':
        for key in ('hwPrfx', 'hwAddress', 'hwExample'):
            form.cleaned_data[key] = base64.standard_b64encode(
                                        form.cleaned_data[key].encode('utf8'))
        for param, value in form.cleaned_data.items():
            response.set_cookie(param, value, path=request.path)
    return response
Exemplo n.º 4
0
def write_ix(filename, data):
    with open(filename, 'wb') as f:
        f.write(_json(data).encode('utf-8'))
Exemplo n.º 5
0
def hellinist_workbench(request):
    if 'hwPrfx' in request.COOKIES:
        request.COOKIES['hwPrfx'] = base64 \
            .standard_b64decode(request.COOKIES['hwPrfx']) \
            .decode('utf8')

    if 'hwAddress' in request.COOKIES:
        request.COOKIES['hwAddress'] = base64 \
            .standard_b64decode(request.COOKIES['hwAddress']) \
            .decode('utf8')

    if request.method == 'POST':
        data = request.POST
    else:
        data = FilterExamplesForm.default_data
        data.update(request.COOKIES)

    form = FilterExamplesForm(data)
    assert form.is_valid(), u'Форма FilterExamplesForm заполнена неправильно'
    examples = filters.get_examples(form.cleaned_data)

    paginator = Paginator(examples, per_page=4, orphans=2)
    if request.method == 'POST':
        pagenum = 1
    else:
        try:
            pagenum = int(request.GET.get('page', 1))
        except ValueError:
            pagenum = 1
    try:
        page = paginator.page(pagenum)
    except (EmptyPage, InvalidPage):
        page = paginator.page(paginator.num_pages)

    vM_examples = [
    {
        'id': e.id,
        'triplet': e.context_ucs,
        'antconc': e.context.strip() or e.example,
        'example': e.example,
        'address': e.address_text,
        'status': e.greek_eq_status,
        'comment': e.additional_info,
        'greqs': [
            {
                'unitext': greq.unitext,
                'initial_form': greq.initial_form,
                'id': greq.id,
                'additional_info': greq.additional_info
            }
            for greq in e.greek_equivs]
    }
    for e in page.object_list]

    context = {
        'examples': page.object_list,
        'form': form,
        'jsonExamples': viewmodels._json(vM_examples),
        'number_of_examples': paginator.count,
        'indicators': {
            'urgent': Example.objects.filter(greek_eq_status=u'U').count(),
            'meaning': Example.objects.filter(greek_eq_status=u'M').count(),
            },
        'page': page,
        'statusList': models.Example.GREEK_EQ_STATUS,
        'title': u'Греческий кабинет',
        'viewmodel': {
            'authors': viewmodels.jsonAuthors,
            'statuses': viewmodels.jsonGreqStatuses,
            'sortdir': viewmodels.jsonSortdir,
            'sortbase': viewmodels.jsonGreqSortbase,
            },
        }
    response = render_to_response('hellinist_workbench.html', context,
                                  RequestContext(request))
    if request.method == 'POST':
        form.cleaned_data['hwPrfx'] = base64 \
            .standard_b64encode(form.cleaned_data['hwPrfx'].encode('utf8'))
        form.cleaned_data['hwAddress'] = base64 \
            .standard_b64encode(form.cleaned_data['hwAddress'].encode('utf8'))
        for param, value in form.cleaned_data.items():
            response.set_cookie(param, value, path=request.path)
    return response