Пример #1
0
def forget_band_from_key(the_band_key):
    # delete all assocs
    the_assoc_keys = assoc.get_assocs_of_band_key(the_band_key,
                                                  confirmed_only=False,
                                                  keys_only=True)
    ndb.delete_multi(the_assoc_keys)

    # delete the sections
    the_section_keys = get_section_keys_of_band_key(the_band_key)
    ndb.delete_multi(the_section_keys)

    # delete the gigs
    the_gigs = gig.get_gigs_for_band_keys(the_band_key,
                                          num=None,
                                          start_date=None)
    the_gig_keys = [a_gig.key for a_gig in the_gigs]

    # delete the plans
    for a_gig_key in the_gig_keys:
        plan_keys = plan.get_plans_for_gig_key(a_gig_key, keys_only=True)
        ndb.delete_multi(plan_keys)

    ndb.delete_multi(the_gig_keys)

    stats.delete_band_stats(the_band_key)

    # delete the band
    the_band_key.delete()
Пример #2
0
    def post(self):
        gig_key_str = self.request.get("gk", None)
        if gig_key_str is None:
            return  # todo figure out what to do if there's no ID passed in
        the_gig = gig.gig_key_from_urlsafe(gig_key_str).get()

        the_plans = plan.get_plans_for_gig_key(the_gig.key)

        stragglers = []
        for p in the_plans:
            if p.value in [0, 3]:
                stragglers.append(p.member)

        if len(stragglers) > 0:
            goemail.announce_new_gig(the_gig,
                                     self.uri_for('gig_info',
                                                  _full=True,
                                                  gk=the_gig.key.urlsafe()),
                                     is_edit=False,
                                     is_reminder=True,
                                     the_members=stragglers)

        # OK, we sent the reminder.
        the_gig.was_reminded = True
        the_gig.put()
Пример #3
0
def set_sections_for_empty_plans(the_gig):
    """ For this gig, get all plans. For plans with no section set, get the users default and set it """
    """ This is used when freezing a gig's plans """
    
    the_plan_keys = plan.get_plans_for_gig_key(the_gig.key, keys_only=True)
    the_band_key = the_gig.key.parent()
    for a_plan_key in the_plan_keys:
        a_plan = a_plan_key.get()
        if a_plan.section is None:
            the_member_key = a_plan.member
            the_assoc = assoc.get_assoc_for_band_key_and_member_key(the_member_key, the_band_key)
            if the_assoc:
                a_plan.section = the_assoc.default_section
                a_plan.put()
Пример #4
0
def set_sections_for_empty_plans(the_gig):
    """ For this gig, get all plans. For plans with no section set, get the users default and set it """
    """ This is used when freezing a gig's plans """
    
    the_plan_keys = plan.get_plans_for_gig_key(the_gig.key, keys_only=True)
    the_band_key = the_gig.key.parent()
    for a_plan_key in the_plan_keys:
        a_plan = a_plan_key.get()
        if a_plan.section is None:
            the_member_key = a_plan.member
            the_assoc = assoc.get_assoc_for_band_key_and_member_key(the_member_key, the_band_key)
            if the_assoc:
                a_plan.section = the_assoc.default_section
                a_plan.put()
Пример #5
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)
Пример #6
0
    def post(self):
        gig_key_str = self.request.get("gk", None)
        if gig_key_str is None:
            return # todo figure out what to do if there's no ID passed in
        the_gig = gig.gig_key_from_urlsafe(gig_key_str).get()

        the_plans = plan.get_plans_for_gig_key(the_gig.key)

        stragglers=[]
        for p in the_plans:
            if p.value in [0,3]:
                stragglers.append(p.member)

        if len(stragglers) > 0:
            goemail.announce_new_gig(the_gig, self.uri_for('gig_info', _full=True, gk=the_gig.key.urlsafe()), is_edit=False, is_reminder=True, the_members=stragglers)


        # OK, we sent the reminder.
        the_gig.was_reminded = True
        the_gig.put()
Пример #7
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)
Пример #8
0
def forget_band_from_key(the_band_key):
    # delete all assocs
    the_assoc_keys = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=False, keys_only=True)
    ndb.delete_multi(the_assoc_keys)
    
    # delete the sections
    the_section_keys = get_section_keys_of_band_key(the_band_key)
    ndb.delete_multi(the_section_keys)

    # delete the gigs
    the_gigs = gig.get_gigs_for_band_keys(the_band_key, num=None, start_date=None)
    the_gig_keys = [a_gig.key for a_gig in the_gigs]
    
    # delete the plans
    for a_gig_key in the_gig_keys:
        plan_keys = plan.get_plans_for_gig_key(a_gig_key, keys_only = True)
        ndb.delete_multi(plan_keys)
    
    ndb.delete_multi(the_gig_keys)
    
    stats.delete_band_stats(the_band_key)
    
    # delete the band
    the_band_key.delete()
Пример #9
0
Файл: grid.py Проект: bklang/GO2
    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)
Пример #10
0
def _makeInfoPageInfo(the_user, the_gig, the_band_key):
    gig_key = the_gig.key

    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:
            # no plan? make a new one
            planval = 0
            if (the_gig.default_to_attending):
                planval = 1

            the_plan = plan.Plan(parent=gig_key,
                                 member=a_member_key,
                                 value=planval,
                                 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

    return the_plans, the_plan_counts, the_sections, band_has_sections
Пример #11
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)
Пример #12
0
Файл: gig.py Проект: 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)
Пример #13
0
def _makeInfoPageInfo(the_user, the_gig, the_band_key):
    gig_key = the_gig.key

    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:
            # no plan? make a new one
            planval = 0
            if ( the_gig.default_to_attending ):
                planval = 1

            the_plan = plan.Plan(parent=gig_key, member=a_member_key, value=planval, 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

    return the_plans, the_plan_counts, the_sections, band_has_sections