Ejemplo n.º 1
0
def add_idea(request, entity):
    description = request.POST.get('description', '').strip()
    if description == '':
        return HttpResponse(u'Пожалуйста, опишите идею')

    idea = Idea.objects.create(task=entity, description=clean_html(description))

    EntityParticipant.objects.add(idea, request.profile, 'admin')

    # TODO: add resources

    NewIdeaNotification.send(idea.id)

    entity.clear_cache()

    return HttpResponse('ok')
Ejemplo n.º 2
0
def update_text_field(request, entity):
    field = request.POST.get('field', '')
    if field not in type(entity).editable_fields:
        return HttpResponse(u'Это поле нельзя редактировать')

    value = request.POST.get('value', '')

    model_field = type(entity)._meta.get_field(field)
    if type(model_field) is models.CharField:
        value = value[:model_field.max_length]
    elif type(model_field) is HTMLField:
        value = clean_html(value)
    else:
        assert False, "Field %s of entity model %s should not be editable" % (field, model_field.__name__)

    setattr(entity, field, value)
    entity.save()

    return HttpResponse('ok')
Ejemplo n.º 3
0
 def clean(self, value):
     html = super(HTMLCharField, self).clean(value)
     return clean_html(html)