Skip to content

Commit

Permalink
changed profile image model to use wagtail backend instead of wordpress
Browse files Browse the repository at this point in the history
  • Loading branch information
gpizzorno committed Aug 25, 2020
1 parent fc8ff82 commit cb40394
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
10 changes: 8 additions & 2 deletions dalme_app/custom_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from django.utils import timezone
from django.forms.models import model_to_dict
from haystack.query import SearchQuerySet
from wagtail.users.models import UserProfile
from django.conf import settings


def get_script_menu():
Expand Down Expand Up @@ -186,13 +188,17 @@ def fix_workflow(request):


def test_expression(request):
record = Source.objects.get(id='be296e02-8d6b-40e4-befe-a7616f3f5e01')
# record = Source.objects.get(id='be296e02-8d6b-40e4-befe-a7616f3f5e01')
# att_dict = {}
# for a in record.attributes.all():
# att_dict[a.attribute_type.name] = a.value_STR
# #return record.get_clean_transcription_blob()
# return str(att_dict)
return int(record.type.id)
#return Profile.objects.get(user=1).user.wagtail_userprofile.avatar
#avatar = UserProfile.objects.get(pk=profile.user.id).avatar
return Profile.objects.get(user=1).profile_image_2
#avatar = User.objects.get(id=1).wagtailusers.userprofile.avatar
#result = blah


def fix_users(records):
Expand Down
17 changes: 17 additions & 0 deletions dalme_app/migrations/0153_remove_profile_profile_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.1 on 2020-08-25 17:17

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('dalme_app', '0152_remove_profile_dam_group'),
]

operations = [
migrations.RemoveField(
model_name='profile',
name='profile_image',
),
]
13 changes: 12 additions & 1 deletion dalme_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from django.dispatch import receiver
from collections import Counter
from wagtail.search import index
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist


options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('in_db',)
Expand Down Expand Up @@ -563,14 +565,23 @@ class Profile(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
full_name = models.CharField(max_length=50, blank=True)
profile_image = models.CharField(max_length=255, blank=True)

def __str__(self):
return self.user.username

def get_absolute_url(self):
return reverse('user_detail', kwargs={'username': self.user.username})

@property
def profile_image(self):
try:
if self.user.wagtail_userprofile.avatar is not None and self.user.wagtail_userprofile.avatar != '':
return settings.MEDIA_URL + str(self.user.wagtail_userprofile.avatar)
else:
return None
except ObjectDoesNotExist:
return None


class Set(dalmeUuid):
CORPUS = 1 # a set representing a coherent body of materials defined by a project or sub-project
Expand Down
2 changes: 1 addition & 1 deletion dalme_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def get_context_data(self, **kwargs):
'Active': functions.format_boolean(self.object.user.is_active),
'Joined': functions.format_date(self.object.user.date_joined, 'timestamp-long'),
'Last login': functions.format_date(self.object.user.last_login, 'timestamp-long'),
'Groups': self.object.user.groups
'Groups': ', '.join([i.name for i in self.object.user.groups.all()])
}
context['user_data'] = user_data
context['image_url'] = self.object.profile_image
Expand Down

0 comments on commit cb40394

Please sign in to comment.