Add support for login and sharing with Facebook and Twitter if app keys are defined
This commit is contained in:
parent
8c3358a60b
commit
aa50e85b9a
9 changed files with 122 additions and 5 deletions
|
@ -73,6 +73,10 @@ class Event(models.Model):
|
|||
def get_absolute_url(self):
|
||||
return reverse('show-event', kwargs={'event_id': self.id, 'event_slug': self.slug})
|
||||
|
||||
def get_full_url(self):
|
||||
site = Site.objects.get(id=1)
|
||||
return "https://%s%s" % (site.domain, self.get_absolute_url())
|
||||
|
||||
@property
|
||||
def slug(self):
|
||||
return slugify(self.name)
|
||||
|
|
|
@ -151,12 +151,16 @@ GOOGLE_ANALYTICS_ID=None
|
|||
GOOGLE_MAPS_API_KEY=None
|
||||
SOCIAL_AUTH_GITHUB_KEY=None
|
||||
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=None
|
||||
SOCIAL_AUTH_FACEBOOK_KEY=None
|
||||
SOCIAL_AUTH_TWITTER_KEY=None
|
||||
SETTINGS_EXPORT = [
|
||||
'DEBUG',
|
||||
'GOOGLE_ANALYTICS_ID',
|
||||
'GOOGLE_MAPS_API_KEY',
|
||||
'SOCIAL_AUTH_GITHUB_KEY',
|
||||
'SOCIAL_AUTH_GOOGLE_OAUTH2_KEY',
|
||||
'SOCIAL_AUTH_FACEBOOK_KEY',
|
||||
'SOCIAL_AUTH_TWITTER_KEY',
|
||||
]
|
||||
|
||||
# Make django messages framework use Bootstrap's alert style classes
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<title>Get Together</title>
|
||||
<title>{% block title %}Get Together{% block add_to_title %}{% endblock %}{% endblock %}</title>
|
||||
|
||||
{% block meta %}{% endblock %}
|
||||
|
||||
{% if settings.GOOGLE_ANALYTICS_ID %}
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
|
|
84
get_together/templates/get_together/events/share_event.html
Normal file
84
get_together/templates/get_together/events/share_event.html
Normal file
|
@ -0,0 +1,84 @@
|
|||
{% extends "get_together/base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block add_to_totle %} | {{event.name}}{% endblock %}
|
||||
|
||||
{% block meta %}
|
||||
<meta property="og:url" content="{{event.get_full_url}}" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:title" content="{{event.name}}" />
|
||||
<meta property="og:description" content="{{event.summary}}" />
|
||||
<meta property="og:image" content="https://gettogether.community{% static 'img/team_placeholder.png' %}" />
|
||||
<link rel="canonical" href="{{event.get_full_url}}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}
|
||||
<script>
|
||||
window.fbAsyncInit = function() {
|
||||
FB.init({
|
||||
appId : '{{settings.SOCIAL_AUTH_FACEBOOK_KEY}}',
|
||||
autoLogAppEvents : true,
|
||||
xfbml : true,
|
||||
version : 'v2.12'
|
||||
});
|
||||
};
|
||||
|
||||
(function(d, s, id){
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) {return;}
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "https://connect.facebook.net/en_US/sdk.js";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
|
||||
function shareFacebook() {
|
||||
FB.ui({
|
||||
display: 'popup',
|
||||
method: 'share',
|
||||
href: '{{event.get_full_url}}',
|
||||
quote: 'I\'m having a Get Together!\n\n{{event.summary}}',
|
||||
hashtag: '#gettogether',
|
||||
summary: "Let's have a Get Together!"
|
||||
}, function(response){});
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
|
||||
<script>window.twttr = (function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0],
|
||||
t = window.twttr || {};
|
||||
if (d.getElementById(id)) return t;
|
||||
js = d.createElement(s);
|
||||
js.id = id;
|
||||
js.src = "https://platform.twitter.com/widgets.js";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
|
||||
t._e = [];
|
||||
t.ready = function(f) {
|
||||
t._e.push(f);
|
||||
};
|
||||
|
||||
return t;
|
||||
}(document, "script", "twitter-wjs"));
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<h2>Announce your Get Together</h2>
|
||||
<div class="layout">
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}<a href="#" onClick="shareFacebook()"; class="btn btn-primary">Facebook</a>{% endif %}
|
||||
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
|
||||
<a class="btn btn-primary"
|
||||
href="https://twitter.com/intent/tweet?text=I'm+having+a+get+together!%0D{{event.summary|urlencode}}&original_referer={{event.get_full_url|urlencode}}&url={{event.get_full_url|urlencode}}&hashtags=gettogether"
|
||||
data-size="large">
|
||||
Twitter</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col">
|
||||
<a href="{{event.get_absolute_url}}" class="btn btn-secondary">Share later</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,5 +1,15 @@
|
|||
{% extends "get_together/base.html" %}
|
||||
{% load markup %}
|
||||
{% load markup static %}
|
||||
|
||||
{% block add_to_totle %} | {{event.name}}{% endblock %}
|
||||
|
||||
{% block meta %}
|
||||
<meta property="og:url" content="{{event.get_full_url}}" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:title" content="{{event.name}}" />
|
||||
<meta property="og:description" content="{{event.summary}}" />
|
||||
<meta property="og:image" content="https://gettogether.community{% static 'img/team_placeholder.png' %}" />
|
||||
{% endblock %}
|
||||
|
||||
{% block styles %}
|
||||
<style>
|
||||
|
@ -26,6 +36,9 @@
|
|||
{% if not is_attending %}
|
||||
<a href="{% url 'attend-event' event.id %}" class="btn btn-success btn-sm">Attend</a>
|
||||
{% endif %}
|
||||
{% if can_edit_event %}
|
||||
<a href="{% url 'share-event' event.id %}" class="btn btn-primary btn-sm">Share</a>
|
||||
{% endif %}
|
||||
</h2><p class="text-muted">Hosted by <a href="{% url "show-team" team.id %}">{{ team.name }}</a></p><hr/>
|
||||
|
||||
<p>{{ event.summary|markdown }}</p>
|
||||
|
|
|
@ -10,8 +10,10 @@
|
|||
<a class="btn btn-primary" href="{% url 'social:begin' 'twitter' %}">Twitter</a>
|
||||
-->
|
||||
{% if settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY %}<span><a class="btn btn-primary" href="{% url 'social:begin' 'google-oauth2' %}">Google</a></span>{% endif %}
|
||||
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}<span><a class="btn btn-primary" href="{% url 'social:begin' 'facebook' %}">Faceboook</a></span>{% endif %}
|
||||
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}<span><a class="btn btn-primary" href="{% url 'social:begin' 'twitter' %}">Twitter</a></span>{% endif %}
|
||||
{% if settings.SOCIAL_AUTH_GITHUB_KEY %}<span><a class="btn btn-primary" href="{% url 'social:begin' 'github' %}">GitHub</a></span>{% endif %}
|
||||
{% if settings.DEBUG %}<span><a class="btn btn-primary" href="{% url 'admin:login' %}">Local</a></span>{% endif %}
|
||||
{% if settings.DEBUG %}<span><a class="btn btn-secondary" href="{% url 'admin:login' %}">Local</a></span>{% endif %}
|
||||
<br>
|
||||
</center>
|
||||
{% endblock %}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<br />
|
||||
<button type="submit" class="btn btn-primary">Announce your Get Together!</button>
|
||||
</form>
|
||||
<a class="btn btn-secondary" href="{{ event.get_absolute_url }}">Add a Place later</a>
|
||||
<a class="btn btn-secondary" href="{% url 'share-event' event.id %}">Add a Place later</a>
|
||||
</div>
|
||||
<div id="map" class="col-5"></div>
|
||||
</div>
|
||||
|
|
|
@ -50,6 +50,7 @@ urlpatterns = [
|
|||
path('events/<int:event_id>/+attend/', event_views.attend_event, name='attend-event'),
|
||||
path('events/<int:event_id>/+delete/', views.delete_event, name='delete-event'),
|
||||
path('events/<int:event_id>/+add_place/', views.add_place_to_event, name='add-place'),
|
||||
path('events/<int:event_id>/+share/', views.share_event, name='share-event'),
|
||||
path('events/<int:event_id>/<str:event_slug>/', views.show_event, name='show-event'),
|
||||
|
||||
path('places/', views.places_list, name='places'),
|
||||
|
|
|
@ -82,7 +82,7 @@ def add_place_to_event(request, event_id):
|
|||
new_place = form.save()
|
||||
event.place = new_place
|
||||
event.save()
|
||||
return redirect(event.get_absolute_url())
|
||||
return redirect('share-event', event.id)
|
||||
else:
|
||||
context = {
|
||||
'event': event,
|
||||
|
@ -92,6 +92,13 @@ def add_place_to_event(request, event_id):
|
|||
else:
|
||||
return redirect('home')
|
||||
|
||||
def share_event(request, event_id):
|
||||
event = Event.objects.get(id=event_id)
|
||||
context = {
|
||||
'event': event,
|
||||
}
|
||||
return render(request, 'get_together/events/share_event.html', context)
|
||||
|
||||
def edit_event(request, event_id):
|
||||
event = Event.objects.get(id=event_id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue