Skip to content

Commit

Permalink
change: class name pin to PinnedPost #6450
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfred committed May 1, 2020
1 parent 349aa7d commit ad1d69f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/townsquare/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils.html import format_html

from .models import (
Announcement, Comment, Flag, Like, Pin, MatchRanking, MatchRound, Offer, OfferAction, SquelchProfile, SuggestedAction,
Announcement, Comment, Flag, Like, PinnedPost, MatchRanking, MatchRound, Offer, OfferAction, SquelchProfile, SuggestedAction,
)


Expand All @@ -30,7 +30,7 @@ class MatchRankingAdmin(admin.ModelAdmin):
list_display = ['created_on', '__str__']
raw_id_fields = ['profile', 'round']

class PinAdmin(admin.ModelAdmin):
class PinnedAdmin(admin.ModelAdmin):
list_display = ['created_on', '__str__']
raw_id_fields = ['user', 'activity']
fields = ['hash_what']
Expand Down Expand Up @@ -156,7 +156,7 @@ class AnnounceAdmin(admin.ModelAdmin):
admin.site.register(Comment, GenericAdmin)
admin.site.register(Like, GenericAdmin)
admin.site.register(Flag, GenericAdmin)
admin.site.register(Pin, PinAdmin)
admin.site.register(PinnedPost, PinnedAdmin)
admin.site.register(MatchRound, ActuallyGenericAdmin)
admin.site.register(MatchRanking, MatchRankingAdmin)
admin.site.register(Announcement, AnnounceAdmin)
18 changes: 18 additions & 0 deletions app/townsquare/migrations/0022_auto_20200501_1436.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2020-05-01 14:36

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0105_auto_20200430_1352'),
('townsquare', '0021_auto_20200428_0137'),
]

operations = [
migrations.RenameModel(
old_name='Pin',
new_name='PinnedPost',
),
]
4 changes: 2 additions & 2 deletions app/townsquare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def __str__(self):
return f"Favorite {self.activity.activity_type}:{self.activity_id} by {self.user}"


class Pin(SuperModel):
"""Model for each Pinned."""
class PinnedPost(SuperModel):
"""Model for each Pinned Post."""

user = models.ForeignKey('dashboard.Profile',
on_delete=models.CASCADE, related_name='pins')
Expand Down
14 changes: 7 additions & 7 deletions app/townsquare/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from retail.views import get_specific_activities

from .models import (
Announcement, Comment, Favorite, Flag, Like, Pin, MatchRanking, MatchRound, Offer, OfferAction, SuggestedAction,
Announcement, Comment, Favorite, Flag, Like, PinnedPost, MatchRanking, MatchRound, Offer, OfferAction, SuggestedAction,
)
from .tasks import increment_offer_view_counts
from .utils import is_user_townsquare_enabled
Expand Down Expand Up @@ -542,22 +542,22 @@ def api(request, activity_id):
elif request.POST['direction'] == 'unfavorite':
Favorite.objects.filter(user=request.user, activity=activity).delete()

# Pin request
# PinnedPost request
elif request.POST.get('method') == 'pin':
hash = hashlib.sha256()
hash.update(str(time.time()))
hash_what = hash.hexdigest()

if request.POST['direction'] == 'pin':
already_pins = Pin.objects.filter(activity=activity, user=request.user, hash_what=hash_what).exists()
already_pins = PinnedPost.objects.filter(activity=activity, user=request.user, hash_what=hash_what).exists()
if not already_pins:
Pin.objects.create(activity=activity, user=request.user, hash_what=hash_what)
PinnedPost.objects.create(activity=activity, user=request.user, hash_what=hash_what)
else:
Pin.objects.filter(activity=activity, user=request.user, hash_what=hash_what).delete()
Pin.objects.create(activity=activity, user=request.user, hash_what=hash_what)
PinnedPost.objects.filter(activity=activity, user=request.user, hash_what=hash_what).delete()
PinnedPost.objects.create(activity=activity, user=request.user, hash_what=hash_what)

elif request.POST['direction'] == 'unpin':
Pin.objects.filter(activity=activity, user=request.user, hash_what=hash_what).delete()
PinnedPost.objects.filter(activity=activity, user=request.user, hash_what=hash_what).delete()

# flag request
elif request.POST.get('method') == 'flag':
Expand Down

0 comments on commit ad1d69f

Please sign in to comment.