Beispiel #1
0
def make_gig_feed(the_band):

    the_gigs = gig.get_gigs_for_band_keys(the_band.key,
                                          show_canceled=False,
                                          show_only_public=True,
                                          show_past=False,
                                          confirmed_only=True,
                                          start_date=datetime.datetime.now())
    feed = u"""<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
"""

    feed = u"{0}\n<title>{1} Gigs</title>".format(feed, the_band.name)
    feed = u"{0}\n<link>{1}{2}</link>".format(
        feed, "http://gig-o-matic.appspot.com/feeds/", the_band.key.urlsafe())
    feed = u"{0}\n<description>{1} Gigs</description>".format(
        feed, the_band.name)

    for a_gig in the_gigs:
        feed = u"{0}\n<item>".format(feed)
        feed = u"{0}\n<title>{1}</title>".format(feed, a_gig.title)
        feed = u'{0}\n<guid isPermaLink="false">{1}</guid>'.format(
            feed, a_gig.key.urlsafe())
        if a_gig.contact:
            the_date = member.format_date_for_member(a_gig.contact.get(),
                                                     a_gig.date, "long")
        else:
            the_date = a_gig.date

        if a_gig.settime:
            the_time = u' - {0}'.format(a_gig.settime)
        else:
            the_time = u''

        if a_gig.rss_description:
            the_desc = a_gig.rss_description
        else:
            the_desc = ''

        feed = u"{0}\n<description><![CDATA[{1}{2}\n\n{3}]]></description>".format(
            feed, the_date, the_time, the_desc)
        # feed=u"{0}\n<description>{1}{2}\n\n{3}</description>".format(feed, the_date, the_time, a_gig.rss_description)
        feed = u"{0}\n</item>".format(feed)
    feed = u"{0}{1}".format(feed, """
</channel>
</rss>
""")

    return feed
Beispiel #2
0
    def get(self):
        the_user = self.user
        the_band_keyurl = self.request.get('bk', '0')

        the_band_key = band.band_key_from_urlsafe(the_band_keyurl)

        self.response.headers['Content-Type'] = 'application/x-gzip'
        self.response.headers[
            'Content-Disposition'] = 'attachment; filename=archive.csv'

        the_band_key_url = self.request.get("bk", None)
        if the_band_key_url is None:
            raise gigoexceptions.GigoException(
                'no band key passed to GigArchivePage handler')
        else:
            the_band_key = band.band_key_from_urlsafe(the_band_key_url)

        # make sure this member is actually in the band
        if assoc.confirm_user_is_member(
                the_user.key,
                the_band_key) is None and the_user.is_superuser is not True:
            raise gigoexceptions.GigoException(
                'user called GigArchivePage handler but is not member')

        the_band = band.get_band(the_band_key)
        if the_band is None:
            raise gigoexceptions.GigoException(
                'GigArchivePage handler called without a band')

        the_gigs = gig.get_gigs_for_band_keys(the_band_key, show_past=True)

        data = "date,name,status,committed,pay"
        for g in the_gigs:
            plans = plan.get_plans_for_gig_key(g.key,
                                               keys_only=True,
                                               plan_values=[1, 2])
            # num=len([p for p in plans if p.value in [1,2]])
            num = len(plans)
            stat = 0
            if (g.status and g.status in [0, 1, 2]):
                stat = g.status
            data = u"{0}\n{1},\"{2}\",{3},{4},\"{5}\"".format(
                data, member.format_date_for_member(the_user, g.date, 'short'),
                g.title, gig.Gig.status_names[stat], num, g.paid)

        self.response.write(data)
Beispiel #3
0
def make_gig_feed(the_band):

    the_gigs = gig.get_gigs_for_band_keys(the_band.key, show_canceled=False, show_only_public=True, show_past=False, confirmed_only=True, start_date=datetime.datetime.now())
    feed = u"""<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
"""

    feed=u"{0}\n<title>{1} Gigs</title>".format(feed, the_band.name)
    feed=u"{0}\n<link>{1}{2}</link>".format(feed, "http://www.gig-o-matic.com/feeds/",the_band.key.urlsafe())
    feed=u"{0}\n<description>{1} Gigs</description>".format(feed, the_band.name)

    for a_gig in the_gigs:
        feed=u"{0}\n<item>".format(feed)
        feed=u"{0}\n<title>{1}</title>".format(feed, a_gig.title)
        feed=u'{0}\n<guid isPermaLink="false">{1}</guid>'.format(feed, a_gig.key.urlsafe())
        if a_gig.contact:
            the_date = member.format_date_for_member(a_gig.contact.get(),a_gig.date,"long")
        else:
            the_date = a_gig.date

        if a_gig.settime:
            the_time = u' - {0}'.format(a_gig.settime)
        else:
            the_time = u''

        if a_gig.rss_description:
            the_desc = a_gig.rss_description
        else:
            the_desc = ''

        feed=u"{0}\n<description><![CDATA[{1}{2}\n\n{3}]]></description>".format(feed, the_date, the_time, the_desc)
        # feed=u"{0}\n<description>{1}{2}\n\n{3}</description>".format(feed, the_date, the_time, a_gig.rss_description)
        feed=u"{0}\n</item>".format(feed)
    feed=u"{0}{1}".format(feed,"""
</channel>
</rss>
""")

    return feed
Beispiel #4
0
    def get(self):
        the_user = self.user
        the_band_keyurl=self.request.get('bk','0')

        the_band_key = band.band_key_from_urlsafe(the_band_keyurl)

        self.response.headers['Content-Type'] = 'application/x-gzip'
        self.response.headers['Content-Disposition'] = 'attachment; filename=archive.csv'
        
        the_band_key_url=self.request.get("bk",None)
        if the_band_key_url is None:
            raise gigoexceptions.GigoException('no band key passed to GigArchivePage handler')
        else:
            the_band_key = band.band_key_from_urlsafe(the_band_key_url)
        
        # make sure this member is actually in the band
        if assoc.confirm_user_is_member(the_user.key, the_band_key) is None and the_user.is_superuser is not True:
            raise gigoexceptions.GigoException('user called GigArchivePage handler but is not member')

        the_band = band.get_band(the_band_key)
        if the_band is None:
            raise gigoexceptions.GigoException('GigArchivePage handler called without a band')

        the_gigs = gig.get_gigs_for_band_keys(the_band_key, show_past=True)

        data="date,name,status,committed,pay"
        for g in the_gigs:
            plans = plan.get_plans_for_gig_key(g.key, keys_only=True, plan_values=[1,2])
            # num=len([p for p in plans if p.value in [1,2]])
            num = len(plans)
            stat=0
            if (g.status and g.status in [0,1,2]):
                stat = g.status
            data=u"{0}\n{1},\"{2}\",{3},{4},\"{5}\"".format(data, member.format_date_for_member(the_user, g.date, 'short'),g.title,gig.Gig.status_names[stat],num,g.paid)

        self.response.write(data)
Beispiel #5
0
    def _make_page(self,the_user):
        """ construct page for grid view """
        
        # find the bands this member is associated with
        if not the_user.is_superuser:
            the_assocs = assoc.get_confirmed_assocs_of_member(the_user)
            the_band_keys = [a.band for a in the_assocs]
        else:
            the_band_keys = band.get_all_bands(keys_only=True)
        
        if the_band_keys is None or len(the_band_keys)==0:
            return self.redirect('/member_info.html?mk={0}'.format(the_user.key.urlsafe()))
            
        # find the band we're interested in
        band_key_str=self.request.get("bk", None)
        if band_key_str is None:
            the_band_key = the_band_keys[0]
        else:
            the_band_key = ndb.Key(urlsafe=band_key_str)

        month_str=self.request.get("m",None)
        year_str=self.request.get("y",None)
        if month_str==None or year_str==None:
            start_date = datetime.datetime.now().replace(day=1)
        else:
            delta=0
            delta_str=self.request.get("d",None)
            if delta_str != None:
                delta=int(delta_str)
            year=int(year_str)
            month=int(month_str)
            month=month+delta
            if month>12:
                month = 1
                year = year+1
            if month<1:
                month=12
                year = year-1
            start_date = datetime.datetime(year=year, month=month, day=1)
        
        end_date = start_date
        if (end_date.month < 12):
            end_date = end_date.replace(month = end_date.month + 1, day = 1)
        else:
            end_date = end_date.replace(year = end_date.year + 1, month=1, day=1)

        show_canceled=True
        if the_user.preferences and the_user.preferences.hide_canceled_gigs:
            show_canceled=False

        the_gigs = gig.get_gigs_for_band_key_for_dates(the_band_key, start_date, end_date, get_canceled=show_canceled)
        the_member_assocs = band.get_assocs_of_band_key_by_section_key(the_band_key, include_occasional=False)

        the_plans = {}
        for section in the_member_assocs:
            for an_assoc in section[1]:
                member_key=an_assoc.member
                member_plans = {}
                for a_gig in the_gigs:
                    the_plan = plan.get_plan_for_member_key_for_gig_key(the_member_key=member_key, the_gig_key=a_gig.key)
                    if the_plan is not None:
                        member_plans[a_gig.key] = the_plan.value
                the_plans[member_key] = member_plans
                

        template_args = {
            'all_band_keys' : the_band_keys,
            'the_band_key' : the_band_key,
            'the_member_assocs_by_section' : the_member_assocs,
            'the_month_string' : member.format_date_for_member(the_user, start_date, 'month'),
            'the_month' : start_date.month,
            'the_year' : start_date.year,
            'the_date_formatter' : member.format_date_for_member,
            'the_gigs' : the_gigs,
            'the_plans' : the_plans,
            'grid_is_active' : True
        }
        self.render_template('grid.html', template_args)
Beispiel #6
0
def send_newgig_email(the_member, the_gig, the_band, the_gig_url, is_edit=False, change_string=""):
 
    the_locale=the_member.preferences.locale
    the_email_address = the_member.email_address
    
    if not mail.is_email_valid(the_email_address):
        return False

    i18n.get_i18n().set_locale(the_locale)
        
    contact_key=the_gig.contact
    if contact_key:
        contact = contact_key.get()
        contact_name=contact.name
    else:
        contact = None
        contact_name="??"        
        
    message = mail.EmailMessage()
    message.sender = SENDER_EMAIL
    if contact is not None:
        message.reply_to = contact.email_address
    message.to = the_email_address
    if is_edit:
        title_string='{0} ({1})'.format(_('Gig Edit'),change_string)
    else:
        title_string=_('New Gig:')
    message.subject = '{0} {1}'.format(title_string, the_gig.title)
#     message.body = u"""
# Hello! A new gig has been added to the Gig-o-Matic for your band {0}:
# 
# {1}
# Date: {2}
# Time: {3}
# Contact: {4}
# 
# {5}
# 
# Can you make it? You can (and should!) weigh in here: {6}
# 
# Thanks,
# The Gig-o-Matic Team
# 
#     """.format(the_band.name, the_gig.title, the_gig.date, the_gig.settime, contact_name, the_gig.details, the_gig_url)
    the_date_string = "{0} ({1})".format(member.format_date_for_member(the_member, the_gig.date),
                                       member.format_date_for_member(the_member, the_gig.date, "day"))

    the_time_string = ""
    if the_gig.calltime:
        the_time_string = u'{0} ({1})'.format(the_gig.calltime, _('Call Time'))
    if the_gig.settime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,the_gig.settime, _('Set Time'))
    if the_gig.endtime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,the_gig.endtime, _('End Time'))
        
    the_status_string=[_('Unconfirmed'), _('Confirmed!'), _('Cancelled!')][the_gig.status]
        
    if is_edit is False:
        message.body=_('new_gig_email').format(the_band.name, the_gig.title, the_date_string, the_time_string, contact_name, the_status_string, the_gig.details, the_gig_url)
    else:
        message.body=_('edited_gig_email').format(the_band.name, the_gig.title, the_date_string, the_time_string, contact_name, the_status_string, the_gig.details, the_gig_url, change_string)
        
    try:
        message.send()
    except:
        logging.error('failed to send email!')
        
    return True
Beispiel #7
0
def send_newgig_email(the_member, the_gig, the_band, the_gig_url, is_edit=False, is_reminder=False, change_string=""):
 
    the_locale=the_member.preferences.locale
    the_email_address = the_member.email_address
    
    if not mail.is_email_valid(the_email_address):
        return False

    i18n.get_i18n().set_locale(the_locale)
        
    contact_key=the_gig.contact
    if contact_key:
        contact = contact_key.get()
        contact_name=contact.name
    else:
        contact = None
        contact_name="??"        

    # get the special URLs for "yes" and "no" answers
    the_yes_url, the_no_url, the_snooze_url = gig.get_confirm_urls(the_member, the_gig)

    reply_to = None
    if contact is not None:
       reply_to = contact.email_address
    if is_edit:
        title_string='{0} ({1})'.format(_('Gig Edit'),change_string)
    elif is_reminder:
        title_string='Gig Reminder:'
    else:
        title_string=_('New Gig:')
    the_date_string = "{0} ({1})".format(member.format_date_for_member(the_member, the_gig.date),
                                       member.format_date_for_member(the_member, the_gig.date, "day"))

    if the_gig.enddate:
        the_date_string = "{0} - {1} ({2})".format( the_date_string,
                                                    member.format_date_for_member(the_member, the_gig.enddate),
                                                    member.format_date_for_member(the_member, the_gig.enddate, "day"))

    the_time_string = ""
    if the_gig.calltime:
        the_time_string = u'{0} ({1})'.format(the_gig.calltime, _('Call Time'))
    if the_gig.settime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,the_gig.settime, _('Set Time'))
    if the_gig.endtime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,the_gig.endtime, _('End Time'))
        
    the_status_string = [_('Unconfirmed'), _('Confirmed!'), _('Cancelled!')][the_gig.status]

    def format_body(body_format_str):
        return body_format_str.format(the_band.name, the_gig.title, the_date_string, the_time_string, contact_name,
                                      the_status_string, the_gig.details, the_gig_url, "", the_yes_url, the_no_url,
                                      the_snooze_url)

    if is_edit:
        body = _('edited_gig_email').format(the_band.name, the_gig.title, the_date_string, the_time_string, contact_name,
                                            the_status_string, the_gig.details, the_gig_url, change_string)
        html = None
    elif is_reminder:
        body = format_body(_('reminder_gig_email'))
        html = format_body(_('reminder_gig_email_html'))
    else:
        body = format_body(_('new_gig_email'))
        html = format_body(_('new_gig_email_html'))

    return _send_admin_mail(the_email_address, u'{0} {1}'.format(title_string, the_gig.title), body, html=html, reply_to=reply_to)
Beispiel #8
0
    def _make_page(self, the_user):
        """ construct page for grid view """

        # find the bands this member is associated with
        if not the_user.is_superuser:
            the_assocs = assoc.get_confirmed_assocs_of_member(the_user)
            the_band_keys = [a.band for a in the_assocs]
        else:
            the_band_keys = band.get_all_bands(keys_only=True)

        if the_band_keys is None or len(the_band_keys) == 0:
            return self.redirect('/member_info.html?mk={0}'.format(
                the_user.key.urlsafe()))

        # find the band we're interested in
        band_key_str = self.request.get("bk", None)
        if band_key_str is None:
            the_band_key = the_band_keys[0]
        else:
            the_band_key = ndb.Key(urlsafe=band_key_str)

        month_str = self.request.get("m", None)
        year_str = self.request.get("y", None)
        if month_str == None or year_str == None:
            start_date = datetime.datetime.now().replace(day=1)
        else:
            delta = 0
            delta_str = self.request.get("d", None)
            if delta_str != None:
                delta = int(delta_str)
            year = int(year_str)
            month = int(month_str)
            month = month + delta
            if month > 12:
                month = 1
                year = year + 1
            if month < 1:
                month = 12
                year = year - 1
            start_date = datetime.datetime(year=year, month=month, day=1)

        end_date = start_date
        if (end_date.month < 12):
            end_date = end_date.replace(month=end_date.month + 1, day=1)
        else:
            end_date = end_date.replace(year=end_date.year + 1, month=1, day=1)

        show_canceled = True
        if the_user.preferences and the_user.preferences.hide_canceled_gigs:
            show_canceled = False

        the_gigs = gig.get_gigs_for_band_key_for_dates(
            the_band_key, start_date, end_date, get_canceled=show_canceled)

        all_plans = []
        for g in the_gigs:
            all_plans.append(plan.get_plans_for_gig_key(g.key))

        the_member_assocs = band.get_assocs_of_band_key_by_section_key(
            the_band_key, include_occasional=False)

        the_plans = {}
        for section in the_member_assocs:
            for an_assoc in section[1]:
                member_key = an_assoc.member
                member_plans = {}
                for i in range(0, len(the_gigs)):
                    gig_plans = all_plans[i]
                    for p in gig_plans:
                        if p.member == member_key:
                            member_plans[p.key.parent()] = p.value
                            break
                the_plans[member_key] = member_plans

        # the_plans = {}
        # for section in the_member_assocs:
        #     for an_assoc in section[1]:
        #         member_key=an_assoc.member
        #         member_plans = {}
        #         for a_gig in the_gigs:
        #             the_plan = plan.get_plan_for_member_key_for_gig_key(the_member_key=member_key, the_gig_key=a_gig.key, keys_only=True)
        #             if the_plan is not None:
        #                 member_plans[a_gig.key] = the_plan.get().value
        #         the_plans[member_key] = member_plans

        template_args = {
            'all_band_keys':
            the_band_keys,
            'the_band_key':
            the_band_key,
            'the_member_assocs_by_section':
            the_member_assocs,
            'the_month_string':
            member.format_date_for_member(the_user, start_date, 'month'),
            'the_month':
            start_date.month,
            'the_year':
            start_date.year,
            'the_date_formatter':
            member.format_date_for_member,
            'the_gigs':
            the_gigs,
            'the_plans':
            the_plans,
            'grid_is_active':
            True
        }
        self.render_template('grid.html', template_args)
Beispiel #9
0
    def _make_page(self, the_user):

        # find the gig we're interested in
        gig_key_str = self.request.get("gk", None)
        if gig_key_str is None:
            self.response.write('no gig key passed in!')
            return  # todo figure out what to do if there's no ID passed in

        gig_key = gig.gig_key_from_urlsafe(gig_key_str)
        the_gig = gig_key.get()

        if the_gig is None:
            template_args = {}
            self.render_template('no_gig_found.html', template_args)
            return  # todo figure out what to do if we didn't find it

        the_comment_text = None
        if the_gig.comment_id:
            the_comment_text = gigcomment.get_comment(the_gig.comment_id)

        if not the_gig.is_archived:

            the_band_key = the_gig.key.parent()
            the_plans, the_plan_counts, the_sections, band_has_sections = _makeInfoPageInfo(
                the_user, the_gig, the_band_key)

            # is the current user a band admin?
            the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(
                the_user, the_band_key)
            the_band = the_band_key.get()
            user_can_edit = gig.can_edit_gig(the_user, the_gig, the_band)
            user_can_create = gig.can_edit_gig(the_user, None, the_band)

            datestr = member.format_date_for_member(the_user,
                                                    the_gig.date,
                                                    format="long")
            if the_gig.enddate:
                enddatestr = u' - {0}'.format(
                    member.format_date_for_member(the_user,
                                                  the_gig.enddate,
                                                  format="long"))
            else:
                enddatestr = ''

            if the_gig.address:
                if the_gig.address.startswith('http'):
                    address_link = the_gig.address
                else:
                    address_link = u"http://maps.google.com?q={0}".format(
                        the_gig.address.replace(' ', '+'))
            else:
                address_link = ''

            template_args = {
                'gig': the_gig,
                'date_str': datestr,
                'enddate_str': enddatestr,
                'the_plans': the_plans,
                'the_sections': the_sections,
                'comment_text': the_comment_text,
                'band_has_sections': band_has_sections,
                'the_user_is_band_admin': the_user_is_band_admin,
                'user_can_edit': user_can_edit,
                'user_can_create': user_can_create,
                'the_plan_counts': the_plan_counts,
                'address_link': address_link
            }
            self.render_template('gig_info.html', template_args)

        else:
            # this is an archived gig
            the_archived_plans = gigarchive.get_archived_plans(
                the_gig.archive_id)
            template_args = {
                'gig': the_gig,
                'archived_plans': the_archived_plans,
                'comment_text': the_comment_text
            }
            self.render_template('gig_archived_info.html', template_args)
Beispiel #10
0
    def _make_page(self, the_user):
        """ construct page for grid view """

        # find the bands this member is associated with
        if not the_user.is_superuser:
            the_assocs = assoc.get_confirmed_assocs_of_member(the_user)
            the_band_keys = [a.band for a in the_assocs]
        else:
            the_band_keys = band.get_all_bands(keys_only=True)

        if the_band_keys is None or len(the_band_keys) == 0:
            return self.redirect('/member_info.html?mk={0}'.format(the_user.key.urlsafe()))

        # find the band we're interested in
        band_key_str = self.request.get("bk", None)
        if band_key_str is None:
            the_band_key = the_band_keys[0]
        else:
            the_band_key = ndb.Key(urlsafe=band_key_str)

        month_str = self.request.get("m", None)
        year_str = self.request.get("y", None)
        if month_str == None or year_str == None:
            start_date = datetime.datetime.now().replace(day=1)
        else:
            delta = 0
            delta_str = self.request.get("d", None)
            if delta_str != None:
                delta = int(delta_str)
            year = int(year_str)
            month = int(month_str)
            month = month + delta
            if month > 12:
                month = 1
                year = year + 1
            if month < 1:
                month = 12
                year = year - 1
            start_date = datetime.datetime(year=year, month=month, day=1)

        end_date = start_date
        if (end_date.month < 12):
            end_date = end_date.replace(month=end_date.month + 1, day=1)
        else:
            end_date = end_date.replace(year=end_date.year + 1, month=1, day=1)

        show_canceled = True
        # if the_user.preferences and the_user.preferences.hide_canceled_gigs:
        #     show_canceled = False

        the_gigs = gig.get_all_gig_dates_for_band(the_band_key)
        gig_date_counts={}
        for g in the_gigs:
            ut = '{0}-{1}'.format(g.date.year, g.date.month)
            if ut in gig_date_counts.keys():
                gig_date_counts[ut] += 1
            else:
                gig_date_counts[ut] = 1

        template_args = {
            'all_band_keys': the_band_keys,
            'the_band_key': the_band_key,
            'the_month_string': member.format_date_for_member(the_user, start_date, 'month'),
            'the_month': start_date.month,
            'the_year': start_date.year,
            'has_gigs': len(the_gigs) > 0,
            'date_counts': gig_date_counts,
            'grid_is_active': True
        }
        self.render_template('grid_new.html', template_args)
Beispiel #11
0
Datei: gig.py Projekt: bklang/GO2
    def _make_page(self, the_user):

        # find the gig we're interested in
        gig_key_str = self.request.get("gk", None)
        if gig_key_str is None:
            self.response.write('no gig key passed in!')
            return  # todo figure out what to do if there's no ID passed in

        gig_key = ndb.Key(urlsafe=gig_key_str)
        the_gig = gig_key.get()

        if the_gig is None:
            template_args = {}
            self.render_template('no_gig_found.html', template_args)
            return  # todo figure out what to do if we didn't find it

        the_comment_text = None
        if the_gig.comment_id:
            the_comment_text = gigcomment.get_comment(the_gig.comment_id)

        if not the_gig.is_archived:
            the_band_key = the_gig.key.parent()

            the_assocs = assoc.get_assocs_of_band_key(the_band_key,
                                                      confirmed_only=True,
                                                      keys_only=False)

            # get all the plans for this gig - might actually not be any yet.
            all_plans = plan.get_plans_for_gig_key(gig_key, keys_only=False)

            # now, for each associated member, find or make a plan
            the_plans = []
            the_new_plans = []  # in case we need to make new ones

            the_plan_counts = {}
            for i in range(len(plan.plan_text)):
                the_plan_counts[i] = 0

            need_empty_section = False
            for the_assoc in the_assocs:
                a_member_key = the_assoc.member
                new_plan = False

                for p in all_plans:
                    if p.member == a_member_key:
                        the_plan = p
                        break
                else:
                    the_plan = plan.Plan(parent=gig_key,
                                         member=a_member_key,
                                         value=0,
                                         comment="",
                                         section=None)
                    the_new_plans.append(the_plan)
                    new_plan = True

                if (not the_assoc.is_occasional) or \
                   (the_assoc.is_occasional and the_plan.value != 0) or \
                   (a_member_key == the_user.key) or \
                   the_user.is_superuser:
                    if the_plan.section == None and the_assoc.default_section == None:
                        need_empty_section = True
                    info_block = {}
                    info_block['the_gig_key'] = the_gig.key
                    info_block['the_plan'] = the_plan
                    info_block['the_member_key'] = a_member_key
                    info_block['the_band_key'] = the_band_key
                    info_block['the_assoc'] = the_assoc
                    if the_plan.section is not None:
                        info_block['the_section'] = the_plan.section
                    else:
                        info_block['the_section'] = the_assoc.default_section
                    the_plans.append(info_block)
                    the_plan_counts[the_plan.value] += 1

            if the_new_plans:
                ndb.put_multi(the_new_plans)

            the_section_keys = band.get_section_keys_of_band_key(the_band_key)
            the_sections = ndb.get_multi(the_section_keys)
            if need_empty_section:
                the_sections.append(None)

            if len(the_section_keys) == 0:
                band_has_sections = False
            else:
                band_has_sections = True

            # is the current user a band admin?
            the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(
                the_user, the_band_key)
            the_band = the_band_key.get()
            user_can_edit = can_edit_gig(the_user, the_gig, the_band)
            user_can_create = can_edit_gig(the_user, None, the_band)

            datestr = member.format_date_for_member(the_user,
                                                    the_gig.date,
                                                    format="long")
            if the_gig.enddate:
                enddatestr = u' - {0}'.format(
                    member.format_date_for_member(the_user,
                                                  the_gig.enddate,
                                                  format="long"))
            else:
                enddatestr = ''

            template_args = {
                'gig': the_gig,
                'date_str': datestr,
                'enddate_str': enddatestr,
                'the_plans': the_plans,
                'the_sections': the_sections,
                'comment_text': the_comment_text,
                'band_has_sections': band_has_sections,
                'the_user_is_band_admin': the_user_is_band_admin,
                'user_can_edit': user_can_edit,
                'user_can_create': user_can_create,
                'the_plan_counts': the_plan_counts
            }
            self.render_template('gig_info.html', template_args)

        else:
            # this is an archived gig
            the_archived_plans = gigarchive.get_archived_plans(
                the_gig.archive_id)
            template_args = {
                'gig': the_gig,
                'archived_plans': the_archived_plans,
                'comment_text': the_comment_text
            }
            self.render_template('gig_archived_info.html', template_args)
Beispiel #12
0
    def _make_page(self, the_user):

        # find the gig we're interested in
        gig_key_str = self.request.get("gk", None)
        if gig_key_str is None:
            self.response.write('no gig key passed in!')
            return # todo figure out what to do if there's no ID passed in

        gig_key = gig.gig_key_from_urlsafe(gig_key_str)
        the_gig = gig_key.get()

        if the_gig is None:
            template_args = {}
            self.render_template('no_gig_found.html', template_args)
            return # todo figure out what to do if we didn't find it

        the_comment_text = None
        if the_gig.comment_id:
            the_comment_text = gigcomment.get_comment(the_gig.comment_id)

        if not the_gig.is_archived:

            the_band_key = the_gig.key.parent()
            the_plans, the_plan_counts, the_sections, band_has_sections = _makeInfoPageInfo(the_user, the_gig, the_band_key)

            # is the current user a band admin?
            the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key)
            the_band = the_band_key.get()
            user_can_edit = gig.can_edit_gig(the_user, the_gig, the_band)
            user_can_create = gig.can_edit_gig(the_user, None, the_band)

            datestr = member.format_date_for_member(the_user, the_gig.date, format="long")
            if the_gig.enddate:
                enddatestr = u' - {0}'.format(member.format_date_for_member(the_user, the_gig.enddate, format="long"))
            else:
                enddatestr = ''

            template_args = {
                'gig' : the_gig,
                'date_str' : datestr,
                'enddate_str' : enddatestr,
                'the_plans' : the_plans,
                'the_sections' : the_sections,
                'comment_text' : the_comment_text,
                'band_has_sections' : band_has_sections,
                'the_user_is_band_admin' : the_user_is_band_admin,
                'user_can_edit' : user_can_edit,
                'user_can_create' : user_can_create,
                'the_plan_counts' : the_plan_counts
            }
            self.render_template('gig_info.html', template_args)

        else:
            # this is an archived gig
            the_archived_plans = gigarchive.get_archived_plans(the_gig.archive_id)
            template_args = {
                'gig' : the_gig,
                'archived_plans' : the_archived_plans,
                'comment_text' : the_comment_text
            }
            self.render_template('gig_archived_info.html', template_args)
Beispiel #13
0
    def _make_page(self, the_user):

        # find the gig we're interested in
        gig_key_str = self.request.get("gk", None)
        if gig_key_str is None:
            self.response.write('no gig key passed in!')
            return # todo figure out what to do if there's no ID passed in

        gig_key = ndb.Key(urlsafe=gig_key_str)
        the_gig = gig_key.get()

        if the_gig is None:
            template_args = {}
            self.render_template('no_gig_found.html', template_args)
            return # todo figure out what to do if we didn't find it

        the_comment_text = None
        if the_gig.comment_id:
            the_comment_text = gigcomment.get_comment(the_gig.comment_id)
            
        if not the_gig.is_archived:
            the_band_key = the_gig.key.parent()

            the_assocs = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=True, keys_only=False)

            the_plans = []
        
            need_empty_section = False
            for the_assoc in the_assocs:
                a_member_key = the_assoc.member
                the_plan = plan.get_plan_for_member_key_for_gig_key(a_member_key, gig_key)
                if (not the_assoc.is_occasional) or \
                   (the_assoc.is_occasional and the_plan.value != 0) or \
                   (a_member_key == the_user.key) or \
                   the_user.is_superuser:
                    if the_plan.section==None and the_assoc.default_section==None:
                        need_empty_section = True
                    info_block={}
                    info_block['the_gig_key'] = the_gig.key
                    info_block['the_plan_key'] = the_plan.key
                    info_block['the_member_key'] = a_member_key
                    info_block['the_band_key'] = the_band_key
                    info_block['the_assoc'] = the_assoc
                    if the_plan.section is not None:
                        info_block['the_section'] = the_plan.section
                    else:
                        info_block['the_section'] = the_assoc.default_section            
                    the_plans.append(info_block)          
        
            the_section_keys = band.get_section_keys_of_band_key(the_band_key)
            the_sections = ndb.get_multi(the_section_keys)
            if need_empty_section:
                the_sections.append(None)
                
            if len(the_section_keys)==0:
                band_has_sections = False
            else:
                band_has_sections = True

            # is the current user a band admin?
            user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key)

            user_can_edit = False
            if user_is_band_admin or the_user.is_superuser:
                user_can_edit = True
            elif the_band_key.get().anyone_can_manage_gigs:
                user_can_edit = True

            datestr = member.format_date_for_member(the_user, the_gig.date, format="long")
            if the_gig.enddate:
                enddatestr = u' - {0}'.format(member.format_date_for_member(the_user, the_gig.enddate, format="long"))
            else:
                enddatestr = ''

            template_args = {
                'gig' : the_gig,
                'date_str' : datestr,
                'enddate_str' : enddatestr,
                'the_plans' : the_plans,
                'the_sections' : the_sections,
                'comment_text' : the_comment_text,
                'band_has_sections' : band_has_sections,
                'user_is_band_admin' : user_is_band_admin,
                'user_can_edit' : user_can_edit
            }
            self.render_template('gig_info.html', template_args)

        else:
            # this is an archived gig
            the_archived_plans = gigarchive.get_archived_plans(the_gig.archive_id)
            template_args = {
                'gig' : the_gig,
                'archived_plans' : the_archived_plans,
                'comment_text' : the_comment_text
            }
            self.render_template('gig_archived_info.html', template_args)
Beispiel #14
0
def send_newgig_email(the_member,
                      the_gig,
                      the_band,
                      the_gig_url,
                      is_edit=False,
                      is_reminder=False,
                      change_string=""):

    the_locale = the_member.preferences.locale
    the_email_address = the_member.email_address

    if not gae_mail.is_email_valid(the_email_address):
        return False

    i18n.get_i18n().set_locale(the_locale)

    contact_key = the_gig.contact
    if contact_key:
        contact = contact_key.get()
        contact_name = contact.name
    else:
        contact = None
        contact_name = "??"

    # get the special URLs for "yes" and "no" answers
    the_yes_url, the_no_url, the_snooze_url = gig.get_confirm_urls(
        the_member, the_gig)

    reply_to = None
    if contact is not None:
        reply_to = contact.email_address
    if is_edit:
        title_string = '{0} ({1})'.format(
            _('Gig Edit').encode('utf-8'), change_string)
    elif is_reminder:
        title_string = 'Gig Reminder:'
    else:
        title_string = _('New Gig:')
    the_date_string = "{0} ({1})".format(
        member.format_date_for_member(the_member, the_gig.date),
        member.format_date_for_member(the_member, the_gig.date, "day"))

    if the_gig.enddate:
        the_date_string = "{0} - {1} ({2})".format(
            the_date_string,
            member.format_date_for_member(the_member, the_gig.enddate),
            member.format_date_for_member(the_member, the_gig.enddate, "day"))

    the_time_string = ""
    if the_gig.calltime:
        the_time_string = u'{0} ({1})'.format(the_gig.calltime, _('Call Time'))
    if the_gig.settime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,
                                                 the_gig.settime,
                                                 _('Set Time'))
    if the_gig.endtime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,
                                                 the_gig.endtime,
                                                 _('End Time'))

    the_status_string = [_('Unconfirmed'),
                         _('Confirmed!'),
                         _('Cancelled!')][the_gig.status]

    def format_details(details, setlist, newline='\n'):
        if setlist:
            the_details_string = u"{0}{1}{2}:{3}{4}".format(
                newline.join(details.splitlines()) if details else '',
                u'{0}{0}'.format(newline) if details else '', _('Setlist'),
                newline, newline.join(setlist.splitlines()))
        else:
            the_details_string = newline.join(details.splitlines())

        return the_details_string

    def format_body(body_format_str, newline='\n'):
        return body_format_str.format(
            the_band.name, the_gig.title, the_date_string, the_time_string,
            contact_name, the_status_string,
            format_details(the_gig.details, the_gig.setlist, newline),
            the_gig_url, "", the_yes_url, the_no_url, the_snooze_url)

    if is_edit:
        body = _('edited_gig_email').format(
            the_band.name, the_gig.title, the_date_string, the_time_string,
            contact_name, the_status_string,
            format_details(the_gig.details,
                           the_gig.setlist), the_gig_url, change_string)
        html = None
    elif is_reminder:
        body = format_body(_('reminder_gig_email'))
        html = format_body(_('reminder_gig_email_html'), newline='<br>')
    else:
        body = format_body(_('new_gig_email'))
        html = format_body(_('new_gig_email_html'), newline='<br>')

    try:
        ret = _send_admin_mail(the_email_address,
                               u'{0} {1}'.format(title_string, the_gig.title),
                               body,
                               html=html,
                               reply_to=reply_to)
    except UnicodeDecodeError:
        logging.error(
            "unicode error title_string with gig {0}  email {1}".format(
                the_gig.key, the_email_address))
    return ret
Beispiel #15
0
def send_newgig_email(the_member,
                      the_gig,
                      the_band,
                      the_gig_url,
                      is_edit=False,
                      is_reminder=False,
                      change_string=""):

    the_locale = the_member.preferences.locale
    the_email_address = the_member.email_address

    if not mail.is_email_valid(the_email_address):
        return False

    i18n.get_i18n().set_locale(the_locale)

    contact_key = the_gig.contact
    if contact_key:
        contact = contact_key.get()
        contact_name = contact.name
    else:
        contact = None
        contact_name = "??"

    # get the special URLs for "yes" and "no" answers
    the_yes_url, the_no_url, the_snooze_url = gig.get_confirm_urls(
        the_member, the_gig)

    reply_to = None
    if contact is not None:
        reply_to = contact.email_address
    if is_edit:
        title_string = '{0} ({1})'.format(_('Gig Edit'), change_string)
    elif is_reminder:
        title_string = 'Gig Reminder:'
    else:
        title_string = _('New Gig:')
    the_date_string = "{0} ({1})".format(
        member.format_date_for_member(the_member, the_gig.date),
        member.format_date_for_member(the_member, the_gig.date, "day"))

    the_time_string = ""
    if the_gig.calltime:
        the_time_string = u'{0} ({1})'.format(the_gig.calltime, _('Call Time'))
    if the_gig.settime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,
                                                 the_gig.settime,
                                                 _('Set Time'))
    if the_gig.endtime:
        if the_time_string:
            the_time_string = u'{0}, '.format(the_time_string)
        the_time_string = u'{0}{1} ({2})'.format(the_time_string,
                                                 the_gig.endtime,
                                                 _('End Time'))

    the_status_string = [_('Unconfirmed'),
                         _('Confirmed!'),
                         _('Cancelled!')][the_gig.status]

    def format_body(body_format_str):
        return body_format_str.format(the_band.name, the_gig.title,
                                      the_date_string, the_time_string,
                                      contact_name, the_status_string,
                                      the_gig.details, the_gig_url, "",
                                      the_yes_url, the_no_url, the_snooze_url)

    if is_edit:
        body = _('edited_gig_email').format(the_band.name, the_gig.title,
                                            the_date_string, the_time_string,
                                            contact_name, the_status_string,
                                            the_gig.details, the_gig_url,
                                            change_string)
        html = None
    elif is_reminder:
        body = format_body(_('reminder_gig_email'))
        html = format_body(_('reminder_gig_email_html'))
    else:
        body = format_body(_('new_gig_email'))
        html = format_body(_('new_gig_email_html'))

    return _send_admin_mail(the_email_address,
                            u'{0} {1}'.format(title_string, the_gig.title),
                            body,
                            html=html,
                            reply_to=reply_to)