danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
594 stars 157 forks source link

the like and flagging... #support #92

Open nicoodakp opened 6 years ago

nicoodakp commented 6 years ago

Hi its me again,

I try to utilized the package with the like/dislike and flagging, I follow the comp example and doc to set up the setting.py and urls.py. but the liked and flagging only allow for authenticated user. (non-authenticated user redirect to my account/login page...)

If i were only using template tag the 'like' returns
'The current path, accounts/login/, didn't match any of these.'

I try to comment with a secondary email and then click liked, still have no luck. again the package is awesome, thanks a lot

urls.py

`from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path, re_path
from django.conf.urls import url, include
from django.views.i18n import JavaScriptCatalog
admin.autodiscover()

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('personal.urls')),
    path('contact', include('contact.urls')),
    path('posts/', include('posts.urls')),

    path('summernote/', include('django_summernote.urls')),
    path('comments/', include('django_comments_xtd.urls')),   # url(r'^comments/', include('tow.django_ajax_comments_xtd.urls')),
    url(r'^api-auth/', include('rest_framework.urls',
                               namespace='rest_framework')),

    ]

urlpatterns.extend([
        url(r'^jsi18n/$', JavaScriptCatalog.as_view(),
            name='javascript-catalog'),
        url(r'admin/', admin.site.urls),
    ])

if settings.DEBUG:
   urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
`

settings.py """

"""
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '+0u3er2%p@*ark_!5zda$e#mbeouyr!12q5*6i@_5qqy**cpsy'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'personal',
    'contact',

    'widget_tweaks',
    'django_summernote',
    'taggit',

    'django_comments_xtd',
    'django_comments',
    'posts',
    'django.contrib.sites',
    'taggit_templatetags2',
    # 'taggit_templatetags',
    'rest_framework',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ]

##XTD SETTING
ADMINS = (
    ('nicooda', 'kai.peng@uconn.edu'),
)
MANAGERS = ADMINS
USE_I18N = True
COMMENTS_APP = 'django_comments_xtd'
COMMENTS_XTD_CONFIRM_EMAIL = False  # Set to False to disable confirmation
COMMENTS_XTD_MAX_THREAD_LEVEL = 4
COMMENTS_XTD_LIST_ORDER = ('-thread_id', 'order')
COMMENTS_XTD_THREADED_EMAILS = True
COMMENTS_XTD_FROM_EMAIL = 'kai.peng@uconn.edu'
COMMENTS_XTD_CONTACT_EMAIL = 'kai.peng@uconn.edu'

SITE_ID = 7

COMMENTS_XTD_APP_MODEL_OPTIONS = {
    'posts.post': {
        'allow_flagging': True,
        'allow_feedback': True,
        'show_feedback': True,
    }
}

COMMENTS_XTD_API_USER_REPR = lambda u: u.get_full_name()

# LOGIN_URL = "/admin/login/"
# LOGIN_REDIRECT_URL = LOGIN_URL

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
                'django.template.context_processors.static',

            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
 'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'EST'

USE_I18N = True

USE_L10N = True

USE_TZ = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

### Media URL set up
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

# sendmail setting

EMAIL_HOST = "smtp.mail.com"
danirus commented 6 years ago

Hi @nicoodakp,

Yes... such a behavior is intentional. The code doesn't allow like/dislike, nor flagging, for non-registered users. Those actions use the CommentFlag model from django-contrib-comments, which require a user.

To allow non-registered users flag and like/dislike comments you would need a new model to either register the user (in case the flagging comes from a registered user) or register the email address. You would also need to send an email to the user to confirm that she's flagging/liking/disliking the comment. At the time of showing the list of users who liked/disliked a comment, would you show the username, email address or complete name?

As a user I don't see myself confirming these operations by email. I think that might as well be the reason behind the decision to require a user in the original django-comments framework. If I put myself in the position of giving my email address to confirm a simple like/dislike operation I would suspect that the final intention of the website is to collect email addresses.

Thanks for your positive feedback! :)

nicoodakp commented 6 years ago

thanks for the note, if I were only want to allow non-register customer to like/dislike, but only once for each ip address. what would be the best approach to this ? A new model ? a social-auth package ? or something else ? thanks

danirus commented 6 years ago

One proxy puts many users behind a single IP. Sorry, that's not a good solution.