Permalink
Browse files

Work in progress.

  • Loading branch information...
1 parent 06a50cd commit 61a528b8389cc1876cf0b79a9c70b0b39161a1f8 @davorg committed Mar 18, 2012
View
@@ -33,3 +33,9 @@ plugins:
global: 1
servers: [ '127.0.0.1:11211' ]
+ DBIC:
+ politicalweb:
+ schema_class: PoliticalWeb::Schema
+ dsn: dbi:mysql:database=politicalweb
+ user: politicalweb
+ pass: p0l171c4lw3b
@@ -1,5 +1,6 @@
package PoliticalWeb;
use Dancer ':syntax';
+use Dancer::Plugin::DBIC;
use Dancer::Plugin::Cache::CHI;
use WebService::TWFY::API;
@@ -11,8 +12,7 @@ our $VERSION = '0.1';
get '/' => sub {
if (params->{pc}) {
- params->{constname} = get_const_name_from_pc(params->{pc});
- redirect '/constituency/' . params->{constname};
+ params->{constit} = get_const_name_from_pc(params->{pc});
}
if (params->{constit}) {
redirect '/constituency/' . params->{constit};
@@ -46,7 +46,14 @@ sub get_const {
}
}
- return cache_get "C:$_[0]";
+ my $con = cache_get "C:$_[0]";
+
+ my $con_rs = schema->resultset('Constituency');
+ if (my $con_db = $con_rs->find({ name => $con->{name} })) {
+ $con->{db} = $con_db;
+ }
+
+ return $con;
}
sub get_const_name_from_pc {
@@ -80,8 +87,9 @@ sub get_mp {
if ($ret->{is_success}) {
$mp->{extra} = from_json($ret->{results});
- cache_set "M:$_[0]", $mp, 60*60*60;
}
+
+ cache_set "M:$_[0]", $mp, 60*60*60;
}
return cache_get "M:$_[0]";
@@ -0,0 +1,19 @@
+package PoliticalWeb::Schema;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->load_namespaces;
+
+
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-03-18 16:38:10
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:u/9/ih+QqFRVhUnfVTcOQg
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
@@ -1,4 +1,4 @@
-package PoliticalWeb::Result::Constituency;
+package PoliticalWeb::Schema::Result::Constituency;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
@@ -11,7 +11,7 @@ use base 'DBIx::Class::Core';
=head1 NAME
-PoliticalWeb::Result::Constituency
+PoliticalWeb::Schema::Result::Constituency
=cut
@@ -55,13 +55,13 @@ __PACKAGE__->set_primary_key("id");
Type: belongs_to
-Related object: L<PoliticalWeb::Result::Mp>
+Related object: L<PoliticalWeb::Schema::Result::Mp>
=cut
__PACKAGE__->belongs_to(
"mp",
- "PoliticalWeb::Result::Mp",
+ "PoliticalWeb::Schema::Result::Mp",
{ id => "mp" },
{
is_deferrable => 1,
@@ -71,25 +71,55 @@ __PACKAGE__->belongs_to(
},
);
+=head2 constituency_links
+
+Type: has_many
+
+Related object: L<PoliticalWeb::Schema::Result::ConstituencyLink>
+
+=cut
+
+__PACKAGE__->has_many(
+ "constituency_links",
+ "PoliticalWeb::Schema::Result::ConstituencyLink",
+ { "foreign.constituency" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
=head2 urls
Type: has_many
-Related object: L<PoliticalWeb::Result::Url>
+Related object: L<PoliticalWeb::Schema::Result::Url>
=cut
__PACKAGE__->has_many(
"urls",
- "PoliticalWeb::Result::Url",
+ "PoliticalWeb::Schema::Result::Url",
+ { "foreign.constituency" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 user_constituencies
+
+Type: has_many
+
+Related object: L<PoliticalWeb::Schema::Result::UserConstituency>
+
+=cut
+
+__PACKAGE__->has_many(
+ "user_constituencies",
+ "PoliticalWeb::Schema::Result::UserConstituency",
{ "foreign.constituency" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
-# Created by DBIx::Class::Schema::Loader v0.07002 @ 2010-09-20 16:33:44
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:s3p9Chd8pPshowLWJazpfQ
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-03-18 16:38:10
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hzCQrsZiMUwIMBxUwQJoPA
-# You can replace this text with custom content, and it will be preserved on regeneration
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
@@ -0,0 +1,95 @@
+package PoliticalWeb::Schema::Result::ConstituencyLink;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+
+=head1 NAME
+
+PoliticalWeb::Schema::Result::ConstituencyLink
+
+=cut
+
+__PACKAGE__->table("constituency_link");
+
+=head1 ACCESSORS
+
+=head2 id
+
+ data_type: 'integer'
+ is_nullable: 0
+
+=head2 description
+
+ data_type: 'varchar'
+ is_nullable: 1
+ size: 200
+
+=head2 url
+
+ data_type: 'varchar'
+ is_nullable: 1
+ size: 200
+
+=head2 type
+
+ data_type: 'varchar'
+ is_nullable: 1
+ size: 50
+
+=head2 constituency
+
+ data_type: 'integer'
+ is_foreign_key: 1
+ is_nullable: 1
+
+=cut
+
+__PACKAGE__->add_columns(
+ "id",
+ { data_type => "integer", is_nullable => 0 },
+ "description",
+ { data_type => "varchar", is_nullable => 1, size => 200 },
+ "url",
+ { data_type => "varchar", is_nullable => 1, size => 200 },
+ "type",
+ { data_type => "varchar", is_nullable => 1, size => 50 },
+ "constituency",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+);
+__PACKAGE__->set_primary_key("id");
+
+=head1 RELATIONS
+
+=head2 constituency
+
+Type: belongs_to
+
+Related object: L<PoliticalWeb::Schema::Result::Constituency>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "constituency",
+ "PoliticalWeb::Schema::Result::Constituency",
+ { id => "constituency" },
+ {
+ is_deferrable => 1,
+ join_type => "LEFT",
+ on_delete => "CASCADE",
+ on_update => "CASCADE",
+ },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-03-18 16:38:10
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tifgLNyGt0lUzNY7Epf1ug
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
@@ -1,4 +1,4 @@
-package PoliticalWeb::Result::Mp;
+package PoliticalWeb::Schema::Result::Mp;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
@@ -11,7 +11,7 @@ use base 'DBIx::Class::Core';
=head1 NAME
-PoliticalWeb::Result::Mp
+PoliticalWeb::Schema::Result::Mp
=cut
@@ -28,19 +28,14 @@ __PACKAGE__->table("mp");
=head2 mp_name
data_type: 'varchar'
- is_nullable: 1
+ is_nullable: 0
size: 45
=head2 twfy_id
data_type: 'integer'
is_nullable: 0
-=head2 twfy_mem_id
-
- data_type: 'integer'
- is_nullable: 0
-
=head2 image_url
data_type: 'varchar'
@@ -77,23 +72,15 @@ __PACKAGE__->table("mp");
is_nullable: 1
size: 100
-=head2 official_site_url
-
- data_type: 'varchar'
- is_nullable: 1
- size: 100
-
=cut
__PACKAGE__->add_columns(
"id",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"mp_name",
- { data_type => "varchar", is_nullable => 1, size => 45 },
+ { data_type => "varchar", is_nullable => 0, size => 45 },
"twfy_id",
{ data_type => "integer", is_nullable => 0 },
- "twfy_mem_id",
- { data_type => "integer", is_nullable => 0 },
"image_url",
{ data_type => "varchar", is_nullable => 1, size => 200 },
"party",
@@ -106,8 +93,6 @@ __PACKAGE__->add_columns(
{ data_type => "varchar", is_nullable => 1, size => 100 },
"wikipedia_url",
{ data_type => "varchar", is_nullable => 1, size => 100 },
- "official_site_url",
- { data_type => "varchar", is_nullable => 1, size => 100 },
);
__PACKAGE__->set_primary_key("id");
@@ -117,21 +102,36 @@ __PACKAGE__->set_primary_key("id");
Type: has_many
-Related object: L<PoliticalWeb::Result::Constituency>
+Related object: L<PoliticalWeb::Schema::Result::Constituency>
=cut
__PACKAGE__->has_many(
"constituencies",
- "PoliticalWeb::Result::Constituency",
+ "PoliticalWeb::Schema::Result::Constituency",
+ { "foreign.mp" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 mp_links
+
+Type: has_many
+
+Related object: L<PoliticalWeb::Schema::Result::MpLink>
+
+=cut
+
+__PACKAGE__->has_many(
+ "mp_links",
+ "PoliticalWeb::Schema::Result::MpLink",
{ "foreign.mp" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
-# Created by DBIx::Class::Schema::Loader v0.07002 @ 2010-09-20 16:33:44
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qMpiRohEtSAqRQkvAmbWGQ
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2012-03-18 16:38:10
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OKBxs5sEHhCR8ygvU02/hA
-# You can replace this text with custom content, and it will be preserved on regeneration
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
Oops, something went wrong.

0 comments on commit 61a528b

Please sign in to comment.