-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/reinstate #8
base: master
Are you sure you want to change the base?
Changes from 9 commits
1afbc04
0fd58d1
15a0222
2e01355
c0ed389
6897ddc
fba7b91
ce623b2
4910ef2
f37879d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
checkout: | ||
post: | ||
- git submodule sync | ||
- git submodule update --init | ||
- git clone git@github.com:WhiskeyMedia/scout.git scout.git | ||
dependencies: | ||
override: | ||
|
||
cache_directories: | ||
- venv/src | ||
- ~/.pip/cache | ||
test: | ||
override: | ||
# - python setup.py test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from datetime import datetime, timedelta | ||
from redis import Redis | ||
|
||
from django.conf import settings | ||
from django.db import models | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.contrib.sites.models import Site | ||
|
@@ -17,6 +19,10 @@ | |
|
||
redis = Redis(**comments_settings.REDIS) | ||
|
||
EDIT_TIMER_ENABLED = getattr(settings, 'EDIT_TIMER_ENABLED', False) | ||
EDIT_TIMER_MINUTES = getattr(settings, 'EDIT_TIMER_MINUTES', 15) | ||
|
||
|
||
class CommentList(object): | ||
@classmethod | ||
def for_object(cls, content_object, reversed=False): | ||
|
@@ -128,6 +134,13 @@ def moderate_comment(self, comment, user=None, commit=True): | |
redis.lrem(self._key, comment.id) | ||
comment_was_moderated.send(FlatComment, comment=comment, user=user) | ||
|
||
def reinstate_comment(self, comment, request=None): | ||
# comments are removed from the redis cache when moderated | ||
# to be visible again, they must be reinstated as well | ||
redis.lrem(self._key, comment.id) | ||
redis.lpush(self._key, comment.id) | ||
return True, None | ||
|
||
def locked(self): | ||
return redis.sismember(comments_settings.LOCKED_KEY, self._id) | ||
|
||
|
@@ -158,7 +171,14 @@ def _comment_list(self, reversed=False): | |
self.__comment_list = CommentList(self.content_type, self.object_id, reversed) | ||
return self.__comment_list | ||
|
||
def reinstate(self, request=None): | ||
# re instate this comment for a user who has been unbanned | ||
return self._comment_list().reinstate_comment(self, request) | ||
|
||
def post(self, request=None): | ||
# update TESTED-442 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plese never reference internal tracker issues in open source code |
||
# must provide temporary submit_date to check if the comment is flooding | ||
self.submit_date = timezone.now() | ||
return self._comment_list().post_comment(self, request) | ||
|
||
def moderate(self, user=None, commit=True): | ||
|
@@ -178,3 +198,34 @@ def save(self, **kwargs): | |
if self.submit_date is None: | ||
self.submit_date = timezone.now() | ||
super(FlatComment, self).save(**kwargs) | ||
|
||
def has_edit_timer(self): | ||
'''has_edit_timer() -> bool | ||
''' | ||
return EDIT_TIMER_ENABLED | ||
|
||
def is_edit_timer_expired(self): | ||
'''is_edit_timer_expired() -> bool | ||
Check whether the comment is still within the allowed edit time | ||
from the creation time. | ||
''' | ||
age = datetime.now(self.submit_date.tzinfo) - self.submit_date | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use ella.utils.timezone.now() instead, this will break if not using TZ |
||
if age >= timedelta(minutes=EDIT_TIMER_MINUTES): | ||
return True | ||
return False | ||
|
||
def get_remaining_edit_time(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this returning a string? what possible use case is there? Return a datetime and use regular methods for rendering it as text There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the utility of returning this as a string. I'm also unable to find any other code that consumes the 'get_remaining_edit_time' function. I'll see if I can track down the original author and figure out the reasoning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in that case just remove it, we can add it later if we find we need it - the less code the better :) |
||
'''get_remaining_edit_time() -> str | ||
Returns the remaining edit time from comment creation. The returned | ||
string is formatted as HH:MM:SS, e.g. 0:01:23 | ||
''' | ||
age = datetime.now(self.submit_date.tzinfo) - self.submit_date | ||
edit_time = timedelta(minutes=EDIT_TIMER_MINUTES) | ||
if age >= edit_time: | ||
return '0:00:00' | ||
seconds = edit_time.total_seconds() - age.total_seconds() | ||
remaining = timedelta(seconds=seconds) | ||
text = str(remaining) | ||
text = text.split('.')[0] | ||
return text | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use comment_settings for these values as well.