-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
117 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,31 @@ | |
from django.shortcuts import get_object_or_404 | ||
from django.contrib.auth.models import User | ||
|
||
from gedgo.models import Gedcom | ||
from gedgo.models import Gedcom, Comment | ||
|
||
|
||
class CommentForm(forms.Form): | ||
message = forms.CharField() | ||
class CommentForm(forms.ModelForm): | ||
class Meta: | ||
model = Comment | ||
fields = ('text', 'upload', 'gedcom', 'person', 'blogpost') | ||
|
||
def email_comment(self, user, noun, file_names): | ||
def email_comment(self, request): | ||
cd = self.cleaned_data | ||
message_body = '%s\n\n%s' % (cd['message'], '\n'.join(file_names)) | ||
content = '%s\n\n---------------\n\n%s' % ( | ||
'%s://%s/admin/gedgo/comment/%s' % ( | ||
'https' if request.is_secure() else 'http', | ||
request.get_host(), | ||
self.instance.id, | ||
), | ||
cd['text'] | ||
) | ||
send_mail( | ||
'Comment from %s %s about %s' % ( | ||
user.first_name, | ||
user.last_name, | ||
noun | ||
request.user.first_name, | ||
request.user.last_name, | ||
self.instance.noun | ||
), | ||
message_body, | ||
content, | ||
'[email protected]', | ||
settings.SERVER_EMAIL | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.2 on 2018-01-20 19:09 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('gedgo', '0002_auto_20180120_1030'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.TextField()), | ||
('posted', models.DateTimeField(auto_now_add=True)), | ||
('upload', models.FileField(blank=True, null=True, upload_to=b'uploads/comments')), | ||
('blogpost', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='gedgo.BlogPost')), | ||
('gedcom', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='gedgo.Gedcom')), | ||
('person', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='gedgo.Person')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ class Meta: | |
) | ||
|
||
def __unicode__(self): | ||
return self.title | ||
return 'Blogpost "%s"' % self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class Comment(models.Model): | ||
class Meta: | ||
app_label = 'gedgo' | ||
|
||
user = models.ForeignKey(User) | ||
text = models.TextField() | ||
posted = models.DateTimeField(auto_now_add=True) | ||
upload = models.FileField(upload_to='uploads/comments', null=True, blank=True) | ||
|
||
gedcom = models.ForeignKey('Gedcom', null=True, blank=True) | ||
person = models.ForeignKey('Person', null=True, blank=True) | ||
blogpost = models.ForeignKey('BlogPost', null=True, blank=True) | ||
|
||
@property | ||
def noun(self): | ||
if self.blogpost: | ||
return self.blogpost | ||
elif self.person: | ||
return self.person | ||
return self.gedcom | ||
|
||
def __unicode__(self): | ||
return 'Comment about %s by %s (%d)' % (self.noun, self.user, self.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
|
||
STORAGES = { | ||
'default': default_storage, | ||
'research': research_storage, | ||
'gedcom': gedcom_storage | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters