class LoginForm(Form): user = None login = fields.StringField( validators=[validators.required(), validators.email()], description={ 'placeholder': ___('email'), }) password = fields.PasswordField(validators=[validators.required()], description={ 'placeholder': ___('password'), }) def validate_password(self, field): try: alleged_user = session.query(User).filter( and_(User.email == self.login.data)).one() password = str(field.data) stored_pwd = str(alleged_user.password) stored_salt = str(alleged_user.password_salt) # try to hash PWD with our salt. Does it match result in DB? hashed_pwd = bcrypt.hashpw(password, stored_salt) if stored_pwd != hashed_pwd: print "NOPE" raise ValidationError("Wrong password") except NoResultFound: raise ValidationError("Could not find user") self.user = alleged_user
class Document(Base): __tablename__ = 'documents' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) filename = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('filename'), 'label': ___('Filename') })
class UserOrganisation(Base): __tablename__ = 'user_organisations' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') })
class ReleaseType(Base): __tablename__ = 'releasetypes' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) type_code = sa.Column(sa.BigInteger, nullable=False, info={ 'description': ___('Type code'), 'label': ___('Type code') })
class PrisonType(Base): __tablename__ = 'prisontypes' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') })
class ActorForm(ModelForm): class Meta: model = Actor __order = ('name', 'birth_date', 'gender', 'telephone', 'address', 'is_activist', 'activist_info', 'organisations', 'professions', 'locations', 'public') def __iter__(self): f = list(super(ModelForm, self).__iter__()) get_field = lambda field_id: next( (fld for fld in f if fld.id == field_id)) return (get_field(field_id) for field_id in self.__order) organisations = QuerySelectMultipleField( query_factory=organisation_factory, get_label='name', allow_blank=True) professions = QuerySelectMultipleField(query_factory=profession_factory, get_label='name', allow_blank=True) locations = QuerySelectMultipleField(query_factory=location_factory, get_label='name', allow_blank=True) gender = fields.SelectField(___('Gender'), validators=[validators.required()], choices=[('M', ___('Male')), ('F', ___('Female'))]) is_activist = fields.SelectField(___('Is activist'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) public = fields.SelectField(___('Public'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool)
class Report(Base): __tablename__ = 'reports' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) text = sa.Column(sa.Text, nullable=False, info={ 'description': ___('Content of report'), 'label': ___('Content of report') }) events = relationship('Event')
class Source(Base): __tablename__ = 'sources' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') }) organisations = relationship('Organisation', secondary=source_org, backref='sources')
class User(Base, UserMixin): __tablename__ = 'users' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) email = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Email'), 'label': ___('Email') }) password = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Password'), 'label': ___('Password') }) password_salt = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Password salt'), 'label': ___('Password salt') }) organisation = relationship('UserOrganisation', backref=backref('members', order_by=id)) organisation_id = sa.Column(sa.BigInteger, ForeignKey('user_organisations.id'), nullable=True) is_admin = sa.Column(sa.Boolean, nullable=False, info={ 'description': ___('Is admin'), 'label': ___('Is admin') })
class UserForm(ModelForm): class Meta: model = User exclude = ['password_salt'] email = EmailField(validators=[validators.required()]) password = PasswordField(validators=[validators.required()]) organisation = QuerySelectField(query_factory=user_org_factory, get_label='name', allow_blank=True) is_admin = SelectField(___('Is admin'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool)
class StateAuthority(Base): __tablename__ = 'stateauthorities' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') }) description = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Description'), 'label': ___('Description') })
class Prison(Base): __tablename__ = 'prisons' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') }) locations = relationship('Location', secondary=prison_location, backref='prisons') prison_types = relationship('PrisonType', secondary=prison_ptype, backref='prisons')
class Organisation(Base): __tablename__ = 'organisations' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') }) description = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Description'), 'label': ___('Description') }) locations = relationship('Location', secondary=org_location, backref='organisations')
class EvidenceType(Base): __tablename__ = 'evidencetypes' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') }) description = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Description'), 'label': ___('Description') }) event_id = sa.Column(sa.BigInteger, ForeignKey('events.id')) event = relationship('Event', backref=backref('evidence_types', order_by=id))
class Action(Base): __tablename__ = 'actions' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) complaint_to_state_authority = sa.Column( sa.Text, nullable=True, info={ 'description': ___('Complaint to state authority'), 'label': ___('Complaint to state authority') }) response_from_state_authority = sa.Column( sa.Text, nullable=True, info={ 'description': ___('Response from state authority'), 'label': ___('Response from state authority') }) complaint_to_international_authority = sa.Column( sa.Text, nullable=True, info={ 'description': ___('Complaint to international authority'), 'label': ___('Complaint to international authority') }) response_from_international_authority = sa.Column( sa.Text, nullable=True, info={'description': ___('Response from international authority')}) state_bodies_approached = relationship('StateAuthority', secondary=action_state, backref='actions') international_bodies_approached = relationship( 'InternationalAuthority', secondary=action_international, backref='actions') events = relationship('Event', secondary=action_event, backref='actions')
class Location(Base): __tablename__ = 'locations' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') }) longitude = sa.Column(sa.Float, nullable=False, info={ 'description': ___('Longitude'), 'label': ___('Longitude') }) latitude = sa.Column(sa.Float, nullable=False, info={ 'description': ___('Latitude'), 'label': ___('Latitude') })
import utils from models import * import entities # Constants # Identifiers for types of legacy documents ORG1_DOCX = 1 ORG2_DOCX = 2 EXCEL_DOC = 4 # Special values # Values compared to these should always be converted to lowercase first. YES = ___('yes') NO = ___('no') MALE = ___('male') FEMALE = ___('female') # Entity names, as presented in the excel document template ACTIONS = u'Actions' ACTORS = u'Actors' REPORTS = u'Reports' EVENTS = u'Events' INTERNATIONAL_AUTHORITIES = u'International Authorities' LOCATIONS = u'Locations' ORGANISATIONS = u'Organisations' PRISONS = u'Prisons' PRISON_TYPES = u'Prison Types'
class DocumentUploadForm(Form): organisation_name = StringField(___('Organisation Name'))
def validate_event_end(self, field): if field.data <= self.event_start.data: raise validators.ValidationError( ___('End date has to be greater than start date.'))
class EventForm(ModelForm): class Meta: model = Event __order = ('event_types', 'title', 'description', 'event_start', 'event_end', 'report_date', 'charges', 'consequences', 'psych_assist', 'material_assist', 'was_activist', 'report', 'victim_is_complainant', 'allow_storage', 'allow_publishing', 'allow_representation', 'data_is_sensitive', 'locations', 'prisons', 'release_types', 'sources', 'witnesses', 'victims', 'perpetrators', 'public', 'documents') def __iter__(self): f = list(super(ModelForm, self).__iter__()) get_field = lambda field_id: next( (fld for fld in f if fld.id == field_id)) return (get_field(field_id) for field_id in self.__order) # Use some example data for populating the form before we have some data to work with release_types = QuerySelectMultipleField( query_factory=release_type_factory, get_label='type_code') locations = QuerySelectMultipleField(query_factory=location_factory, get_label='name') prisons = QuerySelectMultipleField(query_factory=prison_factory, get_label='name') sources = fields.StringField() witnesses = fields.StringField() victims = QuerySelectMultipleField(query_factory=victims_factory, get_label=display_func) perpetrators = QuerySelectMultipleField(query_factory=perpetrators_factory, get_label=display_func) event_types = QuerySelectMultipleField(query_factory=event_type_factory, get_label='name') documents = fields.FileField() psych_assist = fields.SelectField(___('Psychological assistance provided'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) material_assist = fields.SelectField(___('Material assistance provided'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) was_activist = fields.SelectField(___('Was an activist'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) report = fields.TextAreaField() victim_is_complainant = fields.SelectField( ___('Victim is complainant'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) allow_storage = fields.SelectField(___('Allows storage of information'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) allow_publishing = fields.SelectField( ___('Allows publishing of information'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) allow_representation = fields.SelectField( ___('Allows legal representation'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) data_is_sensitive = fields.SelectField(___('Data is hyper sensitive'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) public = fields.SelectField(___('Public'), validators=[validators.required()], choices=[(1, ___('Yes')), (0, ___('No'))], coerce=bool) def validate_event_end(self, field): if field.data <= self.event_start.data: raise validators.ValidationError( ___('End date has to be greater than start date.'))
class Actor(Base): __tablename__ = 'actors' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) name = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Name'), 'label': ___('Name') }) birth_date = sa.Column(sa.Date, nullable=True, info={ 'description': ___('Date of birth'), 'label': ___('Date of birth') }) # telephone = sa.Column(PhoneNumberType(), info={ telephone = sa.Column(sa.Unicode(16), info={ 'description': ___('+1 819 987-6543'), 'label': ___('Phone number') }) address = sa.Column(sa.Unicode(250), nullable=True, info={ 'description': ___('Address'), 'label': ___('Address') }) organisations = relationship('Organisation', secondary=actor_organisation, backref='members') professions = relationship('Profession', secondary=actor_profession, backref='practitioners') locations = relationship('Location', secondary=actor_location, backref='locals') gender = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Gender'), 'label': ___('Gender') }) is_activist = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Is activist'), 'label': ___('Is activist') }) activist_info = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Activist info'), 'label': ___('Activist info') }) owner_id = sa.Column(sa.BigInteger, ForeignKey('users.id'), nullable=False, default=1) owner = relationship('User', backref='actor_owner') public = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Public'), 'label': ___('Public') }, default=0)
class Event(Base): __tablename__ = 'events' id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True) title = sa.Column(sa.Unicode(200), nullable=False, info={ 'description': ___('Title'), 'label': ___('Title') }) description = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Description'), 'label': ___('Description') }) charges = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Charges'), 'label': ___('Charges against victim') }) event_start = sa.Column(sa.DateTime, nullable=True, info={ 'description': ___('YYYY-MM-DD 00:00:00'), 'label': ___('Event start') }) event_end = sa.Column(sa.DateTime, nullable=True, info={ 'description': ___('YYYY-MM-DD 00:00:00'), 'label': ___('Event end') }) report_date = sa.Column(sa.Date, nullable=True, info={ 'description': ___('Date of report'), 'label': ___('Date of report') }) psych_assist = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Psychological assistance provided'), 'label': ___('Psychological assistance provided') }) material_assist = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Material assistance provided'), 'label': ___('Material assistance provided') }) consequences = sa.Column(sa.Text, nullable=True, info={ 'description': ___('Consequences'), 'label': ___('Consequences') }) was_activist = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Was an activist'), 'label': ___('Was an activist') }) victim_is_complainant = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Victim is complainant'), 'label': ___('Victim is complainant') }) allow_storage = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Allows storage of information'), 'label': ___('Allows storage of information') }) allow_publishing = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Allows publishing of information'), 'label': ___('Allows publishing of information') }) allow_representation = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Allows legal representation'), 'label': ___('Allows legal representation') }) data_is_sensitive = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Data is hyper sensitive'), 'label': ___('Data is hyper sensitive') }) report_id = sa.Column(sa.BigInteger, ForeignKey('reports.id'), info={ 'description': 'report id', 'label': 'report id' }) report = relationship('Report', backref='event_report') release_types = relationship('ReleaseType', secondary=event_releasetype, backref='events') locations = relationship('Location', secondary=event_location) prisons = relationship('Prison', secondary=event_prison, backref='events') sources = relationship('Source', secondary=event_source) witnesses = relationship('Actor', secondary=event_witness) victims = relationship('Actor', secondary=event_victim) perpetrators = relationship('Actor', secondary=event_perp) event_types = relationship('EventType', secondary=event_type) documents = relationship('Document', secondary=event_documents, backref='events') owner_id = sa.Column(sa.BigInteger, ForeignKey('users.id'), nullable=False, default=1) owner = relationship('User', backref='event_owner') public = sa.Column(sa.Boolean, nullable=True, info={ 'description': ___('Public'), 'label': ___('Public') }, default=0)