Skip to content

Commit 71504d6

Browse files
committed
personalized fork for Open-Knesset
use at your own risk
1 parent 9742c4e commit 71504d6

File tree

9 files changed

+19
-10
lines changed

9 files changed

+19
-10
lines changed

annotatetext/forms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class NewAnnotationForm(forms.Form):
1212
flags = forms.ChoiceField(choices=enumerate(ANNOTATION_FLAGS),widget=forms.Select(attrs={"class":"annotationflagselect"}), required=True)
1313
content_type = forms.IntegerField(widget=forms.HiddenInput, required=True)
1414
object_id = forms.IntegerField(widget=forms.HiddenInput, required=True)
15-
comment = forms.CharField(widget=forms.Textarea(attrs={'cols': 50, 'rows': 3}), required=False)
15+
comment = forms.CharField(widget=forms.Textarea(attrs={'rows': 5 }), required=False)
1616
color = forms.CharField(initial="#3f0b5c", widget=forms.TextInput(attrs={"size":6}), required=False)
1717
lengthcheck = forms.IntegerField(widget=forms.HiddenInput, required=True)
1818

@@ -49,9 +49,10 @@ def clean(self):
4949
# so not every model can be annotated, don't know if this is cool in practice
5050
if not getattr(obj, "annotatable", False):
5151
raise forms.ValidationError(_("Invalid object"))
52-
if not hasattr(obj,Annotation.field_name):
52+
#TODO: generalize
53+
if not hasattr(obj,'body'):
5354
raise forms.ValidationError(_("Bogus object"))
54-
text = getattr(obj, Annotation.field_name)
55+
text = getattr(obj, 'body')
5556
if len(text) != cleaned_data["lengthcheck"]:
5657
raise forms.ValidationError(_("Text changed"))
5758
if not "selection_start" in cleaned_data or not "selection_end" in cleaned_data:

annotatetext/models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
from django.utils.translation import ugettext_lazy as _
1010
from django.conf import settings
1111

12-
ANNOTATION_FLAGS = getattr(settings, "ANNOTATETEXT_FLAGS", (_("Annotation"), ))
12+
# entries from settings.py are not translated automaticly
13+
# http://docs.djangoproject.com/en/dev/ref/settings/#languages
14+
flags = getattr(settings, "ANNOTATETEXT_FLAGS", None)
15+
if flags is None:
16+
ANNOTATION_FLAGS = (_("Annotation"), )
17+
else:
18+
ANNOTATION_FLAGS = map(_, flags)
1319

1420

1521
class Annotation(models.Model):
@@ -39,7 +45,7 @@ class Annotation(models.Model):
3945
content_type = models.ForeignKey(ContentType)
4046
object_id = models.PositiveIntegerField()
4147
content_object = generic.GenericForeignKey('content_type', 'object_id')
42-
field_name = models.CharField(blank=True, null=True, max_length=100)
48+
field_name = models.CharField(default='body', null=True, max_length=100)
4349
selection_start = models.IntegerField()
4450
selection_end = models.IntegerField(blank=True, null=True)
4551
comment = models.TextField(blank=True)
@@ -119,7 +125,7 @@ def clean_text(self, text):
119125
return text
120126

121127
@classmethod
122-
def get_textfield_from_object(cls, obj, field_name="text"):
128+
def get_textfield_from_object(cls, obj, field_name="body"):
123129
if field_name is None:
124130
return unicode(getattr(obj, "text", ""))
125131
else:
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<div id="a_{{ annotation.id }}" class="semannotation annotationfor-{{ key }}" style="border:1px solid;border-color:{% if annotation.color %}{{ annotation.color }}{% else %}#ff0000{% endif %};">
1+
{% load i18n %}
2+
<div id="a_{{ annotation.id }}" class="semannotation annotationfor-{{ speech_part.id }}" style="border:1px solid;border-color:{% if annotation.color %}{{ annotation.color }}{% else %}#ff0000{% endif %};">
23
<form class="admin really_delete" style="float:right" action="{% url annotatetext-delete_annotation %}" method="post"><input type="hidden" name="next" value="{{ next }}"/><input type="hidden" name="annotation_id" value="{{ annotation.id }}"/><input type="submit" value="X"/></form>
34
<q class="start_{{ annotation.selection_range.0 }} end_{{ annotation.selection_range.1 }}">{{ annotation.selection }}</q>
4-
<p class="annotation_meta" id="annotation-{{ annotation.id }}">{{ annotation.flag_value }} - {% if annotation.user %}{{ annotation.user }}{% else %}anonymous{% endif %} @ {{ annotation.timestamp|date:"d.m.Y H:i"}} - <a href="#annotation-{{ annotation.id }}">Permalink</a></p>
5+
<p class="annotation_meta" id="annotation-{{ annotation.id }}">{{ annotation.flag_value }} {% trans "by" %} {% if annotation.user %}{{ annotation.user }}{% else %}anonymous{% endif %} - <a href="#annotation-{{ annotation.id }}">{% trans "Permalink"%}</a></p>
56
<div class="content">{{ annotation.comment|urlizetrunc:25 }}</div>
67
</div>
File renamed without changes.
File renamed without changes.

annotatetext/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def post_annotation(request):
2020
color=form.cleaned_data["color"])
2121
new_annotation.save()
2222
fragment = "#annotation-%d" % new_annotation.id
23-
return HttpResponseRedirect(request.POST.get("next","/") + fragment)
23+
# return HttpResponseRedirect(request.POST.get("next","/") + fragment)
24+
return HttpResponseRedirect(new_annotation.content_object.get_absolute_url())
2425
else:
2526
return HttpResponseBadRequest()
2627

@@ -37,4 +38,4 @@ def delete_annotation(request):
3738
return HttpResponseBadRequest()
3839
annotation = get_object_or_404(Annotation, id=annoid)
3940
annotation.delete()
40-
return HttpResponseRedirect(request.POST.get("next","/"))
41+
return HttpResponseRedirect(request.POST.get("next","/"))

0 commit comments

Comments
 (0)