Skip to content
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

[#659] Added created_at and last_modified_at to project comments #707

Merged
merged 7 commits into from
Aug 11, 2014
7 changes: 4 additions & 3 deletions akvo/rsr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,10 @@ class ResultIndicatorAdmin(admin.ModelAdmin):


class ProjectCommentAdmin(admin.ModelAdmin):
list_display = ('project', 'user', 'comment', 'time', )
list_filter = ('project', 'time', )
list_display = ('project', 'user', 'comment', 'created_at', )
list_filter = ('project', 'created_at', )
search_fields = ('project__id', 'project__title', 'user__first_name', 'user__last_name',)
readonly_fields = ('created_at', 'last_modified_at')

admin.site.register(get_model('rsr', 'projectcomment'), ProjectCommentAdmin)

Expand All @@ -906,7 +907,7 @@ class ProjectUpdateAdmin(TimestampsAdminDisplayMixin, admin.ModelAdmin):

fieldsets = (
(_(u'General Information'), {
'fields': ('project','user','update_method', ),
'fields': ('project','user','update_method', 'created_at', 'last_modified_at'),
}),
(_(u'Content'), {
'fields': ('title','text','language', ),
Expand Down

Large diffs are not rendered by default.

577 changes: 577 additions & 0 deletions akvo/rsr/migrations/0060_projectcomment_autodates.py

Large diffs are not rendered by default.

570 changes: 570 additions & 0 deletions akvo/rsr/migrations/0061_auto__del_field_projectcomment_time.py

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions akvo/rsr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1844,11 +1844,10 @@ def __unicode__(self):
return u'Project update for %(project_name)s' % {'project_name': self.project.title}


class ProjectComment(models.Model):
class ProjectComment(TimestampsMixin, models.Model):
project = models.ForeignKey(Project, verbose_name=_(u'project'), related_name='comments')
user = models.ForeignKey(User, verbose_name=_(u'user'))
comment = ValidXMLTextField(_(u'comment'))
time = models.DateTimeField(_(u'time'), db_index=True)

class Meta:
verbose_name = _(u'project comment')
Expand Down
15 changes: 7 additions & 8 deletions akvo/rsr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def projectupdates(request, project_id):
'''
project = get_object_or_404(Project, pk=project_id)
updates = project.project_updates.all().order_by('-created_at')
comments = project.comments.all().order_by('-time')[:3]
comments = project.comments.all().order_by('-created_at')[:3]
can_add_update = project.connected_to_user(request.user)
return {
'project': project,
Expand All @@ -650,7 +650,7 @@ def projectupdate(request, project_id, update_id):
can_add_update = project.connected_to_user(request.user)
can_edit_update = (update.user == request.user and can_add_update and
not update.edit_window_has_expired())
comments = project.comments.all().order_by('-time')[:3]
comments = project.comments.all().order_by('-created_at')[:3]
edit_timeout = settings.PROJECT_UPDATE_TIMEOUT
return {
'project': project,
Expand All @@ -673,7 +673,7 @@ def projectcomments(request, project_id):
updates: list of updates, ordered by time in reverse
'''
project = get_object_or_404(Project, pk=project_id)
comments = Project.objects.get(id=project_id).comments.all().order_by('-time')
comments = Project.objects.get(id=project_id).comments.all().order_by('-created_at')
form = CommentForm()
updates = project.project_updates.all().order_by('-created_at')[:3]
can_add_update = project.connected_to_user(request.user)
Expand Down Expand Up @@ -776,7 +776,6 @@ def commentform(request, project_id):
if form.is_valid():
comment = form.save(commit=False)
comment.project = p
comment.time = datetime.now()
comment.user = request.user
comment.save()
return HttpResponseRedirect(reverse('project_comments', args=[project_id]))
Expand Down Expand Up @@ -812,7 +811,7 @@ def projectmain(request, project, draft=False, can_add_update=False):
'''
all_updates = project.project_updates.all().order_by('-created_at')
updates_with_images = all_updates.exclude(photo__exact='').order_by('-created_at')
comments = project.comments.all().order_by('-time')[:3]
comments = project.comments.all().order_by('-created_at')[:3]
# comprehensions are fun! here we use it to get the categories that
# don't contain only 0 value benchmarks
benchmarks = project.benchmarks.filter(
Expand Down Expand Up @@ -846,7 +845,7 @@ def projectdetails(request, project_id):
@render_to('rsr/project/project_partners.html')
def projectpartners(request, project, draft=False, can_add_update=False):
updates = project.project_updates.all().order_by('-created_at')[:3]
comments = project.comments.all().order_by('-time')[:3]
comments = project.comments.all().order_by('-created_at')[:3]
can_add_update = project.connected_to_user(request.user)
return {
'can_add_update': can_add_update,
Expand All @@ -864,7 +863,7 @@ def projectpartners(request, project, draft=False, can_add_update=False):
def projectfunding(request, project, draft=False, can_add_update=False):
public_donations = project.public_donations()
updates = project.project_updates.all().order_by('-created_at')[:3]
comments = project.comments.all().order_by('-time')[:3]
comments = project.comments.all().order_by('-created_at')[:3]
can_add_update = project.connected_to_user(request.user)
return {
'can_add_update': can_add_update,
Expand Down Expand Up @@ -927,7 +926,7 @@ def templatedev(request, template_name):
SAMPLE_ORG_ID = 42
p = Project.objects.get(pk=SAMPLE_PROJECT_ID)
updates = Project.objects.get(id=SAMPLE_PROJECT_ID).project_updates.all().order_by('-created_at')[:3]
comments = Project.objects.get(id=SAMPLE_PROJECT_ID).comments.all().order_by('-time')[:3]
comments = Project.objects.get(id=SAMPLE_PROJECT_ID).comments.all().order_by('-created_at')[:3]
grid_projects = Project.objects.filter(current_image__startswith='img').order_by('?')[:12]

projects = Project.objects.published()
Expand Down
2 changes: 1 addition & 1 deletion akvo/templates/rsr/project/project_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ <h2>{% trans 'Comments' %}</h2>
<p style="padding:5px; margin-bottom:5px;">
{{ c.comment|capfirst }}<br />
<span class="grey small">
{{c.user.get_full_name}}, {{c.time|date:"Y-m-d H:i"}}
{{c.user.get_full_name}}, {{c.created_at|date:"Y-m-d H:i"}}
</span>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion akvo/templates/rsr/project/project_comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2>{% trans 'All comments' %}</h2>
<p style="margin:0;">
{{c.comment|capfirst}}<br />
<span class="grey small">
{{c.user.get_full_name}}, {{c.time|date:"Y-m-d H:i"}},
{{c.user.get_full_name}}, {{c.created_at|date:"Y-m-d H:i"}},
<a href="mailto:[email protected]?subject={% blocktrans with project.id as p_id and c.id as c_id %}Comment%20abuse%20in%20project%20%23{{p_id}}%2C%20comment%20#{{c_id}}{% endblocktrans %}">{% trans 'Report abuse' %}</a>
</span>
</p>
Expand Down