Skip to content

Commit

Permalink
Got the database part of saving perspective for nme videos working #1409
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessel Stoop committed Dec 20, 2024
1 parent 19306b0 commit 46e8dee
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
11 changes: 5 additions & 6 deletions signbank/dictionary/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2442,15 +2442,14 @@ def get_nme_videos(self):
nmevideos = GlossVideoNME.objects.filter(gloss=self)
return nmevideos

def add_nme_video(self, user, videofile, new_offset, recorded):
def add_nme_video(self, user, videofile, new_offset, recorded, perspective='center'):
# Preventing circular import
from signbank.video.models import GlossVideoNME, GlossVideoHistory, get_video_file_path
# Create a new GlossVideo object
existing_nmevideos = GlossVideoNME.objects.filter(gloss=self)
existing_offsets = [nmev.offset for nmev in existing_nmevideos]
if new_offset in existing_offsets:

existing_offsets_for_this_perspective = [nmev.offset for nmev in GlossVideoNME.objects.filter(gloss=self,perspective=perspective)]
if new_offset in existing_offsets_for_this_perspective:
# override given offset to avoid duplicate usage
offset = max(existing_offsets)+1
offset = max(existing_offsets_for_this_perspective)+1
else:
offset = new_offset

Expand Down
6 changes: 1 addition & 5 deletions signbank/dictionary/templates/dictionary/gloss_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -1888,11 +1888,7 @@ <h4>{% trans "Upload New NME Video" %}</h4>

<th>{% trans "Perspective" %}</th>
<td>
<select name="perspective" class="form-control" id="nmevideo_perspective">
<option value="left">Left</option>
<option value="center">Center</option>
<option value="right">Right</option>
</select>
{{nmevideoform.nme_perspective}}
</td>

</table>
Expand Down
4 changes: 3 additions & 1 deletion signbank/settings/server_specific/global_sb_new_aj.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
COUNTRY_NAME = 'Netherlands'
SIGNBANK_VERSION_CODE = 'global'
URL = 'https://signbank.cls.ru.nl/'
ALLOWED_HOSTS = ['signbank.science.ru.nl','signbank.cls.ru.nl','new.signbank.science.ru.nl']
ALLOWED_HOSTS=["*"]

EAF_FILES_LOCATION = 'corpus-ngt/eaf/'
METADATA_LOCATION = 'CNGT_MetadataEnglish_OtherResearchers.csv'
Expand Down Expand Up @@ -81,3 +81,5 @@
'OPTIONS': 'mysql.conf',
'TEST': {'NAME':'sigbank_test'}
}}
SECRET_KEY="vu43ra23e3w4"
CSRF_TRUSTED_ORIGINS = ["https://signbank.cls.ru.nl","https://signbank-dev.cls.ru.nl"]
5 changes: 5 additions & 0 deletions signbank/video/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Meta:
('right', 'Right')
)

NME_PERSPECTIVE_CHOICES = (('left','Left'),('right','Right'),('center', 'Center'))

class VideoUploadForObjectForm(forms.Form):
"""Form for video upload for all video types"""
Expand All @@ -32,6 +33,10 @@ class VideoUploadForObjectForm(forms.Form):
perspective = forms.ChoiceField(label=_('Video Perspective'),
choices=PERSPECTIVE_CHOICES, required=False,
widget=forms.Select(attrs=ATTRS_FOR_FORMS))
nme_perspective = forms.ChoiceField(label=_('NME video perspective'),
choices=NME_PERSPECTIVE_CHOICES, required=False,
widget=forms.Select(attrs=ATTRS_FOR_FORMS))

eaffile = forms.FileField(label="Upload EAF", widget=forms.FileInput(attrs={'accept':'text/xml'}), required=False)
feedbackdata = forms.CharField(widget=forms.HiddenInput, required=False)
translations = forms.CharField(widget=forms.HiddenInput, required=False)
Expand Down
4 changes: 2 additions & 2 deletions signbank/video/migrations/0014_glossvideonme_perspective.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.17 on 2024-12-13 14:34
# Generated by Django 4.2.17 on 2024-12-20 15:00

from django.db import migrations, models

Expand All @@ -13,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='glossvideonme',
name='perspective',
field=models.CharField(choices=[('left', 'Left'), ('right', 'Right')], default='center', max_length=20),
field=models.CharField(choices=[('left', 'Left'), ('right', 'Right'), ('center', 'Center')], default='center', max_length=20),
),
]
5 changes: 3 additions & 2 deletions signbank/video/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def get_two_letter_dir(idgloss):
('right', 'Right')
)

NME_PERSPECTIVE_CHOICES = (('left','Left'),('right','Right'),('center', 'Center'))

class GlossVideoStorage(FileSystemStorage):
"""Implement our shadowing video storage system"""

Expand Down Expand Up @@ -887,10 +889,9 @@ class GlossVideoDescription(models.Model):
def __str__(self):
return self.text


class GlossVideoNME(GlossVideo):
offset = models.IntegerField(default=1)
perspective = models.CharField(max_length=20, choices=PERSPECTIVE_CHOICES, default='center')
perspective = models.CharField(max_length=20, choices=NME_PERSPECTIVE_CHOICES, default='center')

class Meta:
verbose_name = gettext("NME Gloss Video")
Expand Down
6 changes: 4 additions & 2 deletions signbank/video/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ def addvideo(request):
if not gloss:
redirect(redirect_url)
offset = form.cleaned_data['offset']
nmevideo = gloss.add_nme_video(request.user, vfile, offset, recorded)
perspective = form.cleaned_data['nme_perspective']
nmevideo = gloss.add_nme_video(request.user, vfile, offset, recorded, perspective)
translation_languages = gloss.lemma.dataset.translation_languages.all()
descriptions = dict()
for language in translation_languages:
form_field = 'description_' + language.language_code_2char
form_value = form.cleaned_data[form_field]
descriptions[language.language_code_2char] = form_value.strip()
nmevideo.add_descriptions(descriptions)
nmevideo.perspective = form.cleaned_data['perspective'] #This is incorrect
nmevideo.perspective = perspective
nmevideo.save()
elif object_type == 'morpheme_video':
morpheme = Morpheme.objects.filter(id=object_id).first()
if not morpheme:
Expand Down

0 comments on commit 46e8dee

Please sign in to comment.