Ejemplo n.º 1
0
 def description(self):
     context = _merged(self.context)
     return "%s %s (%s %s %s)" % (translate_i18n(_(u"Debate record of ")),
             self.translate(context.sitting, "short_name"),
             context.sitting.start_date.strftime('%Y-%m-%d %H:%M'), 
             _(u"to"),
             context.sitting.end_date.strftime('%H:%M'))
Ejemplo n.º 2
0
def validate_group_membership_dates(action, data, context, container):
    """ A User must be member of a group only once at a time """
    errors = []
    group_id = container.__parent__.group_id
    if interfaces.IBungeniGroupMembership.providedBy(context):
        group_membership = context
    else:
        group_membership = None
    #!(murithi, apr-2011) VALIDATION - this may be improved
    user_id = data.get("user_id", None)
    if user_id is None:
        return errors
    session = Session()
    if data["start_date"]:
        for r in queries.validate_membership_in_interval(
            group_membership, domain.GroupMembership, data["start_date"], user_id, group_id
        ):
            overlaps = r.group.short_name
            errors.append(
                interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "start_date", "user_id")
            )
    if data["end_date"]:
        for r in queries.validate_membership_in_interval(
            group_membership, domain.GroupMembership, data["end_date"], user_id, group_id
        ):
            overlaps = r.group.short_name
            errors.append(
                interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date", "user_id")
            )
    for r in queries.validate_open_membership(group_membership, domain.GroupMembership, user_id, group_id):
        overlaps = r.group.short_name
        errors.append(
            interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date", "user_id")
        )
    return errors
Ejemplo n.º 3
0
 def title(self):
     context = _merged(self.context)
     return "%s %s, %s %s %s" % (translate_i18n(_(u"Debate Record:")), 
             self.translate(context.sitting, "short_name"), 
             context.sitting.start_date.strftime('%Y-%m-%d, %H:%M'), 
             _(u"to"), 
             context.sitting.end_date.strftime('%H:%M'))
Ejemplo n.º 4
0
def validate_party_membership(action, data, context, container):
    errors = []
    parent_id = getattr(container.__parent__, "parent_group_id", None)
    if interfaces.IPartyMember.providedBy(context):
        party_member = context
        user_id = context.user_id
    else:
        party_member = None
        user_id = data["user_id"]
    if data.get("start_date", None):
        for r in queries.validate_membership_in_interval(
            party_member, AllPartyMemberships, data["start_date"], user_id, parent_id=parent_id, with_parent=True
        ):
            overlaps = r.short_name
            errors.append(interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "start_date"))
    if data.get("end_date", None):
        for r in queries.validate_membership_in_interval(
            party_member, AllPartyMemberships, data["end_date"], user_id, parent_id=parent_id, with_parent=True
        ):
            overlaps = r.short_name
            errors.append(interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date"))
    for r in queries.validate_open_membership(
        party_member, AllPartyMemberships, user_id, parent_id=parent_id, with_parent=True
    ):
        overlaps = r.short_name
        errors.append(interface.Invalid(_("The person is a member in (%s) at that date") % overlaps, "end_date"))
    return errors
Ejemplo n.º 5
0
 def description(self):
     context = _merged(self.context)
     return "%s %s (%s %s %s)" % (translate_i18n(_(u"Sitting scheduled for")),
             self.translate(context.group, "short_name"),
             context.start_date.strftime('%Y-%m-%d %H:%M'), 
             _(u"to"),
             context.end_date.strftime('%H:%M'))
Ejemplo n.º 6
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     time = context.sitting_time
     if time is not None:
         return "%s (%s)" % (_(u"Discussion"), context.sitting_time)
     return _(u"Discussion")
Ejemplo n.º 7
0
 def checkEmail(self):
     session = Session()
     users = session.query(User).filter(User.email==self.email)
     if users.count() > 1:
         raise interface.Invalid(_("Email already taken!"),"email")
     if users.count() == 1 and users.first().user_id != get_db_user().user_id:
         raise interface.Invalid(_("Email already taken!"),"email")
Ejemplo n.º 8
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (translate_i18n(_(u"Submitted by")), context.owner.first_name, context.owner.last_name)
     if context.notice_date:
         text += " (%s %s)" % (translate_i18n(_(u"notice given on")), self.formatDate(context.notice_date))
     return text + "."
Ejemplo n.º 9
0
def validate_parliament_dates(action, data, context, container):
    """Parliaments must not overlap."""
    errors = []
    if interfaces.IParliament.providedBy(context):
        parliament = context
    else:
        parliament = None
    results = queries.validate_date_in_interval(parliament, domain.Parliament, data["start_date"])
    for result in results:
        overlaps = result.short_name
        errors.append(interface.Invalid(_("The start date overlaps with (%s)") % overlaps, "start_date"))
    if data["end_date"]:
        results = queries.validate_date_in_interval(parliament, domain.Parliament, data["start_date"])
        for result in results:
            overlaps = result.short_name
            errors.append(interface.Invalid(_("The end date overlaps with (%s)") % overlaps, "end_date"))

    results = queries.validate_date_in_interval(parliament, domain.Parliament, data["election_date"])
    for result in results:
        overlaps = result.short_name
        errors.append(interface.Invalid(_("The election date overlaps with (%s)") % overlaps, "election_date"))

    if parliament is None:
        results = queries.validate_open_interval(parliament, domain.Parliament)
        for result in results:
            overlaps = result.short_name
            errors.append(
                interface.Invalid(_("Another parliament is not yet dissolved (%s)") % overlaps, "election_date")
            )

    return errors
Ejemplo n.º 10
0
def create_simple_workflow( ):
    transitions = []
    add = transitions.append
    
    add( workflow.Transition(
        transition_id = 'create',
        title='Create',
        trigger = iworkflow.AUTOMATIC,
        source = None,
        destination = states.new
        ) )

    add( workflow.Transition(
        transition_id = 'submit-clerk',
        title=_(u'Submit to Clerk'),
        source = states.new,
        destination = states.pending
        ) )

    add( workflow.Transition(
        transition_id = 'Schedule',
        title=_(u'Schedule'),
        source = states.pending,
        destination = states.scheduled
        ) )

    return transitions
Ejemplo n.º 11
0
 def handle_login(self, action, data):
     if IUnauthenticatedPrincipal.providedBy(self.request.principal):
         self.status = _(u"Invalid account credentials")
     else:
         site_url = ui_utils.url.absoluteURL(getSite(), self.request)
         camefrom = self.request.get('camefrom', site_url+'/')
         self.status = _("You are now logged in")
         self.request.response.redirect( camefrom )
Ejemplo n.º 12
0
 def title(self):
     session =Session()
     context = session.merge(removeSecurityProxy(self.context))
     time = context.sitting_time
     if time is not None:
         return _(u"Discussion ($time)",
                  mapping={'time': context.sitting_time})
     return _(u"Discussion")
Ejemplo n.º 13
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s (%s %s %s)" % (_(u"Sitting scheduled for"),
             context.group.short_name,
             context.start_date.strftime('%Y-%m-%d %H:%M'), 
             _(u"to"),
             context.end_date.strftime('%H:%M'))
Ejemplo n.º 14
0
 def description(self):
     context = _merged(self.context)
     text = "%s %s %s" % (translate_i18n(_("Submitted by")), context.owner.first_name, context.owner.last_name)
     if context.group:
         text += " to %s" % IDCDescriptiveProperties(context.group).title
     if context.admissible_date:
         text += " (%s %s)" % (translate_i18n(_(u"Approved on")), self.formatDate(context.admissible_date))
     return text + "."
Ejemplo n.º 15
0
    def title(self):
        if is_translation(self.context):
            language = get_language_by_name(self.context.language)['name']
            return _(u"$language translation",
                     mapping={'language': language})

        return _(u"Version $version",
                 mapping={'version': self.context.version_id})
Ejemplo n.º 16
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s, %s %s %s" % (_(u"Sitting:"), 
             self.translate(context.group, "short_name"), 
             context.start_date.strftime('%Y-%m-%d, %H:%M'), 
             _(u"to"), 
             context.end_date.strftime('%H:%M'))
Ejemplo n.º 17
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (_("Submitted by"),
                         context.owner.first_name, context.owner.last_name)
     if context.publication_date:
         text += " (%s %s)" % (_(u"published on"),
                               self.formatDate(context.publication_date))
     return text + "."
Ejemplo n.º 18
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (_("Submitted by"), context.owner.first_name, context.owner.last_name)
     if context.ministry:
         text += " to %s" % IDCDescriptiveProperties(context.ministry).title
     if context.admissible_date:
         text += " (%s %s)" % (_(u"Approved on"), self.formatDate(context.admissible_date))
     return text + "."
Ejemplo n.º 19
0
 def title(self):
     context = _merged(self.context)
     return "%s %s, %s %s %s" % (
         translate_i18n(_(u"Sitting:")),
         self.translate(context.group, "short_name"),
         context.start_date.strftime("%Y-%m-%d, %H:%M"),
         _(u"to"),
         context.end_date.strftime("%H:%M"),
     )
Ejemplo n.º 20
0
def login_exists(login):
    session = Session()
    users = session.query(domain.User).filter(
                    domain.User.login==login).all()
    if len(users) == 0:
        return False
    else:
        print _(u"Error : That login exists already")
        return True
Ejemplo n.º 21
0
 def __call__(self):
     if self._data is not None:
         #session = Session()
         #parent = session.query(domain.Question).get(self._data)
         context = removeSecurityProxy (self.context.context)
         parent = context.getParentQuestion()
         return _(u"Supplementary Question to: <br/> %s") % parent
     else:
         return _(u"Initial Question")
Ejemplo n.º 22
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s (%s %s %s)" % (
         translate_i18n(_(u"Sitting scheduled for")),
         self.translate(context.group, "short_name"),
         context.start_date.strftime("%Y-%m-%d %H:%M"),
         _(u"to"),
         context.end_date.strftime("%H:%M"),
     )
Ejemplo n.º 23
0
 def save_password(self, action, data):
     password = data.get("pswd","")
     confirm_password= data.get("confirm_password","")
     
     if password:
         if password != confirm_password:
             self.status = _("Password confirmation failed")
             return
         self.user._password = password
     
     self.status = _("Password changed")
Ejemplo n.º 24
0
def email_validator(action, data, context, container):
    session = Session()
    users = session.query(domain.User)\
                   .filter(domain.User.email==data.get("email",""))
    if users.count() > 1:
        return [interface.Invalid(_(u"Email already taken!"),"email"),]
    if context:
        if users.count() == 1 and users.first().user_id != context.user_id:
            return [interface.Invalid(_(u"Email already taken!"),"email"),]
    elif users.count() > 0:
        return [interface.Invalid(_(u"Email already taken!"),"email"),]
    return []
Ejemplo n.º 25
0
def main():
    check_login = True
    while check_login:
        login = raw_input(_("Enter admin login name "))
        check_login = login_exists(login)
    check_pass = False
    while not check_pass:
        password = raw_input(_("Enter password "))
        confirm_password = raw_input(_("Confirm password "))
        check_pass = check_password(password, confirm_password)
    email_address = raw_input(_("Enter Email Address "))
    add_admin(login, password, email_address)
Ejemplo n.º 26
0
 def save_profile(self, action, data):
     email = data.get("email","")
     first_name = data.get("first_name","")
     last_name = data.get("last_name","") 
     middle_name = data.get("middle_name","")
     description = data.get("description","")
     gender = data.get("gender","")
     image = data.get("image","")
     date_of_birth = data.get("date_of_birth","")
     birth_nationality = data.get("birth_nationality","")
     birth_country = data.get("birth_country","")
     current_nationality = data.get("current_nationality","")
                     
     if email:
         users = self.session.query(User).filter(User.email==email)
         if (users.count() == 1 and users.first().user_id == self.user.user_id) or\
             users.count() == 0:
             self.user.email = email
         else:
             self.status = _("Email already taken!")
             return
         
     if first_name:
         self.user.first_name = first_name
         
     if last_name:
         self.user.last_name = last_name
     
     if middle_name:
         self.user.middle_name = middle_name
     
     if description:
         self.user.description = description
     
     if gender:
         self.user.gender = gender
         
     if date_of_birth:
         self.user.date_of_birth = date_of_birth
         
     if image:
         self.user.image = image
         
     if birth_nationality:
         self.user.birth_nationality = birth_nationality
     
     if birth_country:
         self.user.birth_country = birth_country
     
     if current_nationality:
         self.user.current_nationality = current_nationality
             
     self.status = _("Profile data updated")
Ejemplo n.º 27
0
 def verbose_title(self):
     context = _merged(self.context)
     sitting_title = _("verbose_sitting_title", 
         default=u"Sitting of ${group_name} @ ${sitting_venue}",
         mapping = {
             "group_name": IDCDescriptiveProperties(context.group).title,
             "sitting_venue": (
                 IDCDescriptiveProperties(context.venue).title 
                 if context.venue else translate_i18n(_(u"no venue"))
             )
         }
     )
     return translate_i18n(sitting_title)
Ejemplo n.º 28
0
 def handle_restore(self, action, data):
     site_url = ui_utils.url.absoluteURL(getSite(), self.request)
     login = data.get("login", "")
     email = data.get("email", "")
     user = None
     
     app = BungeniApp()
     settings = EmailSettings(app)
     
     session = Session()
     if email:
         user = session.query(User).filter(
                             User.email==email).first()
     elif login:
         user = session.query(User).filter(
                             User.login==login).first()
         email = user.email
 
     if user:
         link = session.query(PasswordRestoreLink).filter(
             PasswordRestoreLink.user_id==user.user_id).first()
         if link:
             if not link.expired():
                 self.status = _(u"This user's link is still active!")
                 return
         else:
             link = PasswordRestoreLink()
         
         link.hash = hashlib.sha224(user.login + 
                                    SECRET_KEY + 
                                    str(datetime.datetime.now())).hexdigest()
         link.expiration_date = datetime.datetime.now() + datetime.timedelta(1)
         link.user_id = user.user_id
         session.add(link)
                 
         mailer = getUtility(ISMTPMailer, name="bungeni.smtp")
         
         
         self.message = _(u"Restore password link: ")\
              + "%s/reset_password?key=%s" % (site_url, link.hash)
         self.message += u"\n\n"
         self.message += _(u"This link will expire in 24 hours.")
         
         text = ViewPageTemplateFile("templates/mail.pt")(self)
         message = MIMEText(text)
         message.set_charset("utf-8")
         message["Subject"] = _(u"Bungeni password restoration")
         message["From"] = settings.default_sender
         
         mailer.send(settings.default_sender, email, str(message))
         self.status = _(u"Email was sent!")
Ejemplo n.º 29
0
 def get_js(self):
     pagedate = datetime.date.today()
     if self.maxDate < pagedate:
         pagedate = self.maxDate
     if ((type(self._data) == datetime.date) or
         (type(self._data) == datetime.datetime)
     ):
         pagedate = self._data
     calendar = self.request.locale.dates.calendars["gregorian"]
     month = _(u"Choose Month")
     year = _(u"Enter Year")
     submit = _("OK")
     cancel = _(u"Cancel")
     invalidYear = _(u"Please enter a valid year")
     months_short = self.jstr(calendar.getMonthAbbreviations())
     months_long = self.jstr(calendar.getMonthNames())
     w_day_1char = self.jstr(
         [dn[:1] for dn in calendar.getDayAbbreviations()])
     w_day_short = self.jstr(
         [dn[:2] for dn in calendar.getDayAbbreviations()])
     w_day_medium = self.jstr(calendar.getDayAbbreviations())
     w_day_long = self.jstr(calendar.getDayNames())
     return self.js_template % {
         "name": self.field_name,
         "sel_day": self._day_name,
         "sel_month": self._month_name,
         "sel_year": self._year_name,
         "txt_date": self.date_name,
         "mindate": self.minDate.strftime("%m/%d/%Y"),
         "maxdate": self.maxDate.strftime("%m/%d/%Y"),
         "pagedate": pagedate.strftime("%m/%Y"),
         "months_short": months_short,
         "months_long": months_long,
         "w_day_1char": w_day_1char,
         "w_day_short": w_day_short,
         "w_day_medium": w_day_medium,
         "w_day_long": w_day_long,
         "month": translate(
             str(month), domain="bungeni", context=self.request),
         "year": translate(
             str(year), domain="bungeni", context=self.request),
         "submit": translate(
             str(submit), domain="bungeni", context=self.request),
         "cancel": translate(
             str(cancel), domain="bungeni", context=self.request),
         "invalidYear": translate(
             str(invalidYear), domain="bungeni", context=self.request)
     }
Ejemplo n.º 30
0
def validate_venues(action, data, context, container):
    """A venue can only be booked for one sitting at once."""
    
    errors = []
    if interfaces.ISitting.providedBy(context):
        sitting = context
    else:
        sitting = None
    venue_id = data.get('venue_id')
    if venue_id is not None:
        venue_id = long(venue_id)
        session = Session()
        svenue = session.query(domain.Venue).get(venue_id)
    else:
        return []
        
    start = data.get('start_date')
    end = data.get('end_date')
    if not(start and end):
        return []
                
    for booking in  venue.check_venue_bookings( start, end, svenue, sitting):
        errors.append(
            interface.Invalid(
                _(u'Venue "$venue" already booked in this time slot',
                  mapping={'venue': booking.short_name}),
                "venue_id"))
    return errors