From 3a9d1b6863496c862405d08bd61ee9fcbb207f04 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Thu, 25 Jan 2018 16:50:19 -0500 Subject: [PATCH] Add Description field to Teams, allow Markdown for team and event descriptions, use Bootstrap layouts for team and event pages --- events/forms.py | 6 +- .../migrations/0008_add-team-description.py | 18 +++++ events/models/profiles.py | 5 +- .../templates/get_together/show_event.html | 63 +++++++++++---- .../templates/get_together/show_team.html | 79 ++++++++++++------- get_together/templatetags/__init__.py | 0 get_together/templatetags/markup.py | 45 +++++++++++ requirements.txt | 5 +- 8 files changed, 168 insertions(+), 53 deletions(-) create mode 100644 events/migrations/0008_add-team-description.py create mode 100644 get_together/templatetags/__init__.py create mode 100644 get_together/templatetags/markup.py diff --git a/events/forms.py b/events/forms.py index 786f895..2ab6bc7 100644 --- a/events/forms.py +++ b/events/forms.py @@ -149,7 +149,7 @@ class DateTimeWidget(SplitDateTimeWidget): class TeamForm(ModelForm): class Meta: model = Team - fields = ['name', 'country', 'spr', 'city', 'web_url', 'tz'] + fields = ['name', 'description', 'country', 'spr', 'city', 'web_url', 'tz'] widgets = { 'country': Lookup(source='/api/country/', label='name'), 'spr': Lookup(source='/api/spr/', label='name'), @@ -160,13 +160,13 @@ class TeamForm(ModelForm): class NewTeamForm(ModelForm): class Meta: model = Team - fields = ['name', 'city', 'web_url', 'tz'] + fields = ['name', 'description', 'city', 'web_url', 'tz'] widgets = { #'country': Lookup(source='/api/country/', label='name'), #'spr': Lookup(source='/api/spr/', label='name'), 'city': Lookup(source='/api/cities/', label='name'), } - raw_id_fields = ('country','spr','city') + raw_id_fields = ('city') class TeamEventForm(ModelForm): class Meta: diff --git a/events/migrations/0008_add-team-description.py b/events/migrations/0008_add-team-description.py new file mode 100644 index 0000000..8d88012 --- /dev/null +++ b/events/migrations/0008_add-team-description.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0 on 2018-01-25 21:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0007_add-city-lonlat'), + ] + + operations = [ + migrations.AddField( + model_name='team', + name='description', + field=models.TextField(blank=True, help_text='Team Description', null=True), + ), + ] diff --git a/events/models/profiles.py b/events/models/profiles.py index 362085d..a5aaf16 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -26,7 +26,7 @@ class UserProfile(models.Model): def __str__(self): try: if self.realname: - return "%s (%s)" % (self.user.username, self.realname) + return self.realname return "%s" % self.user.username except: return "Unknown Profile" @@ -121,6 +121,8 @@ class Team(models.Model): name = models.CharField(_("Team Name"), max_length=256, null=False, blank=False) organization = models.ForeignKey(Organization, null=True, blank=True, on_delete=models.CASCADE) + description = models.TextField(help_text=_('Team Description'), blank=True, null=True) + country = models.ForeignKey(Country, on_delete=models.CASCADE) spr = models.ForeignKey(SPR, null=True, blank=True, on_delete=models.CASCADE) city = models.ForeignKey(City, null=True, blank=True, on_delete=models.CASCADE) @@ -178,7 +180,6 @@ class Member(models.Model): @property def role_name(self): - print("Role name: %s=%s" % (self.role, Member.ROLES[self.role])) return Member.ROLES[self.role][1] def __str__(self): diff --git a/get_together/templates/get_together/show_event.html b/get_together/templates/get_together/show_event.html index 26b97f4..43ca213 100644 --- a/get_together/templates/get_together/show_event.html +++ b/get_together/templates/get_together/show_event.html @@ -1,25 +1,54 @@ {% extends "get_together/base.html" %} +{% load markup %} {% block content %} -

About {{ event.name }}

+
+
+
+

{{ event.name }} + {% if can_edit_event %} + Edit Event + {% endif %} + {% if not is_attending %} + Attend + {% endif %} +

Hosted by {{ team.name }}


-

Hosted by {{ team.name }}

-{% include "events/event_details.html" %} -
+

{{ event.summary|markdown }}

-

Attendees ({{attendee_list.count}})

-{% include "events/attendee_list.html" with attendee_list=attendee_list %} -
+ + + + + + + {% if event.web_url %} + + + {% endif %} + +
Time:{{ event.start_time }} - {{ event.end_time }}
Place:{% if event.place %}{{ event.place }}{% else %}No place selected yet.{% endif %}
Website:{{ event.web_url }}
+
+
-{% if not is_attending %} -
- -
-{% endif %} -{% if can_edit_event %} -
- -
-{% endif %} +
+
+
+

Attendees ({{attendee_list.count}})


+
+ {% for attendee in attendee_list %} +
+

+ {{ attendee.user }} + {% if attendee.role > 0 %}{{ attendee.role_name }}{% endif %} +

+
+
{{ attendee.status_name }}
+
+ {% endfor %} +
+
+
+
{% endblock %} diff --git a/get_together/templates/get_together/show_team.html b/get_together/templates/get_together/show_team.html index 30bd2e1..3fc2c12 100644 --- a/get_together/templates/get_together/show_team.html +++ b/get_together/templates/get_together/show_team.html @@ -1,37 +1,58 @@ {% extends "get_together/base.html" %} +{% load markup %} {% block content %} -

Welcome to {{ team.name }}

+
+
+
+

Welcome to {{ team.name }} + {% if can_edit_team %} + Edit Team + {% endif %} + {% if is_member %} + {% if not team.owner_profile == request.user.profile %}Leave Team{% endif %} + {% else %} + Join Team + {% endif %} +


-

Members

-{% include "events/member_list.html" %} -
+ {% if team.description %}

{{ team.description|markdown }}


{% endif %} -

Upcoming Events

-{% include "events/event_list.html" %} -
+

Upcoming Events

+
+ {% for event in events_list %} +
+ +
{{ event.place }}
+
{{ event.start_time }}
+
+ {% endfor %} + {% if can_create_event %} + + {% endif %} +
+
+
-{% if can_create_event %} -
-
- -
-{% endif %} - -{% if can_edit_team %} -
- -
-{% endif %} - -{% if is_member %} -
- -
-{% else %} -
- -
-{% endif %} +
+
+

Members


+ {% for member in member_list %} +
+

+ {{member.user}} + {% if member.role > 0 %}{{ member.role_name }}{% endif %} +

+
+
+ {% endfor %} +
+
+
+
{% endblock %} diff --git a/get_together/templatetags/__init__.py b/get_together/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/get_together/templatetags/markup.py b/get_together/templatetags/markup.py new file mode 100644 index 0000000..6feca71 --- /dev/null +++ b/get_together/templatetags/markup.py @@ -0,0 +1,45 @@ +""" +Copied from Django 1.4 alpha + +Set of "markup" template filters for Django. These filters transform plain text +markup syntaxes to HTML; currently there is support for: + + * Textile, which requires the PyTextile library available at + http://loopcore.com/python-textile/ + + * Markdown, which requires the Python-markdown library from + http://www.freewisdom.org/projects/python-markdown + + * reStructuredText, which requires docutils from http://docutils.sf.net/ +""" + +from django import template +from django.template.defaultfilters import stringfilter +from django.conf import settings +from django.utils.safestring import mark_safe + +import markdown as md + +register = template.Library() + +@register.filter +@stringfilter +def markdown(value, arg=''): + """ + Runs Markdown over a given value, optionally using various + extensions python-markdown supports. + + Syntax:: + + {{ value|markdown:"extension1_name,extension2_name..." }} + + To enable safe mode, which strips raw HTML and only returns HTML + generated by actual Markdown syntax, pass "safe" as the first + extension in the list. + + If the version of Markdown in use does not support extensions, + they will be silently ignored. + + """ + return mark_safe(md.markdown(value)) + diff --git a/requirements.txt b/requirements.txt index fd056de..f933233 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,12 @@ certifi==2017.11.5 chardet==3.0.4 defusedxml==0.5.0 +dj-database-url==0.4.2 Django==2.0 +django-settings-export==1.2.1 djangorestframework==3.7.7 idna==2.6 +Markdown==2.6.11 oauthlib==2.0.6 PyJWT==1.5.3 python3-openid==3.1.0 @@ -15,5 +18,3 @@ six==1.11.0 social-auth-app-django==2.1.0 social-auth-core==1.6.0 urllib3==1.22 -dj-database-url==0.4.2 -django-settings-export==1.2.1