Skip to content

Commit

Permalink
Update model saving logic, try to fix fotis import
Browse files Browse the repository at this point in the history
  • Loading branch information
MaertHaekkinen committed Oct 27, 2024
1 parent 0dfde78 commit 04fa19e
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 476 deletions.
7 changes: 3 additions & 4 deletions ajapaik/ajapaik/management/commands/fb_rescrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Command(BaseCommand):

def handle(self, *args, **options):
photos = Photo.objects.filter(latest_comment__isnull=False)
query_string = 'https://graph.facebook.com/?id=%s&scrape=true'
url_template = 'https://ajapaik.ee/foto/%d/'

for p in photos:
url = url_template % p.id
requests.post(query_string % url)
url = f'https://ajapaik.ee/photo/{p.id}'
requests.post(f'https://graph.facebook.com/?id={url}&scrape=true')
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ def handle(self, *args, **options):
for profile in profiles:
if profile.first_name and profile.last_name:
profile.display_name = '%s %s' % (profile.first_name, profile.last_name)

elif profile.google_plus_name:
profile.display_name = profile.google_plus_name

elif profile.fb_name:
profile.display_name = profile.fb_name

elif profile.google_plus_email:
try:
profile.display_name = profile.google_plus_email.split('@')[0]
except: # noqa
pass

elif profile.first_name:
profile.display_name = profile.first_name

elif profile.last_name:
profile.display_name = profile.last_name

profile.save()
226 changes: 145 additions & 81 deletions ajapaik/ajapaik/models.py

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions ajapaik/ajapaik/opendata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,10 @@ class Meta:
fields = '__all__'


class CustomLimitOffsetPagination(LimitOffsetPagination):
def get_count(self, queryset):
"""
Determine an object count, supporting either querysets or regular lists.
"""
try:
return queryset.cached_count()
except (AttributeError, TypeError):
return len(queryset)


class PhotoViewSet(viewsets.ModelViewSet):
queryset = Photo.objects.filter(rephoto_of__isnull=True)
serializer_class = PhotoSerializer
pagination_class = CustomLimitOffsetPagination
pagination_class = LimitOffsetPagination
filter_backends = [filters.SearchFilter]
search_fields = list(PhotoIndex.fields)
search_fields.remove('text')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ def get_redirect_url(self, authorization_url, extra_params):
'scope': self.scope,
'response_type': 'code'
}

if self.state:
params['state'] = self.state

params.update(extra_params)
sorted_params = OrderedDict()

for param in sorted(params):
sorted_params[param] = params[param]
return '%s?%s' % (authorization_url, urlencode(sorted_params))

return f'{authorization_url}?{urlencode(sorted_params)}'

def get_access_token(self, code):
data = {'client_id': self.consumer_key,
Expand Down
5 changes: 3 additions & 2 deletions ajapaik/ajapaik/sorl_overrides.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from sorl.thumbnail.base import ThumbnailBackend, EXTENSIONS
from sorl.thumbnail.conf.defaults import THUMBNAIL_PREFIX
from sorl.thumbnail.helpers import tokey, serialize
Expand All @@ -10,6 +11,6 @@ def _get_thumbnail_filename(self, source, geometry_string, options):

filename, _ext = os.path.splitext(os.path.basename(source.name))

path = '%s/%s' % (key, filename)
path = f'{key}/{filename}'

return '%s%s.%s' % (THUMBNAIL_PREFIX, path, EXTENSIONS[options['format']])
return f'{THUMBNAIL_PREFIX}{path}.{EXTENSIONS[options["format"]]}'
4 changes: 3 additions & 1 deletion ajapaik/ajapaik/templatetags/ajapaik_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def __init__(self, values):
def render(self, context):
req = Variable('request').resolve(context)
params = req.GET.copy()

for key, value in self.values.items():
params[key] = value.resolve(context)
return '?%s' % params.urlencode()

return f'?{params.urlencode()}'


@register.tag
Expand Down
4 changes: 2 additions & 2 deletions ajapaik/ajapaik/urls_opendata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import re_path, path
from django.urls import path
from django.views.generic import TemplateView
from rest_framework.routers import DefaultRouter
from rest_framework.urlpatterns import format_suffix_patterns
Expand All @@ -14,5 +14,5 @@
path('photos/<int:photo_id>/geotags/',
PhotoGeoTagViewSet.as_view({'get': 'retrieve'}),
name='opendata-photo-geotags'),
re_path(r'^robots\.txt', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
path('robots.txt', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
])
4 changes: 2 additions & 2 deletions ajapaik/ajapaik/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def _get_filtered_data_for_frontpage(request, album_id=None, page_override=None)
# In some cases it is faster to get number of photos before we annotate new columns to it
albumsize_before_sorting = 0
if not album:
albumsize_before_sorting = Photo.objects.filter(pk__in=photos).cached_count()
albumsize_before_sorting = Photo.objects.filter(pk__in=photos).cached_count(q)

# SORTING BELOW THIS LINE

Expand Down Expand Up @@ -660,7 +660,7 @@ def _get_filtered_data_for_frontpage(request, album_id=None, page_override=None)
p[3] = p[14] + (". " if p[14][-1] != "." else " ") + p[
3] # add title to image description if both are present.

# Failback width/height for photos which imagedata arent saved yet
# Failback width/height for photos which imagedata is not saved yet
if p[1] == '' or p[1] is None:
p[1] = 400
if p[2] == '' or p[2] is None:
Expand Down
Loading

0 comments on commit 04fa19e

Please sign in to comment.