Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyconbalkan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'pyconbalkan.cfp',
'pyconbalkan.contact',
'pyconbalkan.news',
'pyconbalkan.sponsoring',
'pyconbalkan.coc',
# others
'rest_framework',
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions pyconbalkan/sponsoring/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions pyconbalkan/sponsoring/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class SponsoringConfig(AppConfig):
name = 'sponsoring'
25 changes: 25 additions & 0 deletions pyconbalkan/sponsoring/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.0.5 on 2018-06-25 10:56

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Sponsoring',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('organization', models.CharField(blank=True, max_length=100, null=True)),
('name', models.CharField(max_length=256)),
('phone', models.CharField(blank=True, max_length=17, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')])),
('email', models.EmailField(max_length=254)),
],
),
]
Empty file.
63 changes: 63 additions & 0 deletions pyconbalkan/sponsoring/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from django.db import models
from django import forms
from django.forms import ModelForm
from django.core.validators import RegexValidator
from django.forms.widgets import RadioSelect


class Sponsoring(models.Model):
organization = models.CharField(max_length=100, null=True, blank=True)
name = models.CharField(max_length=256)
phone_regex = RegexValidator(
regex=r'^\+?1?\d{9,15}$',
message=
"Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed."
)
phone = models.CharField(
validators=[phone_regex], max_length=17, blank=True)
email = models.EmailField()

def __str__(self):
sponsoring_str = '{} | {} | {}'.format(self.name, self.phone,
self.email)
if self.organization:
return '{} | {}'.format(sponsoring_str, self.organization)
return sponsoring_str


class SponsoringForm(ModelForm):
organization = forms.CharField(
widget=forms.TextInput(attrs={'class': 'form-control'}),
max_length=100,
required=False,
label='Sponsor Organization')
organization_type = forms.ChoiceField(choices=((0, 'For - profit corporation'), (1, 'Foundation / Non profit')), label='Type of organization', widget=RadioSelect())
name = forms.CharField(
widget=forms.TextInput(attrs={'class': 'form-control'}),
max_length=256,
error_messages={'required': 'Please, enter your name.'},
label='Name and Surname')
phone = forms.CharField(
widget=forms.TextInput(attrs={'class': 'form-control'}),
max_length=17,
error_messages={
'required': 'Please enter your phone number.',
'invalid': 'Please enter a valid phone number.'
},
label='Phone number')
email = forms.EmailField(
widget=forms.TextInput(attrs={'class': 'form-control'}),
error_messages={
'required': 'Please, enter a valid email address.',
'invalid': 'Please enter a valid email address.'
},
label='e-mail')
CHOICES = (('platinum', '5000'),
('gold', '2500'),
('silver', '1000'),
('bronze', '500'),)
level = forms.ChoiceField(choices=CHOICES, label='Level of sponsorship', widget=RadioSelect())

class Meta:
model = Sponsoring
fields = '__all__'
8 changes: 8 additions & 0 deletions pyconbalkan/sponsoring/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from pyconbalkan.sponsoring.models import Sponsoring


class SponsoringSerializer(serializers.ModelSerializer):
class Meta:
model = Sponsoring
fields = '__all__'
24 changes: 24 additions & 0 deletions pyconbalkan/sponsoring/templates/sponsoring.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "base.html" %}

{% block main_content %}

{# Sponsoring #}

<h1 class="title title--yellow mb-xs-40">Sponsoring</h1>
<hr class="line line--blue line--short line--spaced">

<form class="form" action="{% url 'sponsoring' %}" method="POST" enctype="multipart/form-data" novalidate>
<div class="form-group">
{% csrf_token %}
{{ form.as_p }}
<input class="button button--yellow button--push" type="submit" value="Donate" />
</div>
</form>

{% if success %}
<div class="success-message">
{{ success }}
</div>
{% endif %}

{% endblock %}
3 changes: 3 additions & 0 deletions pyconbalkan/sponsoring/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
27 changes: 27 additions & 0 deletions pyconbalkan/sponsoring/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from rest_framework import viewsets
from rest_framework.permissions import AllowAny

from pyconbalkan.sponsoring.serializers import SponsoringSerializer
from pyconbalkan.sponsoring.models import Sponsoring
from django.shortcuts import render
from .models import SponsoringForm


class SponsoringViewSet(viewsets.ModelViewSet):
queryset = Sponsoring.objects.all()
serializer_class = SponsoringSerializer
permission_classes = [AllowAny]


def sponsoring_view(request):
context = {}
if request.method == 'POST':
form = SponsoringForm(request.POST)
if form.is_valid():
form.save()
context['success'] = 'Thank you for taking the part in PyCon Balkan 2018! '
form = SponsoringForm()
else:
form = SponsoringForm()
context['form'] = form
return render(request, 'sponsoring.html', context)
2 changes: 2 additions & 0 deletions pyconbalkan/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pyconbalkan.news.api_urls import router as news
from pyconbalkan.coc.api_urls import router as coc
from pyconbalkan.timetable.views import timetable_view
from pyconbalkan.sponsoring.views import sponsoring_view

from markdownx import urls as markdownx

Expand All @@ -44,6 +45,7 @@
path('robots.txt', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
path('organizers/<slug:slug>/', organizer_view, name='organizer_detail'),
path('organizers', organizers_listview, name='organizers'),
path('sponsoring', sponsoring_view, name='sponsoring'),
path('about', about_view, name='about'),
path('contact', contact_view, name='contact'),
path('cfp', cfp_view, name='cfp'),
Expand Down