Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Grund authored and Anna Grund committed Aug 12, 2023
1 parent 1a1d888 commit 4f02068
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.7 on 2023-08-09 16:34

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0029_photomodelsuggestionresult'),
]

operations = [
migrations.AlterUniqueTogether(
name='photomodelsuggestionalternativecategory',
unique_together={('proposer', 'photo_id', 'viewpoint_elevation_alternation', 'scene_alternation')},
),
]
21 changes: 21 additions & 0 deletions ajapaik/ajapaik/migrations/0031_auto_20230809_1940.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.7 on 2023-08-09 16:40

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0030_alter_photomodelsuggestionalternativecategory_unique_together'),
]

operations = [
migrations.AlterUniqueTogether(
name='photomodelsuggestionalternativecategory',
unique_together={('proposer', 'photo_id')},
),
migrations.AlterModelTable(
name='photomodelsuggestionalternativecategory',
table='ajapaik_photomodelsuggestionalternativecategory',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.7 on 2023-08-09 16:41

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0031_auto_20230809_1940'),
]

operations = [
migrations.AlterModelTable(
name='photomodelsuggestionalternativecategory',
table='photomodelsuggestionalternativecategory',
),
]
21 changes: 21 additions & 0 deletions ajapaik/ajapaik/migrations/0033_auto_20230809_1944.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.7 on 2023-08-09 16:44

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0032_alter_photomodelsuggestionalternativecategory_table'),
]

operations = [
migrations.AlterUniqueTogether(
name='photomodelsuggestionalternativecategory',
unique_together={('proposer', 'photo_id', 'scene_alternation')},
),
migrations.AlterModelTable(
name='photomodelsuggestionalternativecategory',
table='ajapaik_photomodelsuggestionalternativecategory',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.7 on 2023-08-09 17:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0033_auto_20230809_1944'),
]

operations = [
migrations.AlterUniqueTogether(
name='photomodelsuggestionalternativecategory',
unique_together={('proposer', 'photo_id', 'viewpoint_elevation_alternation'), ('proposer', 'photo_id', 'scene_alternation')},
),
]
28 changes: 27 additions & 1 deletion ajapaik/ajapaik/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from django.contrib.gis.geos import Point
from django.contrib.postgres.fields import ArrayField
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db.models import CASCADE, DateField, FileField, Lookup, Transform, OneToOneField, Q, F, Sum, Index
Expand Down Expand Up @@ -2128,6 +2128,32 @@ class PhotoModelSuggestionAlternativeCategory(Suggestion):

proposer = ForeignKey('Profile', blank=True, null=True, related_name='photo_scene_suggestions_alternation', on_delete=CASCADE)

def validate_unique(self, exclude=None):
super().validate_unique(exclude)

queryset = self.__class__._default_manager.filter(
Q(scene_alternation=0) | Q(scene_alternation=1),
proposer=self.proposer,
photo_id=self.photo_id
).exclude(pk=self.pk)

print(f"QUERY SET IS {queryset}")
print(type(self.scene_alternation))
print(self.scene_alternation in ['0', '1'])
print(queryset.exists())

if self.scene_alternation in ['0', '1'] and queryset.exists():
raise ValidationError('Only one record with scene_alternation 0 or 1 is allowed.')

def save(self, *args, **kwargs):
self.validate_unique()
super().save(*args, **kwargs)

class Meta:
db_table = 'ajapaik_photomodelsuggestionalternativecategory'
unique_together = (('proposer', 'photo_id', 'scene_alternation'),
('proposer', 'photo_id', 'viewpoint_elevation_alternation'))


class PhotoFlipSuggestion(Suggestion):
proposer = ForeignKey('Profile', blank=True, null=True, related_name='photo_flip_suggestions', on_delete=CASCADE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from django.db.models import Max
from django.http import HttpRequest

from ajapaik.ajapaik.models import PhotoSceneSuggestion, PhotoViewpointElevationSuggestion, \
Expand Down Expand Up @@ -84,9 +85,39 @@ def post_image_category_result_table(request: HttpRequest):
return result


# def aggregate_category_data():
# """
# Methods aggregates data from both Alternative table + User's categories input.
# """
#
# one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
#
# # scene_category = PhotoSceneSuggestion.objects.filter(created__gte=one_week_ago).order_by('-created')
# # view_point_category = PhotoViewpointElevationSuggestion.objects.filter(created__gte=one_week_ago).order_by(
# # '-created')
#
# alternative_category = PhotoModelSuggestionAlternativeCategory.objects.filter(created__gte=one_week_ago).order_by(
# '-created')
#
# result_categories = {}
#
# # if scene_category.exists():
# # scene_category_dict = serializers.serialize('python', scene_category)
# # result_categories['scene_category_data'] = scene_category_dict
# #
# # if view_point_category.exists():
# # view_point_dict = serializers.serialize('python', view_point_category)
# # result_categories['view_point_category_data'] = view_point_dict
#
# if alternative_category.exists():
# confirm_reject_dict = serializers.serialize('python', alternative_category)
# result_categories['alternative_category_data'] = confirm_reject_dict
#
# return result_categories

def aggregate_category_data():
"""
Methods aggregates data from both Alternative table + User's categories input.
Method aggregates data from both Alternative table + User's categories input.
"""

one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
Expand All @@ -112,6 +143,8 @@ def aggregate_category_data():
confirm_reject_dict = serializers.serialize('python', alternative_category)
result_categories['alternative_category_data'] = confirm_reject_dict

print("=====")
print(result_categories)
return result_categories


Expand Down

0 comments on commit 4f02068

Please sign in to comment.