Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

✨ Adding importer models #111

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
625482a
:sparkles: Initial commit for importer models
evict Jan 11, 2019
3db638d
:art: Using newly created models and basic log
evict Jan 11, 2019
fc20123
:sparkles: Added basic security logger
evict Jan 11, 2019
cf3e487
:sparkles: Added ImporterFriend models
evict Jan 26, 2019
f5d169b
:white_check_mark: Adding tests for importer model
evict Jan 26, 2019
d9d3bc2
:sparkles: Added importer models to view
evict Jan 26, 2019
fd81a2a
:rocket: Migrations...
evict Jan 26, 2019
61a237d
:white_check_mark: Archive for importer test
evict Jan 26, 2019
a0c9843
:sparkles: Added deletion of archives
evict Feb 2, 2019
64b562b
:sparkles: Deleting archives using user model
evict Feb 2, 2019
04d86d2
:rocket: Migrations added
evict Feb 8, 2019
34d6624
:white_check_mark: Adding import deleted test
evict Feb 8, 2019
50a1fbe
:wrench: Changing security log -> syslog
evict Feb 8, 2019
b00bb95
:bug: Fixing serializer bug
evict Feb 8, 2019
3ebb620
:sparkles: Changes to parser, serializers, tests and views
evict Feb 8, 2019
1a0c798
:sparkles: Added image processing 'imagekit'
evict Feb 9, 2019
eefb3f2
:sparkles: Working with UUID for public usage
evict Feb 9, 2019
0ea5ef8
:white_check_mark: Tests for new ImportedItem(s) view and UUIDs
evict Feb 9, 2019
46d74a7
:package: Added imagekit
evict Feb 9, 2019
b58a397
:sparkles: Get posts property added
evict Feb 9, 2019
be5e82d
:card_file_box: Adding migrations
evict Feb 9, 2019
cf48fe1
:wheelchair: Using validated data for zipfile
evict Feb 9, 2019
2f97590
:wheelchair: Using ApiMessageResponse
evict Feb 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ django-modeltranslation = {editable = true, git = "https://github.com/lifenautjo
bandit = "*"
pyyaml = "*"
python-magic = "*"
django-imagekit = "*"

[pipenv]
allow_prereleases = true
152 changes: 91 additions & 61 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion openbook/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@
'console': {
# exact format is not important, this is the minimum information
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
}
},
'security': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'console',
},
'file': {
'class': 'logging.StreamHandler',
'formatter': 'console',
}
},
'loggers': {
Expand All @@ -44,6 +51,10 @@
'level': 'INFO',
'handlers': ['console'],
},
'security': {
'level': 'INFO',
'handlers': ['console'],
},
},
})

Expand Down Expand Up @@ -103,6 +114,7 @@
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'imagekit',
'django_nose',
'storages',
'django_media_fixtures',
Expand Down
6 changes: 4 additions & 2 deletions openbook/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from openbook_posts.views.post.views import PostComments, PostCommentItem, PostItem, PostReactions, PostReactionItem, \
PostReactionsEmojiCount, PostReactionEmojiGroups
from openbook_posts.views.posts.views import Posts, TrendingPosts
from openbook_importer.views import ImportItem
from openbook_importer.views import ImportItem, ImportedItem, ImportedItems

auth_patterns = [
path('register/', Register.as_view(), name='register-user'),
Expand Down Expand Up @@ -88,7 +88,9 @@
]

importer_patterns = [
path('upload/', ImportItem.as_view(), name='uploads')
path('upload/', ImportItem.as_view(), name='uploads'),
path('archives/', ImportedItems.as_view(), name='imported-archives'),
path('archive/<str:archive_id>', ImportedItem.as_view(), name='imported-archive'),
]

api_patterns = [
Expand Down
19 changes: 18 additions & 1 deletion openbook_auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from rest_framework.exceptions import ValidationError
from django.db.models import Q

from imagekit.processors import ResizeToFill
from imagekit.models import ProcessedImageField

from openbook.settings import USERNAME_MAX_LENGTH
from openbook_auth.exceptions import EmailVerificationTokenInvalid
from openbook_common.utils.model_loaders import get_connection_model, get_circle_model, get_follow_model, \
Expand Down Expand Up @@ -335,6 +338,9 @@ def has_reacted_to_post_with_id(self, post_id, emoji_id=None):
def has_commented_post_with_id(self, post_id):
return self.posts_comments.filter(post_id=post_id).count() > 0

def has_archive_with_id(self, archive_id):
return self.imports.filter(uuid=archive_id).exists()

def get_lists_for_follow_for_user_with_id(self, user_id):
self._check_is_following_user_with_id(user_id)
follow = self.get_follow_for_user_with_id(user_id)
Expand Down Expand Up @@ -880,6 +886,10 @@ def get_connection_for_user_with_id(self, user_id):
def get_follow_for_user_with_id(self, user_id):
return self.follows.get(followed_user_id=user_id)

def delete_archive_with_id(self, archive_id):
archive = self._check_can_delete_archive_with_id(archive_id)
return self.imports.filter(uuid=archive_id).delete()

def _make_get_post_with_id_query_for_user(self, user, post_id):
posts_query = self._make_get_posts_query_for_user(user)
posts_query.add(Q(id=post_id), Q.AND)
Expand Down Expand Up @@ -1218,6 +1228,12 @@ def _check_list_name_not_taken(self, list_name):
_('You already have a list with that name.'),
)

def _check_can_delete_archive_with_id(self, archive_id):
if not self.has_archive_with_id(archive_id):
raise ValidationError(
_('Can\'t delete an archive that does not belong to you.'),
)


@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
Expand All @@ -1244,7 +1260,8 @@ class UserProfile(models.Model):
location = models.CharField(_('location'), max_length=settings.PROFILE_LOCATION_MAX_LENGTH, blank=False, null=True)
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='profile')
birth_date = models.DateField(_('birth date'), null=False, blank=False)
avatar = models.ImageField(_('avatar'), blank=False, null=True)
avatar = ProcessedImageField(verbose_name=_('avatar'), processors=[ResizeToFill(500, 500)] ,blank=False, null=True, format='JPEG',
options={'quality': 75}, )
cover = models.ImageField(_('cover'), blank=False, null=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cover

bio = models.CharField(_('bio'), max_length=settings.PROFILE_BIO_MAX_LENGTH, blank=False, null=True)
url = models.URLField(_('url'), blank=False, null=True)
Expand Down
4 changes: 3 additions & 1 deletion openbook_common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.utils.translation import ugettext_lazy as _

# Create your views here.
from imagekit.models import ProcessedImageField
from openbook.settings import COLOR_ATTR_MAX_LENGTH
from openbook_common.validators import hex_color_validator

Expand Down Expand Up @@ -36,7 +37,8 @@ class Emoji(models.Model):
# Hex colour. #FFFFFF
color = models.CharField(_('color'), max_length=COLOR_ATTR_MAX_LENGTH, blank=False, null=False,
validators=[hex_color_validator], unique=False)
image = models.ImageField(_('image'), blank=False, null=False, unique=True)
image = ProcessedImageField(verbose_name=_('image'), blank=False, null=False, unique=True,
format='JPEG', options={'quality': 100})
created = models.DateTimeField(editable=False)
order = models.IntegerField(unique=False, default=100)

Expand Down
Loading