Commit 9a7068d9 authored by fred's avatar fred

trivial: apply black

parent bbe60799
from django import forms
from .models import Subscriber, Newsletter
class SubscribeForm(forms.ModelForm):
class Meta:
model = Subscriber
......@@ -10,4 +11,4 @@ class SubscribeForm(forms.ModelForm):
class NewsletterForm(forms.ModelForm):
class Meta:
model = Newsletter
exclude = ('expedition_datetime', )
exclude = ('expedition_datetime',)
......@@ -31,7 +31,7 @@ class Command(BaseCommand):
help = 'Load newsletter subscribers from a Spip dump file'
def handle(self, filename, verbosity, **options):
self.verbose = (verbosity > 1)
self.verbose = verbosity > 1
with open(filename) as fd:
if self.verbose:
......@@ -40,8 +40,10 @@ class Command(BaseCommand):
# the spip_courriers parts of the spip export are not properly
# encoded, we manually remove them here so the XML file can be
# parsed correctly.
content = content[:content.find('<spip_courriers>')] + \
content[content.rfind('</spip_courriers>')+17:]
content = (
content[: content.find('<spip_courriers>')]
+ content[content.rfind('</spip_courriers>') + 17 :]
)
self.root = ET.fromstring(content)
self.load_authors()
......
......@@ -6,9 +6,8 @@ from ...models import Subscriber
class Command(BaseCommand):
def handle(self, verbosity, **kwargs):
self.verbose = (verbosity > 1)
self.verbose = verbosity > 1
for subscriber in Subscriber.objects.filter(is_validated=True).exclude(is_registered=True):
if self.verbose:
......
......@@ -7,18 +7,23 @@ import ckeditor.fields
class Migration(migrations.Migration):
dependencies = [
]
dependencies = []
operations = [
migrations.CreateModel(
name='Newsletter',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
(
'id',
models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True),
),
('subject', models.CharField(max_length=50, verbose_name='Title')),
('date', models.DateField(verbose_name='Date')),
('text', ckeditor.fields.RichTextField(null=True, verbose_name='Text', blank=True)),
('expedition_datetime', models.DateTimeField(null=True, verbose_name='Expedition Date/time', blank=True)),
(
'expedition_datetime',
models.DateTimeField(null=True, verbose_name='Expedition Date/time', blank=True),
),
],
options={
'ordering': ['date'],
......@@ -30,15 +35,17 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Subscriber',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
(
'id',
models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True),
),
('email', models.EmailField(unique=True, max_length=75)),
('inscription_date', models.DateField(auto_now_add=True)),
('is_validated', models.NullBooleanField()),
('is_registered', models.NullBooleanField()),
('password', models.CharField(max_length=100)),
],
options={
},
options={},
bases=(models.Model,),
),
]
......@@ -25,7 +25,7 @@ from django.core.mail import send_mail
from ckeditor.fields import RichTextField
class Subscriber(models.Model) :
class Subscriber(models.Model):
email = models.EmailField(unique=False)
inscription_date = models.DateField(auto_now_add=True)
is_validated = models.NullBooleanField()
......@@ -36,7 +36,7 @@ class Subscriber(models.Model) :
user_agent = models.CharField(max_length=1000, blank=True)
source_ip = models.CharField(max_length=100, blank=True)
def __unicode__(self) :
def __unicode__(self):
return self.email
def is_from_bot(self):
......@@ -49,8 +49,12 @@ class Subscriber(models.Model) :
confirm_subject = loader.get_template('newsletter/confirmation_email_subject.txt')
confirm_body = loader.get_template('newsletter/confirmation_email_body.txt')
context = {'token': self.password}
send_mail(confirm_subject.render(context).strip(), confirm_body.render(context),
settings.NEWSLETTER_SENDER, [self.email])
send_mail(
confirm_subject.render(context).strip(),
confirm_body.render(context),
settings.NEWSLETTER_SENDER,
[self.email],
)
self.is_validated = False
self.save()
......@@ -63,7 +67,6 @@ class Subscriber(models.Model) :
class Newsletter(models.Model):
class Meta:
verbose_name = _('Newsletter')
verbose_name_plural = _('Newsletters')
......
from django.conf.urls import url
from django.conf import settings
from .views import (subscribe, thanks, confirmation, stats,
newsletter_list, newsletter_create, newsletter_view, newsletter_update,
newsletter_send)
from .views import (
subscribe,
thanks,
confirmation,
stats,
newsletter_list,
newsletter_create,
newsletter_view,
newsletter_update,
newsletter_send,
)
urlpatterns = [
url(r'^$', subscribe, name='newsletter-subscribe'),
......
......@@ -38,9 +38,10 @@ class SubscribeView(CreateView):
self.object.bot_check2 = bool('validation2' not in self.request.POST)
# keep various data, for bot stats
self.object.source_ip = (
self.request.META.get('HTTP_X_FORWARDED_FOR') or
self.request.META.get('HTTP_X_REAL_IP') or
self.request.META.get('REMOTE_ADDR'))
self.request.META.get('HTTP_X_FORWARDED_FOR')
or self.request.META.get('HTTP_X_REAL_IP')
or self.request.META.get('REMOTE_ADDR')
)
self.object.user_agent = self.request.META.get('HTTP_USER_AGENT')
self.object.save()
if not self.object.is_from_bot():
......@@ -53,6 +54,8 @@ subscribe = SubscribeView.as_view()
class ThanksView(TemplateView):
template_name = 'newsletter/thanks.html'
thanks = ThanksView.as_view()
......@@ -65,6 +68,8 @@ class ConfirmationView(TemplateView):
subscriber.is_validated = True
subscriber.save()
return context
confirmation = ConfirmationView.as_view()
......@@ -84,20 +89,24 @@ class NewsletterCreateView(CreateView):
initial['date'] = datetime.datetime.today()
return initial
newsletter_create = NewsletterCreateView.as_view()
class NewsletterListView(ListView):
model = Newsletter
newsletter_list = NewsletterListView.as_view()
class NewsletterDetailView(DetailView):
model = Newsletter
newsletter_view = NewsletterDetailView.as_view()
class NewsletterUpdateView(UpdateView):
form_class = NewsletterForm
model = Newsletter
......@@ -107,11 +116,13 @@ class NewsletterUpdateView(UpdateView):
raise PermissionDenied()
return super(NewsletterUpdateView, self).get_form(*args, **kwargs)
newsletter_update = NewsletterUpdateView.as_view()
class NewsletterSendView(RedirectView):
permanent = False
def get_redirect_url(self, pk):
if not self.request.user.has_perm('newsletter.add_newsletter'):
raise PermissionDenied()
......@@ -120,8 +131,10 @@ class NewsletterSendView(RedirectView):
newsletter.send()
return reverse_lazy('newsletter-list')
newsletter_send = NewsletterSendView.as_view()
@csrf_exempt
def stats(request) :
def stats(request):
return JsonResponse({'data': {'registered': Subscriber.objects.filter(is_registered=True).count()}})
......@@ -29,8 +29,11 @@ def get_version():
with open('VERSION', 'r') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(['git', 'describe', '--dirty=.dirty', '--match=v*'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(
['git', 'describe', '--dirty=.dirty', '--match=v*'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
result = p.communicate()[0]
if p.returncode == 0:
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
......@@ -41,9 +44,7 @@ def get_version():
version = result
return version
else:
return '0.0.post%s' % len(
subprocess.check_output(
['git', 'rev-list', 'HEAD']).splitlines())
return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
return '0.0'
......@@ -60,6 +61,7 @@ class compile_translations(Command):
def run(self):
try:
from django.core.management import call_command
for path, dirs, files in os.walk('newsletter'):
if 'locale' not in dirs:
continue
......@@ -107,5 +109,5 @@ setup(
'compile_translations': compile_translations,
'install_lib': install_lib,
'sdist': sdist,
}
},
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment