Skip to content

Commit

Permalink
Merge pull request #1008 from gorkemarslan/restructure-project
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie authored Sep 13, 2021
2 parents 6af86c4 + ae83ee9 commit 763b138
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 73 deletions.
1 change: 0 additions & 1 deletion project/accounts/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.apps import AppConfig
from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import action
from rest_framework.response import Response
Expand Down
44 changes: 4 additions & 40 deletions project/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
import os
import uuid
import io
from django.utils.deconstruct import deconstructible
from django.core.files.storage import default_storage
from django.conf import settings
from django.db import models
from PIL import Image, ImageOps
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.contrib.auth import get_user_model
from core.constants import US_STATES

from taggit.managers import TaggableManager

from api.models.category import Category
from common.utils import PathAndRename


class User(AbstractUser):
Expand Down Expand Up @@ -78,8 +75,7 @@ def card_summarize(self, account, request_account):
"username": account.user.username,
"first_name": account.first_name,
"last_name": account.last_name,
"about_me": account.about_me[:about_me_truncate_length]
+ (ellipsis_if_too_long),
"about_me": account.about_me[:about_me_truncate_length] + ellipsis_if_too_long,
"profile_image": account.profile_image_url,
"follow_state": True
if account in request_account.following.all()
Expand All @@ -95,18 +91,6 @@ def following(self, account):
return [self.chip_summarize(following) for following in account.following.all()]


@deconstructible
class PathAndRename(object):
def __init__(self, sub_path):
self.sub_path = sub_path

def __call__(self, instance, filename):
extension = filename.split(".")[-1]
new_filename = str(uuid.uuid4())
filename = "{}.{}".format(new_filename, extension)
return os.path.join(self.sub_path, filename)


profile_upload_path = PathAndRename("")


Expand Down Expand Up @@ -141,12 +125,9 @@ class Account(models.Model):

@property
def full_name(self):
"Returns the person's full name."
"""Returns the person's full name."""

full_name = "{first_name} {last_name}".format(
first_name=self.first_name, last_name=self.last_name
)
return full_name
return f"{self.first_name} {self.last_name}"

@property
def profile_image_url(self):
Expand Down Expand Up @@ -174,9 +155,6 @@ def profile_image_thumb_url(self):

return "/static/img/no_image_md.png"

def __init__(self, *args, **kwargs):
super(Account, self).__init__(*args, **kwargs)

def save(self, *args, **kwargs):
"""Image crop/resize and thumbnail creation"""

Expand Down Expand Up @@ -240,17 +218,3 @@ def is_full_account(self):
return True
else:
return False

@deconstructible
class PathAndRename(object):
def __init__(self, sub_path):
self.sub_path = sub_path

def __call__(self, instance, filename):
extension = filename.split(".")[-1]
new_filename = str(uuid.uuid4())
filename = "{}.{}".format(new_filename, extension)
return os.path.join(self.sub_path, filename)


profile_upload_path = PathAndRename("")
15 changes: 1 addition & 14 deletions project/api/models/civi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
import json
import datetime
import math
import uuid
from calendar import month_name

from django.core.files.storage import default_storage
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from django.conf import settings
from django.utils.deconstruct import deconstructible

from accounts.models import Account
from .thread import Thread
from taggit.managers import TaggableManager
from .thread import Thread
from core.constants import CIVI_TYPES
from common.utils import PathAndRename


class CiviManager(models.Manager):
Expand Down Expand Up @@ -278,18 +277,6 @@ def dict_with_score(self, req_acct_id=None):
return data


@deconstructible
class PathAndRename(object):
def __init__(self, sub_path):
self.sub_path = sub_path

def __call__(self, instance, filename):
extension = filename.split(".")[-1]
new_filename = str(uuid.uuid4())
filename = "{}.{}".format(new_filename, extension)
return os.path.join(self.sub_path, filename)


image_upload_path = PathAndRename("")


Expand Down
15 changes: 1 addition & 14 deletions project/api/models/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
"""

import os
import uuid
from calendar import month_name

from django.core.files.storage import default_storage
from django.conf import settings
from django.db import models
from django.utils.deconstruct import deconstructible

from accounts.models import Account
from .category import Category
from .fact import Fact
from taggit.managers import TaggableManager
from core.constants import US_STATES
from common.utils import PathAndRename


class ThreadManager(models.Manager):
Expand Down Expand Up @@ -67,18 +66,6 @@ def filter_by_category(self, categories):
return self.all().filter(category__in=categories)


@deconstructible
class PathAndRename(object):
def __init__(self, sub_path):
self.sub_path = sub_path

def __call__(self, instance, filename):
extension = filename.split(".")[-1]
new_filename = str(uuid.uuid4())
filename = "{}.{}".format(new_filename, extension)
return os.path.join(self.sub_path, filename)


image_upload_path = PathAndRename("")


Expand Down
4 changes: 0 additions & 4 deletions project/api/write.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import PIL
import urllib
import uuid

from notifications.signals import notify

Expand All @@ -18,13 +17,10 @@

from django.core.files import File # need this for image file handling
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import user_passes_test
from django.contrib.sites.shortcuts import get_current_site

# civi packages
from api.forms import UpdateProfileImage
from api.models import Thread
from accounts.utils import send_mass_email
from .models import Activity, Category, Civi, CiviImage
from accounts.models import Account
from core.custom_decorators import require_post_params
Expand Down
Empty file added project/common/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions project/common/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import uuid
from django.utils.deconstruct import deconstructible


@deconstructible
class PathAndRename(object):
def __init__(self, sub_path):
self.sub_path = sub_path

def __call__(self, instance, filename):
extension = filename.split(".")[-1]
new_filename = str(uuid.uuid4())
filename = "{}.{}".format(new_filename, extension)
return os.path.join(self.sub_path, filename)

0 comments on commit 763b138

Please sign in to comment.